akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        h2: usize,
        w2: usize,
    }

    let ans = (h - h2) * (w - w2);

    println!("{}", ans);
}


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

typedef long long ll;

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

    string s;
    cin >> s;
    if(s=="Sunny") cout << "Cloudy" << endl;
    else if(s=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
const int INF = 1000000000000000018;

int N, A[100100];

pair<int, bool> C(int n)
{
    for(int i = 0; i < N; i++){
        n = (n / A[i]) * A[i];
    }
    return {n, (n <= 2ll)};
}

pair<int, bool> bsmx(int lb = 0, int ub = INF)
{
    int mid;
    bool ret = false;
    for(int i = 0; i < 64; i++){
        mid = (ub + lb) / 2ll;
        pair<int , bool> res = C(mid);
        if(res.second){
            lb = mid;
            ret |= (res.first == 2ll);
        }
        else {
            ub = mid;
        }
    }
    return {lb, ret};

}

pair<int, bool> Cl(int n)
{
    for(int i = 0; i < N; i++){
        n = (n / A[i]) * A[i];
    }
    return {n, (n >= 2ll)};
}

pair<int, bool> bsmn(int lb = 0, int ub = INF)
{
    int mid;
    bool ret = false;
    for(int i = 0; i < 64; i++){
        mid = (ub + lb) / 2ll;
        pair<int , bool> res = Cl(mid);
        if(res.second){
            ub = mid;
            ret |= (res.first == 2ll);
        }
        else {
            lb = mid;
        }
    }
    return {ub, ret};

}

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    pair<int, bool> res = bsmx();
    if(res.second){
        printf("%lld %lld\n", bsmn().first, res.first);
    }
    else {
        printf("-1\n");
    }

    return 0;
}


Measured memory_bytes: 1024
s=input()
t=input()
slist=[s[i] for i in range(len(s))]
tlist=[t[i] for i in range(len(t))]
slist.sort()
tlist.sort(reverse=True)
s_new=""
t_new=""
for i in range(len(slist)):
  s_new += slist[i]
for i in range(len(tlist)):
  t_new += tlist[i]
if s_new < t_new:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    cout<<(n-1)/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  double l; cin >> l;
  double a=l/3.0,b=l/3.0,c=l-a-b;
  printf("%.9f\n",a*b*c);
  //printf("%.9f\n",a+b+c);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,k[10000],flg,out,zero;
  for(int l=0;l<100;l++){
    flg=0,out=0,zero=0;
    cin>>n;
    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin>>k[i];
    }
    for(int i=0;i<n;i++){
      if(k[i]==0){
	zero++;
      }if(k[i]<2){
	flg++;
      }
    }if(zero==n-1&&k[n-1]<2||flg+zero==n){
      out++;
    }
    if(flg==n){
      out++;
    }
    if(out==0){
      n-=zero;
      n++;
      cout<<n<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> ss(n);
  for (int i = 0; i < n; i++) {
    vector<char> s(10);
    for (int j = 0; j < 10; j++) {
      cin >> s[j];
    }
    sort(s.begin(), s.end());
    for (int j = 0; j < 10; j++) {
      ss[i] += s[j];
    }
  }

  sort(ss.begin(), ss.end());

  ll ans = 0;
  string s1 = ss[0];
  ll tmp = 1;
  for (int i = 1; i < n; i++) {
    string s2 = ss[i];
    if (s1 == s2) {
      tmp++;
    }
    if (s1 != s2 || i==n-1){
      if(tmp>=2){
        ans += tmp * (tmp-1) / 2;
      }

      s1 = s2;
      tmp=1;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <regex>

using namespace std;

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

	s = regex_replace(s, regex("BC"), "D");
	
	long long ans = 0;
	int a = 0;
	for (auto x : s) {
		if (x == 'A') {
			++a;
		}
		else if (x == 'D') {
			ans += a;
		}
		else {
			a = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    int h,w,ch,cw,dh,dw;
    int th[4]={1,-1,0,0};
    int tw[4]={0,0,1,-1};
    cin>>h>>w>>ch>>cw>>dh>>dw;
    ch--;cw--;dh--;dw--;
    vector<string> a(h);
    rep(i,h)cin>>a[i];
    queue<pair<int,int>> q;
    queue<pair<int,int>> q2;
    pair<int,int> pai(ch,cw);
    q.push(pai);
    q2.push(pai);
    vector<vector<int>> b(h,vector<int>(w));
    b[ch][cw]=1;
    while(!q.empty()||!q2.empty()){
    while(!q.empty()){
        pai=q.front();
        q.pop();
        q2.push(pai);
        rep(i,4){
            int y=pai.first-th[i],x=pai.second-tw[i];
            if(y>=0&&y<h&&x>=0&&x<w&&a[y][x]=='.'){
                if(b[y][x]>b[pai.first][pai.second]||b[y][x]==0){
                    pair<int,int> pai2(y,x);
                    q.push(pai2);
                    b[y][x]=b[pai.first][pai.second];
                }
            }
        }
    }
    while(!q2.empty()){
        pai=q2.front();
        q2.pop();
        for(int i=-2;i<=2;i++)for(int j=-2;j<=2;j++){
            int y=pai.first-i,x=pai.second-j;
            if(y>=0&&y<h&&x>=0&&x<w&&a[y][x]=='.'&&b[y][x]==0){
                pair<int,int> pai2(y,x);
                q.push(pai2);
                b[y][x]=b[pai.first][pai.second]+1;
            }
        }
    }
    }
    //     rep(aaa,h){
    //     rep(aaaa,w){
    //         cout<<b[aaa][aaaa];
    //     }
    //     cout<<endl;
    // }
    cout<<b[dh][dw]-1<<endl;
 
}

Measured memory_bytes: 9492
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

LL N, minMax;

int main(){
  FAST_IO
  cin >> N;

  minMax = 15;
  string one, two;

  for(LL mul = 1, other; mul * mul <= N; ++mul){
    if(N % mul) continue;
    one = to_string(mul);
    two = to_string(N / mul);

    other = max(SZ(one), SZ(two));
    min_self(minMax, other);
  }
    
  cout << minMax << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	int n, m;
	cin >> n >> m;
	cout << m * (m - 1) / 2 + n * (n - 1) / 2;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 4 * 1000 * 100 + 47;

int A[MAX];
int B[MAX];
VI g[MAX];
VI I[MAX];
int U[MAX];
int P[MAX];
VI V;

int DA[MAX];
int DB[MAX];
int R[MAX];
int e;
void addEdge(int a, int b)
{
	g[a].push_back(b);
	I[a].push_back(e);

	g[b].push_back(a);
	I[b].push_back(e);
	e++;
}

void euler(int v)
{
	for (; P[v] < SZ(g[v]); P[v]++)
	{
		int to = g[v][P[v]];
		int e = I[v][P[v]];
		if (U[e]) continue;
		U[e] = 1;
		euler(to);
	}

	V.push_back(v);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		cin >> A[i];
		if (A[i] != -1)
		{
			A[i]--;
			DA[A[i]] ^= 1;
		}
	}

	FOR(i, 0, n)
	{
		cin >> B[i];
		if (B[i] != -1)
		{
			B[i]--;
			DB[B[i]] ^= 1;
		}
	}

	FOR(i, 0, n)
	{
		if (DA[i] != DB[i])
		{
			cout << "IMPOSSIBLE" << endl;
			return 0;
		}
	}

	//FOR(i, 0, n)
	//{
	//	cout << DA[i] << " " << DB[i] << endl;
	//}

	int sz = 2 * n + 1;
	FOR(i, 0, n)
	{
		if (A[i] == -1)
		{
			addEdge(i, sz - 1);
			continue;
		}

		addEdge(i, A[i]);
	}

	FOR(i, 0, n)
	{
		if (B[i] == -1)
		{
			addEdge(i + n, sz - 1);
			continue;
		}

		addEdge(i + n, B[i] + n);
	}

	FOR(i, 0, n)
	{
		if (DA[i] == 1) continue;
		addEdge(i, i + n);
	}

	euler(sz - 1);
	//FOR(i, 0, SZ(V))
	//{
	//	if (V[i] == sz - 1)
	//	{
	//		cout << "R ";
	//		continue;
	//	}

	//	if (V[i] < n)
	//	{
	//		cout << "A" << V[i] + 1 << " ";
	//		continue;
	//	}

	//	cout << "B" << V[i] - n + 1 << " ";
	//}
	//cout << endl;
	FOR(i, 0, SZ(V) - 1)
	{
		int a = V[i];
		int b = V[i + 1];
		if (a == b - n)
		{
			R[a] = 1;
		}

		if (b == a - n)
		{
			R[b] = -1;
		}
	}

	cout << "POSSIBLE" << endl;
	FOR(i, 0, n)
	{
		cout << R[i] << " ";
	}

	cout << endl;
}


Measured memory_bytes: 52460
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int INF = 1e9 + 7;
const int N = 107;

char field[N][N];
int dp[N][N][N][N];

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> field[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int a = 0; a <= h; a++) {
				for (int b = 0; b <= w; b++) {
					dp[i][j][a][b] = INF;
				}
			}
		}
	}
	dp[0][0][0][0] = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int a = 0; a <= h; a++) {
				for (int b = 0; b <= w; b++) {
					if (!a || !b) continue;
					dp[i][j][a][b] = min(dp[i][j][a][b], dp[i][j][0][0] + 1);
				}
			}

			for (int a = 0; a <= h; a++) {
				for (int b = 0; b <= w; b++) {
					if ((a >= 1) == (field[i][j] == '#')) {
						dp[i + 1][j][max(a - 1, 0)][(a == 1 ? 0 : b)] = min(dp[i + 1][j][max(a - 1, 0)][(a == 1 ? 0 : b)], dp[i][j][a][b]);
						dp[i][j + 1][(b == 1 ? 0 : a)][max(b - 1, 0)] = min(dp[i][j + 1][(b == 1 ? 0 : a)][max(b - 1, 0)], dp[i][j][a][b]);
					}
				}
			}
		}
	}

	int res = INF;

	for (int a = 0; a <= h; a++) {
		for (int b = 0; b <= w; b++) {
			if ((a > 0) != (field[h - 1][w - 1] == '#')) continue;
			res = min(res, dp[h - 1][w - 1][a][b]);
			/*if (dp[h - 1][w - 1][a][b] == 1) {
				cout << a << " " << b << "\n";
			}*/
		}
	}
	cout << res << "\n";
}


Measured memory_bytes: 483584
N = int(input())
A = list(map(int, input().split()))

B = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()
    else:
        print(1)
        exit()

else:
    if A[0] != 0:
        print(-1)
        exit()
    else:
        B.append(1)
        for i in range(1, N + 1):
            B.append((B[i - 1] - A[i - 1]) * 2)
            if (A[i] > B[i] or (A[i] == B[i] and i != N)):
                print(-1)
                exit()

        ans = 0
        ans += A[N]
        B[N] = A[N]
        for i in range(N - 1, -1, -1):
            ans += min(B[i], B[i + 1] + A[i])
            B[i] = min(B[i], B[i + 1] + A[i])

        print(ans)
        exit()


Measured memory_bytes: 674484
def swap(ch):
    if ch == '0':
        return '1'
    else:
        return '0'


s = list(input())
ct = 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = swap(s[i+1])
        ct += 1

print(ct)


Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int f(int n){
    if(n%2){
        return n*3+1; 
    }
    else {
        return n/2;
    }
}
int main(){
    int s;
    cin >> s;
    bool is_exist = false;
    pair <int,int> answer;

    map <int,pair<int,int> >mp;
    int n=s;
    REP(i,1000005){
        if(mp[n].first == 1){
            answer.first = mp[n].second;
            answer.second = i;
            is_exist = true;
            break;
        }
        mp[n].first++;
        mp[n].second = i;
        n=f(n);
    }
    cout << answer.second+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

void topological_sort(const vector<vector<int>>& G, vector<int>& ord)
{
   ord.resize(G.size());
   vector<int> num(G.size(),0);
   for (int i = 0; i < G.size(); i++) {
      for (int j = 0; j < G[i].size(); j++) {
         num[G[i][j]]++;
      }
   }
   stack<int> st;
   for(int i = 0; i < num.size(); i++) {
      if (num[i] == 0) {
         st.push(i);
      }
   }
   for (int k = 0; !st.empty(); k++) {
      int i = st.top(); st.pop();
      ord[k] = i;
      for(int j = 0; j < G[i].size(); j++) {
         num[G[i][j]]--;
         if (num[G[i][j]] == 0) {
            st.push(G[i][j]);
         }
      }
   }
}

signed main()
{
   int n, m; cin >> n >> m;
   V<V<int>> G(n);
   for (int i = 0; i < m; i++) {
      int x, y; cin >> x >> y;
      x--; y--;
      G[x].push_back(y);
   }

   V<int> ord;
   topological_sort(G, ord);

   V<int> dp(n);
   for (int i = n-1; i >= 0; i--) {
      int v = ord[i];
      for (int j = 0; j < G[v].size(); j++) {
         int u = G[v][j];
         chmax(dp[v], dp[u]+1);
      }
   }
   cout << *max_element(dp.begin(), dp.end()) << endl;

   return 0;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;


 
int main(){
    int n;
    int total=0;
    cin>>n;
    vector<int> t(n);
    rep(i,n){
        cin>>t[i];
        total += t[i];
    }

    int m;
    cin>>m;
    int p,x;
    rep(i,m){
        cin>>p>>x;
        cout<<total-t[p-1]+x<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
import math

def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            return True
    return False
  
x = int(input())

while(True):
  if (trial_division(x)):
    x += 1
  else:
    break

print(x)

Measured memory_bytes: 2940
w,h,n=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
list_w=[1]*w
list_h=[1]*h

for i in range(n):
	if a[i][2]==1:
		for j in range(a[i][0]):
			list_w[j]=0
	elif a[i][2]==2:
		for j in range(w-1,a[i][0]-1,-1):
			list_w[j]=0
	elif a[i][2]==3:
		for j in range(a[i][1]):
			list_h[j]=0		
	elif a[i][2]==4:
		for j in range(h-1,a[i][1]-1,-1):
			list_h[j]=0

h=list_h.count(1)
w=list_w.count(1)
print(h*w)

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

int main() {
int  N,K;
    cin >> N >> K ;
vector<long long> H(N);
for (int i = 0; i < N; i++) {
  cin >> H.at(i);
}
    sort(H.begin(), H.end()); 
    reverse(H.begin(),H.end());
  long long sum=0;

if (N>=K){  
  for (int i = 0; i < K; i++) {
   H[i]=0;
  }  
  for (int i = 0; i < N; i++) {
   sum+=H[i];
  }
}
cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 1000000005
#define mod 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i = 0; i < (n); ++i) /*0からn-1までのrep*/
#define rrep(i,n) for(int i = 1; i <= (n); ++i) /*1からnまでのrep*/
#define drep(i,n) for(int i = (n)-1; i >= 0; --i) /*n-1から0までのrep*/
#define srep(i,s,t) for (int i = s; i < t; ++i) /*sからt-1までのrep*/
#define each(a,b) for(auto& (a): (b)) /*よくわからん*/
#define all(v) (v).begin(),(v).end() /*全選択*/
#define sz(v) (int)(v).size() /*大きさ*/
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) /*重複削除*/
#define cmx(x,y) x=max(x,y) /*最大値*/
#define cmn(x,y) x=min(x,y) /*最小値*/
#define rev(v) reverse((v).begin(),(v).end()); /*逆順*/
#define so(v) sort((v).begin(), (v).end()); /*ソート*/
#define yn {puts("Yes");}else{puts("No");} /*はい・いいえ*/
#define fi first
#define se second
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vp = vector<P>;
using vs = vector<string>; 

int main() {
    int a, b,s,t;
    cin >> a >> b;
    rep(i, b) {
        cin >> t;
        a = a - t;
    }
    if (a >= 0) {
        cout << a << endl;
    }
    else {
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
const int MaxN=100010,mod=1000000007;
int N,a[MaxN];
struct edge{int to;edge*next;}E[MaxN],*fir[MaxN];
int C[MaxN],pos[MaxN],dep[MaxN],cnt[MaxN],ways[MaxN];
bool vis[MaxN];
int solve(){
	int res=1;
	for(int i=0;i<N;i++)if(!vis[i]){
		int len=0,tot=0,j=i,k;
		for(;!vis[j];j=a[j])vis[j]=1;
		for(k=i;vis[k];k=a[k])vis[k]=0;
		for(;!vis[j];j=a[j])vis[C[len++]=j]=1;
		for(j=0,k=len-1;j<k;j++,k--){
			int t=C[j];C[j]=C[k],C[k]=t;
		}
		for(j=0;j<len;j++){
			int x=C[j],d=0;
			for(;;){
				int c=0,t;
				for(edge*e=fir[x];e;e=e->next)if(!vis[e->to])c++,t=e->to;
				if(c>1)return 0;
				if(!c)break;
				vis[x=t]=1;d++;
			}
			if(d)pos[tot]=j,dep[tot++]=d;
		}
		if(tot){
			for(j=0;j<tot;j++){
				int d=(pos[(j+1)%tot]-pos[j])%len;
				if(d<=0)d+=len;
				if(d<dep[j])return 0;
				if(d>dep[j])res=res*2%mod;
			}
		}
		else cnt[len]++;
	}
	for(int i=1;i<=N;i++){
		ways[0]=1;
		for(int j=1;j<=cnt[i];j++){
			ways[j]=ways[j-1]*(i>1&&i%2?2:1)%mod;
			if(j>1)ways[j]=(ways[j]+(j-1ll)*ways[j-2]%mod*i)%mod;
		}
		res=1ll*res*ways[cnt[i]]%mod;
	}
	return res;
}
int main(){
	while(scanf("%d",&N)==1){
		for(int i=0;i<N;i++)scanf("%d",a+i),--a[i],fir[i]=0,vis[i]=0;
		for(int i=0;i<N;i++)E[i]=(edge){i,fir[a[i]]},fir[a[i]]=E+i;
		for(int i=N;i;i--)cnt[i]=0;
		printf("%d\n",solve());
	}
}

Measured memory_bytes: 3840
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==1 && b==0 && c==0) {
		printf("Close\n");
	}
	if(a==0 && b==1 && c==0) {
		printf("Close\n");
	}
	if(a==1 && b==1 && c==0) {
		printf("Open\n");
	}
	if(a==0 && b==0 && c==1) {
		printf("Open\n");
	}
	if(a==0 && b==0 && c==0) {
		printf("Close\n");
	}
	return 0;
}



Measured memory_bytes: 2060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;


public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i=0; i<n; i++){
			String strA = br.readLine();
			BigInteger a = new BigInteger(strA);

			String strB = br.readLine();
			BigInteger b = new BigInteger(strB);

			if(strA.length() > 80 || strB.length() > 80){
				System.out.println("overflow");
			}else{
				if(a.add(b).toString().length()>80){
					System.out.println("overflow");
				}else{
					System.out.println(a.add(b));
				}
			}
		}

	}
}

Measured memory_bytes: 17844
import java.util.Scanner;

class Main {

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

		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		String n = a;

		while (n.length() > 0) {
			if (n.equals(a)) {
				if (a.substring(0, 1).equals("a")) {
					a = a.substring(1);
					n = a;
				} else if (a.substring(0, 1).equals("b")) {
					a = a.substring(1);
					n = b;
				} else if (a.substring(0, 1).equals("c")) {
					a = a.substring(1);
					n = c;
				}
			} else if (n.equals(b)) {
				if (b.substring(0, 1).equals("a")) {
					b = b.substring(1);
					n = a;
				} else if (b.substring(0, 1).equals("b")) {
					b = b.substring(1);
					n = b;
				} else if (b.substring(0, 1).equals("c")) {
					b = b.substring(1);
					n = c;
				}
			} else if (n.equals(c)) {
				if (c.substring(0, 1).equals("a")) {
					c = c.substring(1);
					n = a;
				} else if (c.substring(0, 1).equals("b")) {
					c = c.substring(1);
					n = b;
				} else if (c.substring(0, 1).equals("c")) {
					c = c.substring(1);
					n = c;
				}
			}
		}
		if (n == a) {
			System.out.println("A");
		} else if (n == b) {
			System.out.println("B");
		} else if (n == c) {
			System.out.println("C");
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main(void){

int a,b;
cin>>a>>b;

if((a+b)<24){
    cout<<a+b<<endl;
}

else if((a+b)==24){
    cout<<0<<endl;
}

else{
    cout<<(a+b)-24<<endl;
}
}


Measured memory_bytes: 3540
#include <stdio.h>
#include <vector>
#include <string>

int main(int argc, char* argv[]){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) {
            printf(" %d", i);
            continue;
        }
        for(int x = i; x; x /= 10){
            if(x % 10 == 3){
                printf(" %d", i);
                x = 0;
            }
        }

    }
    printf("\n");
}


Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int d[k],a[n+1];
    a[0] = 1;
    for (int i = 1; i < n+1;i++)
        a[i] = 0;
        for (int i = 0; i < k; i++)
        {
            cin >> d[i];
            int b[d[i]];
            for (int j = 0; j < d[i]; j++)
            {
                cin >> b[j];
                a[b[j]]++;
            }
        }
    int t = 0;
    for (int i = 0; i < n+1;i++)
    if(a[i]==0)
        t++;
    cout << t;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		long n=s.nextLong();
		long r=Long.MAX_VALUE;
		for(long i=1;i*i<=n;++i) {
			if(n%i==0)
				r=Math.min(r,i+n/i-2);
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i ++) {
    cout << s[i] << t[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    ds = []
    for _ in range(N):
        a, b = map(int, input().split())
        ds.append((a, b))

    ds.sort(key=itemgetter(0))

    rest = M
    mi = 0
    for a, b in ds:
        use = min(rest, b)
        mi += a * use
        rest -= use
        if not use:
            break

    print(mi)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 18132
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc163D
    {
        static long mod = 1000000007;

        public static void Main()
        {
            var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var n = nk[0];
            var k = nk[1];

            long sum = 0;
            for (long i = k; i <= n + 1; i++)
            {
                var sMin = i * (1 + i) / 2;
                var sMax = i * (2 * n - i + 3) / 2;
                sum = (sum + (sMax - sMin) + 1) % mod;
            }

            Console.WriteLine((sum + mod) % mod);
        }
    }
}


Measured memory_bytes: 18900
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
    double x1,x2,y1,y2;
    double x,y;
    cin>>x1>>y1>>x2>>y2;
    x = (x2-x1)*(x2-x1);
    y = (y2-y1)*(y2-y1);
    printf("%lf",sqrt((x+y)));
  //  cout<<sqrt((x+y))<<endl;
    return 0;
    
}





Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T = int > T in() {
  T x;
  cin >> x;
  return (x);
}
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vec< vec< int > > G;
vec< int > cost;
vec< int > ans;
vec< bool > flg;
void dfs(int id) {
  flg[id] = true;
  FORA(e, G[id]) {
    if (!flg[e]) {
      cost[e] += cost[id];
      dfs(e);
    }
  }
  return;
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, Q;
  cin >> N >> Q;
  G.resize(N, vec< int >());
  REP(i, N - 1) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].pb(y);
    G[y].pb(x);
  }
  cost.assign(N, 0);
  //  ans.assign(N, 0);
  flg.assign(N, false);
  REP(i, Q) {
    int p, q;
    cin >> p >> q;
    p--;
    cost[p] += q;
  }
  dfs(0);
  REP(i, N) { cout << cost[i] << " "; }
  cout << "\n";

  // print();
}

Measured memory_bytes: 24320
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n = 0, a,b,m = 0,counter = 0;
	string in;
	vector<ll>vec;
	cin >> in;

	if (in[0] == in[1]&&in[1] == in[2]) { cout << "Yes" << endl; }

	else if (in[1] == in[2]&&in[2] == in[3]) { cout << "Yes" << endl; }

	else { cout << "No" << endl; }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;

int n,u=0,h=0,m=0;
int pre[40],in[40],post[40];

void reconstruction(int l,int r){
  if(l>r) return;
  int root=pre[u++];
  reconstruction(l,post[root]-1);
  reconstruction(post[root]+1,r);
  cout<<root;
  if(++m!=n)cout<<" ";
}
int main(){
  cin>>n;
  rep(i,n)cin>>pre[i];
  rep(i,n)cin>>in[i];
  rep(i,n)post[in[i]]=i;
  reconstruction(0,n-1);
  cout<<endl;
  return 0;
}


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

int main() {
	int X;
	cin >> X;
	for (int d = 1; d <= X; ++d) {
		if (X % d != 0) continue;
		int b = 0;
		int dir = pow(b + d, 5) - pow(b, 5) < X ? +1 : -1;
		while (pow(b + d, 5) - pow(b, 5) != X) {
			if ((pow(b + d, 5) - pow(b, 5) - X) * dir > 0) break;
			b += dir;
		}
		if (pow(b + d, 5) - pow(b, 5) == X) {
			cout << b+d << " " << b << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    ll A, B, C; cin >> A >> B >> C;
    for(int i = 0; i <= B; i++){
        ll temp = A*i;
        if(temp % B == C){
            cout << "YES" << endl;
            return 0;
        }
    } 
    cout << "NO" << endl;
}


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 int ll;
const ll MOD = 1000000007;

int main() {
  int n;
  double t, a, h, ma = DBL_MAX, mi = 0;
  cin >> n >> t >> a;
  REP(i, n) {
    cin >> h;
    if (abs(a - (t -h * 0.006)) < ma) {
      ma = abs(a - (t -h * 0.006));
      mi = i;
    }
  }
  cout << mi + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int dp[10][1<<10][331], n; //n?????¶?´??????????????????? s???????????????(ry ??? 331???
int rec( int now, int used,int sum){
  if( sum < 0 ) return 0;
  if( now == n ) return sum == 0;
  if(~dp[now][used][sum]) return dp[now][used][sum];
  int ret = 0;
  for(int i = 0 ; i < 10 ; i++ ){
    if((used >> i) & 1)
      ret += rec( now + 1, used&~(1 << i), sum - i * (now + 1));
  }
  return dp[now][used][sum] = ret;
}
int main(){
  int s;
  while(cin >> n >> s){
    fill_n( **dp, 10 * (1 << 10) * 331, -1);
    cout << rec( 0, (1 << 10) - 1, s) << endl;
  }
}

Measured memory_bytes: 16300
N,D=map(int,input().split())
A=[]
for i in range(N):
  A.append(list(map(int,input().split())))
sum=0
count=0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      sum+=(A[i][k]-A[j][k])**2
    sum=(sum)**0.5
    if sum.is_integer():
      count+=1
    sum=0
print(count)

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

using namespace std;

using ll = long long;

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

    int w, h, x, y; cin >> w >> h >> x >> y;
    cout << ((double)w * h / 2.0) << " ";
    if (2 * x == w && 2 * y == h) cout << "1\n";
    else cout << "0\n";
    return 0;
}


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

string rec(long long N) {
    if (N == 0) return "";
    N--;
    return rec(N/26) + string(1, 'a' + N%26);
}

int main()
{
    long long N; cin >> N;
    cout << rec(N) << endl;
    return 0;
}

Measured memory_bytes: 3628
def main():
    n = int(input())
    if n <= 599:
        print(8)
    elif n <= 799:
        print(7)
    elif n <= 999:
        print(6)
    elif n <= 1199:
        print(5)
    elif n <= 1399:
        print(4)
    elif n <= 1599:
        print(3)
    elif n <= 1799:
        print(2)
    else:
        print(1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <unordered_map>

int main()
{
	unsigned long long N = 0;
  	std::uint64_t ans = 0;

	std::cin >> N;
	std::vector<std::string> S(N);

	std::unordered_map<std::string, long long> mp;

	for (long long i = 0; i < N; i++)
	{
		std::cin >> S[i];
		std::sort(S[i].begin(), S[i].end());
		mp[S[i]] += 1;
	}

	for(auto& s : mp) {
		ans += s.second * (s.second - 1) / 2;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 17700
#include<stdio.h>
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int main(){
  long long a=0,b=0,i,n,M=1e9+7;
  scanf("%lld",&n);
  while(n--){
    scanf("%lld",&i);
    a=(a+(i*i)%M)%M;
    b=(b+i)%M;
  }
  printf("%lld\n",((b*b%M)+M-a)*inv(2,M)%M);
  return 0;
}
			      


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

int  main()
{
	map<string, int> m;
	int b,r;
	cin >> b;
	vector<string> s(b);
	rep(i, b)
	{
		cin >> s.at(i);
		m[s[i]] += 1;
	}
	cin >> r;
	vector<string> t(r);
	rep(i, r)
	{
		cin >> t.at(i);
		m[t[i]] -= 1;
	}
	int ans = 0;
	rep(i, b)
		ans = max(ans, m[s[i]]);
	cout << ans << endl;
	return (0);
}

Measured memory_bytes: 256
N = int(input())

memo = {i:i for i in range(6)}
def f(n):
    tmp = memo.get(n,None)
    if tmp != None:
        return tmp
    i,j = 0,0
    a,b = n,n
    while a >= 6:
        i += 1
        a //= 6
    while b >= 9:
        j += 1
        b //= 9
    ret = min(1+f(n-6**i),1+f(n-9**j))
    memo[n] = ret
    return ret

print(f(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(All(a));
  reverse(All(a));
  ll ans = 0;
  rep(i,k) {
    ans += a[i];
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int N; cin >> N;
    for(int i = 1; i <= 100; i++)
    {
        if(i * 1000 >= N)
        {
            cout << i * 1000 - N << endl;
            return;
        }
    }
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3664
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int n, q;
	cin >> n >> q;

	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	vector<ll> x(q);
	for (int i = 0; i < q; i++)
	{
		cin >> x.at(i);
	}

	for (int i = 0; i < q; i++)
	{
		ll res = 0;

		int r = 0;
		ll s = 0;
		for (int l = 0; l < n; l++)
		{
			while (r < n && a.at(r) + s <= x.at(i))
			{
				s += a.at(r);
				r++;
			}

			res += r - l;

			if (r == l)
			{
				r++;
			}
			else
			{
				s -= a.at(l);
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 3524
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<pair<ll, string>> q;
  for (int i = 0; i < a; ++i)
  {
    ll t;
    cin >> t;
    q.push({t, "red"});
  }
  for (int i = 0; i < b; ++i)
  {
    ll t;
    cin >> t;
    q.push({t, "green"});
  }
  for (int i = 0; i < c; ++i)
  {
    ll t;
    cin >> t;
    q.push({t, "none"});
  }
  ll sum = 0;
  int r = 0, g = 0, n = 0;
  while (q.size())
  {
    if (r + g + n >= x + y)
      break;
    pair<ll, string> p = q.top();
    q.pop();
    if (p.second == "red" && r < x)
    {
      r++;
      sum += p.first;
    }
    if (p.second == "green" && g < y)
    {
      g++;
      sum += p.first;
    }
    if (p.second == "none")
    {
      n++;
      sum += p.first;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 22508
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		double r = Double.parseDouble(line);
		final double PI = 3.141592653589;
		System.out.printf("%.6f %.6f",r*r*PI ,2*r*PI);
	}
}

Measured memory_bytes: 24536
from collections import defaultdict
from heapq import heappop, heappush
k = int(input())

dist = []
for i in range(k):
    if i != k - 1:
        dist.append([i, i + 1, 1])
    else:
        dist.append([i, 0, 1])

for i in range(k):
    dist.append([i, (10 * i) % k, 0])

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
# (src, dst, weight)
inputs = dist

g = Graph()
for src, dst, weight in inputs:
    g.add_edge(src, dst, weight)
    #g.add_edge(dst, src, weight)
spdi = {}

d = Dijkstra(g, 1)
sp = format(d.shortest_distance(0))
print(int(sp) + 1)

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

int main()
{
    string a,b,c;
    cin >> a >> b >> c;

    char n = a[0];
    a.erase(0,1);

    while(true) {
        if(n == 'a') {
            if(a.length()==0) {
                cout << "A" << endl;
                break;
            }
            n = a[0];
            a.erase(0,1);
        }
        else if(n == 'b') {
            if(b.length()==0) {
                cout << "B" << endl;
                break;
            }
            n = b[0];
            b.erase(0,1);
        }
        else if(n == 'c') {
            if(c.length()==0) {
                cout << "C" << endl;
                break;
            }
            n = c[0];
            c.erase(0,1);
        }
    }
    return 0;
}


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


using namespace std;

void func141b (){
	string s;
	char check[2] = { 'L', 'R' };
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == check[i % 2]) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}



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



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

long long a, b, c;

int main(){
	cin >> a >> b >> c;
	if(c <= a+b) cout << "No" << endl;
	else {
		if(4LL * a * b < (c-a-b) * (c-a-b)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

int main() {
	//入力
	int n;
	cin >> n;
	string s[100];
	for (int i = 0; i < n; i++) cin >> s[i];

	int m;
	cin >> m;
	string t[100];
	for (int i = 0; i < m; i++) cin >> t[i];

	//計算
	int max = 0;

	for (int i = 0; i < n; i++) {
		int sc = 0;
		for (int j = 0; j < n; j++) {
			if (s[i] == s[j]) sc++;
		}
		for (int j = 0; j < m; j++) {
			if (s[i] == t[j]) sc--;
		}

		if (sc > max) max = sc;
	}

	//出力
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256