akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int H,W;
    cin >> H >> W;
    int C[10][10];
    rep(i,10)rep(j,10){
        cin >> C[i][j];
    }
    rep(k,10)rep(i,10)rep(j,10){
        C[i][j] = min(C[i][j],C[i][k] + C[k][j]);
    }
    ll ans = 0;
    rep(h,H)rep(w,W){
        int num;
        cin >> num;
        if(num!=-1) ans += C[num][1]; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9; 
int n;
std::vector<int> a(N); 
vector<ll> dp(N,-1);
ll solve(int x){
    if(x>=n-1) return 0;
    if(dp[x]!=-1) return dp[x];
    dp[x]=min(abs(a[x+1]-a[x])+solve(x+1),abs(a[x+2]-a[x])+solve(x+2));
    //cout<<ans<<endl;
    return dp[x];
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	if(n==2) cout<<(abs(a[0]-a[1]));
	else  cout<<solve(0);
	return 0; 
	
}


Measured memory_bytes: 6576
// Problem : E - Change a Little Bit
// Contest : AtCoder - AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

int binpow(int x,int y){
    x %= mod;
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%mod;
        x = (x*x)%mod;
        y = y/2;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vi a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a.begin()+1,a.end(),greater<int>());
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans = (ans+(i+1)*a[i])%mod;
    }
    ans = (ans*binpow(4,n-1))%mod;
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4764
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char[] n = new char[3];
		int counterA = 0;
		int counterB = 0;
		int counterC = 0;

		for(int i = 0; i < 3; i++){
			n[i] = a.charAt(i);
		}

		for(int j = 0; j < 3; j++){
			if(n[j] == 'a'){
				counterA++;
			}else if(n[j] == 'b'){
				counterB++;
			}else if(n[j] == 'c'){
				counterC++;
			}
		}

		if(counterA == 1 && counterB == 1 && counterC == 1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int M, N, MM, tw[3][20], c1[15], c2[15];

int min(int a, int b){
    return a<b?a:b;
}

int abs(int a){
    return a<0?-a:a;
}

void set(){
    for(int x = 0; x < 15; x++){
        c1[x] = 0;
        c2[x] = 0;
    }
    for(int x = 1; x <= M; x++){
        for(int y = 0; y < 20 && !(c1[x] && c2[x]); y++){
            for(int z = 0; z < 3; z++){
                if( tw[z][y] == x ){
                    c1[x] = z;
                    c2[x] = 2-z;
                    break;
                }
            }
        }
    }
}

int count(int n,int d){
    int a = 1;
    while( n++ < M ) a *= 3;
    return (a-1)*d + d;
}
        
int solve(){
    set();
    int ans1 = 0, ans2 = 0;
    for(int x = 1; x <= M; x++){
        ans1 += count(x, c1[x]);
        if(c1[x] == 1){
            for(int y = x+1; y <= M; y++){
                c1[y] = 2 - c1[y];
            }
        }
        ans2 += count(x, c2[x]);
        if(c2[x] == 1){
            for(int y = x+1; y <= M; y++){
                c2[y] = 2 - c2[y];
            }
        }
    }
    return min(ans1, ans2);
}

int main(){
    cin >> M >> N;
    while( M + N > 0 ){
        for(int i = 0; i < 3; i++){
            int j,k;
            cin >> k;
            for(j = 0; j < k; j++){
                cin >> tw[i][j];
            }
            for(; j < 20; j++){
                tw[i][j] = 0;
            }
        }
        cout << solve() << endl;
        cin >> M >> N;
    }
    return 0;
}

Measured memory_bytes: 1160
require 'pp'

s = gets.chomp.chars


loop do
  if s[-7..-1]&.join == "dreamer"
    7.times do
      s.pop
    end
  elsif s[-5..-1]&.join == "dream"
    5.times do
      s.pop
    end
  elsif s[-5..-1]&.join == "erase"
    5.times do
      s.pop
    end
  elsif s[-6..-1]&.join == "eraser"
    6.times do
      s.pop
    end
  else
    puts "NO"
    exit
  end

  if s.empty?
    puts "YES"
    exit
  end
end


Measured memory_bytes: 12924
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto p = readln.chomp.split.to!(int[]);
  int cnt;
  foreach (i; 0..n) {
    if (p[i] != i + 1) {
      cnt++;
    }
  }
  if (cnt <= 2) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
int main()
{
	ninja
  ll n, k;
      cin >> n >> k;
 
      ll ans = abs(n-k);
      ans = min(ans, abs(ans-k));
      if( n <= k )
      {
            cout << ans;
            return 0;
      }
      else
      {
            ll x = n/k;
            ans = n - x*k;
            ans = abs(ans-k);
            ans = min(ans, abs(ans-k));
            cout << ans ;
      }
      
 }


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;cin>>N;
    vint A(N);rep(i,N)cin>>A[i];
    sort(all(A));
    cout<<A[N-1]-A[0]<<endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<ll> A(N),B(N),C(N);
  for(ll i=0;i<N;++i) cin >> A[i];
  for(ll i=0;i<N;++i) cin >> B[i];
  for(ll i=0;i<N;++i) cin >> C[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  ll ans = 0;
  for(ll i=0;i<N;++i){
    auto itrA = lower_bound(A.begin(),A.end(),B[i]);
    auto itrC = lower_bound(C.begin(),C.end(),B[i]+1);
    ans += (N-distance(itrA,A.end())) * distance(itrC,C.end());
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def fast_pow(num, kata, mod):
        if kata == 0:
            return 0

        res = 1
        while kata > 0:
            if kata & 1 == 1:
                res = res * num % mod
            num = num * num % mod

            kata >>= 1
        return res

    # MODのCombination nがでかくても関係なくrに依存　r<10**6なら回せる
    MOD = 10 ** 9 + 7

    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            res %= MOD
            fac *= i + 1
            fac %= MOD
        return res * fast_pow(fac, MOD - 2, MOD) % MOD

    n, k = ns()

    for i in range(1, k + 1):
        blue_pair = choose(k - i + (i - 1), i - 1)
        red_pair = choose((n - k) + 1, i)
        print(blue_pair * red_pair % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69100
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
bool zorome(int a){
    int x,tmp;
    tmp=a%10;    
    a/=10;
    while(a){
        if(tmp != a%10)return false;
        tmp = a%10;
        a/=10;
    }
    return true;
}
int main(){
    int n;
    cin >> n;
    while(!zorome(n)){
        n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    long long a,b,c,d = 4;
    cin >> a >> b >> c;
    if(d*a*b < (c-a-b)*(c-a-b) && c-a-b>0)
    {
       cout << "Yes" << endl; 
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X=0,Y=0;
  cin>>N;
  vector<int>vecV(N);
  vector<int>vecC(N); 
  for(int i=0;i<N;i++)
    cin>>vecV.at(i);
  for(int i=0;i<N;i++)
    cin>>vecC.at(i);
  for(int i=0;i<N;i++){
    if(vecV.at(i)>vecC.at(i)){
      X+=vecV.at(i);
      Y+=vecC.at(i);
    }else continue;
  }
  cout<<X-Y<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,a,sum=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&a);
		int cnt=0;
		while(a%2==0)
		{
			cnt++;
			a/=2;
		}
		sum+=cnt;
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_e

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/

pair<int,pair<int,int> >in[N];

int dsu[N],sz[N],numVertex[N];

int f(int x) {
  if(x==dsu[x]) {
    return x;
  }
  return dsu[x] = f(dsu[x]);
}
void merge(int x,int y) {
  x = f(x),y = f(y);
  if(x!=y) {
    dsu[y] = x;
    sz[x] += sz[y];
    numVertex[x] += numVertex[y];
  }
  ++numVertex[x];
}

void solve() {
  int n,h,w;
  scanf("%d %d %d ", &n,&h,&w);
  set<int> s;
  for(int i=0;i<n;++i) {
    int r,c,w;
    scanf("%d %d %d ", &r,&c,&w);
    c += h;
    in[i] = {w,{r,c}};
  }
  for(int i=1;i<=w+h;++i) {
    dsu[i] = i,sz[i] = 1,numVertex[i];
  }
  sort(in,in+n);
  reverse(in,in+n);
  int num = 0;
  ll ret = 0;
  for(int i=0;i<n;++i) {
    int x= f(in[i].second.first),y = f(in[i].second.second);
    int numS = 0,numRem;
    if(x!=y) {
      numRem = numVertex[x] + numVertex[y];
      numS = sz[x] + sz[y];
    } else {
      numRem = numVertex[x];
      numS = sz[x];
    }
    if(numRem + 1 <= numS) {
      ret += in[i].first;
      merge(x,y);
    }
  }
  printf("%lld\n", ret);
}

int main() {
    ///freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 4480
#include<stdio.h>
int main(void){
  int N,i,a,b,c,x;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a);
    scanf("%d",&b);
    if(b>a){
      x=a;
      a=b;
      b=x;
    }
    scanf("%d",&c);
    if(a<c){
      x=a;
      a=c;
      c=b;
      b=x;
    }
    if(b<c){
      x=b;
      b=c;
      c=x;
    }
    if(a*a==b*b+c*c)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return(0);
}

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

int main() {
  string s;
  cin >> s;
  bool r = true;
  for (int i = 0; i < s.size(); i++) r &= !(i % 2 == 0 && s[i] == 'L') && !(i % 2 == 1 && s[i] == 'R');
  cout << (r ? "Yes" : "No") << endl;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    int L, R, d;
    cin >> L >> R >> d;

    int x = L/d, y = R/d;
    int xr = L%d, yr = R%d;
    if (xr) {
        ++x;
    }

    if (x > y) {
        cout << 0 << endl;
    } else {
        cout << (y-x+1) << endl;
    }
}

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

using ll = long long;

const int MAXN = 2.1e6;
ll N;
int A[MAXN];

ll M, K, L;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//cin >> N;
	cin >> N >> M;
	//cin >> N >> M >> K;
	//cin >> N >> M >> K >> L;
	//cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; }
	
	ll ans = min(M * !!(N % 3), N * !!(M % 3));
	for (int z = 0; z < 2; z++, swap(N, M)) {
		for (int i = 1; i < N; i++) {
			vector<ll> v({M * i, M / 2 * (N-i), (M - M / 2) * (N-i)});
			sort(v.begin(), v.end());
			ans = min(ans, v[2]-v[0]);
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
int a[51];
bool cmp(const int &a,const int &b)
{
	return a<b;
}

using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		if(n==0) break;
		vector <int> ans;
		for(int i=1;i<=n;i++) cin>>a[i];
		if(n==1) cout<<a[n]<<endl;
		else
		{
			sort(&a[1],&a[n+1],cmp);
			int pre=a[1];
			ans.push_back(pre);
			int t=1;
			for(int i=2;i<=n;i++)
			{
				if(a[i]!=a[i-1]+1)
				{
					ans.push_back(a[i-1]);
					ans.push_back(a[i]);
					if(i==n) {ans.push_back(a[i]);t++;}
					t+=2;
					pre=a[i];
				}
				else if(i==n)
				{
					ans.push_back(a[n]);
					t++;
				}
			}
			//for(int i=0;i<t;i++) cout<<ans[i]<<endl;
			for(int i=0;i<t;i+=2)
			{
				if(i!=t-2){
				if(ans[i]!=ans[i+1]) cout<<ans[i]<<"-"<<ans[i+1]<<" ";
				else cout<<ans[i]<<" ";
			}
			else 
			{
				if(ans[i]!=ans[i+1]) cout<<ans[i]<<"-"<<ans[i+1]<<endl;
				else cout<<ans[i]<<endl;
			}
		}
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
A.sort()
ans = 1
if A[0] == 0:
    print(0)
    exit()
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 22344
//Auuthor:Avdhoot
//Editor:Geany
//Favourite:One Piece
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>

//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t;
    cin>>t;
    string s="";
    for(int i=1;i<=t;i++){
        s=s+"ACL";
    }
    cout<<s <<"\n";
}


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

void _149() {
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

void _148() {
    int a, b;
    cin >> a;
    cin >> b;

    int c = 0;
    if ((a != 1) && (b != 1))
        c = 1;
    else if ((a != 2) && (b != 2))
        c = 2;
    else if ((a != 3) && (b != 3))
        c = 3;
    cout << c << endl;
}

void _147() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
}

void _146() {
    string s;
    cin >> s;

    vector<string> list = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    for (int i = 0; i < list.size(); ++i) {
        if (s == list[i])
            cout << i + 1 << endl;
    }
}

void _145() {
    int r;
    cin >> r;
    cout << pow(r, 2) << endl;
}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define in(n) scanf("%d",&n)
#define pb push_back
#define N 100005
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
vector<vector<int> > ad(N);
int po[20],ar[4*N],lev[N],sp[2*N][20],vp[2*N],fist[N],vis[N];
int C;
void pre()
{
    int i,k;
    ar[1]=0,k=1,po[0]=1;
    while(k<2*N)
    {
        for(i=k+1;i<2*k;i++)
            ar[i]=ar[k];
        ar[2*k]=1+ar[k],k*=2;
    }
    for(i=1;i<20;i++)
        po[i]=2*po[i-1];
        return ;
}
void dfs(int s)
{
    fist[s]=C,vp[C]=s,C++,vis[s]=1;
    int a,i,x=ad[s].size();
    for(i=0;i<x;i++)
    {
        a=ad[s][i];
        if(vis[a]==0)
            lev[a]=lev[s]+1,dfs(a),vp[C]=s,C++;
    }
    return ;
}
void build()
{
    int j,k;
    for(j=C-1;j>=0;j--)
    {
        sp[j][0]=vp[j];
        for(k=1;j+po[k]<=C;k++)
            sp[j][k]=lev[sp[j][k-1]]<lev[sp[j+po[k-1]][k-1]]?sp[j][k-1]:sp[j+po[k-1]][k-1];
    }
    return ;
}
int lca(int u,int v)
{
    int a=fist[u],b=fist[v];
    if(a>b)
        swap(a,b);
    int y,x=b-a+1;
    y=ar[x],x-=po[y];
    return lev[sp[a][y]]<lev[sp[a+x][y]]?sp[a][y]:sp[a+x][y];
}
int dist(int u,int v)
{
    int z=lca(u,v);
    return lev[u]+lev[v]-2*lev[z];
}
int main()
{
    int n,q,i,a,b,x,y;
    in(n);
    in(x),in(y);
    pre();
    for(i=1;i<n;i++)
    {
        in(a),in(b);
        ad[a].pb(b);
        ad[b].pb(a);
    }
    lev[1]=0;
    dfs(1);
    build();
    a=0;
    for(i=1;i<=n;i++)
    {
        if(dist(i,y)>dist(i,x))
            a=max(a,dist(i,y));
    }
    out(a-1);
}


Measured memory_bytes: 28288
n,m = map(int, input().split())
max_l = float("-inf")
min_r = float("inf")
for _ in range(m):
  l,r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
ans = min_r - max_l + 1
if ans > 0:
  print(ans)
else:
  print(0)

Measured memory_bytes: 9144
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    char ch;
    
    while(1){
        scanf("%c", &ch);
        if(ch == '\n')break;
        if('a'<= ch && ch <='z'){
            ch = (ch - 'a') + 'A';
        }else if('A'<= ch && ch <='Z'){
            ch = (ch - 'A') + 'a';
        }
        printf("%c",ch);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> num(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ++num[a], ++num[b];
  }
  rep(i, n)
    cout << num[i] << '\n';
  return 0;
}

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//================================================================//



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=2e5+5;


int main(){
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
    fast

    ll n; cin>>n;
    ll ans = (1000 - n%1000)%1000;
    pt(ans);
}


/*


*/





Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	ll s; cin >> s;
	ll M = 1e9;

	if (s == 1e18) {
		cout << "0 0 " << M << " 0 0 " << M << endl;;
	}
	else {
		cout << "0 0 " << M << " 1 ";
		ll p = (ll)s / M;
		ll r = (ll)s % M;

		cout << M - r << " " << p + 1 << endl;
	}
	return 0;
}

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

int main(){
  int K = 0;
  long long ans = 0;
  cin >> K;
  
  for(int i = 1; i <= K; i++){
    for(int j = 1; j <= K; j++){
      for(int l = 1; l <= K; l++){
        ans += gcd(gcd(i,j),l);
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

const int MAX = 1<<17;
char s[125252], t[125252];

struct seg{
  vi dat;
  seg(char s[125252]){
    dat.assign(2*MAX,0);
    int n = strlen(s);
    REP(i,n)dat[i+MAX-1] = s[i]=='A' ? 1 : 2;
    FORR(i,0,MAX-1){
      dat[i] = (dat[2*i+1] + dat[2*i+2]) % 3;
    }
  }
  int query(int l,int r,int a,int b,int k){
    if(r<=a || b<=l)return 0;
    if(l<=a && b<=r)return dat[k];
    int m = (a+b)/2;
    return (query(l,r,a,m,2*k+1) + query(l,r,m,b,2*k+2)) % 3;
  }
  int query(int l,int r){
    return query(l,r,0,MAX,0);
  }
};

int main(){
  scanf("%s",s);
  scanf("%s",t);
  seg x(s);
  seg y(t);
  int q;
  scanf("%d",&q);
  while(q--){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    --a;--c;
    if(x.query(a,b) == y.query(c,d)){
      puts("YES");
    }else{
      puts("NO");
    }
  }
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<stdio.h>
#include<vector>
#include<stdlib.h>
#include<set>
#include<string>
#include<queue>
#include<map>

#define INF 9999999

using namespace std;

int main(){

	int n, m;
	int a, b, c, t;

	int resultOfCost[110][110] = {0};
	int resultOfTime[110][110] = {0};

	for (;;){
		cin >> n >> m;

		if (n == 0 && m == 0)
			break;

		
		for (int i = 0; i < m; i++){
			for (int j = 0; j < m; j++){
				if (i != j){
					resultOfCost[i][j] = INF;
					resultOfTime[i][j] = INF;
				}
			}
		}
		
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c >> t;
			a--; b--;
			resultOfCost[a][b] = c;
			resultOfCost[b][a] = c;
			resultOfTime[a][b] = t;
			resultOfTime[b][a] = t;
		}

		for (int y = 0; y < m; y++){
			for (int x = 0; x < m; x++){
				for (int z = 0; z < m; z++){
					resultOfCost[x][z] = min(resultOfCost[x][z], resultOfCost[x][y] + resultOfCost[y][z]);
					resultOfTime[x][z] = min(resultOfTime[x][z], resultOfTime[x][y] + resultOfTime[y][z]);
				}
			}
		}

		int k;
		cin >> k;

		int p, q, r;
		for (int i = 0; i < k; i++){
			cin >> p >> q >> r;
			p--; q--;
			if (r == 0){
				cout << resultOfCost[p][q] << endl;
			}
			else{
				cout << resultOfTime[p][q] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	string S;
	cin >> S;

	auto result = 0;
	for (auto i = 0; i < 4; ++i)
	{
		if (S[i] == '+')
		{
			++result;
		}
		else
		{
			--result;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main()
{
    char b[2];
    cin >> b;
    if (strcmp(b, "A") == 0)
        cout << 'T' << endl;
    else if (strcmp(b, "T") == 0)
        cout << 'A' << endl;
    else if (strcmp(b, "C") == 0)
        cout << 'G' << endl;
    else if (strcmp(b, "G") == 0)
        cout << 'C' << endl;
    return 0;
}


Measured memory_bytes: 3500
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

const ll p=1000000007;
ll qp(ll a,ll b){if(!b)return 1;ll w=qp(a,b>>1);w=w*w%p;return b&1?w*a%p:w;}
ll a[100005];
int main()
{
	int n,k;
	cin>>n>>k;
	F(i,1,k) a[i]=qp(k/i,n)%p;
	ll ans=0;
	UF(i,k,1) {F(j,2,k/i) a[i]=(a[i]-a[i*j]+p)%p;ans+=a[i]*i%p;}
	cout<<ans%p<<endl;
	return 0;
}

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

struct edge{
	int to,cost;
};
using graph=vector<vector<edge>>;
graph G;
vector<int> dist;

signed main(){
	int N; cin>>N;
	G.assign(N,vector<edge>(0));

	for(int i=0;i<N-1;i++){
		int a,b,c; cin>>a>>b>>c; a--; b--;
		edge tmp; tmp.to=b; tmp.cost=c;
		G[a].push_back(tmp); tmp.to=a;
		G[b].push_back(tmp);
	}
	dist.assign(N,-1);
	int Q,K; cin>>Q>>K; K--;
	dist[K]=0;
	queue<int> que;
	que.push(K);
	while(!que.empty()){
		int now=que.front();
		que.pop();
		for(auto e : G[now]){
			if(dist[e.to]!=-1)continue;
			dist[e.to]=dist[now]+e.cost;
			que.push(e.to);
		}
	}

	for(int i=0;i<Q;i++){
		int x,y; cin>>x>>y; x--; y--;
		cout<<dist[x]+dist[y]<<endl;
	}

	return 0;

}

Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		StringBuilder sb = new StringBuilder();
		
		String t = sb.append(s).reverse().toString();
		
		
		t = t.replaceAll("resare", "1");
		t = t.replaceAll("esare", "1");
		t = t.replaceAll("remaerd", "1");
		t = t.replaceAll("maerd", "1");
		t = t.replaceAll("1", "");
		
		
		if(t.equals("")){
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 32668
class Node:
    def __init__(self,left,right):
        self.parent = None
        self.left = left
        self.right = right
    
    def __repr__(self):
        return str(self.parent) + ' ' + str(self.left) + ' ' + str(self.right)

class Tree:
    def __init__(self,n):
        self.T = [Node(None,None) for i in range(n)]
    
    def insert(self,key,left,right):
        self.T[key].left = left
        self.T[key].right = right
        if right != -1:
            self.T[right].parent = key
        if left != -1:
            self.T[left].parent = key
    
    def beforePrint(self):
        self.root = None
        for i in range(len(self.T)):
            if self.T[i].parent == None:
                self.root = i
                break
        return self.root

    def printAll(self):
        #print(self.T)
        root = self.beforePrint()
        #print(root)
        print("Preorder")
        self.printPreOrder(root)
        print()
        print("Inorder")
        self.printInOrder(root)
        print()
        print("Postorder")
        self.printPostOrder(root)
        print()

    
    def printPreOrder(self,key):
        if key == None or key == -1:
            return
        print('',key,end='')
        self.printPreOrder(self.T[key].left)
        self.printPreOrder(self.T[key].right)
    
    def printInOrder(self,key):
        if key == None or key == -1:
            return
        self.printInOrder(self.T[key].left)
        print('',key,end='')
        self.printInOrder(self.T[key].right)
    
    def printPostOrder(self,key):
        if key == None or key == -1:
            return
        self.printPostOrder(self.T[key].left)
        self.printPostOrder(self.T[key].right)
        print('',key,end='')

    


N = int(input())
T = Tree(N)
for i in range(N):
    Q = list(map(int,input().split()))
    T.insert(Q[0], Q[1], Q[2])
T.printAll()






Measured memory_bytes: 5624
import sys


class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None

    def preorder(self):
        nodeList = [self.key]
        if self.left:
            nodeList += self.left.preorder()
        if self.right:
            nodeList += self.right.preorder()
        return nodeList

    def inorder(self):
        nodeList = []
        if self.left:
            nodeList += self.left.inorder()
        nodeList += [self.key]
        if self.right:
            nodeList += self.right.inorder()
        return nodeList


class BinaryTree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def print(self):
        print(" " + " ".join(map(str, self.root.inorder())))
        print(" " + " ".join(map(str, self.root.preorder())))


if __name__ == "__main__":
    tree = BinaryTree()
    n = int(sys.stdin.readline())
    for inp in sys.stdin.readlines():
        inp = inp.split()
        if inp[0] == "insert":
            tree.insert(int(inp[1]))
        else:
            tree.print()

Measured memory_bytes: 231872
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[666][666];
signed main(){
  Int n,d1,d2;
  cin>>n>>d1>>d2;

  memset(dp,0,sizeof(dp));
  auto calc=
    [&](Int d,Int x){
      Int k=1;
      while(d%4==0) d/=4,k*=2;
      for(Int a=0;a<n*2;a+=k)
	for(Int b=((d&1)&((a/k)&1))*k;b<n*2;b+=k*2)
	  for(Int i=0;i<k;i++)
	    for(Int j=0;j<k;j++)
	      if(a+i<n*2&&b+j<n*2) dp[a+i][b+j]|=x;
    };
  
  calc(d1,1);
  calc(d2,2);

  Int cnt[4]={};
  for(Int i=0;i<n*2;i++)
    for(Int j=0;j<n*2;j++)
      cnt[dp[i][j]]++;

  for(Int k=0;k<4;k++){
    if(cnt[k]>=n*n){
      Int res=0;
      for(Int i=0;i<n*2;i++){
	for(Int j=0;j<n*2;j++){
	  if(dp[i][j]!=k) continue;
	  cout<<i<<" "<<j<<endl;
	  if(++res==n*n) return 0;
	}
      }
    }
  }
  
  return 0;
}


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

int main(){
    int n,x,i,j,k,c = 0;
    while(1){
        cin >> n >> x;
        int s[n+1][n+1][n+1];
        if (n == 0 && x == 0) break;
        else{
            for (i = 1; i <= n; i++){
                for (j = 1; j <= n; j++){
                    for (k = 1; k <= n; k++){
                        s[i][j][k] = i + j + k;
                        if (j >= k || j == i || k == i){
                            s[i][j][k] = 0;
                        }
                        else if (s[i][j][k] == x){
                            c = c + 1;
                        }
                    }
                }
            }
        }
        cout << c/3 << '\n'; 
        c = 0;
    }
    return 0;
}


Measured memory_bytes: 7068
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

suma = [0] * (n)
sumb = [0] * (m)
suma[0] = a[0]
sumb[0] = b[0]

for i in range(1,n):
    suma[i] = suma[i-1]+a[i]
for j in range(1,m):
    sumb[j] = sumb[j-1]+b[j]
    
suma.insert(0,0)
sumb.insert(0,0)

ans, cur = 0, m
for i in range(n+1):
  target = k - suma[i]
  if target < 0:
      break
  while sumb[cur] > target:
      cur -= 1
  ans = max(ans, i+cur)
print(ans)

Measured memory_bytes: 50312
import sys
n = int(sys.stdin.readline().rstrip("\n"))
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
step = 0
tallest = a[0]
for p in a:
    if p >= tallest:
        tallest = p
    else:
        step += (tallest-p)
print(step)

Measured memory_bytes: 94220
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    d = defaultdict(int)
    ans = 0
    for i in range(n):
        x = i + 1 - a[i]
        ans += d[x]
        d[a[i] + i + 1] += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 151724
N, M, X = gets.chomp.split.map(&:to_i)

s = Array.new(N)
gets.chomp.split.map(&:to_i).each do |n|
  s[n] = true
end

ans = 0
X.upto(N) do |n|
  ans +=1 if s[n]
end

c = 0
X.downto(1) do |n|
  c +=1 if s[n]
end

puts [ans, c].min


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

using namespace std;
#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    deque<char> dq;
    for (auto &c:s)dq.push_back(c);
    int q;
    cin >> q;
    bool rev = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            rev ^= 1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 2) {
                if (rev)dq.push_front(c);
                else dq.push_back(c);
            } else {
                if (!rev)dq.push_front(c);
                else dq.push_back(c);
            }
        }
    }
    if (rev) reverse(dq.begin(), dq.end());
    for (auto &x:dq) cout << x;
    return 0;

}

Measured memory_bytes: 976
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

const yes = "Yes"
const no = "No"

func solve(n int64, hs []int64) bool {
	prev := hs[n - 1]
	for i := n - 1 ; i >= int64(0); i-- {
		if hs[i] > prev + 1 {
			return false
		}
		if hs[i] > prev {
			hs[i] --
		}
		prev = hs[i]
	}
	return true
}

func main() {
	defer out.Flush()

	n := nextInt()
	hs := nextInts(n)
	if solve(n, hs) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 4260
inputs=[]
while True:
  try:
    inputs.append(input())
  except EOFError:
    break

for i in inputs:
  a,c=i.split("=")
  a,b=a.split("+")
  # a+b=c
  for x in range(0,10):
    if x==0:
      if (a[0]=="X" and len(a)>1)or(b[0]=="X" and len(b)>1)or(c[0]=="X" and len(c)>1):
          continue
    A=a.replace("X",str(x))
    B=b.replace("X",str(x))
    C=c.replace("X",str(x))
    if int(A)+int(B)==int(C):
      print(x)
      break
    if x == 9:
      print("NA")

Measured memory_bytes: 7592
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}
*/

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}


void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  int i;


  for(i=0;x != NIL;i++){
    y=x;

    if(z->key < x->key){
      x=x->left;
    }
    else x=x->right;
  }

  z->parent=y;


  if(y==NIL){
    /*
      root=x;
    */
    root=z;
  }

  else if(z->key < y->key) y->left=z;
  else y->right = z;



}






void inorder(Node u){

  if(u != NIL){

    inorder(u->left);

    printf(" %d",u->key);

    inorder(u->right);
  }

}
void preorder(Node u){
  if(u != NIL){

    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);

  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
  
}

Measured memory_bytes: 24040
#include <stdio.h>
#include <string.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int count = 0;
	for (int i = a; i <= b; i++) {
		int num = i;
		int parts[5];
		int j = 0;
		while (num >= 1) {
			parts[j++] = num % 10;
			num = num / 10;
		}
		if (parts[0] == parts[4] && parts[1] == parts[3]) {
			count++;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        var a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        int left = 0;
        int right = 1000000000;
        while(right-left > 1){
            int mid = (left + right) / 2;
            if(b(n, a, mid) <= k){
                right = mid;
            }else{
                left = mid;
            }
        }
    
        System.out.println(right);
    }
    
    static long b(int n, int[] a, int mid){
        
        long l = 0;
        for(int i = 0; i < n; i++){
            l += a[i] / mid;
            if(a[i] % mid == 0) l -= 1;
        }
        return l;
    }
}

Measured memory_bytes: 59940
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int k;
    cin>>k;
    ll sum=0;
    for (int i=1;i<=k;i++){
        for (int j=1;j<=k;j++){
            for (int l=1;l<=k;l++){
                int op=__gcd(i,j);
                op=__gcd(op,l);
                sum+=op;
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3640
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, M, Q = map(int, input().split())
    L = [0]*M
    R = [0]*M
    p = [0]*Q
    q = [0]*Q
    for i in range(M):
        L[i], R[i] = map(int, input().split())
    for i in range(Q):
        p[i], q[i] = map(int, input().split())

    temp = [[0]*N for _ in range(N)]
    #s[i][j]: 左がi、右が0からjまでのものの累積個数
    s = [[0]*(N+1) for _ in range(N)]
    for m in range(M):
        temp[L[m]-1][R[m]-1] += 1
    for i in range(N):
        for j in range(N):
            s[i][j+1] = s[i][j] + temp[i][j]

    for i in range(Q):
        ans = 0
        for j in range(p[i]-1, q[i]):
            ans += s[j][q[i]]-s[j][p[i]-1]
        print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 58332
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
		//変数
		ArrayList<Integer> cards = new ArrayList<>();	//カードの格納
		int n = -1;																//カードの枚数
		int r = -1;																//シャッフルの回数
		Scanner sc = new Scanner(System.in);						//標準入力
		
		while (true){
			//カードの枚数と、シャッフルの回数を読み取り
			n = sc.nextInt();
			r = sc.nextInt();
		
			//終了条件の判定
			if (n == 0 && r == 0){
				break;	
			}
			
			//データの初期化
			for (int i = 1; i <= n; i++){
				cards.add(i);
			}
		
			//データのシャッフル
			for (int i = 0; i < r; i++){
				int end = n - sc.nextInt();
				int start = end - (sc.nextInt() - 1);
				cards = shuffle(cards, start, end);
			}
		
			System.out.println(cards.get(n - 1));
			
			//カード情報の削除
			cards.clear();
		}
	}
	
	private static ArrayList<Integer> shuffle(ArrayList<Integer> cards,int start, int end){
		for (int i = start; i <= end; i++){
			int temp = cards.get(start);
			cards.remove(start);
			cards.add(temp);
		}
		return cards;
	}
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;

	vector <int> p(n);

	for(int i = 0; i < n; i++){
		cin >> p[i];
	}

	sort(p.rbegin(), p.rend());



	cout << p[0] / 2 + accumulate(next(p.begin()), p.end(), 0) << endl;



	return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    string s; cin >> s;
    cout << ((s[0] == s[2]) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
bool hs[10][10];
bool used[10][10];
int cx,cy;
int nh;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int w,h;
int dfs(int x,int y,int f){
	if(f==nh){
		if(x==cx||y==cy)return 1;
		return 0;
	}
	int i,j;
	int res=0;
	for(i=0;i<4;i++){
		for(j=1;j<10;j++){
			int nx=x+j*dx[i];
			int ny=y+j*dy[i];
			if(nx<0||nx>=h||ny<0||ny>=w)break;
			if(hs[nx][ny]){
				if(!used[nx][ny]){
					used[nx][ny]=true;
					res+=dfs(nx,ny,f+1);
					used[nx][ny]=false;
					break;
				}
			}
		}
	}
	return res;
}
int main(){
	while(1){
	int i,j;
	scanf("%d %d",&w,&h);
	if(w==0)return 0;
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		hs[i][j]=false;
		used[i][j]=false;
	}
	nh=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			char c;
			scanf(" %c",&c);
			if(c=='1'){
				hs[i][j]=true;
				used[i][j]=false;
				nh++;
			}
			if(c=='2'){cx=i;cy=j;}
		}
	}
	printf("%d\n",dfs(cx,cy,0));
	}
}

Measured memory_bytes: 1028