akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e6;

struct S {
  int x, y, t;  
};

map<int, bool> koma[300010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int H, W, N;
  cin >> H >> W >> N;

  // assert(H+W < 200000);  

  int ans = H;
  vector<pair<int, int> > dat(N);  
  for ( int i = 0; i < N; i++ ) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    dat[i] = make_pair(x, y);    
    koma[y][x] = true;    
  }
  
  int path[300010];
  fill_n(path, 300010, INF);  
  {
    int x = 0, y = 0, t = 0;    
    while ( 1 ) {
      if ( x > H || y > W ) break;
      path[y] = min(path[y], x);      
      if ( !t ) {
	if ( !koma[y][x+1] ) {
	  x++;	  
	} else {
	  break;	  
	}
	t = 1;	
      } else {
	if ( !koma[y+1][x] ) {
	  y++;	  
	}
	t = 0;
      }
    }
  }

  for ( int i = 0; i < N; i++ ) {
    auto e = dat[i];
    int x = e.first, y = e.second;
    if ( path[y] < x ) ans = min(ans, x);    
  }  

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 52992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
const int maxc=26;
const int mod=998244353;
char s[1100];
int len;
bool check(){
    int tot=1;
    for(int i=1;i<=len;i++){
        if(s[i]!=s[len-i+1])
            return 0;
    }
    for(int i=1;i<=(len-1)/2;i++){
        if(s[i]!=s[(len-1)/2-i+1])
            return 0;
    }
    for(int i=(len+3)/2;i<=len;i++){
        if(s[i]!=s[len-(tot++)+1])
            return 0;
    }
    return 1;
}
int main()
{
    scanf("%s",s+1);
    len=strlen(s+1);
    if(check())
        puts("Yes");
    else
        puts("No");
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


signed main()
{
	std::cin.sync_with_stdio(false);
	std::cin.tie(0);

	int N;
	cin >> N;
	vector<int>P(N);
	rep(i, N)cin >> P[i];

	vector<int>invP(N + 1);
	rep(i, N)invP[P[i]] = i;
	
	int count = 1;
	int maxcount = 1;
	for(int i = 2; i <= N; ++i) {
		if (invP[i] > invP[i - 1])count++;
		else count = 1;
		maxcount = max(maxcount, count);
	}

	cout << N - maxcount << endl;
	
	return 0;
}

Measured memory_bytes: 3456
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            Console.WriteLine(getAns(n));
        }
    }
    public static string getAns(int n)
    {
        if (n == 1) return "deficient number";
        var ret = 1;
        for (int i = 2; i <= Math.Sqrt(n); i++)
            if (n % i == 0)
            {
                ret += i;
                if (i != n / i) ret += n / i;
                if (ret > n) return "abundant number";
            }
        if (ret == n) return "perfect number";
        return "deficient number";
    }
}



Measured memory_bytes: 8716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int a, b, c, d;
  bool k = false;
  cin >> a >> b >> c >> d;
  if(abs(a-b)<=d && abs(b-c)<=d) k = true;
  if(abs(a-c)<=d || k == true) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {

	var N int
	var S string

	fmt.Scan(&N)
	fmt.Scan(&S)

	res := SliceInt(N-1)

	var left,right string 

	for i:=1;i<N;i++{

		left  = S[:i]
		right = S[i:]

		res[i-1] = match(left,right)
	}

	sort.Sort(sort.IntSlice(res))

	fmt.Println(res[len(res)-1])
}

//match return match count
func match(a,b string) int{

	result  := make(map[string]int)

	for i:=0;i<len(a);i++{

	   if strings.Contains(b,a[i:i+1]){

	    val,ok := result[a[i:i+1]]

		if ok ==true{
			
			result[a[i:i+1]] = val +1

		}else{

			result[a[i:i+1]] = 1
		}

	  }

	}

	return len(result)

}

//SliceInt 引数サイズのSliceを返す
func SliceInt(a int) []int {

	IntSample := make([]int, a)

	return IntSample

}

Measured memory_bytes: 768
n = int(input())
if n > 0:key = 1
if n < 0:key = 0
lis = []
if n == 0:
  lis.append("0")
while abs(n) >= 1:
  if n % 2 == 1:
    n -= 1
    lis.insert(0,"1")
  else:
    lis.insert(0,"0")
  n = n // (-2)
print("".join(lis))
  

Measured memory_bytes: 3060
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;

///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 1000001;
const int MOD = 1000000007;
const ll INF = LLONG_MAX;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)
#define time() cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///



int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        int n,i,k,j;
        cin>>n>>k;
        vii h(n),dp(n,INT_MAX);
        cinv(h);
        dp[0]=0;
        for(i=0; i<n; i++)
            for(j=1; i+j<n&&j<=k; j++)
                    dp[i+j]=min(dp[i+j],(dp[i]+abs(h[i]-h[i+j])));
        cout<<dp[n-1]<<nl;
    }
}


Measured memory_bytes: 4044
#include <stdio.h>

int main() {
	int K, A, B;
	scanf("%d", &K);
	scanf("%d %d", &A, &B);
	
	int ans = 0;
	for(int p = A; p <= B;  p++) {
		if(p % K == 0) {
			ans++;
		}
	} if(ans > 0) {
		printf("OK\n");
	} else {
		printf("NG\n");
	}

	
	return 0;
}

Measured memory_bytes: 1612
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;


int main(){
    int A, B; cin >> A >> B;
    A--;
    B--;

    vector<string> ans(100);
    
    string fixed_part = "";
    rep(i,50) fixed_part += "#";
    rep(i,50) fixed_part += ".";

    rep(i,100){
        if (i%2==0) ans[i] = fixed_part;
        else{
            rep(j,50){
                if (j%2==0 || j == 49) ans[i] += "#";
                else{
                    if (A > 0){
                        ans[i] += ".";
                        A--;
                    }
                    else{
                        ans[i] += "#";
                    }
                }
            }
            rep(j,50){
                if (j%2==0 || j == 49) ans[i] += ".";
                else{
                    if (B > 0){
                        ans[i] += "#";
                        B--;
                    }
                    else{
                        ans[i] += ".";
                    }
                }
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    rep(i,100) cout << ans[i] << endl;
} 

Measured memory_bytes: 3632
def num(a,b,d):
    if a[0] == b:
        c=int(a[1])
        d.append(c)
        
def printcard(d,b):
    for i in range(1,14):
        if (i in d) == False:
            print(b+str(i))
        
n=int(input())
d1=[]
d2=[]
d3=[]
d4=[]
for i in range (n):
    x=list(input().split())
    num(x,'S',d1)
    num(x,'H',d2)
    num(x,'C',d3)
    num(x,'D',d4)

printcard(d1,'S ')
printcard(d2,'H ')
printcard(d3,'C ')
printcard(d4,'D ')


Measured memory_bytes: 5596
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
//int dx[] = { 1, 0 };
//int dy[] = { 0, 1 };
#define mod7 1e9+7;
#define mod9 1e9+9;

int nextInt(){
	int a;	cin >> a;return a;
}
string next(){
	string s;cin >> s;return s;
}
char nextChar(){
	char c;cin >> c;return c;
}

unsigned long long strtoint(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	int x = nextInt();
	int a = nextInt();
	int b = nextInt();
	int ans = x - a - ((x-a)/b)*b;
	P(ans);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18
#define ret return

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<int> minx[222222];
int x, y, h, w, n;
set <ii> block;

int f(int x, int pos){
	int ans = h+1;
	int lo=0;
	int hi=minx[pos].size();
	int mid;
	while(lo<=hi){
		mid=lo+(hi-lo)/2;
		if(minx[pos][mid]>x){
			ans=min(ans,minx[pos][mid]);
			hi=mid-1;
		}
		else{
			lo=mid+1;
		}
	}
	return ans;
}

int main(){
	cin >> h >> w >> n;
	for(int i = 0; i < n; i++){
		cin >> x >> y;
		block.insert(mp(x,y));
		minx[y].pb(x);
	}
	for(int i = 1; i <= h; i++){
		block.insert(mp(i,w+1));
	}
	for(int i = 1; i <= w; i++){
		block.insert(mp(h+1,i));
		minx[i].pb(h+1);
	}
	for(int i = 1; i <= w; i++){
		sort(minx[i].begin(),minx[i].end());
	}
	x=1;y=1;
	int t=1;
	int ans = h+w+1;
	int cnt = 0;
	while(x<=h && y<=w){
		//cout << "*" << x << " " << y << " " << ans << endl;
		if(t>0){
			if(block.count(mp(x+1,y))){
				x=h+1;
				y=w+1;
			}
			else{
				x++;
				cnt++;
			}
		}
		else{
			ans=min(ans,cnt+f(x,y)-x-1);
			if(block.count(mp(x,y+1))==0){
				y++;
				
			}
			ans=min(ans,cnt+f(x,y)-x-1);
		}
		t*=-1;
	}
	
	//cout << "*" << x << " " << y << " " << ans << endl;
	cout << min(cnt,ans)+1;
	
}


Measured memory_bytes: 39936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807

int main()
{
ll n;
cin >> n;
string s;
cin >> s;
char ans[n+1];


ans[0]='S';
ans[1]='S';

for(ll i=2;i<n+1;i++){
    if(ans[i-1]=='S'&&s[i-1]=='o')ans[i]=ans[i-2];
    else if(ans[i-1]=='W'&&s[i-1]=='x')ans[i]=ans[i-2];
    else if(ans[i-2]=='W')ans[i]='S';
    else ans[i]='W';
}
if(ans[0]==ans[n]&&((s[0]=='x'&&ans[1]!=ans[n-1])||(s[0]=='o'&&ans[1]==ans[n-1]))){
    rep(i,n){
        cout << ans[i];
    }
    cout  << endl;
    return 0;
}
ans[0]='S';
ans[1]='W';
for(ll i=2;i<n+1;i++){
    if(ans[i-1]=='S'&&s[i-1]=='o')ans[i]=ans[i-2];
    else if(ans[i-1]=='W'&&s[i-1]=='x')ans[i]=ans[i-2];
    else if(ans[i-2]=='W')ans[i]='S';
    else ans[i]='W';
}
if(ans[0]==ans[n]&&((s[0]=='x'&&ans[1]!=ans[n-1])||(s[0]=='o'&&ans[1]==ans[n-1]))){
    rep(i,n){
        cout << ans[i];
    }
    cout  << endl;
    return 0;
    return 0;
}
ans[0]='W';
ans[1]='W';
for(ll i=2;i<n+1;i++){
    if(ans[i-1]=='S'&&s[i-1]=='o')ans[i]=ans[i-2];
    else if(ans[i-1]=='W'&&s[i-1]=='x')ans[i]=ans[i-2];
    else if(ans[i-2]=='W')ans[i]='S';
    else ans[i]='W';
}
if(ans[0]==ans[n]&&((s[0]=='x'&&ans[1]==ans[n-1])||(s[0]=='o'&&ans[1]!=ans[n-1]))){
    rep(i,n){
        cout << ans[i];
    }
    cout  << endl;
    return 0;
    return 0;
}
ans[0]='W';
ans[1]='S';
for(ll i=2;i<n+1;i++){
    if(ans[i-1]=='S'&&s[i-1]=='o')ans[i]=ans[i-2];
    else if(ans[i-1]=='W'&&s[i-1]=='x')ans[i]=ans[i-2];
    else if(ans[i-2]=='W')ans[i]='S';
    else ans[i]='W';
}
if(ans[0]==ans[n]&&((s[0]=='x'&&ans[1]==ans[n-1])||(s[0]=='o'&&ans[1]!=ans[n-1]))){
    rep(i,n){
        cout << ans[i];
    }
    cout  << endl;
    return 0;
    return 0;
}


cout << -1 << endl;
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    while (b != 0) {
        ll x = a, y = b;
        a = y;
        b = x % y;
    }
    return a;
}

int main()
{
    ll n; cin >> n;
    ll a[n];
    REP(i, n) cin >> a[i];

    ll l_gcd[n]; ll r_gcd[n];
    l_gcd[0] = a[0]; r_gcd[n-1] = a[n-1];
    REP(i, n-1) {
        l_gcd[i+1] = gcd(l_gcd[i], a[i+1]);
        r_gcd[n-2-i] = gcd(r_gcd[n-1-i], a[n-2-i]);
    }
    ll ans = 0;
    REP(i, n) {
        if (i == 0) ans = max(ans, r_gcd[1]);
        else if (i == n - 1) ans = max(ans, l_gcd[n-2]);
        else ans = max(ans, gcd(l_gcd[i-1], r_gcd[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[1000];
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];

	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;i++)
		sum+=a[i];

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 3580
import java.util.*;
public class Main {
public static void main(String...args) {
final Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();
final int[][] matrix = new int[n][n];
for(int i = 0; i < n; i++) {
final int u = sc.nextInt();
final int k = sc.nextInt();
for(int j = 0; j < k; j++)
matrix[u-1][sc.nextInt()-1] = 1;
}
final StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(j > 0) sb.append(' ');
sb.append(matrix[i][j]);
}
sb.append('\n');
}
System.out.print(sb);
}
}

Measured memory_bytes: 20932
import java.util.Scanner;
public class Main {

	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	if(B%A ==0)System.out.println(A+B);
    	else System.out.println(B-A);
	  
  }
}

Measured memory_bytes: 23508
import java.util.*;
import java.io.*;

public class Main {
	static int  N;
	static long A,B;
	static long[] HP;
	public static long binary(int low, int high){//answer is low, low+1,... high
		if(low>=high) return low;
		int center = low + (high-low)/2;
		//analyze the magic
		//1."attack all enemies, damage 'B'"
		//2."attack one enemy, damage 'A'-'B'"
		//the magicians can use both magics for 'center' times. Can I defeat all enemies?
		
		//use magic1 for c times, and then use magic2 as many times as I need
		long need =0;
		//
		for(int n=0;n<N;n++){
			need += Math.max(0, ((HP[n]-B*center)+A-B-1)/(A-B));
		}
		if(need<=center){//you can defeat enemies in 'center' times
			return binary(low, center);
		}else{
			return binary(center+1,high);
		}
	}
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	N = sc.nextInt();
    	A = sc.nextLong();
    	B = sc.nextLong();
    	HP = new long[N];
    	for(int n=0;n<N;n++){
    		HP[n]=sc.nextLong();
    	}
    	System.out.println(binary(1,1_000_000_000));
    }
}

Measured memory_bytes: 51568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i,N) cin >> P[i];
    int MIN = 999999999;
    int ans = 0;
    rep(i,N){
        if(MIN>=P[i]){
            MIN = P[i];
            ans ++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  Solver(LL n) : n(n){};

  void solve() {
    cout << (n / 500) * 1000 + (n % 500) / 5 * 5 << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
#初期値
n_max = 2000000
a_max = 10000

#インプットdata
input_n = int(input())
input_a = list(map(int, input().split()))
output = list()

#カウンタ配列Cの作成
c_list = [0] * (a_max + 1)
for i in input_a:
    c_list[i] += 1
for i in range(1, a_max+1):
    c_list[i] += c_list[i-1]

#ソートリスト作成
sort_list = [0 for i in range(input_n)]
for i in range(input_n-1, -1, -1):
    sort_list[c_list[input_a[i]]-1] = input_a[i]
    c_list[input_a[i]] -= 1

#結果表示
print(" ".join(map(str, sort_list)))


Measured memory_bytes: 242176
#include <bits/stdc++.h>
using namespace std;
 
// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
 
const int MOD = 1000000007;
const lint INF = 1LL << 60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define p pair<int, int>
#define plint pair<lint, lint>

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}

// Union-Find-Tree
class UnionFind {
    vector<int> par;
    UnionFind(int n):par(n){rep(i,n)par[i]=i;}
    int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
    void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
    bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main(void) {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while(n > 0) {
        n /= k;
        ans++;
    }
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <cstring>
#define LL long long
using namespace std;

int cal(int x){
	if (x == 0) return 0;
	if (x >= 1) return x % 2 + 2;
	if (x < 0) return x % 2 - 2;
}
int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	a = cal(a);
	b = cal(b);
	int x = 1;
	for (int i = a; i <= b; ++ i)
		x = x * i;
	if (x == 0)  puts("Zero");
	if (x < 0) puts("Negative");
	if (x > 0) puts("Positive");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k;
	cin >> n >> k;
	long long int a[1001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<long long int> sums;
	for(int i = 0; i < n; i++){
		long long int nowsum = 0;
		for(int j = i; j < n; j++){
			nowsum += a[j];
			sums.push_back(nowsum);
		}
	}

	long long int ans = 0;
	vector<bool> ok(sums.size(), true);
	for(int i = 40; i >= 0; i--){
		long long int tmp = (long long int)1 << i;
		vector<bool> tmpok(sums.size(), true);
		int okcnt = 0;
		for(int j = 0; j < sums.size(); j++){
			tmpok[j] = ok[j] && ((sums[j] & tmp) > 0);
			if(tmpok[j]) okcnt++;
		}
		if(okcnt >= k){
			ans += tmp;
			ok = tmpok;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    int A  = 1;
    for(int i = 0 ; i < M; i++) A *= 2;
    int X = (1900 * M + 100 * (N - M)) * A;
    cout << X << endl;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    k = inp()
    t = list(input())
    n = len(t)
    if n <= k:
        print(''.join(t))
        return
    ans = []
    for i in range(k):
        ans.append(t[i])
    for i in range(3):
        ans.append('.')
    print(''.join(ans))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10848
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<double> x(N);
  vector<double> y(N);
  for(int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  double a, b, c;
  for(int i = 0; i < N; i++) {
    for(int j = i+1; j < N; j++) {
      b = pow(x.at(i)-x.at(j),2);
      c = pow(y.at(i)-y.at(j),2);
      a += sqrt(b + c);
    }
  }
  cout << fixed << setprecision(15) << 2 * a  / N << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <queue>
#include <unordered_map>
#define ll long long
#define pii pair <int, int>
#define pll pair <long long, long long>
#define plxy pair <long long, pll>
#define INT_MAX 1e18
using namespace std;
using namespace std;
const int mod=1e9+7;
const int N=2e5+5;
ll ncr(ll n,ll r){
 ll ans=1,fact=2;
 for(ll i=n-r+1;i<=n;i++){
    ans*=i;
    if(ans%fact==0 && fact<=r)
        ans/=fact++;
 }
  return ans;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    cout<<ncr(n,2)+ncr(m,2);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){
    while(1){
    int x,y,z,dp[50][50]={0};
    cin>>x>>y;
    if(x==0 && y==0)break;
    cin>>z;
    for(int i=0;i<z;++i){
        int xx,yy;
        cin>>xx>>yy;
        dp[xx][yy]=-1;
        }
    for(int i=1;i<=x;i++){
        for(int j=1;j<=y;j++){
            if(dp[i][j]!=-1){
                int xxx,yyy;
                xxx=dp[i][j-1];
                yyy=dp[i-1][j];
                if(xxx==-1)dp[i][j]=yyy;
                else if(yyy==-1)dp[i][j]=xxx;
                else dp[i][j]=xxx+yyy;
                }
                if(i==1 && j==1)dp[i][j]=1;
            }
        }
    cout<<dp[x][y]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1176
N,K=map(int,input().split())

#kaijou
kk=[1]
a=1
for i in range(0,N):
  a=a*(i+1)
  kk.append(a)
#print(kk)
  
for i in range(0,K):
  j=i+1
  if N-K-j+1<0:
    print("0")
  else:
    aaa=(kk[N-K+1]//(kk[N-K-j+1]*kk[j]))%(10**9+7)
    bbb=(kk[K-1]//(kk[K-j]*kk[j-1]))%(10**9+7)
    #print(j,aaa,"aaa",bbb,"bbb")
    ccc=aaa*bbb
    print(int(ccc%(10**9+7)))
  

Measured memory_bytes: 5748
n,m = map(int,input().split())
a = list()
b = list()
for i in range(n):
    a_i = list(map(int,input().split()))
    a.append(a_i)
for i in range(m):
    b.append(int(input()))

for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j] * b[j]
    print(sum)



Measured memory_bytes: 6012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
            int N = int.Parse(Console.ReadLine());
            int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();

            int count = 0;
            for (int i=0; i<N;i++) {
                if (vs[i] != i + 1) {
                    count++;
                }
            }
            if (count <= 2) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13268
<?php
fscanf(STDIN,"%d %d",$r,$c);
$sum_c=array_fill(0,$c,0);
for($i=0;$i<$r;++$i){
    $input=explode(" ",trim(fgets(STDIN)));
    for($j=0;$j<$c;++$j){
        $sum_c[$j]=$sum_c[$j]+$input[$j];
    }
    echo join(" ",$input)," ",array_sum($input),PHP_EOL;
}
echo join(" ",$sum_c)," ",array_sum($sum_c);
?>

Measured memory_bytes: 15456
import sys
input = sys.stdin.readline

def linput():
    return [int(x) for x in input().split()]

k = int(input())

ans = 0

from math import gcd

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            g = gcd(a, b)
            ans += gcd(g, c)
    
print(ans)



Measured memory_bytes: 68844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(){
ll n;cin>>n;
vector<ll> v(n);
for(ll i=0;i<n;i++)cin>>v[i];
sort(v.begin(),v.end());
ll a=0,b=0;
for(ll i=n-1;i>0;i--){
    if(v[i]==v[i-1]&&a==0){a=v[i];i--;}
    else if(a!=0&&v[i]==v[i-1]){b=v[i];break;}
}
cout<<a*b;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define MAP map<int,int>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e17;

void ANS(bool flag){
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Ans(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void ans(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	int N;
	cin >> N;
	VS s(N);
	REP(i, N) cin >> s[i];
	int M;
	cin >> M;
	VS t(M);
	REP(i, M) cin >> t[i];

	int money_max = 0;
	REP(i,N){
		string S = s[i];
		int money = 0;
		REP(j,N){
			if (S == s[j]) money++;
					
		}
		REP(j, M) {
			if (S == t[j]) money--;
		}
		money_max = max(money_max, money);
	}
	cout << money_max << endl;





	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long

const int N = 1000020;
int lp[N + 5];
vector<int> pr;
#define pii pair<int,int>
vector<long long>tr;
void triangular_numbers() {
	for (int i(1);; ++i) {
		ll x = ((i * (i + 1)) / 2);

		if (x > N)
			break;
		tr.emplace_back((i * (i + 1)) / 2);
	}
}

void pre() {
	for (int i = 2; i <= N; ++i) {
		if (lp[i] == 0) {
			lp[i] = i;
			pr.push_back (i);
		}
		for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
			lp[i * pr[j]] = pr[j];
	}
}
vector<pii>fac;
bool is_prime(ll n) {
	if (n & 1 ^ 1)return false;
	for (int i(3); i * i <= n; i += 2) {
		if (n % i == 0)
			return false;
	}
	return true;
}
bool flag = true;
void factor(ll x) {
	for (ll i(0); pr[i]*pr[i] <= x && i < pr.size(); ++i) {
		ll p = pr[i];

		ll cnt = 0;
		if (x % p == 0) {
			flag = false;
			while (x % p == 0) {

				cnt++; x /= p;
			}
			fac.emplace_back(p, cnt);
		}
	}
	if (x > 1) {
		fac.emplace_back(x, 1);
	}
}
int main() {
	ll n;
	pre();
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}

	factor(n);
	/*if (!flag) {
		cout << 1 << endl;
		return 0;
	}*/
	ll ans = 0;
	triangular_numbers();

	for (auto& x : fac) {
		auto it = upper_bound(tr.begin(), tr.end(), x.second);

		it--;
		auto k = (it - tr.begin());
		ans += (k + 1);
	}


	cout << ans << endl;
}

Measured memory_bytes: 7676
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    ll N, M;
    scanf("%lld", &N);

    double ans = ((double)N * 2.) * acos(-1);


    printf("%lf\n", ans);

    return 0;

}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)
#define FORE(i, v) for (__typeof (v.begin()) i = v.begin(); i != v.end(); ++i)
#define FORR(i, v) for (__typpeof (v.rbegin()) i = v.rbegin(); i != v.rend(); ++i)
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sqr(x) 1ll * (x) * (x)
#define EPS 1e-9

template <class T> int getBit(T x, int k) { return x >> k & 1; }
template <class T> T onBit(T x, int k) { return x  (T(1) << k); }
template <class T> T offBit(T x, int k) { return x & (~(T(1) << k)); }
template <class T> void read(T &x) {
    x = 0; char c; bool nega = 0;
    while (!isdigit(c = getchar()) && c != '-');
    if (c == '-') nega = 1, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    if (nega) x = -x;
}
template <class T> void wri(T x) { if (x / 10) wri(x / 10); putchar(x % 10 + '0'); }
template <class T> void write(T x) { if (x < 0) putchar('-'); wri(abs(x)); }
template <class T> void writeln(T x) { write(x); putchar('\n'); }

const int N = 3e5 + 10;

int n;
int a[N];
long long f[N];

void load() {
    read(n);
    FOR(i, 1, 3 * n) read(a[i]);
}

void process() {
    priority_queue <int> q;
    long long sum = 0;
    FOR(i, 1, n) {
        q.push(-a[i]);
        sum += a[i];
    }
    f[n] = sum;
    FOR(i, n + 1, 2 * n) {
        if (-q.top() < a[i]) {
            sum += a[i] + q.top();
            q.pop(); q.push(-a[i]);
        }
        f[i] = sum;
    }
    while (!q.empty()) q.pop();
    sum = 0;
    FORD(i, 3 * n, 2 * n + 1) {
        sum += a[i];
        q.push(a[i]);
    }
  //  FOR(i, n, 2 * n) cerr << f[i] << "\n";
    long long ans = f[2 * n] - sum;
    FORD(i, 2 * n, n + 1) {
        if (q.top() > a[i]) {
            sum += a[i] - q.top();
            q.pop(); q.push(a[i]);
        }
        ans = max(ans, f[i - 1] - sum);
    }
    writeln(ans);
}

int main() {
  //  freopen("input.in", "r", stdin);
 //   freopen("output.out", "w", stdout);

    load();
    process();

    return 0;
}


Measured memory_bytes: 2808
#include <stdio.h>

int main()
{
  int A1, A2, A3;
  scanf("%d %d %d", &A1, &A2, &A3);
  int sum = A1 + A2 + A3;
  if(sum >= 22){
    printf("bust\n");
  }else{
    printf("win\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
char S[1000002];
int e[1000002];
int w[1000002];
int main() {
	int N;
	int  min = 1000002;
	int tmp = 0;
	int ans;
	scanf("%d", &N);
	scanf("%s", &S);
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'E')
		{
			e[i]++;
		}
		else if (S[i] == 'W')
		{
			w[i]++;
		}
		if (i > 0)
		{
			e[i] = e[i - 1] + e[i];
			w[i] = w[i - 1] + w[i];
		}
	}


	for (int i = 0; i < N; i++)
	{
		if (i == 0) {
			tmp = e[N - 1] - e[i];
		}
		else if (i == N - 1) {
			tmp = w[i - 1];
		}
		else {
			tmp = w[i - 1] + (e[N - 1] - e[i]);
		}

		if (tmp < min)
		{
			min = tmp;
		}
	}
	ans = min;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();

        if (Math.abs(a - b) <= d &&
            Math.abs(b - c) <= d ||
            Math.abs(a - c) <= d){
                System.out.println("Yes");
            } else {
                System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = vec![vec![]; n];
    for i in 0..n {
        a[i] = read_vec::<usize>()
            .into_iter()
            .map(|x| x - 1)
            .collect::<Vec<_>>();
    }

    let mut pointers = vec![n - 2; n];
    let mut ended_count = 0;
    let mut ended = vec![false; n];
    let mut days = 0;
    let mut prev_changed = BTreeSet::new();
    for i in 0..n {
        prev_changed.insert(i);
    }
    while ended_count < n {
        let mut used = BTreeSet::new();
        for &i in prev_changed.iter() {
            if used.contains(&i) || ended[i] {
                continue;
            }
            let to = a[i][pointers[i]];
            assert!(!ended[to]);
            if used.contains(&to) {
                continue;
            }
            if a[to][pointers[to]] == i {
                if pointers[i] == 0 {
                    ended[i] = true;
                    ended_count += 1;
                } else {
                    pointers[i] -= 1;
                }
                if pointers[to] == 0 {
                    ended[to] = true;
                    ended_count += 1;
                } else {
                    pointers[to] -= 1;
                }
                used.insert(i);
                used.insert(to);
            }
        }
        days += 1;
        if used.is_empty() {
            println!("-1");
            return;
        }
        prev_changed = used;
    }
    println!("{}", days);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12540
MOD = 998244353


def main():
    # 配るdp + imos法
    N, K = (int(i) for i in input().split())
    LR = [[int(i) for i in input().split()] for j in range(K)]

    dp = [0] * (N+2)
    dp[1] = 1
    dp[2] = -1
    for i in range(1, N+1):
        for le, ri in LR:
            if i+le <= N:
                dp[i+le] += dp[i]
                dp[i+le] %= MOD
            if i+ri+1 <= N:
                dp[i+ri+1] -= dp[i]
                dp[i+ri+1] %= MOD
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 75188
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, k, cnt=0; cin >> n >> k;
    string s; cin >> s;
    REP(i, n-1) if(s[i] == s[i+1]) cnt++;
    cout << min(n-1, cnt + 2 * k) << endl;
    return 0;
}

Measured memory_bytes: 512
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var s = Console.ReadLine().Trim();
        var R = getR(n, k, c, s);
        getAns(n, k, c, s, R);
    }
    static int[] getR(int n, int k, int c, string s)
    {
        var a = new int[k + 1];
        var p = n - 1;
        var kc = k;
        while (p >= 0 && kc >= 1)
        {
            if (s[p] == 'o')
            {
                a[kc--] = p + 1;
                p -= c + 1;
            }
            else p--;
        }
        return a;
    }
    static void getAns(int n, int k, int c, string s, int[] R)
    {
        var ans = new List<int>();
        var p = 0;
        var kc = 1;
        while (p < n && kc <= k)
        {
            if (s[p] == 'o')
            {
                if (R[kc] == p + 1) ans.Add(p + 1);
                p += c + 1;
                kc++;
            }
            else p++;
        }
        Console.WriteLine(string.Join("\n", ans));
    }
}


Measured memory_bytes: 27356
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
*/

main:-
    get_number(A),
    get_number(B),
    X is max(0, A - 2 * B),
    writeln(X).


Measured memory_bytes: 8164
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A = map(int, read().split())

print('Yes' if N % 500 <= A else 'No')


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<float.h>

int main(){
  double a,b,C,S,L,h,c,x,y;
  scanf("%lf %lf %lf",&a,&b,&C);
  x = sin(C*M_PI/180);
  y = cos(C*M_PI/180);
  S = a * b * x / 2;
  L = a + b + sqrt(a*a+b*b-2*a*b*y);
  h = 2*S/a;
  printf("%lf\n%lf\n%lf\n",S,L,h);
  return 0;
}

Measured memory_bytes: 1076
#include <iostream>
using namespace std;

int main() {
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(k <= a)
        cout << k << endl;
    else if(k <= a+b)
        cout << a << endl;
    else
        cout << a - (k-(a+b)) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long

const int MAX_V=1000;

int dist[MAX_V][MAX_V];
int V;

void warshall_floyd(int V){
    REP(k,V){
        REP(i,V){
            REP(j,V){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    int n,m,r;
    int tmp;
    int ans=INF;
    cin>>n>>m>>r;

    int hoge[r];

    REP(i,r){
        cin>>hoge[i];
        hoge[i]--;
    }

    vector<int> from;
    vector<int> to;
    vector<int> cost;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j==i)dist[i][j]=0;
            else dist[i][j]=INF;
        }
    }

    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;

        from.pb(a);
        to.pb(b);
        cost.pb(c);

        from[i]--;
        to[i]--;

        dist[from[i]][to[i]]=cost[i];
        dist[to[i]][from[i]]=cost[i];

    }

    warshall_floyd(n);

    sort(hoge,hoge+r);
    // REP(i,r){
    //     cout<<hoge[i]<<" ";
    // }cout<<endl;

    // cout<<endl;
    // cout<<endl;
    // cout<<"WFdebug"<<endl;
    // REP(i,n){
    //     REP(j,n){
    //         cout<<i<<" "<<j<<" "<<dist[i][j]<<endl;
    //     }
    // }cout<<endl;

   

    int sum;
    do{ 

        
        // cout<<"--------------"<<endl;
            //      REP(l,r){
    //     cout<<hoge[l]<<" ";
    // }cout<<endl;


        sum=0;
        for(int i=0;i<r-1;i++){

        sum+=dist[hoge[i]][hoge[i+1]];
        // cout<<hoge[i]<<" "<<hoge[i+1]<<" "<<dist[hoge[i]][hoge[i+1]]<<endl;
        }
        // cout<<endl;
        // cout<<"sum:"<<sum<<endl;
        ans=min(ans,sum);

        // cout<<ans<<endl;
        // cout<<"ans:"<<ans<<" tmp:"<<tmp<<endl;
        
        // cout<<"------------"<<endl;
    }while(next_permutation( hoge, hoge + r));


    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a,b,ins=0,ans=0;
  cin>>n>>m;
  ins+=m;
  for(int i=0;i<n;i++){
    if(ins<0) break;
    cin>>a>>b;
    ins+=a;
    ins-=b;
    if(ins>ans) ans=ins;
    if(ins<0) ans=0;
  }
  cout<<ans<<endl;
  
return 0;
}



Measured memory_bytes: 3080
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

def kai(n):
  if(n==1 or n==0):
    return 1
  return n*kai(n-1)

op = 1
oq = 1

for i in range(N):
  tp = P[i] - 1
  tq = Q[i] - 1
  for j in range(i+1):
    if (P[j]<P[i]):
      tp -= 1
    if (Q[j]<Q[i]):
      tq -= 1

  op += tp*kai(N-(i+1))
  oq += tq*kai(N-(i+1))

print (abs(oq-op))

Measured memory_bytes: 3064
#include <bits/stdc++.h>

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void){
    
    int N;
    cin >> N;
    vector<int> p(N);
    REP(i, N)cin >> p[i];

    vector<int> q = p;
    sort(p.begin(), p.end());
    int count = 0;
    REP(i, N){
        if(p[i] != q[i]){
            count++;
        }
    }
    if(count <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	  int b[1000],f[1000],r[1000],V[1000];
	 int n,a,g,c,d,i;
	 int e[4][3][10]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b[i],&f[i],&r[i],&V[i]);
		e[b[i]-1][f[i]-1][r[i]-1]+=V[i];
	}
	for(a=0;a<4;a++){
		for(g=0;g<3;g++){
			for(c=0;c<10;c++){
				if(c==0){
					printf(" ");
				}
				printf("%d",e[a][g][c]);
				if(c!=9){
					printf(" ");
				}else if(c==9 && a!=3){
					printf("\n");
				}else if(a==3 && c==9 ){
					printf("\n");
					
				}
			}
			
		}
		if(a!=3){
		printf("####################\n");
		}
	}           
	return 0;
}


Measured memory_bytes: 2776