akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

 class Main {
	static List<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
	static int t_dist[], a_dist[];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long u = sc.nextLong()-1;
        long v = sc.nextLong()-1;
        
        int ai;
        int bi;
        int ans=1;
        
        for(long i=0;i<=N;i++)list.add(new ArrayList<Integer>());
        for(long i=0;i<N-1;i++) {
        	ai = sc.nextInt()-1;
        	bi = sc.nextInt()-1;
        	list.get(ai).add(bi);
        	list.get(bi).add(ai);
        }
        
        t_dist = new int[(int)N+1];
        a_dist = new int[(int)N+1];
        
        tdfs((int)u,0,-1);
        adfs((int)v,0,-1);
        
        for(int i=0;i<=N;i++) {
        	if(t_dist[i]<a_dist[i]) {
        		if(ans<a_dist[i]) {
        			ans=a_dist[i];
        		}
        	}	
        }
 
        System.out.println(ans-1);	
        
        
    }
    
	static void adfs(int now, int cnt, int parent) {
		a_dist[now]=cnt;
		for(int i=0;i<list.get(now).size();i++) {
			int next = list.get(now).get(i);
			if(next == parent)continue;
			adfs(next, cnt+1, now);
		}
	}
    
	static void tdfs(int now, int cnt, int parent) {
		t_dist[now]=cnt;
		for(int i=0;i<list.get(now).size();i++) {
			int next = list.get(now).get(i);
			if(next == parent)continue;
			tdfs(next, cnt+1, now);
		}
	}

}

Measured memory_bytes: 113360
#include <algorithm>
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
int dp[100005], sum[100005];
ll arr[100005];
int main()
{
	// freopen("AGC009-C.in", "r", stdin);
	int n;
	ll a, b;
	scanf("%d%lld%lld", &n, &a, &b);
	if (a > b)
		std::swap(a, b);
	arr[0] = -1e18;
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", arr + i);
		if (i >= 2 && arr[i] - arr[i - 2] < a)
		{
			puts("0");
			return 0;
		}
	}
	dp[0] = sum[1] = 1;
	int l = 0, r = 0;
	for (int i = 1; i <= n; i++)
	{
		while (arr[i] - arr[r] >= b)
			r++;
		dp[i] = (sum[r] - sum[l] + MOD) % MOD;
		sum[i + 1] = (sum[i] + dp[i]) % MOD;
		if (arr[i] - arr[i - 1] < a)
			l = r = i - 1;
	}
	printf("%d\n", (sum[n + 1] - sum[l] + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>

using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
    lint a, b, c, d;
    std::cin >> a >> b >> c >> d;

    lint ans = -INF;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            ans = std::max(ans, a * c);
            std::swap(c, d);
        }
        std::swap(a, b);
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main(){
  int i,j,v,N;
  int A[1000];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
    printf("%d",A[N-1]);

  printf("\n");
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(j=0;j<N-1;j++){
      printf("%d ", A[j]);
    }
    printf("%d",A[N-1]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2052
#include <iostream>

using namespace std;

int h,w;

bool c[505][505],a[505][505],b[505][505];

int main()
{
	cin>>h>>w;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            char ch;
            cin>>ch;
            c[i][j]=(ch=='#')?1:0;
            a[i][j] = c[i][j];
            b[i][j] = c[i][j];
        }
    }
    for(int i = 0; i < h; i++)
    {
        if(i%2 == 0)
        {
            for(int j = 0; j < w-1; j++)
            {
                a[i][j]=1;
            }
        }
        else
        {
            a[i][0]=1;
        }
    }
    for(int i = 0; i < h; i++)
    {
        if(i%2 == 1)
        {
            for(int j = 1; j < w; j++)
            {
                b[i][j]=1;
            }
        }
        else
        {
            b[i][w-1]=1;
        }
    }

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            cout<<(a[i][j]?'#':'.');
        cout<<'\n';
    }
    cout<<'\n';
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            cout<<(b[i][j]?'#':'.');
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int x; cin >> x;
    vector<int> dp(x+1100,INF);
    vector<int> a = {100,101,102,103,104,105};
    queue<int> q;
    dp[0] = 0;
    q.push(0);
    int cur = 0;
    while (cur < x) {
        int cur = q.front(); q.pop();
        rep(i,6) {
            int v = cur + a[i];
            if (dp[v] > dp[cur]+1) {
                dp[v] = dp[cur]+1;
                q.push(v);
            }
        }
        if (cur >= x) break;
    }
    
    if (dp[x]==INF) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#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 N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  vector<double> w;
  double b = 1;
  rep(i,N){
    b *= 2;
    w.push_back(b);
  }
  w[w.size()-1] = w[w.size()-2];
  reverse(ALLOF(w));

  double ret = 0;
  rep(i,N){
    ret += v[i] / w[i];
  }

  printf("%.12lf\n", ret);
  
  return 0;
}



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

using namespace std;

int main()
{
  int n;
  int b;
  int f;
  int r;
  int v;
  int count[4][3][10]={0};
  int i;
  int j;
  int k;
  
  cin >> n;
  
  for(i=0;i<n;i++)
  {
    cin >> b >> f >> r >>v;
    count[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++)
  {
    for(j=0;j<3;j++)
    {
      for(k=0;k<10;k++)
      {
        cout << " " << count[i][j][k];
      }
      cout <<"\n";
    }
    if(i==3)
      break;
    cout <<"####################\n";
  }
}

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

typedef long long ll;
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
ll fac[N], inv[N];
char s[N];
int k;

ll qp(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = fac[1] = 1;
    for(int i = 2; i < N; i++) fac[i] = fac[i - 1] * i % mod;
    inv[N - 1] = qp(fac[N - 1], mod - 2);
    for(int i = N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll a, ll b) {
    if(b > a) return 0ll;
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

ll add(ll a, ll b) {
    return (a + b) % mod;
}

int main()
{
    init();
    scanf("%d", &k);
    scanf("%s", s);

    ll res = 0;
    int len = strlen(s);

    for(int i = len; i <= k + len; i++) //枚举前i个字符为S的所在地，即第i个位置是字符s[len-1]的所在地
        res = add(res, C(i - 1, len - 1) * qp(25ll, i - len) % mod * qp(26ll, k + len - i) % mod);
    printf("%lld\n", res);

    return 0;
}


Measured memory_bytes: 35988
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	if(n==1||n==2||n==3||n==4||n==5||n==6||n==7||n==8||n==9||n==10||n==12||n==16||n==18||n==14||n==15||n==20||n==21||n==25||n==24||n==27||n==28||n==36||n==32||n==30||n==35||n==40||n==49||n==45||n==42||n==48||n==54||n==56||n==63||n==64||n==81||n==72){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    h,n = mi()
    a = li()
    if h <= sum(a):
        print("Yes")
    else:
        print("No")

        



main()


Measured memory_bytes: 16188
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int h;
    cin >> h;
    int k = 1, ans = 0;
    while (h > 1) {
        h /= 2;
        ans += k;
        k *= 2;
    }
    ans += k;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int a, b;

int main() {
    while (cin >> a >> b) {
        if (a <= b) cout << a << endl;
        else cout << a-1 << endl;
    }
}

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

typedef long long ll;

const int MAX_N = 100;
const int MAX_W = 1e5;

vector<vector<ll> > memo(MAX_N, vector<ll>(MAX_W + 1, -1));
int N; int W;
vector<pair<int, int> > WandV(MAX_N);

ll dp(int i, int j) {
    if (memo[i][j] == -1) {
        int w = WandV[i].first;
        int v = WandV[i].second;
        if (i == 0) {
            if (j >= w) {
                memo[i][j] = v;
            } else {
                memo[i][j] = 0;
            }
        } else {
            if (j >= w) {
                memo[i][j] = max(dp(i - 1, j - w) + v, dp(i - 1, j));
            } else {
                memo[i][j] = dp(i - 1, j);
            }
        }
    }
    return memo[i][j];
}

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> WandV[i].first;
        cin >> WandV[i].second;
    }
    cout << dp(N - 1, W) << endl;
}


Measured memory_bytes: 79360
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 105, inf = 1e9 + 7 ;
using namespace std ;

int n, a[N] ;

int main() {
    scanf("%d", &n) ;
    rep(i, 1, n) {
        scanf("%d", &a[i]) ;
    }
    int ans = inf ;
    rep(x, - 100, 100) {
        int res = 0 ;
        rep(i, 1, n) {
            res += (a[i] - x) * (a[i] - x) ;
        }
        ans = min(ans, res) ;
    }
    printf("%d\n", ans) ;
    return 0 ;
}

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

const int mod = 998244353;
int dp[305][305][305];
int dp2[305][305][305];
int dp3[305][305][305];

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

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	string s; int K;
	cin >> s >> K;

	vector<int> a = { 0 };
	for (auto i : s)
	{
		if (i == '1') ++a.back();
		else a.push_back(0);
	}

	int n = a.size();
	int l = s.length();
	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= l; ++j)
			for (int k = 0; k <= l; ++k)
			{
//				for (int x = 0; x <= min(a[i], j); ++x)
//					add(dp[i+1][j-x][k], dp[i][j][k]);
//				for (int x = 1; x + j <= l; ++x)
//					add(dp[i+1][j+x][k+x], dp[i][j][k]);
				add(dp2[i+1][j][k], dp[i][j][k]);
				if (j - min(a[i], j) > 0)
					add(dp2[i+1][j - min(a[i], j) - 1][k], mod - dp[i][j][k]);

				add(dp3[i+1][j+1][k+1], dp[i][j][k]);
			}

		for (int j = 0; j <= l; ++j)
			for (int k = 0; k <= l; ++k)
				add(dp3[i+1][j+1][k+1], dp3[i+1][j][k]);

		for (int j = l; j >= 0; --j)
			for (int k = 0; k <= l; ++k)
				add(dp2[i+1][j][k], dp2[i+1][j+1][k]);

		for (int j = 0; j <= l; ++j)
			for (int k = 0; k <= l; ++k)
			{
				dp[i+1][j][k] = dp2[i+1][j][k];
				add(dp[i+1][j][k], dp3[i+1][j][k]);
			}
	}
	int ans = 0;
	for (int k = 0; k <= min(K, l); ++k)
		add(ans, dp[n][0][k]);
	cout << ans << "\n";

	return 0;
}


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

int main() {
    

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    int a;
    
    string b;
    
    cin >> a >> b;
    
    if (a >= 3200) {
        cout << b << endl;
    } else {
        cout << "red" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000

int main(){
	
	int K,X;
	cin>>K>>X;
	bool f = false;
	for(int i=X-K+1;i<=X+K-1;i++){
		if(f){
			cout<<' ';
		}
		cout<<i;
		f=true;
	}
	
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

n, a, *x = map(int, sys.stdin.read().split())

def main():
    dp = np.zeros((n + 1, 2501), dtype=np.int64)
    dp[0, 0] = 1
    for i in range(n):
        dp[1:, x[i]:] += dp[:-1, :-x[i]].copy()
    i = np.arange(1, n + 1)
    print(dp[i, i * a].sum())

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 21908
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=998244353;
ll n,ans,a[500010],b[1000010],f[1000010],ny[1000010],c[1000010];
int main(){
	ll i,xlh,fm,sum;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		b[a[i]]=b[a[i]]+a[i];c[a[i]]=(c[a[i]]+a[i]*a[i])%p;
	}
	ny[0]=ny[1]=1;
	for(i=2;i<=1000000;i++)ny[i]=ny[p%i]*(p-p/i)%p;
	for(fm=1000000;fm;fm--){
		xlh=0;sum=0;
		for(i=fm;i<=1000000;i+=fm)xlh=(xlh+c[i])%p,sum=(sum+b[i])%p;
		//if(xlh%2==0)xlh=xlh/2%p*(xlh+1);
		 //else xlh=(xlh+1)/2%p*xlh;
		xlh=(sum*sum%p-xlh+p)%p*ny[2]%p;
		//xlh=xlh*(xlh+1)%p*ny[2]%p;
		f[fm]=xlh;
		for(i=fm*2;i<=1000000;i+=fm)f[fm]=(f[fm]-f[i]+p)%p;
		//if(f[fm]>0)printf("%lld %lld\n",fm,f[fm]);
		ans=(ans+f[fm]*ny[fm])%p;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 35072
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;
const ll MAX=5e5;

ll n,qn,sq;
ll c[MAX+5];
ll tmp[MAX+5];
struct query{
    ll idx,l,r,ans;
    query(ll idx,ll l,ll r):idx(idx),l(l),r(r){}
    bool operator<(query& x){
        if(r/sq!=x.r/sq) return r/sq<x.r/sq;
        return l<x.l;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>qn;
    sq=sqrt(n);
    FOR(i,1,n) cin>>c[i];
    vector<query> qu;
    FOR(i,0,qn-1){
        ll l,r;
        cin>>l>>r;
        qu.eb(i,l,r);
    }
    sort(ALL(qu));
    ll ans=0,l=1,r=0;
    for(query& q:qu){
        while(r<q.r){
            ++r;
            if(!tmp[c[r]]) ++ans;
            ++tmp[c[r]];
        }
        while(q.r<r){
            --tmp[c[r]];
            if(!tmp[c[r]]) --ans;
            --r;
        }
        while(l<q.l){
            --tmp[c[l]];
            if(!tmp[c[l]]) --ans;
            ++l;
        }
        while(q.l<l){
            --l;
            if(!tmp[c[l]]) ++ans;
            ++tmp[c[l]];
        }
        q.ans=ans;
    }
    sort(ALL(qu),[](query& x,query& y){return x.idx<y.idx;});
    for(query& x:qu){
        cout<<x.ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 27288
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),a =sc.nextInt(),b=sc.nextInt();
        int ans = 0;
        for(int i = 1;i<=n;i++){
            int j = i, tmp = 0;
            while(j>0){
                tmp += j%10;
                j/=10;
            }
            if(tmp>=a&&tmp<=b){
                ans += i;
            }
        }
        System.out.println(ans);
    }
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef unordered_map<ll,ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false);cout<<fixed;cout<<setprecision(0);
#define sqr(x) ((ll)(x) * (x))
#define reset(a, b) memset(a, b, sizeof(a))
#define FOR(i,a,b,c) for(ll i=a;i<b;i+=c)
#define FORD(i,a,b,c) for(ll i=a;i>b;i-=c)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define allr(arr, r) arr, arr + r
#define showv(v) for(auto it: (v))cout<<it<<" ";newl;
#define showvp(v) for(auto it: (v)){cout<<it.F<<" "<<it.S;newl;}
#define show2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define printv(v) for(auto it: (v)) {cout<<it;newl;}
#define newl cout<<"\n"
#define N 100000


const ll MAXN=1e+2+7;
const ll MOD=1e+9+7, INF=0x7f7f7f7f7f7f7f7f;const int INFi=0x7f7f7f7f;
double EPS = 1e-9;
double PI = acos(-1);
/*
vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/

//<<-----Declare Variables Here------->>//;
ll n,k,temp,m;
vvll dp;
vvll v;
vll tempv;
//<<-----Define Functions Here------->>//;
//<<-----Start of Main--------------->>//
int main()
{
	fastio;
	cin>>n;

	dp.resize(n,vll(3,0));
	v.resize(n,vll(3,0));

	FOR(i,0,n,1)
	{
	    FOR(j,0,3,1)
	    {
            cin>>v[i][j];
            if(i==0)
                dp[i][j]=v[i][j];
	    }
	}
	FOR(i,1,n,1)
	{
	    FOR(j,0,3,1)
	    {
	        tempv=dp[i-1];
	        tempv.erase(tempv.begin()+j);
	        dp[i][j]=v[i][j]+*max_element(tempv.begin(),tempv.end());
	    }
	}
	//show2d(dp);
	cout<<*max_element(dp[n-1].begin(),dp[n-1].end());
}

Measured memory_bytes: 11264
#!/usr/bin/env python3
import sys
import fractions


def solve(N: int, a: "List[int]"):
    ans = sum(a) - N
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5372
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<pair<int, int>> as(n);
    for(int i=0;i<n;i++){
        cin >> as[i].first;
        as[i].second = i;
    }
    sort(as.begin(), as.end());
    vector<ll> ans(n);
    int maxPos = M, w = 1;
    for(int i=n-1;i>=0;i--){
        maxPos = min(maxPos, as[i].second);
        int d = as[i].first - (i ? as[i-1].first : 0);
        ans[maxPos] += 1ll * d * w;
        w++;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

void phouse(int s[15][10])
{
    int i,j;
    for (i=0;i<15;i++)
    {
        for (j=0; j<10;j++)
        {
            if (i%4==3) printf("##");
            else printf(" %d",s[i][j]);
        }
        printf("\n");
    }
}

int main(void)
{
    int house[15][10] = {{0}};
    int n,b,f,r,v;
    scanf("%d",&n);
    int i,j,p,k;
    for (i=0;i<n;i++)
    {

        scanf("\n%d %d %d %d",&b,&f,&r,&v);
        p = (b-1)*4+f-1;
        k = r-1;
        house[p][k] += v;
    }
    phouse(house);
    return 0;
}


Measured memory_bytes: 2124
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int y=sc.nextInt();
    boolean f=false;
    for(int i=0;i<=x;i++)
    {
      int j=x-i;
      if(4*i+2*j==y)
        f=true;
    }
    if(f)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


Measured memory_bytes: 35780
#include <string>
#include <iostream>
#include<list>
#include<array>
#include<vector>
#include <algorithm>
#include <functional>
using namespace std;




int main()
{
	int N;
	int X;
	int T;
	cin >> N;
	cin >> X;
	cin >> T;
	int answer;
	if (N % X == 0) {
		answer = N / X * T;
	}
	else {
		answer = ((N / X) + 1) * T;
	}
	cout << answer;
	return 0;
}



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

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> data(100005, vector<int>());
    rep(i, n) {
        int a, b; cin >> a >> b;
        data[a].push_back(b);
    }

    int ans = 0;
    priority_queue<int> q;
    for (int i = 1; i <= m; ++i) {
        for (auto e: data[i]) q.push(e);
        if (!q.empty()) {
            int tmp = q.top();
            ans += tmp;
            q.pop();
        }
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll N; cin >> N;
  auto p = prime_factor(N);
  ll ans = 0;
  for(auto x : p) {
    ll a = 1;
    while(x.second >= a) {
      ans++;
      x.second -= a;
      a++;
    }
  }
  cout << ans << endl;
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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(){
  string S;
  cin >> S;
  int n = S.length();
  for(int i = 0; i < n / 2; i++){
    if(S.at(i) != S.at(n - 1 - i)) {
      no;
      return 0;
    }
  }

  for(int i = 0; i < ((n / 2) / 2); i++){
    if(S.at(i) != S.at((n / 2) - 1 - i)){
      no;
      return 0;
    }
  }

  for(int i = ((n + 3) / 2) - 1; i < n; i++){
      if(i >= n - 1 - i) break;
      if(S.at(i) != S.at(n - 1 - i)) {
      no;
      return 0;
    }
  }
yes;
return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{



    IOS

    int n;
    cin >> n;

    int k = n/1000 + bool(n%1000);

    cout << 1000*k - n;







    return 0;
}


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

using namespace std;

int weight[110],value[110];
int pesomax , qtd;
long long dp[110][100009];

long long funcao(int i, int pesoatual){
	if(i==qtd || pesoatual <= 0){
		return 0;
	}

	if(dp[i][pesoatual]>=0){
		return dp[i][pesoatual];
	}

	long long naocoloca = funcao(i+1,pesoatual);

	if(pesoatual-weight[i] >= 0){
		long long coloca = funcao(i+1,pesoatual-weight[i]) + value[i];
		return dp[i][pesoatual] = max(coloca,naocoloca);
	}

	return dp[i][pesoatual] = naocoloca;
}


int main(){

	cin >> qtd >> pesomax;

	int peso,valor;

	for(int i=0;i<qtd;i++){
		cin >> peso >> valor;
		weight[i] = peso;
		value[i] = valor;
	}

	memset(dp,-1,sizeof(dp));

	long long resposta = funcao(0,pesomax);

	cout << resposta << endl;

	return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    int x, y;
    cin >> x >> y;
    //a + b = x;
    //2*a + 4*b = y;
    //2a + 4(x - a) = y;
    //2a - 4a = y - 4x;
    //a = (4x - y) /2
    if((4*x - y) % 2 == 0 && (4*x-y)/2 >= 0 && (4*x - y)/2 <= x){
    	cout << "Yes\n";
    } else {
    	cout << "No\n";
    }
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    long long int sum = 0;
    for (int i = 0; i < N; i++) {
        int c; cin >> c;
        sum += c;
    }

    cout << sum / N << endl;

    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a[9], state[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    int n;
    for(int i=0;i<9;++i) cin >> a[i];
    cin >> n;
    for(int i=0;i<n;++i){
        int b;
        cin >> b;
        for(int j=0;j<9;++j){
            if(a[j] == b) state[j] = 1;
        }
    }
    for(int i=0;i<3;++i){
        if(state[3*i+0] && state[3*i+1] && state[3*i+2]){
            cout << "Yes" << endl;
            return 0;
        }
        if(state[3*0+i] && state[3*1+i] && state[3*2+i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if((state[0] && state[4] && state[8]) || (state[2] && state[4] && state[6])){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}

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

int N;
const int MAX_N = 100 + 10; 
double A[MAX_N];

int main() {
    cout << fixed << setprecision(10);

    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    double sum = 0;
    for (int i = 0; i < N; i++) {
        sum += 1.0/A[i];
    }

    cout << 1.0/sum << endl;
    

    return 0;
}


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

//Leap Year
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean f = true;
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if((a|b)==0)break;
			if(!f)System.out.println();
			f = false;
			List<Integer> l = new ArrayList<Integer>();
			for(int i=a;i<=b;i++){
				if(i%4==0&&(i%100!=0||i%400==0))l.add(i);
			}
			if(l.isEmpty())System.out.println("NA");
			else for(int i:l)System.out.println(i);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> a(N); REP(i, N) cin >> a[i];

    REP(i, N) a[i] /= 2;
    
    ll lcm_A = 1;
    REP(i, N) {
        lcm_A = lcm(lcm_A, a[i]);
        if (lcm_A > M) break;
    }

    ll p = M / lcm_A;
    if (p%2 == 0) p /= 2;
    else p = p / 2 + 1;

    ll two = 2;
    while (true) {
        int warikireru = 0, warikirenai = 0;
        REP(i, N) {
            if (a[i] % two == 0) warikireru++;
            else warikirenai++;
        }
        if (warikireru == 0) break;
        else if (warikirenai == 0) two *= 2;
        else {
            p = 0;
            break;
        }
    }

    PRINT(p);

    return 0;
}

Measured memory_bytes: 4056
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=ja
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <list>

using namespace std;

#define PI 3.14159265358979

class Coord
{
public:
	Coord(double _x, double _y) : x(_x), y(_y)
	{
	}

	void println() const
	{
		printf("%.8f %.8f\n", x, y);
		// cout << setprecision(8) << x << " " << setprecision(8) << y << endl;
	}

	const double x;
	const double y;
};

list<Coord> coords;

void solve(const Coord start, const Coord dest, list<Coord>::iterator &c)
{
	const double sq3 = sqrt(3.0);
	double vec_x = (dest.x - start.x);
	double vec_y = (dest.y - start.y);

	double x1 = (start.x * 2.0 + dest.x) / 3.0;
	double y1 = (start.y * 2.0 + dest.y) / 3.0;

	double x2 = start.x + (3.0 * vec_x - sq3 * vec_y) / 6.0;
	double y2 = start.y + (sq3 * vec_x + 3.0 * vec_y) / 6.0;

	double x3 = (start.x + dest.x * 2.0) / 3.0;
	double y3 = (start.y + dest.y * 2.0) / 3.0;
	
	coords.insert(c, Coord(x1, y1));
	coords.insert(c, Coord(x2, y2));
	coords.insert(c, Coord(x3, y3));
}

int main()
{
	coords.push_back(Coord(0.0, 0.0));
	coords.push_back(Coord(100.0, 0.0));
	
	int n = 0;
	cin >> n;

	for(int i = 0; i < n; ++i)
	{
		auto c = coords.begin();
		while(next(c) != coords.end())
		{
			Coord start = *c;
			c++;
			Coord dest = *c;
			solve(start, dest, c);
		}
	}

	for_each(coords.begin(), coords.end(), [](Coord& c) { c.println(); });

	return 0;
}


Measured memory_bytes: 3280
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int in_A;
    int in_B;

    int   ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");
      in_A         = Integer.parseInt(in_str_split[0]);
      in_B         = Integer.parseInt(in_str_split[1]);

      /*----------------
       * 計算
       *----------------*/
      ans = (in_A * in_B) - in_A - in_B + 1;

      System.out.println(String.valueOf(ans));
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


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

namespace kakomon
{
    class Program
    {
        static void Main(string[] args)
        {
            abc148_b();
        }

        static void abc148_b()
        {
            // B - Strings with the Same Length
            // sとtから1文字ずつ取り出してつなげる
            int n = int.Parse(Console.ReadLine());
            string[] st = Console.ReadLine().Trim().Split();
            string ans = "";
            for (int i=0; i<n; i++)
            {
                ans += st[0].Substring(i, 1) + st[1].Substring(i, 1);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const ll INF = 10000000000;//INFinity
using namespace std;//namespace

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}//transform
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//#define int long long // yabai

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout

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

#define ALL(obj) (obj).begin(),(obj)// iterator

#define pb(a) push_back(a)end()//push_back
#define mp make_pair// make_pair

int main(){

    auto solve = [](string str){
    if(str.size() < 5)return false;
    while(str.size()!=0){
            if(str.substr(0,5) == "dream"){// || str.substr(0,5) == "erase"){
                str.erase(str.begin() , str.begin() + 5);
             if(str.size()>1)if(str.substr(0,2) == "er" && str.substr(0,5) != "erase")str.erase(str.begin(),str.begin() + 2);
            }else if(str.substr(0,5)=="erase"){
                str.erase(str.begin(),str.begin() + 5);
                if(str.size()!=0)if(str.substr(0,1)=="r")str.erase(str.begin(),str.begin() + 1);
            }else return false;
    
        if(str.size() < 5 && str.size()!=0)return false;
    }
    return true;
    };
    // kokoni kaku
    string s;
    cin>>s;
    cout<<(solve(s)?"YES":"NO")<<endl;


}


Measured memory_bytes: 640
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;

int a, b;

int main() {
	cin >> a >> b;
	if ((a*b) % 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()

    ans = 1
    while N >= 3:
        N -= 3
        ans += 1
    
    ans -= 1
    print(ans)






if __name__ == "__main__":
    main()

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

int main() {
	int n;
	while ( cin >> n ) {
		double prob[ n+5 ];
		
		for (int i = 1; i <= n; ++i) cin >> prob[i];
		
		double dp[ n+5 ][ n+5 ]; memset( dp, 0, sizeof (dp) );
		dp[1][0] = prob[1];
		dp[1][1] = 1 - prob[1];
		
		for (int i = 1; i < n; ++i) {
			for (int j = 0; j <= i; ++j) {
				dp[ i+1 ][j] += dp[i][j] * prob[ i+1 ];
				dp[ i+1 ][ j+1 ] += dp[i][j] * ( 1-prob[ i+1 ] );
//				printf("  %.5lf", dp[i][j] );
			}
//			cout << '\n';
		}
		
//		for (int i = 1; i <= n; ++i) {
//			for (int j = 0; j <= i; ++j) {
//				printf(" %2.3lf", dp[i][j] );
//			}
//			printf("\n");
//		}
		
		double ans = 0;
		
		for (int i = 0; i <= n/2; ++i) ans += dp[n][i];
		
//		for (int i = 0; i <= n; ++i) printf("  %.5lf", dp[n][i] ); cout << '\n';
		
		printf("%.10lf\n", ans );
	}
	return 0;
}

Measured memory_bytes: 70784
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    int n;
    cin >> n;

    n = n % 1000;
    if(n == 0){
        cout << n << endl;
    }
    else{
        cout << 1000 - n << endl;
    }
   
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
std::map<int, bool> to1, to2;
int main(int argc, char const *argv[]) {
	int n = read(), m = read();
	while (m --) {
		int x = read(), y = read();
		if (x > y) swap(x, y);
		if (x == 1) to2[y] = 1;
		if (y == n) to1[x] = 1;
	}
	for (int i = 2; i < n; i++)
		if (to1[i] && to2[i])
			return puts("POSSIBLE")&0;
	puts("IMPOSSIBLE");
	return 0;
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}

int a[5],h;///0..52

int main()
{
	a[1]=read(); a[2]=read(); a[3]=read();
	//O 1??? 
//	dfs(a,b,c);
    sort(a+1,a+4);
    h=a[1]+a[2]+a[3];
    if((h&1)^(a[3]&1)){
    	//& ^ ~  |
		//！ && ||
		printf("%d\n",((a[3]+1)*3-h)/2); 
	}else printf("%d\n",((a[3])*3-h)/2); //{}
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;

// long long modexpo(long long x, long long p){
//     int res = 1;x = x%mod;
//     while(p){
//         if(p%2)res = res * x;
//         p >>= 1;
//         x = x*x % mod;
//         res %= mod;
//     }
//     return res;
// }

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


struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

void yes(){
    cout << "Yes" << endl;
}

int32_t main(){
    IOS
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 1; i < n-1; i++){
        if((arr[i] > arr[i-1] || arr[i] > arr[i+1]) && (arr[i] < arr[i-1] || arr[i] < arr[i+1])){
            ans++;
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3640
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		WriteLine(Console.ReadLine().Count(x => x == '1'));
	}
}


Measured memory_bytes: 13268
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	map<int, int>mp;
	bool F = true;
	REP(i, N) {
		int a;
		cin >> a;
		if (a != 0 && N % 2 == 1 && a % 2 == 1) {
			F = false;
		}
		else if (a != 0 && N % 2 == 0 && a % 2 == 0) {
			F = false;
		}
		mp[a]++;
		if (a == 0 && mp[a] >= 2) {
			F = false;
		}
		if (mp[a] >= 3) {
			F = false;
		}
	}
	int ans = 1;
	REP(i, N / 2) {
		ans *= 2;
		ans %= mod;
	}
	if (F) {
		cout << ans % mod << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	string s;
	cin >> s;
	int cnt_b = 0;
	ll ans = 0;
	for(int i = 0; i < s.length(); i++){
		if (s[i] == 'B') {
			cnt_b++;
		}
		else {
			ans += cnt_b;
		}

	}
	cout << ans << endl;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define Min(a, b) ((a) > (b) ? (b) : (a))

typedef struct {int a, b;} war;

int war_sort(const void *x, const void *y){
  war *X = (war *)x, *Y = (war *)y;
  return X->a - Y->a;
}

int
main(int argc, char *argv[])
{
  int n, m;
  scanf("%d %d", &n, &m);
  war w[100001];
  for(int i = 0; i < m; i++){
    scanf("%d %d", &w[i].a, &w[i].b);
  }

  qsort(w, m, sizeof(war), war_sort);

  int ans = 1;
  int min = w[0].a, max = w[0].b;
  for(int i = 1; i < m; i++){
    if(w[i].a < max){
      max = Min(max, w[i].b);
    }else{
      max = w[i].b;
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;
 
int main() {
	ll X;
	cin >> X;
	ll cnt=0,ans=0;
	while(ans<X){
		ans+=cnt+1;
		cnt++;
	}//ans>Xのとき、答えはcntになる。1,2,3,,,となるがans=X-1なら1の時に飛ばない、ans=x-2なら2の時に飛ばない、とか考える

	cout << fixed << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int a, b;
    cin >> a >> b;
    int ans;
    if (a <= 5) ans = 0;
    else if (a <= 12) ans = b/2;
    else ans = b;
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

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

int main(){

  int N;
  cin>>N;
  string s;
  cin>>s;
  
  if(s.length()<=N)cout<<s<<endl;
  else cout<<s.substr(0,N)<<"..."<<endl;
}

Measured memory_bytes: 3632