akhauriyash/Code-Regression huggingface dataset:
import copy
import itertools
import sys

if sys.version[0] == '2':
    range, input = xrange, raw_input

drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
C_NUM = 6


while True:
    H, W, C = map(int, input().split())
    if not (H | W | C):
        break
    board = [[int(x) - 1 for x in input().split()] for _ in range(H)]
    ans = 0
    for ope in itertools.product(range(C_NUM), repeat=5):
        # print(ope)
        if ope[0] == board[0][0] or ope[-1] != C - 1 or any(ope[i] == ope[i + 1] for i in range(4)):
            continue
        ps = [(0, 0)]
        tmp_board = copy.deepcopy(board)
        for color in ope:
            now_c = tmp_board[0][0]
            if now_c == color:
                continue

            for r, c in ps:
                tmp_board[r][c] = color
            stack = ps[:]
            while stack:
                r, c = stack.pop()
                for dr, dc in drc:
                    nr, nc = r + dr, c + dc
                    if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c:
                        tmp_board[nr][nc] = color
                        stack.append((nr, nc))
                        ps.append((nr, nc))
        for r, c in ps:
            tmp_board[r][c] = -1
        stack = ps[:]
        while stack:
            r, c = stack.pop()
            for dr, dc in drc:
                nr, nc = r + dr, c + dc
                if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1:
                    tmp_board[nr][nc] = -1
                    stack.append((nr, nc))
        cand = sum(row.count(-1) for row in tmp_board)
        if cand > ans:
            ans = cand
    print(ans)

Measured memory_bytes: 8212
from decimal import Decimal, ROUND_HALF_UP

N = int(input())
X = [int(i) for i in input().split()]

ans = 0
X_mean = Decimal(str(sum(X) / N))
X_mean = X_mean.quantize(Decimal('0'), rounding=ROUND_HALF_UP)

for i in range(N):
    ans += (X[i] - X_mean) ** 2

print(ans)

Measured memory_bytes: 5076
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

string repStr(string &obj, string from, string to) {
    int pos = obj.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return obj;
    }
 
    while ((pos = obj.find(from, pos)) != string::npos) {
        obj.replace(pos, from.length(), to);
        pos += toLen;
    }
    return obj;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    cin.ignore();
    while(--n >= 0){
        string s;
        getline(cin,s);
        repStr(s, "Hoshino", "Hoshina");
        cout << s << endl;
    }
    return EXIT_SUCCESS;
}


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

int main() {
  int A,B,K;
  cin >> A >> B >> K;
  int COUNT = 0;
  int ans = 0;
  
  for (int i = 100; COUNT < K; i--)
  if (A%i == 0 && B%i == 0){
    COUNT++;
    ans = i;
    }
     cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define ll long long
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    vector<vector<ll>> dp(n, vector<ll>(n));
    for (int i = 0; i < n; i++)
        for (int j = 1; j < n; j++)dp[i][j] = 1145141919810364364;
    for (int len = 1; len < n; len++) {//start+len 個のスライム
        for (int start = 0; start + len < n; start++) {
            for (int cut = 1; cut <= len; cut++) {
                dp[start][len] =
                        min(dp[start][len],
                            dp[start][cut - 1] + dp[start + cut][len - cut] + a[start + len + 1] - a[start]);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n;
vector<int> vec[100005];
int visited[100005];
int ans[100005][2];
void dfs(int u){
    visited[u] = 1;
    long long int pro1 = 1, pro2 = 1;
        for(int v:vec[u]){
            if(!visited[v]){
                dfs(v);
                long long int a = ((long long int)ans[v][0] + ans[v][1])%mod;
                long long int b = ans[v][0];
                pro1 = (pro1 *a)%mod;
                pro2 = (pro2 *b)%mod;
            }
        }
        ans[u][0] = pro1;
        ans[u][1] = pro2;
        // cout << u << " " << ans[u][0] << " " << ans[u][1] << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i=1;i<n;i++){
        int u, v;
        cin >> u >> v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }    
    dfs(1);
    cout << ((long long int)ans[1][0] + ans[1][1])%mod;
}

Measured memory_bytes: 17072
import collections

n = int(input())
a = list(map(int, input().split()))

b = collections.deque()
for i in range(len(a)):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

b = list(b)
if n % 2 == 1:
    b.reverse()

print(" ".join([str(x) for x in b]))


Measured memory_bytes: 114692
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,m;
    cin >> n >> m;
    vector<ll>a[3];
    rep(i,3)a[i].resize(n);
    rep(i,n)rep(j,3)cin >> a[j][i];
    ll ans = 0;
    for(int x:{-1,1}){
        for(int y:{-1,1}){
            for(int z:{-1,1}){
                vector<ll>b;
                rep(i,n){
                    b.push_back(a[0][i]*x+a[1][i]*y+a[2][i]*z);
                }
                sort(b.rbegin(),b.rend());
                ll temp = 0;
                rep(i,m)temp+=b[i];
                ans = max(ans,temp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string t;
    cin>>t;
    int flag=0;
    for(int i = 0; i<s.size(); i++){
        if(s==t){
            flag = 1;
            break;
        }
        s = s.back()+s.substr(0,s.size()-1);
    }
    
    if(flag == 1){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}
        
    

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int v[n],c[n];
    for(int i=0;i<n;i++) cin >> v[i];
    for(int i=0;i<n;i++) cin >> c[i];
    int res=-1000000;
    for(int o=0;o<(1<<n);o++)
    {
        int x=0,y=0;
        for(int i=0;i<n;i++)
        {
            if((o>>i)&1)
            {
                x+=v[i];
                y+=c[i];
            }
        }
        res=max(res,x-y);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, M = map(int, input().split())
    xyz = [None for _ in range(N)]
    for i in range(N):
        xyz[i] = list(map(int, input().split()))
    # print(xyz)
    ans = 0
    for i in range(2**3):
        tmp = [0] * N
        for j in range(N):
            for k in range(3):
                if i >> k & 1:
                    tmp[j] += xyz[j][k]
                else:
                    tmp[j] -= xyz[j][k]
        tmp.sort(reverse=True)
        ans = max(ans, sum(tmp[:M]))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9680
import math
n, a, b = map(int, input().split())
MOD = 1000000007

def cmb(n, r, MOD):
    x, y = 1, 1
    for i in range(r):
        x = x * (n - i) % MOD
        y = y * (i + 1) % MOD
    return x * pow(y, MOD - 2, MOD) % MOD

N = pow(2, n, MOD) - 1
A = cmb(n, a, MOD)
B = cmb(n, b, MOD)

print((N - A - B) % MOD)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main()
{
	string s;
    cin>>s;
    
    if(s=="RRS"||s=="SRR")cout<<2;
    else if(s=="RRR")cout<<3;
    else if(s=="RSR"||s=="RSS"||s=="SSR"||s=="SRS")cout<<1;
    else if(s=="SSS")cout<<0;
        
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string S;
    cin >> S;
    int l = S.size();
    int a[l-2];
    int b[l-2];

    for(int i = 0; i < l-2; i++) {
        a[i] = stoi(S.substr(i, 3));
    }

    for(int i = 0; i < l-2; i++) {
        if(a[i] - 753 < 0) {
            b[i] = 753 - a[i];
        }
        else {
            b[i] = a[i] - 753;
        }
    }

    sort(b, b+l-2);

    cout << b[0];

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

int main() {
	char s[10], t[10];
	scanf("%s", s);
	scanf("%s", t);
	int ans = 0;
	for(int i = 0; i < 3; i ++)
		if(s[i] == t[i])
			ans ++;
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include<stdio.h>
#define SM 100000
#define TM 50000
main()
{

  int i,n,q,l,m,r,c = 0,han = 0;
  int s[SM];
  int t[TM];


  scanf("%d",&n);

  for(i = 0;i < n;i++)
    {
      scanf("%d",&s[i]);
    }


  scanf("%d",&q);

 for(i = 0;i < q;i++)
    {
      scanf("%d",&t[i]);
    }



 for(i = 0;i < q;i++)
   {
     l = 0;
     r = n;
     while(1)
       {
	 m = (l + r)/2;
	 if(s[m] == t[i])
	   {
	     c++;
	     break;
	   }
	 else if(l == m || r == m)
	   {
	     break;
	   }

	 else if(s[m] > t[i])
	   {
	     r = m;
	   }
	 else if(s[m] < t[i])
	   {
	     l = m + 1;
	   }
	}
    }


  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 1184
data = []
for looop in range(1,10000):
    n,x = map(int, input().split())
    if n == 0 and x ==0:
        break
    else:
        num = 0
        for i in range(3,n+1):
            for j in range(2,i):
                for k in range(1,j):
                    if i + j + k == x:
                        num += 1
        data.append(num)
for x in range(len(data)):
    print(data[x])


Measured memory_bytes: 7600
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



/*const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}*/

/*int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/

using namespace std;



int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;
    vector <int> a(n);
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    multiset < pair <int, int> > mst;
    vector <int> b(n);
    for(i = 0; i < n; i++) {
        cin >> b[i];
        mst.insert({b[i], i});
    }

    ll ans = 0;
    while(mst.size()) {
        auto it = prev(mst.end());
        if(b[it -> second] < a[it -> second]) {
            cout << -1;
            return 0;
        }
        if(b[it -> second] == a[it -> second]) {
            mst.erase(it);
            continue;
        }
        int step = b[(it -> second - 1 + n) % n] + b[(it -> second + 1) % n];
        int cnt = (b[it -> second] - a[it -> second]) / step;
        if(cnt == 0) {
            cout << -1;
            return 0;
        }
        int pos = it -> second;
        mst.erase(it);
        b[pos] -= step * cnt;
        ans += cnt;
        if(b[pos] != a[pos]) {
            mst.insert({b[pos], pos});
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 13312
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long gcd(long long a,long long b){
    if(b > a){
        swap(a,b);
    }
    bool flag = true;
    long long gcdl;
    while(flag){
        if(a%b == 0){
            flag = false;
            gcdl = b;
        }
        else{
            swap(a,b);
            b = b % a;
        }
    }
    return gcdl;
}
int main(){
    long n,m;
    cin >> n >> m;
    string sn,sm;
    cin >> sn >> sm;
    long gcdnm = gcd(n,m);
    int a = n/gcdnm;
    int b = m/gcdnm;
    bool fl = true;
    rep(i,gcdnm){
        if(sn[i*a] != sm[i*b]){
            cout << -1 << endl;
            fl = false;
            break;
        }
    }
    if(fl){
        cout << n*m/gcdnm << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
const int N = 100010;
char s[N], s1[N];

int main()
{
	int n, cnt = 0;
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n / 2; i++)
		s1[i] = 'p';
	for (int i = n / 2; i < n; i++)
		s1[i] = 'g';
	for (int i = 0; i < n; i++)
		if (s[i] == 'p' && s1[i] == 'g')
			cnt--;
		else if (s[i] == 'g' && s1[i] == 'p')
			cnt++;
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 66;
const int M = 40000 + 10;
const int O = 20000 + 5;
const long double INF = 1e10;

int n, r;
int st, test;
int x[N], y[N];
int nx[N], ny[N];
bool ok[N][N];
long double f[N][M];

int sign(int x)
{
	return x < 0 ? -1 : x > 0;
}

int xmult(int p1, int p2, int q)
{
	return sign((x[p1] - x[q]) * (y[p2] - y[q]) - (x[p2] - x[q]) * (y[p1] - y[q]));
}

int on(int p1, int p2, int q)
{
	if (xmult(p1, p2, q)) return false;
	return (x[p1] - x[q]) * (x[p2] - x[q]) + (y[p1] - y[q]) * (y[p2] - y[q]) < 0;
}

int xmult(int p1, int p2)
{
	return x[p1] * y[p2] - x[p2] * y[p1];
}

int intersect(int p1, int p2, int q1, int q2)
{
	return xmult(p1, p2, q1) * xmult(p1, p2, q2) < 0 && xmult(q1, q2, p1) * xmult(q1, q2, p2) < 0;
}

void update(long double &a, long double b)
{
	if (a > b) a = b;
}

long double dis(int u, int v)
{
	return hypot(x[u] - x[v], y[u] - y[v]);
}

void solve()
{
	st = 0;
	for(int i = 0; i < n; ++ i) {
		cin >> x[i] >> y[i];
		if (x[i] < x[st]) {
			st = i;
		}
	}
	for(int i = 0; i < n; ++ i) {
		nx[i] = x[(i + st) % n];
		ny[i] = y[(i + st) % n];
	}
	for(int i = 0; i < n; ++ i) {
		x[i] = nx[i];
		y[i] = ny[i];
	}
	x[n] = x[0];
	y[n] = y[0];

	memset(ok, 0, sizeof ok);
	for(int i = 0; i < n; ++ i) {
		for(int j = i + 2; j <= n; ++ j) {
			if (i == 0 && j == n) continue;
			bool flag = true;
			{
				for(int k = 0; k < n; ++ k) {
					if (k == i || k == j % n) continue;
					if (on(i, j, k)) {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				for(int k = 0; k < n; ++ k) {
					if (intersect(i, j, k, k + 1)) {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				int area = xmult(i, j);
				for(int k = j - 1; k >= i; -- k) {
					area += xmult(k + 1, k);
				}
				if (area <= 0) flag = false;
			}
			ok[i][j] = flag;
		}
	}

	for(int i = 0; i <= n; ++ i) {
		for(int j = 0; j < M; ++ j) {
			f[i][j] = INF;
		}
	}
	f[0][O] = 0;

	for(int i = 0; i < n; ++ i) {
		for(int j = 0; j < M; ++ j) {
			if (f[i][j] >= INF) continue;
			update(f[i + 1][j + xmult(i, i + 1)], f[i][j]);
			for(int k = i + 2; k <= n; ++ k) {
				if (ok[i][k]) {
					update(f[k][j + xmult(i, k)], f[i][j] + dis(i, k));
				}
			}
		}
	}

	int ret = 0;
	for(int i = O; i < M; ++ i) {
		if (f[n][i] - 1e-8 > r) continue;
		ret = i - O;
	}
	if (ret & 1)
		printf("%d.5\n", ret >> 1);
	else
		printf("%d.0\n", ret >> 1);
}

int main()
{
	test = 0;
	for( ; cin >> n >> r && (n || r); ) {
		printf("case %d: ", ++ test);
		solve();
	}
	return 0;
}

Measured memory_bytes: 42120
n = int(input())

abc = list('abcdefghij')


def solve(ans):
    if len(ans) == n:
        print(*ans, sep='')
    else:
        idx = max([abc.index(ans[i]) for i in range(len(ans))])
        for i in range(idx+2):
            nans = ans + [abc[i]]
            solve(nans)


solve(['a'])

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

int main(void) {
	int h, w;
	bool c = 1;

	cin >> h >> w;

	char s[51][51];

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) cin >> s[i][j];
	}

	for (int i = 1; i<=h; i++) {
		for (int j = 1; j<=w; j++) if (s[i][j] == '#') if (s[i - 1][j] != '#' && s[i][j - 1] != '#' && s[i + 1][j] != '#' && s[i][j + 1] != '#') { c = 0; s[i][j] = '1'; }
	}

	if (c == 1) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def dfs(v, par):
    for nv in g[v]:
        if nv == par:
            continue
        memo[nv] += memo[v]
        dfs(nv, v)

n, q = na()
g = [deque() for _ in range(n)]
for i in range(n-1):
    a, b = na()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
memo = [0] * n
for i in range(q):
    #seen = [False] * n
    p, x = na()
    p -= 1
    memo[p] += x

dfs(0, -1)
print(*memo)

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

int main() {
    int a;
    cin >> a;
    stack<int> sta;
    while(a) {
        int num;
        cin >> num;
        sta.push(num);
        a--;
    }
    
    while(!sta.empty()) {
        int num = sta.top();
        sta.pop();
        if (sta.empty()) {
          cout << num ;  
        } else {
          cout << num << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);
#define tie cin.tie(0);
#define x first
#define y second
#define ll long long
#define mod 666013

using namespace std;
int n, road[200100], m, rail[200100], k;
int x, a, b;
int A[200005];
map<pair<int, int>, int> M;

int find1(int nod)
{
    if (road[nod] == nod) return nod;
    int p = find1(road[nod]);
    road[nod] = p;
    return p;
}

void unite1(int a, int b)
{
    a = find1(a);
    b = find1(b);
    road[a] = b;
}

int find2(int nod)
{
    if (rail[nod] == nod) return nod;
    int p = find2(rail[nod]);
    rail[nod] = p;
    return p;
}
 
void unite2(int a, int b)
{
    a = find2(a);
    b = find2(b);
    rail[a] = b;
}

int main(){
	
	ios_base::sync_with_stdio(0);

	cin >> n >> m >> k;
	
    for (int i = 1; i <= n; i++)
        road[i] = rail[i] = i;
    for (int i = 1; i <= m; i++)
    {
        cin >> a >> b;
        unite1(a, b);
    }
    for (int i = 1; i <= k; i++)
	{
		cin >> a >> b;
		unite2(a, b);
	}
	
	for (int i = 1; i <= n; i++)
		M[{find1(i), find2(i)}]++;
	for (int i = 1; i <= n; i++) cout << M[{find1(i), find2(i)}] << " ";
    return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int  a, b;
	cin >> a >> b;
	cout << a + b/2.0 << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	int n = (x-a)/b;
	cout << x-a-n*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for (int i=(int)(s);i<(int)(n);i++)

int main(){
  using v2=vector<vector<int64_t>>;
  int N;
  cin >>N;
  v2 vec;
  rep(i,0,N){
    int64_t a,b,c;
    cin >> a >>b>>c;
    vector<int64_t> vec1 = {a,b,c};
    vec.push_back(vec1);
  }
  v2 dp(N,vector<int64_t> (3,0));
  dp[0][0]=vec[0][0];
  dp[0][1]=vec[0][1];
  dp[0][2]=vec[0][2];
  rep (i,1,N){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+vec[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+vec[i][1];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+vec[i][2];
  }
  vector<int64_t> lastvec;
  lastvec = dp.at(N-1);
  sort(lastvec.begin(),lastvec.end());
  cout << lastvec.at(2) << endl;
}
    
    
  
  
  

Measured memory_bytes: 11696
#include <cstdio>

using namespace std;

int main() {
	int a = 0;
	int b = 0;

	scanf("%d%d", &a, &b);
	if (a < b) {
		for (int i = 0; i < b; i++) {
			printf("%d", a);
		}
	} else {
		for (int i = 0; i < a; i++) {
			printf("%d", b);
		}
	}
	return 0;
}

Measured memory_bytes: 128
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> P;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m,d[200000], t[200000];

ll k;
string s;

int main() {
	cin >> n;
	REP(i, n){
		cin>>d[i];
	}
	cin >> m;
	priority_queue<int> q;
	REP(i, m){
		cin>>t[i];
		q.push(t[i]);
	}
	sort(d, d+n);
	int i = n-1;
	while(!q.empty()){
		int f = q.top();
		while(d[i]>f)i--;
		if(i<0)break;
		q.pop();
		f-=d[i];
		if(f!=0)q.push(f);
		i--;
		if(i<0)break;
	}
	cout<<(q.empty() ? "YES" : "NO")<<endl;
}


Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,p,k,j,q,b;
    string s,s1;
    cin>>s>>s1;
    k=s1.size();p=0;q=0;m=0;b=1;
    int a[1000];
    for(i=0; i<=s.size()-k; i++)
    {
        p=0;m=0;
        for(j=i; j<k+i; j++)
        {
            if(s1[p]!=s[j])
            {

                m++;
            }
            p++;
        }

        a[q]=m;
        q++;
    }
    sort(a,a+q);
    cout<<a[0];
}


Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long H = long.Parse(str[0]);
		long N = long.Parse(str[1]);
		long[]A = new long[N];
		long sum = 0;
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			sum += long.Parse(str2[i]);
		}
		string ans = "No";
		if(sum >= H){
			ans = "Yes";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_10_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            const int STL_LENGTH = 32;
            uint[] line = Array.ConvertAll(Console.ReadLine().Split(' '), e => uint.Parse(e));

            Console.WriteLine(Convert.ToString(line[0] & line[1], 2).PadLeft(STL_LENGTH, '0'));
            Console.WriteLine(Convert.ToString(line[0] | line[1], 2).PadLeft(STL_LENGTH, '0'));
            Console.WriteLine(Convert.ToString(line[0] ^ line[1], 2).PadLeft(STL_LENGTH, '0'));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 20044
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n), b(n);

    long i,j;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    for(i=0; i<n; i++) {
        scanf("%d", &b[i]);
    }

    ll ans = 0;
    for(j=0; j<30; j++) {
        vector<int> bb(n);
        for(i=0; i<n; i++) {
            bb[i]=b[i]%(1<<(j+1));
        }
        sort(bb.begin(), bb.end());

        int sum=0;
        for(i=0; i<n; i++) {
            int aa = a[i]%(1<<(j+1));
            int k0 = lower_bound( bb.begin(), bb.end(),   (1<<j)-aa ) - bb.begin();
            int k1 = lower_bound( bb.begin(), bb.end(), 2*(1<<j)-aa ) - bb.begin();
            int k2 = lower_bound( bb.begin(), bb.end(), 3*(1<<j)-aa ) - bb.begin();
            int cnt = (k1-k0)+(n-k2);
            sum += cnt;
        }
        if(sum%2) ans += (1<<j);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let mut seq = vec![a, b, c];
    let mut ans = 0;
    while seq[0] != seq[1] || seq[0] != seq[2] {
        ans += 1;
        seq.sort();
        if seq[0] + 2 <= seq[1] {
            seq[0] += 2;
        } else {
            seq[0] += 1;
            seq[1] += 1;
        }
    }
    println!("{}", ans);
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	ll V;
	cin >> V;
	vector< list<ll> >G(V+1);
	for(ll i=2;i<=V;i++){
		ll x;
		cin >> x;
		G[x].push_back(i);
	}
	for(ll i=1;i<=V;i++){
		cout << G[i].size() << "\n";
	}
	return 0;
}

Measured memory_bytes: 14324
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")  //デバッグ時にoptimized-outされて邪魔だった
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(int x){
  int i;
  if(x < 2)return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int X;
  cin >> X;
  while(true) {
    if(isPrime(X)) {
      fin(X);
      return 0;
    }
    X++;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private int pow(int x, int n) {
        int ans = 1;
        while (n != 0) {
            if ((n & 1) == 1) ans = ans * x;
            x = x * x;
            n = n >> 1;
        }
        return ans;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] s = new int[M];
        int[] c = new int[M];

        Map<Integer, Integer> rules = new HashMap<>();
        for (int i = 0; i < M; i++) {
            s[i] = sc.nextInt();
            c[i] = sc.nextInt();
            if (rules.containsKey(s[i])) {
                int v = rules.get(s[i]);
                if (v == c[i]) {
                    // ok
                } else {
                    System.out.println("-1");
                    return;
                }
            } else {
                rules.put(s[i], c[i]);
            }
        }

        boolean[] generated = new boolean[N];
        int ans = 0;
        for (Map.Entry e : rules.entrySet()) {
            int dig = N - (Integer)e.getKey() + 1;
            int val = (Integer)e.getValue();
            int x3 = -1;

            if (dig == N && N >= 2) {
                if (val >= 1 && val <= 9) {
                    ans += val * pow(10, dig - 1);
                } else {
                    ans = -1;
                    break;
                }
            } else  {
                ans += val * pow(10, dig - 1);
            }
            generated[dig - 1] = true;
        }

        if (ans != -1) {
            if (N == 1) {
                if (!generated[0]) ans = 0;
            } else {
                for (int i = N - 1; i >= 0; i--) {
                    if (!generated[i] && i == N - 1) ans += 1 * Math.pow(10, i);
                }
            }
        }

        System.out.println(ans);
        return;
    }

}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll labs(ll x){
	if(x<0LL)return -x;
	return x;
}

int n;
ll k;
ll a[100001];
int main(void){
	scanf("%d%lld",&n,&k);
	ll all=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(a[i]>0)all+=labs(a[i]);
	}
	ll res=0;
	ll sum=0;
	for(int i=0;i<k;i++){
		if(a[i]<0LL){
			sum+=labs(a[i]);
		}
	}
	res=all-sum;
	for(int i=k;i<n;i++){
		if(a[i]<0LL){
			sum+=labs(a[i]);
		}
		if(a[i-k]<0LL){
			sum-=labs(a[i-k]);
		}
		res=max(res,all-sum);
	}
	sum=0;
	for(int i=0;i<k;i++){
		if(a[i]>0LL){
			sum+=a[i];
		}
	}
	res=max(res,all-sum);
	for(int i=k;i<n;i++){
		if(a[i]>0LL){
			sum+=labs(a[i]);
		}
		if(a[i-k]>0LL){
			sum-=labs(a[i-k]);
		}
		res=max(res,all-sum);
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int d ,n;
    cin >> d >> n;
    int m=1;
    n = n+ n/100;
    for(int i = 0;i<d;i++){
        m = m*100;
    }

    cout << m*n;
    return 0;
}

Measured memory_bytes: 256
//\\                            ||                     ||
            ////          //  \\                           ||                     ||
                         //    \\          //\\    //\\    ||                     ||
            ////        //      \\       //   \\  //  \\   ||                     ||
            ////       ____________     ||     \\//    ||  ||_______      ________||
            ////      //          \\    ||             ||  ||______\\    //_______||
            ////     //            \\   ||             ||  ||       ||   ||       ||
            ////    //              \\  ||             ||  ||_______||   ||_______||
            ////   //                \\ ||             ||  ||______//     \\______||





                     /*WHO CARES IF ONE MORE LIGHT GOES OUT ?
                           IN A SKY OF A MILLION STARS
                               IT FLICKERS,FLICKERS
                       WHO CARES WHEN SOMEONE'S TIME RUNS OUT ?
                            IF A MOMENT IS ALL WE ARE.
                       WHO CARES IF ONE MORE LIGHT GOES OUT ?
                                WELL I DO...*/
#include<bits/stdc++.h>
using namespace std;
long long int fa[1022];

long long int powe(long long int d,long long int s)
{
    if(s==1) return d;
    else if(s==0) return 1;
    else
    {
        long long int u,v=d;
        for(u=1;u<s;u++)
        {
            d=d*v;
        }
        return d;
    }
}
long long int phi(long long int n)
{
    double result=n;
    for (long long int p=2;p*p<=n;++p){
        if (n%p==0){
            while(n%p==0)
                n/=p;
            result*=(1.0-(1.0/(double)p));
        }
    }
    if(n>1)
        result*=(1.0-(1.0/(double)n));

    return (long long int)result;
}
long long int bigmod(long long int a, long long int b,long long int m)
{
    long long int r;
    if(b==0) return 1;
    if(b%2==0)
    {
        r=bigmod(a,b/2,m)%m;
        r=(r*r)%m;
        return  r;
    }
        return ((a%m)*bigmod(a,b-1,m)%m)%m;
}
int main()
{
    int n,count=0,i;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=1;i<n-1;i++)
    {
        if((ara[i]>ara[i-1]&&ara[i]<ara[i+1]) || (ara[i]<ara[i-1]&&ara[i]>ara[i+1]))
            count++;
    }
    cout<<count<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int S, W;
    cin >> S >> W;

    if (W >= S) print("unsafe");
    else print("safe");
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc164/abc164_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc164/abc164_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc164/abc164_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
const long long mod = 1000000007;
void disp(int *p) {
	rep(i, 8) {
		if (i)cout << ' '; cout << p[i];
	}
	cout << endl;
}
signed main() {
	int n; cin >> n; string s; cin >> s;
	string cor;
	rep(i, n * 2) {
		if (i & 1)cor.push_back('W');
		else cor.push_back('B');
	}
	vector<int>V1, V2;
	rep(i, 2 * n) {
		if (s[i] == cor[i])V1.push_back(i);
		else V2.push_back(i);
	}
	int cnt = 1;
	if (V1.size() != V2.size())cout << 0 << endl;
	else {
		for (int i = V1.size() - 1; i >= 0; i--) {
			int val = lower_bound(V2.begin(), V2.end(), V1[i]) - V2.begin();
			val = i - val + 1;
			cnt *= val;
			cnt %= mod;
		}
		for (int i = 0; i < n; i++) {
			cnt *= i + 1; cnt %= mod;
		}
		cout << cnt << endl;
	}
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

string solve(int n)
{
    if (n > 0) {
        //auto p = ('a' - 1L) + n % 26L;
        auto p = 'a' + n % 26L;
        string st = solve(n/26L-1L);
        st.pb(p);
        return st;
    } else if (n == 0) {
        return "a";
    } else {
        return "";
    }
}

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

    Int(n);
    cout << solve(n-1) << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    if(n%1000 == 0) {cout<<"0";return 0;}
    cout<<1000-(n%1000);
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, x[365], y[365], b[365], p[365], mi;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> b[i] >> p[i];
        mi = x[i] * b[i] + y[i] * p[i];
        if(b[i] >= 5 && p[i] >= 2){
            mi *= 0.8f;
        }
        else{
            if(b[i] < 5){
                b[i] = 5;
            }
            if(p[i] < 2){
                p[i] = 2;
            }
            int tmp = (x[i] * b[i] + y[i] * p[i]) * 0.8f;
            mi = min(mi, tmp);
        }
        cout << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
ll f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}
 
int main() {
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    for(int i=1;i*k<=b;i++){
        if(k*i>=a && k*i<=b){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main(){ _
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	bool ok = true;
	if (n+1 != m){
		ok = false;
		goto leave;
	}
	for (int i = 0; i < n; i++)
		ok &= (s[i] == t[i]);
	leave:	
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	exit(0);
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,e=0,f=0,j,i;
string s,ss;
    map<ll,ll>m,n;
    m[1]=1;m[3]=1;m[5]=1;m[7]=1;
    m[8]=1;m[10]=1;m[12]=1;
    n[4]=1;n[6]=1;n[9]=1;n[11]=1;
    cin>>a>>b;
    if(m[a]==1&&m[b]==1)cout<<"Yes\n";
else if(n[a]==1&&n[b]==1)cout<<"Yes\n";
else cout<<"No\n";
    
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc134/tasks/abc134_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<ll> an(N+1);
    for(ll i=1;i<=N;++i){
        cin>>an[i];
    }
    vector<ll> bn(N+1,0);
    ll num=0;
    for(ll i=N;i>=1;--i){ //うしろから決める
        ll sum=0;
        for(ll j=i;j<=N;j+=i){
            sum+=bn[j];
        }
        if(sum%2!=an[i]){
            bn[i]=1;
            ++num;
        }
    }
    cout<<num<<endl;
    bool fst=true;
    for(ll i=1;i<=N;++i){
        if (bn[i]) {
            if(!fst){
                cout<<" ";
            }
            fst=false;
            cout<<i;
        }
    }
    if(!fst) cout<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++)
    {
        cout << s[i];
        if(i == 3)
            cout << " ";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] input = br.readLine().split(" ");
		String[][] output = new String[2][n];

		for(int i = 0; i < n; i++){
			output[0][i] = input[i];
			output[1][i] = input[i];
		}

		bubbleSort(output[0], n);
		selectionSort(output[1], n);

		for(int j = 0; j < output.length; j++){

			for(int i = 0; i < n; i++){

				System.out.print(output[j][i]);

				if(i != (n - 1)){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}

			if(isStable(input, output[j], n)){
				System.out.println("Stable");
			}else{
				System.out.println("Not stable");
			}
			
		}


	}

	public static void bubbleSort(String[] array, int n){

		for(int i = 0; i < (n - 1); i++){
			for(int j = (n - 1); j > 0; j--){

				int x = Character.getNumericValue(array[j].charAt(1));
				int y = Character.getNumericValue(array[j - 1].charAt(1));

				if(x < y){
					String temp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = temp;
				}
				
			}
		}

	}

	public static void selectionSort(String[] array, int n){

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

			int min = i;

			for(int j = (i + 1); j < n; j++){
				int x = Character.getNumericValue(array[j].charAt(1));
				int y = Character.getNumericValue(array[min].charAt(1));

				if(x < y){
					min = j;
				}
				
			}

			String temp = array[min];
			array[min] = array[i];
			array[i] = temp;
			
		}

	}

	public static boolean isStable(String[] before, String[] after, int n){

		for(int i = 0; i < (n - 1); i++){
			for(int j = (i + 1); j < n; j++){

				for(int a = 0; a < (n - 1); a++){
					for(int b = (a + 1); b < n; b++){

						int x = Character.getNumericValue(before[i].charAt(1));
						int y = Character.getNumericValue(before[j].charAt(1));

						if(x == y && before[i].equals(after[b]) && before[j].equals(after[a])){
							return false;
						}
						
					}
				}

			}
		}

		return true;

	}

}

Measured memory_bytes: 25472
N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
    B = [0 for k in range(N)]
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    # 累積和
    for i in range(1, N):
        B[i] += B[i-1]
    A = B.copy()
   
for b in B:
    print(b, end=" ")

Measured memory_bytes: 219460