akhauriyash/Code-Regression huggingface dataset:
import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n: number = 0;
    let xn: number[] = [];
    let yn: number[] = [];
    let ans: number = 0;
    // init
    n = Number(input.shift());
    for (let nx = 0; nx < n; nx++) {
        [xn[nx], yn[nx]] = input[nx].split(" ").map(x => Number(x));
    }
    // solve
    let x2nmax = Number.MIN_SAFE_INTEGER;
    let x2nmin = Number.MAX_SAFE_INTEGER;
    let y2nmax = Number.MIN_SAFE_INTEGER;
    let y2nmin = Number.MAX_SAFE_INTEGER;
    for (var nx = 0; nx < n; nx ++) {
        let x2n = xn[nx] + yn[nx];
        let y2n = xn[nx] - yn[nx];
        x2nmax = Math.max(x2nmax, x2n);
        x2nmin = Math.min(x2nmin, x2n);
        y2nmax = Math.max(y2nmax, y2n);
        y2nmin = Math.min(y2nmin, y2n);
    }
    let x2nlen = Math.abs(x2nmax - x2nmin);
    let y2nlen = Math.abs(y2nmax - y2nmin);
    ans = Math.max(x2nlen, y2nlen);
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();


Measured memory_bytes: 93016
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 double abs(double x)
 {
   if(x<0) return -x;
   else return x;       
 }
  
 int main()
 {
   double x1,y1,x2,y2,x3,y3,x4,y4;
   int n;
   cin>>n;
   while(n--)
   {
     cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    
       double k1=(y2-y1)/(x2-x1);
       double k2=(y4-y3)/(x4-x3);
       double judge=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
       if((abs(judge)<0.000000000001)) cout<<"YES"<<endl;
       else cout<<"NO"<<endl;     
           
   }
   //while(1);      
   return 0;    
 }

Measured memory_bytes: 3068
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <set>
#include <queue>
#include <map>

using namespace std;

const double EPS = 1e-7;

typedef complex<double> Vector;

inline bool eqv(double a, double b) {
    return fabs(a-b) < EPS;
}

inline bool eqv(const Vector &a, const Vector &b) {
    return eqv(a.real(), b.real()) && eqv(a.imag(), b.imag());
}

inline bool contain(const Vector &p1, const Vector &p2, double y) {
    return min(p1.imag(), p2.imag()) < y && y < max(p1.imag(), p2.imag());
}

Vector linepos(const Vector &p1, const Vector &p2, double y) {
    const Vector &v = p2-p1;
    const double dy = p2.imag()-p1.imag();

    Vector res = p1 + v*(y-p1.imag())/dy;
    res.imag() = y;
    return res;
}

struct Tag {
    double cost;
    int left, right;

    Tag() {}
    Tag(double c, int l, int r) : cost(c), left(l), right(r) {}

    bool operator < (const Tag &other) const {
        return cost > other.cost;
    }
};

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<Vector> v;
        set<int> ys;
        for(int i = 0; i < N; ++i) {
            int x, y;
            cin >> x >> y;
            v.push_back(Vector(x, y));
            ys.insert(y);
        }

        for(set<int>::iterator it = ys.begin(); it != ys.end(); ++it) {
            vector<Vector> new_v;
            for(int i = 0; i+1 < v.size(); ++i) {
                new_v.push_back(v[i]);
                if(contain(v[i], v[i+1], *it)) {
                    const Vector pt = linepos(v[i], v[i+1], *it);
                    new_v.push_back(pt);
                }
            }
            new_v.push_back(v.back());
            v = new_v;
        }
        N = v.size();

        double ans = 0;
        priority_queue<Tag> q;
        map<pair<int,int>, double> memo;
        q.push(Tag(0, 0, N-1));
        while(!q.empty()) {
            Tag t = q.top();
            q.pop();

            assert(eqv(v[t.left].imag(), v[t.right].imag()));
            if(t.left == t.right) {
                ans = t.cost;
                break;
            }
            pair<int,int> key = make_pair(t.left, t.right);
            if(memo.count(key) && memo[key] < t.cost) continue;
            memo[key] = t.cost;

            for(int dl = -1; dl <= 1; ++dl) {
                int nl = t.left + dl;
                if(nl < 0 || N <= nl) continue;
                for(int dr = -1; dr <= 1; ++dr) {
                    int nr = t.right + dr;
                    if(nr < 0 || N <= nr) continue;
                    if(!eqv(v[nl].imag(), v[nr].imag())) continue;

                    pair<int,int> nk = make_pair(nl, nr);
                    double nc = t.cost + abs(v[t.left]-v[nl]) + abs(v[t.right]-v[nr]);
                    if(!memo.count(nk) || nc < memo[nk]) {
                        memo[nk] = nc;
                        q.push(Tag(nc, nl, nr));
                    }
                }
            }
        }

        printf("%.3f\n", ans);
    }

    return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, H) rep(j, W) {
        string n = to_string(i + 1);
        char s = 'A' + j;
        string ans = s + n;
        string S;
        cin >> S;
        if (S == "snuke") cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	vi b={0};
	rep1(i,N){
		int x;
		cin>>x;
		b.push_back(x);
	}
	bool ok=true;
	rep1(i,N)if(b[i]>i)ok=false;
	if(!ok){
		cout<<-1<<endl;
		return 0;
	}
	int ans[101];
	vi c={0};
	rep1(i,N)c.push_back(i);
	
//  	rep(i,N+1)cout<<b[i]<<" ";
//  	cout<<endl;
//  	rep(i,N+1)cout<<c[i]<<" ";
  	cout<<endl;
	for(int j=N;j>=1;j--){
		for(int i=j;i>=1;i--)if(b[i]==c[i]){
			ans[j]=b[i];
			b.erase(b.begin()+i);
			c.erase(c.begin()+i);
			for(int k=i;k<=j-1;k++)c[k]--;
          	break;
		}
	}
	rep1(i,N)cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
from itertools import accumulate
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
R = [0]+list(accumulate(A))
C = sorted(list(Counter(R).values()))
C.reverse()
ans = 0
for c in C:
  if c == 1:
    break
  ans += c*(c-1)//2
print(ans)


Measured memory_bytes: 41492
def mine_count(x, y, ans):
    ans[y][x] = 0
    for nx, ny in (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1):
        if 0 <= y+ny < H and 0 <= x+nx < W:
            if ans[y+ny][x+nx] == "#":
                ans[y][x] += 1
    return ans


H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
ans = S
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = mine_count(j, i, ans)

for row in ans:
    for item in row:
        print(item, end="")
    print()


Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=1e5+5,W=11;
vector<int> g[N];
int f[N],d[N],c[N];
int a[N];
bool u[N][W];
pii qu[N];
void bfs(int s,int dist,int col){
    if(u[s][dist])return;
    int l=0,r=0;
    qu[r++]={s,dist};
    for(int j=0;j<=dist;++j)u[s][j]=1;
    while(l<r){
        pii p=qu[l++];
        int v=p.f,x=p.s;
        if(!a[v])a[v]=col;
        if(x){
            for(int to:g[v]){
                if(!u[to][x-1]){
                    forn(j,x)u[to][j]=1;
                    qu[r++]={to,x-1};
                }
            }
        }
    }
}
int32_t main(){
    int n,m,q;
    cin>>n>>m;
    forn(i,m){
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    cin>>q;
    forn(i,q)cin>>f[i]>>d[i]>>c[i];
    for(int i=q-1;i>=0;--i)bfs(f[i],d[i],c[i]);
    for(int i=1;i<=n;++i)cout<<a[i]<<'\n';
    return 0;
}

Measured memory_bytes: 15212
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int X[3], Y[3];
ld r, mx_e, E[3];

ld len(int x1, int y1, int x2, int y2){
    double x = abs(x1-x2);
    double y = abs(y1-y2);
    return sqrt(x*x+y*y);
}

bool check(ld x){
    ld a=mx_e*(r-x)/r;
    return (a>=2*x);
}

void calc(){
    E[0] = len(X[0],Y[0],X[1],Y[1]);
    E[1] = len(X[0],Y[0],X[2],Y[2]);
    E[2] = len(X[1],Y[1],X[2],Y[2]);
    mx_e = max(E[0],max(E[1],E[2]));
    ld s = (E[0]+E[1]+E[2])/2;
    ld S = sqrt(s*(s-E[0])*(s-E[1])*(s-E[2]));
    r = S/s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,3) cin>>X[i]>>Y[i];
    calc();
    
    ld lb=0, ub=r, mid;
    while(ub-lb>1e-10){
        mid=(ub+lb)/2;
        if(check(mid)) lb=mid;
        else ub=mid;
    }
    printf("%.12llf\n",lb);
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Set;


import java.util.HashSet;
import java.util.Collections;


public class Main{
    static Scanner sc=new Scanner(System.in);
    static int N=sc.nextInt();
    static int C=sc.nextInt();
    static int[][]D=new int[C][C];
    static int[][]c=new int[N][N];
    public static void main(String[] args){
        for(int i=0;i<C;i++){
            for(int j=0;j<C;j++){
                D[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                c[i][j]=sc.nextInt()-1;
            }
        }
        int[][]kazu=new int[3][C];
        for(int i=0;i<3;i++){
            for(int j=0;j<C;j++){
                kazu[i][j]=0;
            }
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                kazu[(i+j)%3][c[i][j]]++;
            }
        }
        long min=334334334;
        long sum=0;
        for(int i=0;i<C;i++){
            for(int j=0;j<C;j++){
                for(int k=0;k<C;k++){
                    if((i!=j)&&(j!=k)&&(i!=k)){
                        sum=0;
                        for(int l=0;l<C;l++){
                            sum+=D[l][i]*kazu[0][l];
                            sum+=D[l][j]*kazu[1][l];
                            sum+=D[l][k]*kazu[2][l];
                        }
                        min=Math.min(min,sum);
                        
                        
                    }
                }
            }
        }
        System.out.println(min);


        
        

            

        
        
        
        
            

        
        

    }
    }


Measured memory_bytes: 91208
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	long a, b, lcm, gcd;
	String[] input;
	while (scan.hasNext()){
	    input = scan.nextLine().split(" ");
	    a = Integer.parseInt(input[0]);
	    b = Integer.parseInt(input[1]);
	    lcm = solveLCM(a, b);
	    gcd = solveGCD(a, b);
	    System.out.println(gcd + " " + lcm);
	}
    }
    static long solveGCD (long a, long b) {
	long gcd = a % b;
	if (gcd == 0) {
	    return b;
	}
	return solveGCD(b, gcd);
    }

    static long solveLCM (long a, long b) {
	if (a == 0 || b == 0) {
	    return 0;
	}
	return a * b / solveGCD(a,b);
    }
}

Measured memory_bytes: 26232
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next()), temp = 0;
            long ret = 0;
            int[] num = new int[n];
            
            for(int i=0; i<n; i++){
            	num[i] = Integer.parseInt(sc.next());
            }
            
            for(int i=n-1; i>=0; i--){
            	if(num[i] > i){
            		ret = -1;
            		break;
            	}
            	
            	if(num[i] < temp){
            		ret = -1;
        			break;
            	}else if(num[i] > temp){
            		temp = num[i];
            		ret += num[i];
            	}
            	temp--;
            }
            
            System.out.println(ret);
            sc.close();
        }
    }
	

Measured memory_bytes: 65644
#include "bits/stdc++.h"
using namespace std;
signed main()
{
	int n;
	cin >> n;
	set<string> a;
	string s;
	for(int i = 0; i < n; ++i)
	{
		cin >> s;
		a.insert(s);
	}
	cout << a.size() << "\n";	
}


Measured memory_bytes: 19176
#include<iostream>

int main(){
    int pos[5], d;
    for(int i = 0; i < 5; i++) std::cin >> pos[i];
    std::cin >> d;
    if(pos[4] - pos[0] <= d) std::cout << "Yay!" << std::endl;
    else std::cout << ":(" << std::endl;
    return 0;
}


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


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.teamFormationMake();
		return;
	}
	
	private void teamFormationMake() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		
		try {
			
			String inputStr = bufferedReader.readLine();
			int yearNum = Integer.parseInt(inputStr); //入力される年数
			LinkedList<LinkedList<Integer>> programmerList = new LinkedList<LinkedList<Integer>>(); //プログラマのリスト
			int teamNum = 0; //年ごとのチーム数
			
			for (int i = 0; i < yearNum; i++) {
				
				String teamStr = bufferedReader.readLine();
				String[] teamStrs = teamStr.split(" ");
				programmerList.add(new LinkedList<Integer>());
				
				for (int j = 0; j < teamStrs.length; j++) {
					programmerList.get(i).add(Integer.parseInt(teamStrs[j]));
				}
			}
			
			for (int i = 0; i < yearNum; i++) {
				
				int c = programmerList.get(i).get(0);
				int a = programmerList.get(i).get(1);
				int n = programmerList.get(i).get(2);
				
				while(true) {
					
					if (c >= 1 && a >= 1 && n >= 1) {
						teamNum++;
						c--;
						a--;
						n--;
					} else if (c >= 2 && a >= 1) {
						teamNum++;
						c = c - 2;
						a--;
					} else if (c >= 3) {
						teamNum++;
						c = c - 3;
					} else {
						break;
					}
					
				}
				
				System.out.println(teamNum);
				
				teamNum = 0;
			}
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}

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

int main() {
  int N;
  int a[101];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a+N, greater<int>());
  int first = 0, last = 0;
  for (int i = 0; i < N; i++) {
    if(i % 2 == 0) {
      first += a[i];
    }else{
      last += a[i];
    }
  }

  cout << first - last << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
   int r,g,b;
   cin>>r>>g>>b;
    int n;

    n=r*100+g*10+b;
    if(n%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    return 0;
}

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

struct Trie{
	int v;
	int nx[27];
} tr[800010];

int n, qn, cnt, p[27], cs[100010][27][27];
char buf[400010];
vector<char> v[100010];
queue<int> q;
stack<int> st;

void go(int &t, int c){
	if(!tr[t].nx[c]) tr[t].nx[c] = ++cnt;
	t = tr[t].nx[c];
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%s", buf);
		int t = 0;
		for(int j = 0; buf[j]; j++){
			v[i].push_back(buf[j]);
			int c = buf[j] - 'a' + 1;
			go(t, c);
		}
		go(t, 0);
		tr[t].v++; 
	}
	q.push(0);
	while(!q.empty()){
		int cur = q.front(); q.pop();
		st.push(cur);
		for(int i = 0; i < 27; i++){
			if(tr[cur].nx[i]) q.push(tr[cur].nx[i]);
		}
	}
	while(!st.empty()){
		int cur = st.top(); st.pop();
		for(int i = 0; i < 27; i++){
			if(tr[cur].nx[i]) tr[cur].v += tr[tr[cur].nx[i]].v;
		}
	}
	for(int i = 1; i <= n; i++){
		int t = 0;
		for(int j = 0; j < v[i].size(); j++){
			int c = v[i][j] - 'a' + 1;
			for(int k = 0; k <= 26; k++) if(tr[t].nx[k]) cs[i][c][k] += tr[tr[t].nx[k]].v;
			go(t, c);
		}
	}
	scanf("%d", &qn);
	for(int k; qn--; ){
		scanf("%d%s", &k, buf + 1);
		for(int i = 1; i <= 26; i++) p[i] = buf[i] - 'a' + 1;
		int ret = 0;
		for(int i = 1; i <= 26; i++){
			for(int j = 0; p[j] != i; j++){
				ret += cs[k][i][p[j]];
			}
		}
		printf("%d\n", ret + 1);
	}
}

Measured memory_bytes: 318208
#include<cstdio>
#include<vector>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;
typedef	vector<pii>		vpii;

vector<vpii> rect;
int w,h,n,land[10][10],test[10][10],ans[10][10];

bool search(int i0,int j0){
	for(int i=i0;i<h;i++){
		for(int j=(i==i0?j0:0);j<w;j++){
			int id=land[i][j];
			if(id==0)	continue;
			if(id<0 || n<id)	continue;

			// try to put a rectangle
			int cnt=0;
			for(int k=0;k<rect[id].size();k++){
				int rh=rect[id][k].first,rw=rect[id][k].second;
				for(int y=i-rh+1;y<=i;y++){
					for(int x=j-rw+1;x<=j;x++){
						if(!(0<=y && y+rh<=h && 0<=x && x+rw<=w))	continue;
						bool canput=true;
						for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++){
							if(test[yy][xx]!=0
							||(land[yy][xx]!=0 && land[yy][xx]!=id))	canput=false;
						}
						if(!canput)	continue;
						for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++)test[yy][xx]=id;
						cnt+=search(i,j+1);
						for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++)test[yy][xx]=0;
						if(cnt>=2)	return false;
					}
				}
			}

			return cnt==1;
		}
	}

	bool suc=true;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		if(test[i][j]==0)	suc=false;
	}
	if(suc){
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	ans[i][j]=test[i][j];
		return true;
	}
	return false;
}

int main(){
	for(;scanf("%d%d%d",&w,&h,&n),w;){
		rect=vector<vpii>(n+1);

		for(int i=0;i<n;i++){
			int id,area;	scanf("%d%d",&id,&area);
			for(int j=1;j<=area;j++){
				if(area%j==0)	rect[id].pb(mp(j,area/j));
			}
		}
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	scanf("%d",&land[i][j]);

		if(search(0,0)){
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++)	printf("%s%d",(j?" ":""),ans[i][j]);
				putchar('\n');
			}
		}
		else	puts("NA");
	}

	return 0;
}

Measured memory_bytes: 832
#include <iostream>
using namespace std;
int main() {
    long long N;string str;
    long long count=0;
    long long R=0;
    long long G=0;
    long long B=0;
    long long answer=0;
    cin>>N>>str;
   
   for(long long i=0;i<N;i++)
   {
      if(str[i]=='R')R++;
      if(str[i]=='G')G++;
      if(str[i]=='B')B++;
   }
   answer=(R*G*B);
 
   
   for(long long i= 0;i<=N-2;i++)
      for(long long j=i+1;j<=N-1;j++)
      {
        long long k=2*j-i;
        if(k<N){
        if((str[i]!=str[j])&&(str[j]!=str[k])&&(str[k]!=str[i]))
           count++;
        }
      }
 
    answer=answer-count;
    if(answer<=0)answer=0;
    cout<<answer<<endl;
 
    return 0;
}

Measured memory_bytes: 3624
year,month,day = input().split("/")
#1 =平成
year = int(year)
month = int(month)
day = int(day)
flg = 0
if year<=2019:
    if year == 2019:
        if month<=4 and day <=30:
            flg = 1
    else:
        flg = 1

else:
    pass

if flg==1:
    print("Heisei")
else:
    print("TBD")


Measured memory_bytes: 3060
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import permutations

def resolve():
    N=int(input())
    l=[[0,0] for i in range(N)]
    for i in range(N):
        x,y=map(int,input().split())
        l[i][0],l[i][1]=x,y

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)**0.5

    print(dist/len(list(permutations((l)))))


resolve()

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

using namespace std;

int main(){
  unsigned long long N = 0;
  unsigned long long M=0, A=0, R=0, C=0, H=0;
  cin >> N;
  string s;
  for(int i=0; i<N; i++){
    cin >> s;
    if(s[0]=='M'){
      M+=1;
    }else if(s[0]=='A'){
      A+=1;
    }else if(s[0]=='R'){
      R+=1;
    }else if(s[0]=='C'){
      C+=1;
    }else if(s[0]=='H'){
      H+=1;
    }
  }
  unsigned long long sum = 0;
  sum += M * A * R;
  sum += M * A * C;
  sum += M * A * H;
  sum += M * R * C;
  sum += M * R * H;
  sum += M * C * H;
  sum += A * R * C;
  sum += A * R * H;
  sum += A * C * H;
  sum += R * C * H;
  printf("%llu\n", sum);
  return 0;
}


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


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

    int N;
    cin >> N;

    int c[N][3];
    for (int i = 0; i < N; ++i) {
        cin >> c[i][0] >> c[i][1] >> c[i][2];
        if (c[0][2] == 0 && c[i][2] > 0) {
            swap(c[i], c[0]);
        }
    }

    int tmp_h;
    int res[3] = {};
    for (int X = 0; X <= 100; ++X) {
        for (int Y = 0; Y <= 100; ++Y) {
            tmp_h = 0;
            for (int k = 0; k < N; ++k) {
                int dis = abs(X - c[k][0]) + abs(Y - c[k][1]);
                if (tmp_h == 0) {
                    tmp_h = c[k][2] > 0? c[k][2] + dis : 0;
                }

                if (c[k][2] != max(tmp_h - dis, 0)) break;
                if (k == N - 1 && res[2] < tmp_h) {
                    res[0] = X;
                    res[1] = Y;
                    res[2] = tmp_h;
                    cout << res[0] << ' ' << res[1] << ' ' << res[2] << '\n';
                    return 0;
                }
            }
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
const double PI = acos(-1);

int C[30];

int main(){
    int N;
    cin>>N;
    C[0]++;
    for(int i=0;i<N;i++){
        int d;
        cin>>d;
        C[d]++;
    }
    for(int i=0;i<23;i++){
        if(C[i]<=1) continue;
        if(C[i]>=3){
            cout<<0<<endl;
            return 0;
        }
        if(i==0 || i>=12){
            cout<<0<<endl;
            return 0;
        }
        C[24-i]++;
    }
    vector<int> V,T;
    for(int i=0;i<=12;i++){
        if(i==0 || i==12){
            if(C[i]) V.push_back(i);
            continue;
        }
        if(C[i] && C[24-i]){
            V.push_back(i);
            V.push_back(24-i);
        }else if(C[i] || C[24-i]){
            T.push_back(i);
        }
    }
    int nV=(int)V.size(),nT=(int)T.size();
    int ans=0;
    for(int S=0;S<(1<<nT);S++){
        vector<int> D;
        for(int i=0;i<nV;i++){
            D.push_back(V[i]);
        }

        for(int i=0;i<nT;i++){
            if(bit(S,i)) D.push_back(24-T[i]);
            else D.push_back(T[i]);
        }
        D.push_back(24);
        int temp=24;
        for(int i=0;i<(int)D.size();i++){
            for(int j=i+1;j<(int)D.size();j++){
                temp=min(temp,   abs(D[i]-D[j])   );
            }
        }

        ans=max(ans,temp);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",&x)
#define rep(i,a,b) for(int i = a ; i <= b ; i++)
#define per(i,a,b) for(int i = b ; i >= a ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL INF = 1e12;
const int mod = 1e4 + 7;
const int maxn = 2e5 + 7;

int main() {
    LL x,y;
    while(cin >> x >> y) {
        if(x == 1 || y == 1) cout << 1 << endl;
        else cout << y * (x / 2LL) + (x % 2LL == 0 ? 0 : (y + 1LL) / 2LL) << endl;
    }
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,m;
  cin >> n >> m;

  map<ll, ll> ac, wa;
  REP(i, m){
    ll p;
    string s;
    cin >> p >> s;
    p--;
    if(ac[p] == 0 && s=="WA")
      wa[p]+= 1;
    else if(s=="AC")
      ac[p] += 1;
  }

  vll ans(2);
  REP(i, n){
    if(ac[i]!=0){
      ans[0]++;
      ans[1] += wa[i];
    }
  }
  cout << ans[0] << " " << ans[1] << endl;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long K){
    ll left = 0, right = 1e12;
    while (right - left > 1) {
        ll middle = (right + left) / 2;
        stringstream ss;
        ss << middle;
        string N = ss.str();

        // dp[by top i digits][top i digit(10 == leading zero)][already smaller than N]
        vector<vector<vector<ll>>> dp(N.size()+1, vector<vector<ll>>(11, vector<ll>(2, 0)));

        // initialize
        rep(i,1,N[0] - '0') dp[0][i][1] = 1;
        dp[0][N[0] - '0'][0] = 1;
        rep(i,0,N.size()) dp[i][10][1] = 1;

        // calculate dp
        rep(i,1,N.size()) {
            rep(smaller, 0, 2) {
                rep(x,0,11) { // prev digit
                    int maxDigit = (smaller ? 10 : (N[i] - '0' + 1))-1; // if not smaller, current digit should not be over N
                    int minDigit = (x == 10 ? 1 : 0); // if prev is leading zero, current digit should not be zero
                    rep(k,minDigit,maxDigit+1) { // current digit
                        if (abs(k-x) <= 1 || x == 10) dp[i][k][smaller || k < (N[i] - '0')] += dp[i-1][x][smaller];
                    }
                }
            }
        }

        // get sum
        ll sum = 0;
        rep(i,0,10) rep(j,0,2) sum += dp[N.size()-1][i][j];

        if (sum < K) left = middle;
        else right = middle;
    }
    cout << right << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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


int main() {
  char c;
  cin >> c;
  int x = c;
  x++;
  c = x;
  cout << c << endl;
}


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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
typedef long long ll;

int main() {
  ll n, sum = 0, temp;
  cin >> n;
  rep (i,n) {
    cin >> temp;
    sum += temp;
  }
  cout << sum / n << endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
    int m , i ;
    string S ;
    cin >> S ;
    m = 0 ;
    for(i=0 ; i <= 2 ; i++)
    {
        if(S[i] == 'o')
        {
            m = m + 100 ;
        }
    }
    cout << m + 700 << endl;
    return 0;
}


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

int main() {
    int K;
    cin >> K;
    vector<long long> A(K);
    for(int i=0; i<K; ++i) cin >> A[i];

    if(A[K - 1] > 2) {
        cout << -1 << endl;
        return 0;
    }

    long long l = 2, r = 2 + A[K - 1] - 1;
    for(int i = K - 2; i>=0; --i) {
        long long s = (l % A[i] == 0 ? (l / A[i]) : (l / A[i] + 1));
        long long t = r / A[i];
        if(s > t) {
            cout << -1 << endl;
            return 0;
        } else {
            l = s * A[i];
            r = t * A[i] + A[i] - 1;
        }
    }

    cout << l << ' ' << r << endl;
}

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

using namespace std;

typedef long long int lli;

int main() {
    int n, k, t, d;
    priority_queue< pair<int, int> > pq;

    cin >> n >> k;
    for (int i=0; i<n; i++) {
        scanf("%d %d", &t, &d);
        pq.push(make_pair(d, t));
    }

    priority_queue< pair<int, int> > eat;
    int neta[100001] = { 0 };
    lli oishisa = 0, x = 0;
    for (int i=0; i<k; i++) {
        auto s = pq.top();
        pq.pop();
        if (neta[s.second] == 0) x++;
        neta[s.second]++;
        oishisa += s.first;
        eat.push(make_pair(-s.first, s.second));
    }

    lli ans = oishisa + x*x;
    while (!pq.empty() && x < k) {
        /*
        cout << oishisa << " " << x << " " << ans << endl;
        for (int i=0; i<10; i++) cout << neta[i] << " ";
        cout << endl;
        */

        auto s = pq.top();
        pq.pop();
        if (neta[s.second]) continue;

        auto out = eat.top();
        while(!eat.empty()) {
            eat.pop();
            if (neta[out.second] >= 2) {
                neta[out.second]--;
                oishisa += out.first;
                break;
            }
            out = eat.top();
        }

        oishisa += s.first;
        neta[s.second]++;
        x++;
        ans = max(ans, oishisa + x*x);
    }

    /*
    cout << oishisa << " " << x << " " << ans << endl;
    for (int i=0; i<10; i++) cout << neta[i] << " ";
    cout << endl;
    */

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2932
#include<iostream>
using namespace std;
int t[100050],x[100050],y[100050];

int main(){
  int n; cin >> n;
  for(int i=1;i<=n;++i) cin >> t[i] >> x[i] >> y[i];
  for(int i=0;i<=n-1;++i){
    int dt,D;
    dt=t[i+1]-t[i];
    D=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(!(D<=dt && (D-dt)%2==0)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int main(){
  ll a,b;
  cin >> a >> b;
  if (abs(a-b) > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  REP(i,a) {
    ans *= (i+1);
    ans %= MOD;
  }
  REP(i,b) {
    ans *= (i+1);
    ans %= MOD;
  }
  if (a == b) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;

long long int gcd2(long long int a, long long int b) {
	long long int tmp,memoa,memob;
	memoa = a;
	memob = b;
	long long int r = 1;
	if (b > a) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {


		a = b;
		b = r;
		r = a % b;

	}
	memob /= b;
	return memoa*memob;
}

int main() {
	long long int n, d = 0, q, s[2000] = {}, leng = 0, goal, two = 0, three = 0, temp = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	temp = s[0];
	for (int i = 1; i < n; i++) {
		temp = gcd2(temp, s[i]);
	}
	cout << temp;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,m,x;
	cin>>n;
	cin>>m;
	int box[300],pre[300];
	for(int i=0;i<2*n;i++)
	box[i+1]=i+1;
	for(int i=0;i<m;i++){
		cin>>x;
		if(x==0){
			for(int j=1;j<=n;j++){
				pre[2*j-1]=box[j];
				pre[2*j]=box[j+n];
			 }
			for(int j=1;j<=2*n;j++)
			box[j]=pre[j];
		}
		else{
			for(int j=x+1;j<=2*n;j++)
			pre[j-x]=box[j];
			for(int j=1;j<=x;j++)
			pre[2*n+j-x]=box[j];
			for(int j=1;j<=2*n;j++)
			box[j]=pre[j];
		}
	}for(int i=1;i<=2*n;i++)
		cout<<box[i]<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {

    int N, Q; cin >> N >> Q;
    string S; cin >> S;

    // 累積和
    int sum[100010];
    sum[0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (S[i] == 'A' && S[i+1] == 'C') sum[i+1] = sum[i] + 1;
        else sum[i+1] = sum[i];
    }

    for (int i = 0; i  < Q; ++i) {
        int l, r; cin >> l >> r;
        int res = sum[r-1] - sum[l-1];
        cout << res << endl;
    }
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(void)
{
	double ans;
	int a, b;
	cin >> a >> b;
	ans = (a + b) / 2.0+0.5;
	ans = (int)ans;
	cout << ans << endl;
	return 0;
}


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

using namespace std;
int a[100001];
int b[100001];
int main()
{
    int i,j,k,n,m,x,y,z;
    cin>>n;

    x=0;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>1 && a[i]<=a[i-1])
        {
            x++;
            //cout<<x<<endl;
            if(i==n)
        {
            b[i]=x;
        }
        }
        else
        {
            b[i]=x;
            x=0;
        }
    }

    cout<<*max_element(b,b+100001)<<endl;
}


Measured memory_bytes: 1024
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
 
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	let s = parseInt(input);
	//出力
	let u = Math.floor(s/500);
	s-=u*500;
	let u1 = Math.floor(s/5);
	console.log(u*1000+u1*5);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7752
#include<stdio.h>
int main(void)
{
  int num = 0,i;
  char str[8];
  
  fgets(str,sizeof(str),stdin);
  
  for(i=0;i<4;i++)
  {
    if(str[i] == '+')
    {
      num++;
    }else if(str[i] == '-')
    {
      num--;
    }else
    {
      puts("error");
    }
  }
  
  printf("%d",num);
  
  return 0;
}
    

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

bool ng[1<<20] = {};
int popcnt[1<<20] = {};

int main(){
    int n, k;
    cin >> n >> k;
    int a[n], ret = n;
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int s = 1; s < 1<<n; s++){
        int sum = 0;
        for(int i = 0; i < n; i++)  if((s>>i)&1)    sum += a[i], popcnt[s]++;
        ng[s] = sum==k;
        for(int i = 0; i < n; i++)  if((s>>i)&1)    ng[s] |= ng[s^(1<<i)];
        if(!ng[s])  ret = min(ret, n-popcnt[s]);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 8220
use text_io::*;

fn main() {
    let n: usize = read!();
    let k: usize = read!();
    let mut vec = vec![];
    for _ in 0..n {
        let a: usize = read!();
        vec.push(a - 1);
    }
    
    let mut doubling = vec![vec![0; n]; 63];
    
    for i in 0..n {
        doubling[0][i] = vec[i];
    }
    
    for i in 1..63 {
        for j in 0..n {
            let next = doubling[i - 1][j];
            doubling[i][j] = doubling[i - 1][next];
        }
    }
    
    let mut ans = 0;
    let mut now_k = k;
    
    for i in (0..63).rev() {
        if (1 << i) <= now_k {
            now_k -= 1 << i;
            ans = doubling[i][ans];
        }
    }
    
    println!("{}", ans + 1)
}


Measured memory_bytes: 102236
import java.util.*;
public class Main {
    public static boolean isValid(char c){
        if(c == 'A' || c == 'C' || c == 'T' || c=='G'){
            return true;
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int max = 0;
        for(int i = 0 ; i < s.length() ; i++){
            int count = 0;
            for(int j = i ; j < s.length() ; j++){
                if(isValid(s.charAt(j))){
                    count++;
                    max = Math.max(max,count);
                } else {
                    break;
                }
            }
        }
        System.out.println(max);
    }
}

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

typedef long long int ll;

const int sz=3003;
ll dp[sz][sz];
int main()
{

    memset(dp,0, sizeof dp);
    int n;
    cin>>n;
    int inp[n];
    for(int i=0;i<n;i++)
    {
        cin>>inp[i];
    }
    for(int l=n-1;l>=0;l--)
    {
        for(int r=l;r<n;r++)
        {
            if(r==l)
                dp[l][r]=inp[l];
            else
                dp[l][r]=max(inp[l]-dp[l+1][r],inp[r]-dp[l][r-1]);
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}


Measured memory_bytes: 74064
#include <stdio.h> // C++???????????????
#include <string.h> // c++???????????????
#include <math.h> // c++???????????????
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long int lli;
#define PI 3.1415926535897932
#define N 100
#define MAX(a,b) ((a>b)?(a):(b)) // ?????§????????????
#define MIN(a,b) ((a<b)?(a):(b)) // ????°?????????????
#define INRANGE(a,b,c) ((a<=b&&b<=c)?(1):(0)) // a<=b<=c??????????????????????????????


void swap(int &a, int &b) { // c??????*
	int w = a;
	a = b;
	b = w;
}

int getdigit(int num) { // ??´??°????????°?????????
	int i, j;
	if (num<0) num *= -1; // ?????°???????????¢
	if (num == 0)return 1;
	for (i = 10, j = 1;; i *= 10, j++) {
		if (INRANGE(i / 10, num, i - 1))return j;
	}
	return 0; // ????????¨??????
}

int getN(int num, int digit) {
	int i = 1, j;
	for (j = 1; j<digit; i *= 10, j++);
	return (num / i) % 10;
}

int zeller(int y, int m, int d) { // 0????????\????????§??????
	if (m<3) { y--; m += 12; }
	return (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + d) % 7;
}

int gcd(int a, int b) {	// ?????§??¬?´???°
	if (b == 0) return a;
	return gcd(b, a%b);
}

int lcm(int a, int b) {	// ????°???¬?????°
	return a*b / gcd(a, b);
}

int stoi(const string str) { // ?????????????????´??°
	int i = 0, j;
	int len = str.length();
	int w = 0;
	for (i = 1, j = 1; i <= len && INRANGE('0', str[len - i], '9'); i++, j *= 10) {
		w += (str[len - i] - '0')*j;
	}
	if (str[0] == '-')w *= -1;
	return w;
}

string itos(int a) { // ??´??°???????????????
	int i;
	string str = "";
	int keta;
	if (a<0) { str += '-'; a *= -1; } // ?????°??????????????????
	for (keta = 10; a / keta != 0; keta *= 10);
	for (i = keta / 10; i != 0; i /= 10) {
		str += ((a / i) % 10) + '0';
	}
	return str;
}

char kaezi[100][100] = { {"XXXXXXX"},{"Xabcde"},{"Xfghij"},{"Xklmno"},{"Xpqrst"},{"Xuvwxy"},{"Xz.?! "} };

int main(void) {
	string str;
	string det;
	int i, j;
	while (cin>>str) {
		det = "";
		for (i = 0; i < str.length(); i+=2) {
			if (str.length() % 2 == 1) { det = "NA"; break; }
			if (INRANGE('1', str[i], '6') && INRANGE('1', str[i + 1], '5')) {
				det += kaezi[str[i] - '0'][str[i + 1] - '0'];
			}
			else {
				det = "NA"; break;
			}
		}
		cout << det << endl;

	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long int 
int main(){
  ll a,b,c,ans;
  cin >> a >> b >> c;
  if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) ans = 0;
  else{
    ans = min(a * b, b * c);
    ans = min(ans , a * c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[3333];
int main(){
	int A,B,C,D,E,F;
	int X=-1,Y=1;
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	for(int i=0; i<=F; i++)if(dp[i] == 0){
		dp[i + C] = 0;
		dp[i + D] = 0;
	}
	for(int i=1; i<=F; i++){
		if(dp[i] == 0)dp[i] = i;else
			dp[i] = dp[i-1];
	}
	for(int a=0; a*A*100 <= F; a++)
	for(int b=0,tot; (tot=a*A*100 + b*B*100) <= F; b++){
		int e = min((a * A + b * B) * E, F - tot);
		int res = dp[e];
		if(res * Y > (res + tot) * X){
			X = res;
			Y = res + tot;
		}
	}
	printf("%d %d\n",Y,X);
	return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a=0,b=0;
    int l = (int)s.size();
    REP(i,l){
        a*=10;
        a+=s[i]-'0';
    }
    for(int i=l-1;i>=0;--i){
        b*=10;
        b+=s[i]-'0';
    }
    if(a==b){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 1000001;
ll K;
int ans = -1;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>K;
    ll num = 7;
    owo(i, 2, mxN) {
        num%=K;
        if(ans==-1&&num==0) {
            ans = i-1;
            break;
        }
        num = (num*10+7);
    }
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second
#define deb(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
bool isPar(string s)
{
    ll n=s.size();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        {
            return 0;
        }
    }
    return 1;
}

ll nOfD(ll n)
{
    ll d=0;
    ll i=1;
    while(i * i < n)
    {
        if(n%i ==0) d+=2;
        i++;
    }
    if(i * i == n)d++;
    return d;
}
ll sOfD(ll n)
{
    ll sum=0;
    ll i=1;
    while(i * i < n)
    {
        if(n%i ==0) sum+=i,sum+=n/i;
        i++;
    }
    if(i * i == n)sum+=i;
    return sum;
}
bool isP(int x)
{
    if(x==2)return 1;
    if(x<2 || x%2==0)return 0;
    for(int i=3;i * i <= x;i+=2)
    {
        if(x%i==0)return 0;
    }
    return 1;
}

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    //freopen("op.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
      ll n;
      cin>>n;
      cout<<(((n/1000)*1000 - n%(1000))+1000)%1000;
    }
    return 0;
}


Measured memory_bytes: 3580