akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)

template<typename T>
struct Fenwick {
    std::vector<T> data;
    Fenwick(int sz=1e5): data(sz+1, 0) {}

    void add(int idx, T x){
		idx++;
		while(idx<data.size()){
	    	data[idx] += x;
	    	idx += idx & -idx;
		}
    }

	T __sum(int r){
		T ret = 0;
		while(r>0){
			ret += data[r];
			r -= r & -r;
		}
		return ret;
	}

	T sum(int l, int r){
		return __sum(r+1) - __sum(l);
	}

};


int main(){
	int n, q;
	scanf("%d %d", &n, &q);
	Fenwick<ll> bit(n);
	REP(i, 0, n){
		ll a;
		scanf("%ld", &a);
		bit.add(i, a);
	}

	REP(i, 0, q){
		ll t, x, y;
		scanf("%ld %ld %ld", &t, &x, &y);
		if(t==0) bit.add(x, y);
		else printf("%ld\n", bit.sum(x, y-1));
	}
	return 0;
}



Measured memory_bytes: 8232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No\n";
        return 0;
    }
    if (N == 2) {
        cout << "Yes\n1\n2\n3\n";
        return 0;
    }
    vector<int> ans(2 * N - 1);
    if (x == 2) {
        int cnt = 1;
        rep(i, 2 * N - 1) {
            if (i == N - 3) {
                ans[i] = 3;
            } else if (i == N - 2) {
                ans[i] = 1;
            } else if (i == N - 1) {
                ans[i] = 2;
            } else if (i == N) {
                ans[i] = 4;
            } else if (i == N + 1) {
                ans[i] = 5;
            } else {
                while (cnt == 1 || cnt == 2 || cnt == 3 || cnt == 4 || cnt == 5) ++cnt;
                ans[i] = cnt;
                ++cnt;
            }
        }
    } else {
        int cnt = 1;
        rep(i, 2 * N - 1) {
            if (i == N - 3) {
                ans[i] = x - 1;
            } else if (i == N - 2) {
                ans[i] = x + 1;
            } else if (i == N - 1) {
                ans[i] = x;
            } else if (i == N) {
                ans[i] = x - 2;
            } else {
                while (cnt == x - 1 || cnt == x + 1 || cnt == x || cnt == x - 2) ++cnt;
                ans[i] = cnt;
                ++cnt;
            }
        }
    }
    cout << "Yes\n";
    rep(i, 2 * N - 1) cout << ans[i] << "\n";
    return 0;
}


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

int a[1010];
int n, m;
int main(){
  while(true){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    for(int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < n; i++){
      for (int j = i + 1; j < n; j++){
        tmp = a[i] + a[j];
        if(tmp <= m){
          ans = max(ans, tmp);
        }
      }
    }
    if(ans == 0){
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
}



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

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int a = n / x;
    if(n%x!=0) a++;
    cout << a*t << endl;
}

Measured memory_bytes: 3632
n = int(input())
s = input()
#アルファベットとすうじを対応させる辞書
dic = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,\
       'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
dic_items = {0:'A',1:'B',2:'C',3:'D',4:'E',5:'F',6:'G',7:'H',8:'I',9:'J',10:'K'\
             ,11:'L',12:'M',13:'N',14:'O',15:'P',16:'Q',17:'R',18:'S'
             ,19:'T',20:'U',21:'V',22:'W',23:'X',24:'Y',25:'Z'}
ans =""
for i in range(len(s)):
  ans += dic_items[(dic[s[i]]+n)%26]
print(ans)

Measured memory_bytes: 9212
string = input()
 
n = int(input())
 
for i in range(n):
    command = input().split()
    c_n = command[0]
    c_i1 = int(command[1])
    c_i2 = int(command[2]) + 1
    if c_n == "print":
        print(string[c_i1:c_i2])
    elif c_n == "reverse":
        string = string[:c_i1] + string[c_i1:c_i2][::-1] + string[c_i2:]
    else:
        string = string[:c_i1] + command[3] + string[c_i2:]

Measured memory_bytes: 7692
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

if N == 1:
  print(1)
  exit()

import math
def prime(x):
  p = {}
  cnt = 2
  Flag = True
  while Flag:
    last = math.ceil(x ** 0.5) 
    if cnt > last:
      break
    for i in range(cnt, last + 1):
      if x % i == 0:
        x //= i
        p[i] = 1
        cnt = i + 2
        while x % i == 0:
          x //= i
          p[i] += 1
        cnt = i + 1
        break
      if i == last:
        Flag = False
  if x != 1:
    p[x] = 1
  return p


class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L

p = prime(A[0])

for i in range(1, N):
  q = prime(A[i])
  for n in q:
    if n in p:
      p[n] = max(p[n], q[n])
    else:
      p[n] = q[n]

inv = Inv(MOD)
t = 1
for n in p:
  t = t * inv.modpow(n, p[n]) % MOD

ans = 0
for i in range(N):
  ans = (ans + t * inv.invx(A[i])) % MOD
print(ans)


Measured memory_bytes: 53980
import math
def main():
    a, b = map(int, input().split())
    ra = [math.ceil(i/0.08) for i in range(1, 102)]
    rb = [math.ceil(i/0.1) for i in range(1, 102)]
    x = ra[a-1] 
    while x < ra[a] :
        if int(x*0.1) == b:
            return x
        x+=1
    return -1



if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3064
N, P = map(int, input().split())

from collections import defaultdict
d = defaultdict(int)
i = 2
while P >= i*i:
    if P%i==0:
        P //= i
        d[i] += 1
    elif i == 2:
        i += 1
    else:
        i += 2
if P != 1:
    d[P] += 1

ans = 1
for k, v in d.items():
    # print(k, v)
    z = v // N
    ans *= k**z
print(ans)


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

int main() {
  int N, K;
  cin >> N >> K;
  
  int total = 0;
  int i = 0;
  while(i < N){
    int x;
    cin >> x;
    if (x > abs(K - x)) {
      total += abs(K - x) * 2;
    } else {
      total += x * 2;
    }
    i++;
  }
  cout << total << endl;
}


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


typedef long long ll;

#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define binary(n) cout << bitset<31>(n) << "\n";
#define FOR(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define input_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print_arr(a, n)         \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";
#define deb(n) cerr << #n << "=" << n << "\n";

const int MS = 2e6 + 5, mod = 1e9 + 7;

ll fact[MS];

// calculating factorial 
void cal_fact()
{
    fact[0] = 1;
    for (int i = 1; i < MS; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= mod;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg, ll mod)
{
    if (!deg)
        return 1 % mod;
    if (deg & 1)
        return binpow(val, deg - 1, mod) * val % mod;
    ll res = binpow(val, deg >> 1, mod);
    return (res * res) % mod;
}

ll cal_c(ll n, ll i)
{
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= mod;
    // using fermat little theorum
    div = binpow(div, mod - 2, mod); // modular inverse  
    return (res * div) % mod; 
}

int main()
{
    cal_fact();
    ll n, k;
    cin >> k;
    string s;
    cin >> s;
    n = s.size();

    ll ans = 0;
    for (int i = n; i <= n + k; i++)
    {
        ans+=cal_c(n+k,i)*binpow(25,n+k-i,mod);
        ans%=mod;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 20940
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;
    
    //累積和
    vector<int> s(N+1, 0);
    for(int i = 0; i < N; ++i) {
        if(str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }
    
    //クエリ
    for(int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        --l, --r;
        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 1536
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a > 0 {
		fmt.Println("Positive")
		return
	}

	if a == 0 || b == 0 {
		fmt.Println("Zero")
		return
	}

	if a < 0 && 0 < b {
		fmt.Println("Zero")
		return
	}

	if (b - a) % 2 == 0 {
		fmt.Println("Negative")
	} else {
		fmt.Println("Positive")
	}
}


Measured memory_bytes: 512
#![allow(non_snake_case)]
 
use std::collections::*;
use std::io::prelude::*;
 
pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}
 
macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}
 
macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}
 
pub fn main() {
	let (x, y, z) = read!(u8, u8, u8);
	println!("{} {} {}", z, x, y);
}
 

Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str != "-"){
    cin >> m;
    for(i = 0;i < m; i++){
      cin >> b;
      str=str.substr(b, str.size()-b)+str.substr(0, b);
    }
    cout << str << endl;
    cin >> str;
  }
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
long long x,y,ans,sum;
int main()
{
    cin>>x>>y;
    ans=((long long)(y/x));
    while(ans>=1)
    {
        ans/=2;
        sum++;
    }
    cout<<sum<<endl;
    return 0;
}

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

int main() {
  string a;
  cin>>a;
  int b=0;
  for(int i=0;i<a.size();i++){
    if(a[i]=='7')b++;
  }
  if(b==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
    int w,sum=0;
    while(true){
        cin >> w;;
        if(w == -1)break;
        sum = 1150;
        if(w > 10){
            sum += 125*(min(10,w-10));
        }
        if(w > 20){
            sum += 140*(min(10,w-20));
        }
        if(w > 30){
            sum += 160*(w-30);
        }
        cout << 4280-sum << endl;
 
    }
 
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UP(a,b,i) for(int i=(a);i<=(b);i++)
#define DOWN(a,b,i) for(int i=(a);i>=(b);i--)
#define rep(a,b,i) UP(a,b-1,i)
#define I(n) cin>>n;
#define O(n) cout<<n;
#define Enter() cout<<'\n';
ll n,z;
int main()
{
	I(n);z=1;
	for(int i=1;;i++)
	{
		z*=2;
		if(z>n)break;;
	}
	O(z/2);
	Enter();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int rf = -2,lf = -1;
    REP(i,S.size()){
        if(S[i] == 'R'&&lf > rf){
            if(i == 0){
                rf = 0;
                continue;
                }
            REP(l,lf-rf - 1){
                cout << 0 << "\n";
            }
            cout << (i-lf)/2 + (lf - rf)/2 + (lf - rf)%2 << "\n";
            cout << (i-lf)/2 + (lf - rf)/2 + (i-lf)%2 << "\n";
            REP(l,i-lf - 1){
                cout << 0 << "\n";
            }
            rf = i;
        }
        if(S[i] == 'L'&&rf > lf){
            lf = i;
        }
    }
            REP(l,lf-rf - 1){
                cout << 0 << "\n";
            }
            cout << (S.size() -lf)/2 + (lf - rf)/2 + (lf - rf)%2 << "\n";
            cout << (S.size()-lf)/2 + (lf - rf)/2 + (S.size()-lf)%2 << "\n";
            REP(l,S.size()-lf - 1){
                cout << 0 << "\n";
            }
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

int main(){
        int n;
        scanf("%d", &n);
        int a[n];
        rep(i, n) scanf("%d", &a[i]);
        sort(a, a+n);
        vector<pii> ans;
        int m=a[0], M=a[n-1];
        For(i, 1, n-1){
                if(a[i]>0){
                        ans.emplace_back(m, a[i]);
                        m-=a[i];
                }
                else{
                        ans.emplace_back(M, a[i]);
                        M-=a[i];
                }
        }
        ans.emplace_back(M, m);
        printf("%d\n", M-m);
        for(pii p: ans) printf("%d %d\n", p.fi, p.se);
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int N,W;
    scanf("%d%d",&N,&W);
    vector<ll> dp(W+1);
    for(int i=1;i<=N;++i){
        int weight,value;
        scanf("%d%d",&weight,&value);
        for(int w=W; w>=weight;--w){
            dp[w]=max(dp[w],dp[w-weight]+value);
        }
    }
    ll ans=0;
    for(int i=0;i<=W;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<'\n';
    //while(1);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define int long long
#define endl "\n"
 
 
 
signed main()
{
    FAST;
    int t;
    t=1;
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>n>>m>>k;
        int a[n] , b[m];
        int prefa[n+1] , prefb[m+1];
        prefa[0]=0;
        prefb[0]=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            prefa[i+1] = prefa[i] + a[i];
        }
        
        for(j=0;j<m;j++)
        {
            cin>>b[j];
            prefb[j+1] = prefb[j] + b[j];
        }
        
        start = 0;
        end = m;
        //cout<<prefb[end]<<endl;
        while(1)
        {
            
            if(prefa[start] + prefb[end] <=k )
            {
                ans = max(ans , start+end);
                //cout<<start<<" "<<end<<endl;
                start++;
                if(start==n+1) break;
            }
            
            else if(end!=0)
            {
                end--;
            }
            
            else if(start!=n)
            {
                start++;
            }
            
            else break;
        }
        
        cout<<ans<<endl;
    
    
        
    }
        
    
    
    
    
}

Measured memory_bytes: 9904
#include <cstdio>
int main ()
{	int n;
	scanf("%d",&n);
	int l[100005],r[100005];
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		scanf("%d%d",&l[i],&r[i]);
		for (int i = 1; i <= n; i++)
		{
			for (int j = l[i]; j <= r[i]; j++)
				cnt++;
			}
			printf("%d",cnt);


	}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef unsigned long long ULL;
typedef long long ll;

int n;

struct node{
    double x,y;
    char dir[4];
}A[100050];

double cal(double x){
    double ml=1e10,mr=-1e10,mu=-1e10,md=1e10;
    FOR(i,1,n){
        pair<double,double>tmp;
        tmp.first=A[i].x,tmp.second=A[i].y;
        switch(A[i].dir[0]){
            case 'U':tmp.second+=x;break;
            case 'D':tmp.second-=x;break;
            case 'L':tmp.first-=x;break;
            case 'R':tmp.first+=x;break;
        }
        ml=min(ml,tmp.first);
        mr=max(mr,tmp.first);
        mu=max(mu,tmp.second);
        md=min(md,tmp.second);
    }
    //cout<<x<<" "<<(mr-ml)*(mu-md)<<endl;
    return (mr-ml)*(mu-md);
}

int main(){
    cin>>n;
    FOR(i,1,n){
        scanf("%lf%lf%s",&A[i].x,&A[i].y,A[i].dir);
    }
    double l=0,r=1e12,ans=1e18;
    FOR(k,0,300){
        double m1=(l+(r-l)/3),m2=(l+(r-l)*2/3);
        double tmp1=cal(m1),tmp2=cal(m2);
        if(tmp1>tmp2)l=m1;
        else r=m2;
        ans=min(ans,tmp1);
        ans=min(ans,tmp2);
    }
    printf("%.10f",ans);
}


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

int main() {
  long long n;
  cin>>n;
  if (n % 2 == 1) {
    cout<<0<<endl;
    return 0;
  }
  long long ans = 0;
  while (n > 0) {
    ans += n / 10;
    n /= 5;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		if (n == 1) {
			System.out.println("Hello World");
		} else {
			System.out.println(scanner.nextInt() + scanner.nextInt());
		}
		scanner.close();
	}
}

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

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define ll long long
#define vi vector <int>
#define pb push_back
using namespace std;

#define bs 1000000007

int tests;
map<int,int> mapp;
int n;
vector<int> order;
map<int,int> ::iterator it;

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

    ll n1;cin>>n1;
    cout<<3.14*2*n1<<endl;

}



Measured memory_bytes: 3800
#include <iostream>
using namespace std;
typedef long long ll;
ll K,N,inf = 998244353;
ll func[4010] = {0};
ll inv[4010] = {0};

ll mult(ll n, ll m){
	if(n==0 || m==0) return 1;
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(n<k || n<0 || k<0) return 0;
//	if(k==0 || n==k) return 1;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll hcomb(ll n,ll k){
	if(n==0 && k==0) return 1;
	return comb(n+k-1,k);
}

int main(){
	cin >> K >> N;
	factorial(4000);
	for(ll i=2;i<=2*K;i++){
		ll ans = 0;
		ll n = min(i,(2*K+2-i))/2;
		if(i%2==1){
			for(ll j=0;j<=n;j++){
				ans = (ans+(j%2==0? 1:-1)*hcomb(K,N-2*j)*comb(n,j))%inf;
			}
		}else{
			n--;
			for(ll j=0;j<=n;j++){
				ll t = (hcomb(K-1,N-2*j)+hcomb(K-1,N-2*j-1))%inf;
				ans = (ans+(j%2==0? 1:-1)*t*comb(n,j))%inf;
			}
		}
//		ans = (hcomb(K,N)-ans);
		cout << (ans+inf)%inf << endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC")
    cout<<"ARC";
    else
    cout<<"ABC";
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    rep(i,n){
        cin>>v[i];
    }
    int a=1;
    rep(i,n){
        if(v[i]==a){
            a++;
        }
    }
    if(a==1){
        cout<<-1<<endl;
    }else{
    cout<<n-(a-1)<<endl;}







return 0;
}


Measured memory_bytes: 1792
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ab_total_list = []
total_list = []

A.sort()
A.reverse()
if len(A) > K:
    A = A[0:K+1]

B.sort()
B.reverse()
if len(B) > K:
    B = B[0:K+1]

C.sort()
C.reverse()
if len(C) > K:
    C = C[0:K+1]

ab_total_list = []
for i in A:
    for j in B:
        ab_total_list.append(i+j)

ab_total_list.sort()
ab_total_list.reverse()
if len(ab_total_list) > K:
    ab_total_list = ab_total_list[0:K+1]

for i in range(0, K):
    for j in range(0, int(K/(i+1))):
        if j >= len(C) or i >= len(ab_total_list):
            break
        total = ab_total_list[i] + C[j]
        total_list.append(total)
        if (i*j) > K:
            break

total_list.sort()
total_list.reverse()
for i in range(0, K):
    print(total_list[i])

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

int D, G;
int p[20], c[20];

int N, A, B, C, ans = 2e9;
vector<int> l(10, -1);

void calc(vector<int> v) {
    int sum=0;
    int tmp=0;
    for(int i=0; i<D; i++){
    	if(v[i] == 0){
    	}
    	else if(v[i] == 1){
    	    sum += 100*(i+1)*p[i]+c[i];
    	    tmp+=p[i];
    	}
    	else{
    	    cout << "error"<<endl;
    	}	
    }
    int flag=0;
    for(int i=D-1; i>=0; i--){
    	if(v[i]==0){
    	    for(int j=0; j<p[i]-1; j++){
    		flag=1;
    		if(sum < G){
    		    sum += 100*(i+1);
    		    tmp++;
    		}	  
    	    }
    	}
    	if(flag==1)
    	    break;
    }
    
    if(sum >= G)
    	ans = min(ans, tmp);    
}

void DFS(int depth, vector<int> v) {    
    if(depth == D){
	calc(v);
	return;
    }    
    for(int i=0; i<2; i++){
	v[depth] = i;
	DFS(depth+1, v);	
    }
}

int main(){
    cin >> D >> G;
  
    for(int i=0; i<D; i++)
	cin >> p[i] >> c[i];
    vector<int> v(11);    
    DFS(0, v);			    
    cout << ans << "\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
	int aux;
	if(a < b){
		aux = b;
		b = a;
		a = aux;
	}
	if(a % b == 0)
		return b;
	else
		return gcd(b, (a%b));
}

int main() {
	int k;
	int dp[201][201]; memset(dp, -1, sizeof(dp));
	while(cin >> k) {
		long long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int w = 1; w <= k; w++) {
					if(dp[j][w] == -1) {
						dp[j][w] = gcd(j, w);
					}
					if(dp[i][dp[j][w]] == -1) {
						dp[i][dp[j][w]] = gcd(i, dp[j][w]);
					}
					sum += dp[i][dp[j][w]];
				}
			}
		}
		cout << sum << endl;
	}
	return 0;	
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template<typename T> T DUP(T x, T y) { return (x + y - 1) / y; };
template <typename A, size_t N, typename T>
void arrayFill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main() {
    int n;
    cin >> n;
    vint l(n);
    rep(i, n)cin >> l[i];

    sort(ALL(l));
    ll ans = 0;
    rep(i, n) {
        REP(j, i + 1, n) {
            int mi = abs(l[i] - l[j]);
            int ma = l[i] + l[j];

            auto min_itr = upper_bound(l.begin() + j, l.end(), mi);
            auto max_itr = lower_bound(l.begin() + j, l.end(), ma) - 1;

            ans += max_itr - min_itr;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int parent,left,right;};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u , int d) {
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].right,d + 1);
    setDepth(T[u].left,d + 1);
}

int setHeight(int u) {
    int h1 = 0,h2 = 0;
    if(T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL) 
    h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
    return NIL;
}

void print(int i) {
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", " ;
    cout << "sibling = " << getSibling(i) << ", ";
    int degree = 0;
    if(T[i].right != NIL) degree++;
    if(T[i].left != NIL) degree++;
    cout << "degree = " << degree << ", ";
    cout << "depth = " << D[i] << ", ";

    cout << "height = " << H[i] << ", ";

    if(T[i].parent == NIL) cout << "root";
    else if(T[i].left == NIL && T[i].right == NIL) cout << "leaf";
    else cout << "internal node";

    // cout << '[';
    // for(int j = 0,c = T[i].left;c != NIL;j++,c = T[c].right) {
    //     if(j) cout << ", ";
    //     cout << c;
    // }
    // cout << ']';
}

int main() {
   int N,id,l,r;
   cin >> N;

    for(int i = 0; i < N; i++) {
        T[i].parent = NIL;
    }

    for(int i = 0; i < N;i++) {
        cin >> id >> l >> r;
        T[id].left = l;
        T[id].right = r;
        if(l != NIL)T[l].parent = id;
        if(r != NIL)T[r].parent = id;
    }


    for(int i = 0; i < N;i++) {
        if(T[i].parent == NIL) r = i;
    }

    setDepth(r,0);
    setHeight(r);

    for(int i = 0; i < N; i++) {
        print(i);
        cout << endl;
    }

}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <queue>


struct Dist {
    int target;
    int dist;
};


int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<Dist>> g(n);
    for (int i = 0; i < m; ++i) {
        int l, r, d;
        std::cin >> l >> r >> d;
        --l;
        --r;
        Dist dist;
        dist.target = r;
        dist.dist = d;
        g[l].push_back(dist);

        dist.target = l;
        dist.dist = -d;
        g[r].push_back(dist);
    }

    std::vector<bool> used(n);
    std::vector<int> d (n);
    for (int i = 0; i < n; ++i) {
        used[i] = false;
        d[i] = 0;
    }

    for (int s = 0; s < n; ++s) {
        if (used[s]) { continue; }

        if (g[s].size() == 0) { continue; }

        d[s] = 0;
        std::queue<int> q;
        q.push (s);
        used[s] = true;
//        std::cout << "s = " << s + 1 << "\n";
        while (!q.empty()) {
            int v = q.front();
//            std::cout << "v = " << v + 1 << "\n";
            q.pop();
            for (size_t i = 0; i < g[v].size(); ++i) {
                auto to = g[v][i];
//                std::cout << "to: " << to.target + 1 << " " << to.dist << "\n";
                if (used[to.target]) {
                    if (d[v] + to.dist != d[to.target]) {
//                        for (int j = 0; j < n; ++j) {
//                            std::cout << d[j] << " ";
//                        }
//                        std::cout << "\n";

                        std::cout << "No";
                        return 0;
                    }
                } else {
                    used[to.target] = true;
                    q.push (to.target);
                    d[to.target] = d[v] + to.dist;
                }
            }
        }
    }

    std::cout << "Yes";

    return 0;
}

Measured memory_bytes: 9344
def judge_game_set(game_num):
    a_point, b_point = 0, 0
    for _ in range(game_num):
        a_point, b_point = judge_game(a_point, b_point)
    print(a_point, b_point, sep=' ')

def judge_game(a_point, b_point):
    a_card, b_card = map(int, input().split(' '))

    if a_card > b_card:
        a_point += (a_card + b_card)
    elif a_card < b_card:
        b_point += (a_card + b_card)
    else:
        a_point += a_card
        b_point += b_card

    return a_point, b_point

def judge_game_sets():
    game_num = int(input())
    while game_num != 0:
        judge_game_set(game_num)
        game_num = int(input())

if __name__ == '__main__':
    judge_game_sets()



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int X;
  cin >> X;

  if(X < 600) cout << 8 << endl;
  else if(X < 800) cout << 7 << endl;
  else if(X < 1000) cout << 6 << endl;
  else if(X < 1200) cout << 5 << endl;
  else if(X < 1400) cout << 4 << endl;
  else if(X < 1600) cout << 3 << endl;
  else if(X < 1800) cout << 2 << endl;
  else if(X < 2000) cout << 1 << endl;

  return 0;
}




Measured memory_bytes: 3620
f=lambda:map(int,input().split());n,m=f();g=[[] for _ in range(n)]
for _ in [0]*m:a,b=f();g[a-1]+=[b-1];g[b-1]+=[a-1]
p=[0]*n;from collections import*;q=deque([0])
while q:
    for c in g[(v:=q.popleft())]:
        if p[c]<1:p[c]=v+1;q.append(c)
print('Yes',*p[1:],sep='\n')

Measured memory_bytes: 39384
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False

def ddprint(x):
  if DBG:
    print(x)

a = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
s = input().strip()
print(a[s])


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

int compar(const int *val1, const int *val2) {//降順並び替え
    if ( *val1 > *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
  qsort(a, n, sizeof(int),(int (*)(const void *, const void *))compar);
  int check = 0,answer = 0;
  for(int i = 0; i < n; ++i){
    if(check == 0) answer += a[i];//Alice
    else answer -= a[i];
    check = 1 - check;
  }
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
s = [input() for i in range(h)]
ans=[[0 for i in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            ans[i][j]='#'
            if i>0:
                try:
                    ans[i-1][j]+=1
                except:
                    pass
                try:
                    ans[i-1][j+1]+=1
                except:
                    pass
                if j>0:
                    try:
                        ans[i-1][j-1]+=1
                    except:
                        pass
            try:
                ans[i+1][j]+=1
            except:
                pass
            try:
                ans[i+1][j+1]+=1
            except:
                pass
            if j>0:
                try:
                    ans[i+1][j-1]+=1
                except:
                    pass
            try:
                ans[i][j+1]+=1
            except:
                pass
            if j>0:
                try:
                    ans[i][j-1]+=1
                except:
                    pass
for x in ans:
    y = list(map(str, x))
    print(''.join(y))

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

#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int N,X;
	X = 0;
	string S;
	cin >> N >> S;
	rep(i, N) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
			X++;
	}
	cout << X;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int X,Y,x,y,r;
	int check=0;
	cin>>X>>Y>>x>>y>>r;
	if(y>Y){
		check=1;
	}
	else if(x>X){
		check=1;
	}
	else if(0>x){
		check=1;
	}
	else if(0>y){
		check=1;
	}
	else if(x-r<0){
		check=1;
	}
	else if(y-r<0){
		check=1;
	}
	else if(x+r>X){
		check=1;
	}
	else if(y+r>Y){
		check=1;
	}
	if(check==1){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
    // 計算量短縮のためのメモ化
    vector<int> d;
    // 最初は全て親で初期化
    // 親だけは負の値でサイズ管理
    // 正の値は親のindexを返す
    UnionFind(int n): d(n, -1) {}

    // グループIDを返す関数
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    // 結合処理
    bool unite(int x, int y) {
        // 親同士を結合
        x = find(x); y = find(y);
        // 同じグループだったら何もしない
        if (x == y) return false;
        // 小さい方(負の値なので、つまりサイズが大きい方)に結合
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    // 同じグループか確認する関数
    bool same(int x, int y) { return find(x) == find(y); }
    // グループサイズを返す関数
    int size(int x) { return -d[find(x)]; }
};

int deg[100005];
vector<int> block[100005];

int main() {
    int n, m, k; cin >> n >> m >> k;
    UnionFind uf(n);
    // 友達関係
    rep(i, m) {
        int a,b; cin >> a >> b;
        --a; --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    // ブロック関係
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        block[a].push_back(b);
        block[b].push_back(a);
    }
    rep(i, n) {
        int ans = uf.size(i)-1-deg[i];
        for (int u : block[i]) {
            if (uf.same(i,u)) --ans;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 998244353;

long long power(int x){
    long long ret=1;
    for(int i=0; i<x; i++){
        ret*=3;
        ret%=MOD;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<int> a(N,0);
    vector<int> sumA(N+1,0);
    for(int i=0; i<N; i++){
        cin >> a[i];
        sumA[i+1]=sumA[i]+a[i];
    }
    vector<vector<long long> > dp(301,vector<long long>(90001,0));
    dp[0][0]=1;
    long long ans =0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=min(sumA[N]/2,sumA[i]); j++){
            int tmp=j+a[i];
            if(j==sumA[N]/2 and sumA[N]%2==0)continue;
            (dp[i+1][tmp]+=dp[i][j])%=MOD;
            (dp[i+1][j]+=2*dp[i][j])%=MOD;
            if(tmp>sumA[N]/2){
                ans+=dp[i+1][tmp]*power(N-i-1);
                ans%=MOD;
            }else if(sumA[N]%2==0 and tmp==sumA[N]/2){
                ans+=dp[i+1][tmp]*power(N-i-1);
                ans%=MOD;
            }
        }
    }

    if(sumA[N]%2==1){
        ans*=3;
        ans%=MOD;
        ans=power(N)-ans;
        ans%=MOD;
        if(ans<0){
            ans+=MOD;
        }
        cout << ans << endl;
        return 0;
    }

    vector<vector<long long> > dp2(301,vector<long long>(90001,0));
    dp2[0][0]=1;
    for(int i=0; i<N; i++){
        for(int j=0; j<=min(sumA[N]/2,sumA[i]); j++){
            int tmp=j+a[i];
            (dp2[i+1][tmp]+=dp2[i][j])%=MOD;
            (dp2[i+1][j]+=dp2[i][j])%=MOD;
            if(tmp==sumA[N]/2){
                ans-=dp2[i+1][tmp];
                ans%=MOD;
            }
        }
    }

    ans*=3;
    ans%=MOD;
    ans=power(N)-ans;
    ans%=MOD;
    if(ans<0){
        ans+=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 424512
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(long long i=a;i<=(b);++i)
#define dF(i,a,b) for(long long i=a;i>=(b);--i) 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e3+10; 
const int N = 1e5+10;
const int E = 1e6+10;  
ll n,k,p,m;
ll a[maxn];

int main(){
	cin>>n;
	n%=1000;
	if(n) n = 1000-n;
	cout<<n<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;
 
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.first< right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.second < right.second;
}
 
void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}
 
lli gcd(lli a, lli b){
    if(a < b)return gcd(b, a);
    lli temp;
    while((temp = a%b)){
        a=b;
        b=temp;
    }
    return b;
}

struct nCr{
  vector<lli> f, rf;
  lli count=0;
  nCr(lli num): f(num), rf(num){
      count = num;
      f[0] = 1;
      rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
      rep0(i, num+1) rf[i] = inv(f[i]);
  }
    
  lli inv(lli x) {
      lli res = 1;
      lli k = MOD - 2;
      lli y = x;
      while (k) {
          if (k & 1) res = (res * y) % MOD;
          y = (y * y) % MOD;
          k /= 2;
      }
      return res;
  }
  lli C(lli n, lli k) {
      lli a = f[n];
      lli b = rf[n-k];
      lli c = rf[k];
   
      lli bc = (b * c) % MOD;
   
      return (a * bc) % MOD;
  }
};

struct UF{
    vector<int> par,size;

    UF(int N) : par(N), size(N, 1){
        rep0(i,N)par[i] = i;
    }

    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        size[rx] += size[ry];
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getSize(int x){
        return size[x];
    }
};
int main(){
  lli n;
  cin >> n;
  lli N=n, n2=n-1;
  map<lli,lli> m2;
  set<lli> m;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      m.insert(i);
      m.insert(n/i);
    }
  }
  for(int i=2;i<=sqrt(n2)+1;i++){
    while(n2%i==0){
      n2/=i;
      m2[i]++;
    }
  }
  if(n2>1)m2[n2]++;
  lli ans=0,ans2=1;
  for(auto e: m){
    n=N;
    if(e==1)continue;
    while(n%e==0)n/=e;
    if(n%e==1)ans++;
  }
  for(auto e: m2){
    ans2*=e.second+1;
  }
  cout << ans + (ans2 - 1 > 0? ans2 - 1:0);
}


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

int SelectionSort(int *,int );
void OutputData(int *,int);

int main(){

  int *a;
  int i,n,c;

  scanf("%d",&n);

  a=(int*)malloc(n*sizeof(int));

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

  c=SelectionSort(a,n);
  OutputData(a,n);
  printf("%d\n",c);

  return 0;
}

int SelectionSort(int *a,int n){

  int i,j,min,tmp,c=0;

  for(i=0;i<n-1;i++){
    min=i;
    
    for(j=i+1;j<n;j++){
      if(a[j]<a[min]){
	min=j;
      }
    }
    if(a[i]>a[min]){
      tmp=a[i];
      a[i]=a[min];
      a[min]=tmp;
      c++;
    }
  }
  return c;
}

void OutputData(int *a,int n){

  int i;

  for(i=0;i<n;i++){
    if(i!=n-1){
      printf("%d ",a[i]);
    }
    else{
      printf("%d",a[i]);
    }
  }
  printf("\n");
}
	 
  



Measured memory_bytes: 2128
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename lx> inline void read(lx &x){
	x = 0;int f = 1;char c = getchar();
	for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
	for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;return;
}
template <typename lx> inline void print(lx x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
	return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
const int inf = 2147483647;
const int maxn = 2e5 + 7;
int n,ans = 1,cnt,len;
char s[maxn];
char last;
int main()
{
	scanf("%s",s + 1);n = strlen(s + 1);
	last = s[1];
	for(rg int i = 2;i <= n; i++){
		char c = s[i];
		if(c == last){
			if(i != n) ans++;
			i++;
			last = '~';
		}
		else{
			ans++;
			last = c;
		}
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    long long L0 = 2;
    long long L1 = 1;
    long long Ln = 0;
    for(int i = 2; i <= N; i++){
        Ln = L0 + L1;
        L0 = L1;
        L1 = Ln;
    };
    if(N == 1) Ln = 1;
    cout << Ln << endl;
}

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

// dp[0] = 0
// dp[i] = min(dp[i-2] + |h[i] - h[i-2]|, dp[i-1] + |h[i] - h[i-1]|)

int main() {
    int N;
    int h[100101];
    int dp[100101] = {};
    cin >> N;
    for(int i = 0; i < N; ++i) {
        scanf("%d", h + i);
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 0; i < N - 2; ++i) {
        dp[i+2] = min(dp[i+1] + abs(h[i+2] - h[i+1]), dp[i] + abs(h[i+2] - h[i]));
    }

    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        System.out.println((a == b && b == c)? "Yes" : "No");

        sc.close();
    }
}

Measured memory_bytes: 22736
N , X = list(map(int, input().split()))
S = list(map(int, input().split()))

MOD = 10**9+7
memo = [{} for i in range(N)]
S.sort(reverse=True)

def ddp(cur_N, cur_x):
    if cur_N == N:
        return cur_x
    if cur_x in memo[cur_N]:
        return memo[cur_N][cur_x]
    ret = ddp(cur_N+1, cur_x % S[cur_N]) + ddp(cur_N+1, cur_x)*(N-cur_N-1)
    ret = ret % MOD
    memo[cur_N][cur_x] = ret
    return ret
print(ddp(0, X))

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

int N, T, ans;

int main() {
	scanf("%d", &N);
	ans = N / 2;
	if (N % 2 == 1) {
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256