akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	if (k%n == 0) { cout << (k + n); }
	else { cout << (k - n); }
	return 0;
}

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

using namespace std;
int a,b,c,k;
long long tinh(int x, int k){
    long long s=x;
    for (int i=1;i<=k;i++) s*=2;
    return s;
}
int main()
{
    cin>>a>>b>>c>>k;
    cout<<a+b+c+tinh(max(a,max(b,c)),k)-max(a,max(b,c));
    return 0;
}


Measured memory_bytes: 256
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i
res = 0
pos = B
if A < 0 then
    res += A.abs * C + D
elsif A == 0 then
    res += D
else
    pos -= A
end
res += pos * E
puts res


Measured memory_bytes: 6868
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
a,p = map(int,input().split())

chunk = 3*a +p
ans = chunk//2

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int r[2048][64];

int main(){
	int k=38;
	int n=k*(k-1)+1;
	fore(i,0,k){
		r[i][0]=1;
		fore(j,1,k)r[i][j]=(k-1)*i+1+j;
	}
	fore(i,k,k+k-1){
		r[i][0]=2;
		fore(j,1,k){
			int ii=i-k,jj=j-1;
			r[i][j]=r[1+jj][1+ii];
		}
	}
	fore(l,0,k-2){
		fore(ii,0,k-1){
			int i=k+k-1+l*(k-1)+ii;
			r[i][0]=l+3;
			fore(jj,0,k-1){
				int j=jj+1;
				r[i][j]=r[k+jj][1+(ii+jj*(l+1))%(k-1)];
			}
		}
	}
	printf("%d %d\n",n,k);
	fore(i,0,n){
		fore(j,0,k){
			if(j)putchar(' ');
			printf("%d",r[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define LL long long
#define PB push_back
using namespace std;
const LL mod = 1000 * 1000 * 1000 + 7;
const LL ob = (mod + 1) >> 1;

int main()
{
	ios_base::sync_with_stdio(0);
	string s;
	int k;
	cin >> s >> k;
	for(auto &x : s)
		x -= 'a';
	for(int i = 0; i < s.size(); i++)
	{
		int cnt = 26 - s[i] - (s[i] == 0) * 26;
		if(k >= cnt)
		{
			s[i] = 0;
			k -= cnt;
		}
	}
	k %= 26;
	s.back() += k;
	s.back() %= 26;
	for(auto &x : s)
		x += 'a';
	cout << s << endl;
}




Measured memory_bytes: 592
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long m = (long) 1e9 + 7;

	int[] depth;

	void dfs(int cur, int par, ArrayList<Integer>[] g) {
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			depth[dst] = depth[cur] + 1;
			dfs(dst, cur, g);
		}
	}

	int u, v;

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		u = sc.nextInt();// T
		v = sc.nextInt();// A
		--u;
		--v;
		int[] A = new int[N - 1];
		int[] B = new int[N - 1];
		ArrayList<Integer>[] g = new ArrayList[N];
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<Integer>();
		for (int i = 0; i < N - 1; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			--A[i];
			--B[i];
			g[A[i]].add(B[i]);
			g[B[i]].add(A[i]);
		}
		depth = new int[N];
		dfs(v, -1, g);
		ArrayDeque<long[]> dq = new ArrayDeque<>();
		dq.addLast(new long[] { u, 0, depth[u], 0, -1 });
		long ans = 0;
		while (!dq.isEmpty()) {
			long[] cur = dq.pollFirst();
			int curv = (int) cur[0];
			if (g[curv].size() == 1 && cur[3] == 1) {
				long diff = cur[2];
				if (diff % 2 == 0) {
					ans = Math.max(ans, cur[1] + diff - 1);
				} else {
					ans = Math.max(ans, cur[1] + diff - 1);
				}
				continue;
			}

			for (int dst : g[(int) cur[0]]) {
				if (depth[dst] > depth[(int) cur[0]]) {
					ans = Math.max(ans, cur[1] + 1);
					if (cur[3] == 0 && cur[4] == dst)
						continue;
					dq.addLast(new long[] { dst, cur[1] + 1, cur[2], 1, cur[0] });
				} else {
					if (cur[2] - 2 > 0) {
						if (cur[3] == 0 || g[(int) cur[0]].size() == 1) {
							dq.addLast(new long[] { dst, cur[1] + 1, cur[2] - 2, cur[3],
									(g[(int) cur[0]].size() == 1 ? -1 : cur[0]) });
						}
						ans = Math.max(ans, cur[1] + 1);
					} else if (cur[2] == 2) {
						ans = Math.max(ans, cur[1] + 1);
					}
				}
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 112728
//18:10~
#include <bits/stdc++.h>
using namespace std;

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

    int n, m;
    static int deg[100000];
    static vector<int> edges[100000];

    cin >> n >> m;
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        ++deg[a]; ++deg[b];
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }
    static bool odd, six;
    vector<int> four;
    for(int i=0;i<n;++i){
        if(deg[i] & 1) odd = true;
        if(deg[i] >= 6) six = true;
        if(deg[i] == 4) four.emplace_back(i);
    }
    if(odd) cout << "No" << endl;
    else if(six) cout << "Yes" << endl;
    else if(four.size() >= 3) cout << "Yes" << endl;
    else if(four.size() <= 1) cout << "No" << endl;
    else{
        for(int i=0;i<4;++i){
            queue<pair<int, int>> q;
            q.emplace(edges[four[0]][i], four[0]);
            while(!q.empty()){
                auto t = q.front();
                q.pop();
                if(t.first == four[1]) break;
                if(t.first == four[0]){ cout << "Yes" << endl; return 0; }
                for(int to: edges[t.first]){
                    if(to == t.second) continue;
                    q.emplace(to, t.first);
                }
            }
        }
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    string S; cin>>S;
    vec num(30,1);
    rep(i,N){
        num[S[i]-'a']++;
    }
    ll ans=1;
    rep(k,26){
        ans=(ans*num[k])%mod;
    }
    cout<<ans-1<<endl;
}

Measured memory_bytes: 512
import sys
n,m=map(int,input().split())
a={int(input()) for i in range(m)}
dp=[0]*(n+1)
dp[0]=1
if 1 not in a:dp[1]=1
for i in range(2,n+1):
    if i in a:continue
    if dp[i-1]==dp[i-2]==0:break
    dp[i]=(dp[i-1]+dp[i-2])%1000000007
print(dp[-1])

Measured memory_bytes: 11884
#include<stdio.h>

int main(){
  int i;
  int k,n;
  scanf("%d %d",&k,&n);
  int a[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  int min=k;  
  //i番目の家から反時計回りに移動する時
  for(i=1;i<=n;i++){
    if(i==n){
      if(k-(a[0]+k-a[n-1])<min)
        min=k-(a[0]+k-a[n-1]);
    }
    else{
      if(k-(a[i]-a[i-1])<min)
        min=k-(a[i]-a[i-1]);
    }
  }
  //i番目の家から時計回りに移動する時
  for(i=1;i<=n;i++){
    if(i==1){
      if(k-(a[0]+k-a[n-1])<min)
        min=k-(a[0]+k-a[n-1]);
    }
    else{
      if(k-(a[i-1]-a[i-2])<min)
        min=k-(a[i-1]-a[i-2]);
    }
  }
  
  printf("%d",min); 
}

Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int  Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

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

int main() {
	int n,t,a;
	scanf("%d%d%d", &n,&t,&a);

	int h[1000];
	int ans;
	double min=INF;
	REP(i, n) {
		scanf("%d", &h[i]);
		double tmp = a - (t - h[i] * 0.006);
		if (tmp < 0)tmp = -tmp;
		if (tmp < min) {
			ans = i;
			min = tmp;
		}
	}
	PRINTD(ans+1);
}

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

int w[300];
int can[310][310];
int dp[310];

int len(int l, int r) {
	return r - l + 1;
}

int f(int l, int r) {
	if(can[l][r] != -1) return can[l][r];
	int L = len(l, r);
	if(L <= 2) {
		if(L == 0) {
			can[l][r] = 1;
			return 1;
		}
		if(L == 1) {
			can[l][r] = 0;
			return 0;
		}
		else {
			can[l][r] = abs(w[l] - w[r]) <= 1;
			return can[l][r];
		}
	}
	if(L % 2) {
		can[l][r] = 0;
		return 0;
	}
	if(abs(w[l] - w[r]) <= 1 && f(l + 1, r - 1)) {
		can[l][r] = 1;
		return 1;
	}
	for(int i = l + 1; i < r; i++) {
		if(f(l, i) && f(i + 1, r)) {
			can[l][r] = 1;
			return 1;
		}
	}
	can[l][r] = 0;
	return 0;
}

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

	int N;
	while(cin >> N, N) {
		for(int i = 0; i < N; i++) {
			cin >> w[i];
		}

		memset(can, -1, sizeof can);
		for(int l = 0; l < N; l++) {
			for(int r = l; r < N; r++) {
				f(l, r);
			}
		}

		memset(dp, 0, sizeof dp);
		for(int l = 0; l < N; l++) {
			dp[l + 1] = max(dp[l + 1], dp[l]);
			for(int r = l + 1; r < N; r++) {
				if(f(l, r)) {
					dp[r + 1] = max(dp[r + 1], dp[l] + len(l, r));
				}
			}
		}
		cout << dp[N] << endl;
	}
}

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

int main(){
  
  int N, Y;
  cin >> N >> Y;

  for(int i = 0; i <= N; i++){
    for(int j = 0; j + i <= N; j++){
      
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
        cout << i << " " << j << " " << N - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

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

int K, N;


int ans[3*100000];
int stop;

void dec_ans(){
    if(ans[stop] == 1){
        ans[stop] = 0;
        stop--;
        return;
    }
    ans[stop] -= 1;
    for(int i = stop+1; i < N; i++){
        ans[i] = K;
    }
    stop = N-1;
    return;
}


int main(){
    cin >> K >> N;

    if(K % 2 == 0){
        for(int i = 0; i < N; i++){
            cout << (i?" ":"") << (i?K:K/2);
        }
        cout << endl;
        return 0;
    }

    for(int n = 0; n < N; n++){
        ans[n] = (K+1)/2;
    }

    stop = N-1;
    for(int i = 0; i < (N)/2; i++){
        dec_ans();
        /*for(int j = 0; j < N && ans[j] != 0; j++){
            cout << (j?" ": "") << ans[j];
        }cout << endl;
        */
    }

    for(int i = 0; i < N && ans[i] != 0; i++){
        cout << (i?" ":"") << ans[i];
    }
    cout << endl;


    return 0;

}

Measured memory_bytes: 3456
main :: IO ()
main = do
  n <- readLn
  [d, x] <- map read . words <$> getLine
  as <- sequence $ replicate n readLn
  print $ solve d x as

solve :: Int -> Int -> [Int] -> Int
solve d x as = x + sum [ (d - 1) `div` a + 1 | a <- as ]

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

int main(){
    int n, m;
    cin >> n >> m;
    
    vector<int> k(m), p(m);
    vector<vector<int>> s(m, vector<int>(n));
    
    for (int i = 0; i < m; i++){
        cin >> k[i];
        
        for (int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    
    for (int i = 0; i < m; i++) cin >> p[i];
    
    int ans = 0;
    
    for (int temp = 0; temp < (1<<n); temp++){
        
        bool check = true;
        
        //電球一個一個
        for (int i = 0; i < m; i++){
            int swi = 0;
            for (int j = 0; j < k[i]; j++){
                if(temp & (1<<s[i][j])) swi++;
            }
            
            if (swi % 2 != p[i]) check = false;
        }
        if (check) ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
N, W = map(int, input().split())
vs = []
ws = []
for i in range(N):
    v, w = map(int, input().split())
    vs.append(v)
    ws.append(w)


def knapsack_duplicate(N, W, weight, value):
    # initialize
    inf = float('inf')
    dp = [[-inf for i in range(W+1)] for j in range(N+1)]
    for i in range(W+1):
        dp[0][i] = 0

    # DP
    for i in range(N):
        for w in range(W+1):
            if w >= weight[i]:
                dp[i+1][w] = max(dp[i][w-weight[i]] + value[i],
                                 dp[i][w],
                                 dp[i+1][w-weight[i]] + value[i])
            else:
                dp[i+1][w] = dp[i][w]
    return dp[N][W]


print(knapsack_duplicate(N, W, ws, vs))



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

int main()
{
  string s;
  cin >> s;
  vector<int> v(4);
  for (int i = 0; i < 4; i++)
  {
    v[i] = s[i] - '0';
  }
  
  for (int j = 0; j < (1 << 3); j++)
  {
    int tmp = v[0]; //tmpの初期値をv[0]にしてtmpに対してBCDを足すか引くか。
    for (int k = 0; k < 3; k++)
    {
      if (j & (1 << k))
        tmp += v[k + 1];//3242の時はj=ob110
      else
        tmp -= v[k + 1];
    }
    if (tmp == 7)
    {
      cout << v[0];
      for (int k = 0; k < 3; k++)
      {
      	if (j & (1 << k))
        	cout  << '+';
      	else
        	cout << '-';
      	cout << v[k + 1];
      }
      cout << "=7" << endl;
      //cout << j << endl;
      return 0; //ないと2つ出力されちゃう。
    }
  }
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    
    al = sum(a)
    for i in range(n):
        a[i] -= b[i]
        if a[i] < 0:
            a[i+1] += max(-a[i+1], a[i])
            a[i] = 0
    print(al-sum(a))
    
if __name__ == "__main__":
    main()

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

	reverse(s.begin(), s.end());
	rep(i, 4)
		reverse(divide[i].begin(), divide[i].end());
	
	bool can = true;
	for(int i = 0; i < s.size();){
		bool can2 = false;
		for(int j = 0; j < 4; j++){
			string d = divide[j];
			if(s.substr(i, d.size()) == d){
				can2 = true;
				i += d.size();
			}
		}
		if(!can2){
			can = false;
			break;
		}
	}

	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
class Com:
    def __init__(self, MAX = 1000000, MOD = 1000000007):
        self.MAX = MAX
        self.MOD = MOD
        self._fac = [0]*MAX
        self._finv = [0]*MAX
        self._inv = [0]*MAX
        self._fac[0], self._fac[1] = 1, 1
        self._finv[0], self._finv[1] = 1, 1
        self._inv[1] = 1
        for i in range(2,self.MAX):
            self._fac[i] = self._fac[i - 1] * i % self.MOD
            self._inv[i] = self.MOD - self._inv[self.MOD%i] * (self.MOD // i) % self.MOD
            self._finv[i] = self._finv[i - 1] * self._inv[i] % self.MOD
    
    def com(self, n, k):
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return self._fac[n] * (self._finv[k] * self._finv[n - k] % self.MOD) % self.MOD
a,b = list(map(int,input().split()))
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
    x = (2*a-b)//3
    y = a-2*x
    com = Com()
    print(com.com(x+y, x))
    exit()
a,b = b,a
if 2*a-b >= 0 and (2*a-b)%3 == 0 and a-2*((2*a-b)//3) >= 0:
    x = (2*a-b)//3
    y = a-2*x
    com = Com()
    print(com.com(x+y, x))
    exit()
print(0)

Measured memory_bytes: 127588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    string s;
    cin >> s;
    cout << s.rfind('Z') - s.find('A') + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>

using namespace std;
long long x, ans = 2;
int main() {
	cin >> x;
	for(int i = 1; i <= x; i++)
		ans = ans * 2 + 2;
	cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std; typedef long long ll; const int MAXN=1e5+10; struct edge{int nxt,to;}e[MAXN*8];//一定要开8倍空间 struct data{int x,y,id;}dat[MAXN]; int n,d,a,b,x,y,head[MAXN],vis[MAXN],cnt[MAXN],tot=0; ll res=0;
 struct data{int x,y,id;}dat[MAXN]; int n,d,a,b,x,y,head[MAXN],vis[MAXN],cnt[MAXN],tot=0; ll res=0;
void add_edge(int from,int to) 
{e[++tot].nxt=head[from];e[tot].to=to;head[from]=tot;e[++tot].nxt=head[to];e[tot].to=from;head[to]=tot; }

 
 
bool operator < (data a,data b) { if(a.x!=b.x) return a.x<b.x;
return a.y<b.y; }
 
void solve(int k) {sort(dat+1,dat+n+1); int cur,lst,l,r;for(cur=lst=l=r=1;cur<=n;cur++) { while((dat[l].x<dat[cur].x+d||dat[l].x==dat[cur].x+d &&dat[l].y<dat[cur].y-k)&&l<=n) l++;while((dat[r].x<dat[cur].x+d||dat[r].x==dat[cur].x+d &&dat[r].y<=dat[cur].y+k)&&r<=n) r++; if(l>n) break;cnt[dat[cur].id]+=r-l;lst=max(lst,l); if(lst>=r) continue;add_edge(dat[cur].id,dat[lst].id); for(;lst<r-1;lst++) add_edge(dat[lst].id,dat[lst+1].id); } }
 
void dfs(int x) { vis[x]=true;res+=cnt[x]; for(int i=head[x];i;i=e[i].nxt)if(!vis[e[i].to]) dfs(e[i].to); }
 
int main() { scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++) scanf("%d%d",&x,&y),dat[i]={x+y,x-y,i}; d=max(abs(dat[a].x-dat[b].x),abs(dat[a].y-dat[b].y)); solve(d);
for(int i=1;i<=n;i++) swap(dat[i].x,dat[i].y);solve(d-1); dfs(a);printf("%lld",res); cout << endl; return 0; }
 

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int x, y;
    cin >> x >> y;

    cout << x + y/2 << endl;
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

bool flag[60][60][60][60];

lli dataL[60][60];
lli dataR[60][60];

class edge
{
public:
	lli lx,ly;
	lli rx,ry;
};

void solve(lli h,lli w)
{
	string s;
	string r;

	edge start;

	REP(i,0,60)REP(j,0,60)REP(k,0,60)REP(l,0,60)flag[i][j][k][l]=false;

	REP(i,0,h){
		cin>>s>>r;
		reverse(r.begin(),r.end());

		if(DEBUG)cout<<s<<" "<<r<<endl;

		REP(j,0,w){
			if(s.at(j)=='.')dataL[i][j]=0;
			else if(s.at(j)=='#')dataL[i][j]=1;
			else if(s.at(j)=='L'){
				dataL[i][j]=0;
				start.lx=j;
				start.ly=i;
			}
			else dataL[i][j]=2;
		}

		REP(j,0,w){
			if(r.at(j)=='.')dataR[i][j]=0;
			else if(r.at(j)=='#')dataR[i][j]=1;
			else if(r.at(j)=='R')
			{
				dataR[i][j]=0;
				start.rx=j;
				start.ry=i;
			}
			else dataR[i][j]=2;
		}
	}
	if(DEBUG)cout<<start.ly<<" "<<start.lx<<" "<<start.ry<<" "<<start.rx<<endl;

	flag[start.ly][start.lx][start.ry][start.rx]=true;
	queue<edge> q;
	q.push(start);

	while(q.size())
	{
		edge top;
		top.lx = q.front().lx;
		top.ly = q.front().ly;
		top.rx = q.front().rx;
		top.ry = q.front().ry;

		if(DEBUG)cout<<top.ly<<" "<<top.lx<<" "<<top.ry<<" "<<top.rx<<endl;

		q.pop();

		lli dx[4]={-1,0,1,0};
		lli dy[4]={0,1,0,-1};

		REP(i,0,4){
			edge next;
			next.lx = top.lx+dx[i];
			next.ly = top.ly+dy[i];
			next.rx = top.rx+dx[i];
			next.ry = top.ry+dy[i];

			if(DEBUG)cout<<"next="<<next.ly<<" "<<next.lx<<" "<<next.ry<<" "<<next.rx<<endl;


			if(next.lx < 0 || w <= next.lx || next.ly < 0 || h <= next.ly)
			{
				next.ly = top.ly;
				next.lx = top.lx;
			}
			if(next.rx < 0 || w <= next.rx || next.ry < 0 || h <= next.ry)
			{
				next.rx = top.rx;
				next.ry = top.ry;
			}

			if(dataL[next.ly][next.lx]==1)
			{
				next.lx = top.lx;
				next.ly = top.ly;
			}
			if(dataR[next.ry][next.rx]==1)
			{
				next.rx = top.rx;
				next.ry = top.ry;
			}
			if(dataL[next.ly][next.lx]==2 && dataR[next.ry][next.rx]==2)
			{
				cout<<"Yes"<<endl;
				return ;
			}
			if(dataL[next.ly][next.lx]==2 || dataR[next.ry][next.rx]==2)
			{
				continue;
			}
			if(flag[next.ly][next.lx][next.ry][next.rx])continue;
			q.push(next);
			flag[next.ly][next.lx][next.ry][next.rx]=true;
		}
	}

	cout<<"No"<<endl;
	return ;
}

int main(){

	lli w,h;
	while(cin>>w>>h){
		if(w==0 && h==0)break;
		solve(h,w);
	}


	return 0;
}



Measured memory_bytes: 17500
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
y = [ele-a for ele in x]
m = n*max(a, max(x))
dp = [[0 for _ in range(2*m+1)]for _ in range(n+1)]
dp[0][m] = 1
for j in range(1, n+1):
  for t in range(2*m+1):
    if t-y[j-1]<0 or 2*m<t-y[j-1]:
      dp[j][t] = dp[j-1][t]
    elif 0<=t-y[j-1]<=2*m:
      dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j-1]]
print(dp[n][m]-1)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    
    int ans = INT_MAX;
    for(int l = 0; l+k-1 < n; l++){
        int r = l+k-1;
        if(x[l]*x[r]<=0){
            ans = min(ans, x[r] - x[l] + min(x[r], -x[l]));
        }else{
            ans = min(ans, max(abs(x[r]), abs(x[l])));
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	// your code goes here
	ll a,v;
	cin>>a>>v;
	ll b,w;
	cin>>b>>w;
	ll t;
	cin>>t;
	ll d_a=v*t;
	ll d_b=w*t;
	ll d_btw=abs(b-a);
	if(d_b+d_btw<=d_a || a==b){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#include <unistd.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int ops[25000];
int cnt_ops =0;

void move(int cur, vector<int> &P, vector<int> &par) {
	assert(cnt_ops < 15000);
	ops[cnt_ops++] =cur;
	int v =cur, tmp =P[0];
	while(true) {
		swap(P[v], tmp);
		if(v == 0) break;
		v =par[v];
	}
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> P(N), par(N, 0), D(N, 0);
	vector< vector<int> > G(N);
	for(int i =1; i < N; i++) {
		cin >> par[i];
		G[par[i]].push_back(i);
		D[par[i]]++;
	}
	for(int i =0; i < N; i++) cin >> P[i];

	vector<bool> bl(N, false);
	while(!bl[0]) {
		vector<int> in_path(N, -1), in_path_id(N, -1);
		vector< vector< pair<int, int> > > paths;
		for(int i =N-1; i >= 0; i--) if(!bl[i] && D[i] == 0) {
			vector< pair<int, int> > path;
			int v =i;
			while(D[v] <= 1) {
				in_path[v] =paths.size();
				path.push_back(make_pair(v, -1));
				if(v == 0) break;
				v =par[v];
			}
			reverse(begin(path), end(path));
			for(int j =0; j < (int)path.size(); j++) in_path_id[path[j].ff] =j;
			paths.push_back(path);
		}

		int cur =N-1;
		while(true) {
//			for(int i =0; i < N; i++) cerr << P[i] << " "; cerr << "\n";
			int v =P[0];
			if(in_path[v] != -1) {
				int p =in_path[v], x =(int)paths[in_path[v]].size()-1;
				while(paths[p][x].ss > v) x--;
				for(int i =1; i <= x; i++) paths[p][i-1].ss =paths[p][i].ss;
				paths[p][x].ss =v;
				move(paths[p][x].ff, P, par);
			}
			while(cur >= 0) {
				if(bl[cur]) cur--;
				else if(in_path[cur] != -1 && paths[in_path[cur]][in_path_id[cur]].ss != -1) cur--;
				else break;
			}
			if(cur < 0) break;
			if(in_path[v] == -1) {
				move(cur, P, par);
				cur--;
			}
		}
//		for(int i =0; i < N; i++) cerr << P[i] << " "; cerr << ".\n";

		for(int i =0; i < N; i++) if(in_path[i] != -1) {
			bl[i] =true;
			D[par[i]]--;
		}
	}

	cout << cnt_ops << "\n";
	for(int i =0; i < cnt_ops; i++) cout << ops[i] << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll A,B,C,D;

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

void solve(){
    if (A < B || D < B) {
        printf("No\n");
        return;
    }
    if (C >= B) {
        printf("Yes\n");
        return;
    }
    //讨论的式子：C < A-xB+yD < B 是不可以的
    ll m_gcd = gcd(B, D);
    ll ans = (A-C-1)/m_gcd - (A-B)/m_gcd;
    if (ans > 0) {
        printf("No\n");
    }
    else printf("Yes\n");
    return;
}

void input(){
    int T;
    scanf("%d",&T);
    while (T--){
        scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
        solve();
    }
}

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

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

int nodes[200005];
int colors[200005];
int used[200005];
int num[2];


int main(){
    int n;
    cin>>n;
    vector<vector<int>> tree(n+1);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    queue<int> que;
    que.push(1);
    used[1]=1;
    num[0]++;
    while(!que.empty()){
        int t=que.front();que.pop();
        for(auto v:tree[t]){
            if(used[v]) continue;
            used[v]=1;
            colors[v]=colors[t]^1;
            num[colors[v]]+=1;
            que.push(v);
        }
    }
    if(num[0]<=n/3||num[1]<=n/3){
        int t=num[0]<num[1]?0:1;
        queue<int> mz,me;
        REP(i,n){
            if(i%3==0){
                mz.push(i);
            }else{
                me.push(i);
            }
        }
        REP(i,n){
            if(colors[i]==t){
                nodes[i]=mz.front();mz.pop();
            }else{
                if(!me.empty()){
                    nodes[i]=me.front();me.pop();
                }else{
                    nodes[i]=mz.front();mz.pop();
                }
            }
        }
    }else{
        int t=num[0]<num[1]?0:1;
        queue<int> mz,mo,mt;
        REP(i,n){
            if(i%3==0) mz.push(i);
            else if(i%3==1)mo.push(i);
            else mt.push(i);
        }
        REP(i,n){
            if(colors[i]!=t){
                if(!mo.empty()){
                    nodes[i]=mo.front();mo.pop();
                }else{
                    nodes[i]=mz.front();mz.pop();
                }
            }else{
                if(!mt.empty()){
                    nodes[i]=mt.front();mt.pop();
                }else{
                    nodes[i]=mz.front();mz.pop();
                }
            }
        }
    }
    REP(i,n){
        cout<<nodes[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 16244
//Scoring

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int d,m{},c[26];
vector<vector<int>>s;
vector<int>t;
vector<int>last(26,0);

void scr(int day){
    m+=s[day][t[day]];
    last[t[day]]=day+1;
    rep(i,0,26)m-=c[i]*(day+1-last[i]);
}

signed main (){
    cin>>d;
    rep(i,0,26)cin>>c[i];
    s.resize(d);
    rep(i,0,d){
        s[i].resize(26);
        rep(j,0,26)cin>>s[i][j];
    }
    t.resize(d);
    rep(i,0,d)cin>>t[i];
    rep(i,0,d)t[i]--;

    rep(i,0,d){
        scr(i);
        cout<<m<<nnn;
    }
    return 0;
}

Measured memory_bytes: 3692
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll x; cin >> x;
    if(x < 1200){
        cout << "ABC" << endl;
    }else{
        cout << "ARC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

long double myabs(long double a) {
    return a >= 0 ? a : -a;
}
int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    ll v[200000] = {0};
    REP(i, N) {
        in >> v[i];
    }
    ll ans = 0;
    ll recent_distance = 0;
    double min_distance = 10010010010010010010;
    ll distance = 0;
    ll total = 0;
    for(ll i = 0; i < N; ++i) {
        total += v[i];
    }
    for(ll i = 0; i < N; ++i) {
        distance += v[i];
        auto ds = myabs((double)distance - ((double)total /2));
        if (ds < min_distance) {
            min_distance = ds;
            recent_distance = distance;
        }
    }
    ans = abs((total - recent_distance) - recent_distance);
    out << ans << endl;
    debug(ans);
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String... nui) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		System.out.println((s.charAt(0) == '9' || s.charAt(1) == '9') ? "Yes" : "No");
		
	}

}


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

int main() {
  int a, b;
  if (scanf("%d %d", &a, &b) < 0) {
    exit(1);
  }
  int product = a * b;
  if (product % 2 == 0) {
	printf("Even\n");
  } else {
    printf("Odd\n");
  }
}

Measured memory_bytes: 128
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	a, b, m := nextInt(), nextInt(), nextInt()

	am := int(1e9)
	as := make([]int, a)
	for i := 0; i < a; i++ {
		as[i] = nextInt()
		am = min(am, as[i])
	}

	bm := int(1e9)
	bs := make([]int, b)
	for i := 0; i < b; i++ {
		bs[i] = nextInt()
		bm = min(bm, bs[i])
	}

	ans := am + bm
	for i := 0; i < m; i++ {
		x, y, c := nextInt()-1, nextInt()-1, nextInt()
		ans = min(ans, as[x]+bs[y]-c)
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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


int A, B;


void input() {
    cin >> A >> B;
}


int main() {
    input();
    if (A % 2 == 0 || B % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <map>

using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define all(co) co.begin(), co.end()
const int INF = 1 << 29;
signed main()
{
	int n, t, s;
	while (cin >> n >> t >> s && n)
	{
		vector<int> a(n), b(n);
		rep(i, n) cin >> a[i] >> b[i];

		vector<int> dp(t + 1);
		int ans = 0;
		rep(i, n) for (int j = t; j >= 0; j--) if (j + b[i] <= t && (j + b[i] <= s || s <= j))
		{
			dp[j + b[i]] = max(dp[j + b[i]], dp[j] + a[i]);
			ans = max(ans, dp[j + b[i]]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [usize1; n-1]
    }
    let mut ans = vec![0; n];
    for &a in &a {
        ans[a] += 1;
    }
    for i in 0..n {
        puts!("{}\n",ans[i]);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 3472
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
const int SIZE = 100010;
int dp[3][110];
int num[3][110];

int main()
{
	int n;
	cin>>n;
	for(int i = 1;i <= n;i ++)	cin>>num[1][i];
	for(int i = 1;i <= n;i ++)	cin>>num[2][i];
	for(int i = 1;i <= n;i ++)
	{
		dp[1][i] = dp[1][i-1] + num[1][i];
		dp[2][i] = max(dp[1][i],dp[2][i-1]) + num[2][i];
	}
	cout<<dp[2][n]; 
	return 0;
}


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

using namespace std;

typedef long long ll;

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

	int N;
	cin >> N;

	if(N <= 9){
		cout << N << endl;
	}else if(N <= 99){
		cout << 9 << endl;
	}else if(N <= 999){
		cout << 9 + N - 100 + 1 << endl;
	}else if(N <= 9999){
		cout << 909 << endl;
	}else if(N <= 99999){
		cout << 909 + N - 10000 + 1 << endl;
	}else if(N <= 999999){
		cout << 90909 << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

const int INF = 1001001001;
int c[10][1005];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  REP(i, h) cin >> s[i];
  int ans = INF;
  REP(div, 1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    REP(i, h) {
      id[i] = g;
      if (div>>i&1) ++g;
    }
    ++g;
    REP(i, g)REP(j, w) c[i][j] = 0;
    REP(i, h)REP(j, w) c[id[i]][j] += (s[i][j]-'0');

    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      REP(i, g) now[i] += c[i][j];
      REP(i, g) if (now[i]>k) return false;
      return true;
    };
    REP(j, w) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    chmin(ans, num);
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
	int N, K;
	cin >> N >> K;
	int ans = K;
	rep2(i, N, 1, 1){
		ans *= (K - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
char s[305][305];
char t[305][305];
int main(){
	int n, ans = 0;
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%s", s[i]);
	for(int A=0;A<n;A++){
		int B = 0;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				t[(j+A)%n][(k+B)%n] = s[j][k];
			}
		}
		bool ok = 1;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(t[j][k] == t[k][j]) continue;
				ok = 0;
				break;
			}
			if(!ok) break;
		}
		ans += ok;
	}
	printf("%d\n", ans*n);
}

Measured memory_bytes: 384
#from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
AB = [readInts() for _ in range(n)]
#print(AB)
AB = sorted(AB,key = lambda x:x[1])
time = 0
for i in range(n):
    if time + AB[i][0] <= AB[i][1]:
        time += AB[i][0]
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 55616
using System;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int cnt = 0;

            for (int i = 1; i <= n - 1; i++)
            {
                for (int j = 1; j <= (n - 1) / i; j++)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 27480
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, pre[300009], sfx[300009];
string s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    if (s[0] == 'W') pre[0] = 1;
    for (int i = 1; i < n; i++) {
        pre[i] = pre[i - 1];
        if (s[i] == 'W') pre[i]++;
    }
    if (s[n - 1] == 'E') sfx[n - 1] = 1;
    for (int i = n - 2; i >= 0; i--) {
        sfx[i] = sfx[i + 1];
        if (s[i] == 'E') sfx[i]++;
    }
    int ans = 1e9;
    ans = min(ans, sfx[1]);
    ans = min(ans, pre[n - 2]);
    for (int i = 1; i < n - 1; i++) {
        ans = min(ans, pre[i - 1] + sfx[i + 1]);
    }
    cout << ans << E;
    //system("pause");
    return 0;
}

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

const int M=10;
char s[M];

int main()
{
	cin>>s;
	sort(s,s+4);
	cout<<(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2] ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {


  def read() = {
    val sc = new Scanner(System.in)
    val nJewelry, maxNOpes = sc.nextInt()
    val jewelries = IndexedSeq.fill(nJewelry)(sc.nextLong())
    (nJewelry, maxNOpes, jewelries)
  }

  /*
  いらないものは捨てたい
  最後に捨てればいい
  何個回収するか？

   */
  def solve(nJewelry: Int, maxNOpes: Int, jewelries: IndexedSeq[Long]): Long = {
    // nLeft
    // nRight
    // maxNOpes - (nLeft + nRight)回を上限に捨てることができる。

    // 左からnLeft, 右からnRight回収したとき、価値が最大になるように捨てた場合の価値
    def calcMax(nLeft: Int, nRight: Int): Long = {
      assert(nLeft + nRight <= nJewelry)
      assert(nLeft + nRight <= maxNOpes)

      val popedList =
        IndexedSeq.concat((0 until nLeft), (nJewelry - nRight until nJewelry))
          .map(jewelries).sorted

      val maxNPushing = maxNOpes - (nLeft + nRight)
      val popedNegativeList = popedList.filter(_ < 0)
      val pushingList = popedNegativeList.take(maxNPushing)
      popedList.sum - pushingList.sum

    }

    val resultList = for (nLeft <- 0 to math.min(nJewelry, maxNOpes);
                          nRight <- 0 to math.min(nJewelry, maxNOpes) - nLeft) yield {
      calcMax(nLeft, nRight)
    }
    resultList.max
  }

  def main(args: Array[String]): Unit = {
    val (nJewelry, maxNOpes, jewelries) = read()
    val result = solve(nJewelry, maxNOpes, jewelries)
    println(result)
  }
}

Measured memory_bytes: 33120
#include <iostream>
#include <vector>

int main(){
  int N;
  std::cin >> N;
  std::vector<int> A_arr(N), B_arr(N), C_arr(N-1);
  for(int i = 0; i < N; i++){
    std::cin >> A_arr[i];
    A_arr[i]--;
  }
  for(int i = 0; i < N; i++) std::cin >> B_arr[i];
  for(int i = 0; i < N-1; i++) std::cin >> C_arr[i];
  int ans = 0;
  for(int i = 0; i < N-1; i++){
    if(A_arr[i+1] == A_arr[i]+1) ans += C_arr[A_arr[i]];
  }
  for(int i = 0; i < N; i++) ans += B_arr[i];
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T=sc.nextInt();
        int[] c=new int[N];
        int[] t=new int[N];
        for(int i=0;i<N;i++){
            c[i]=sc.nextInt();
            t[i]=sc.nextInt();
        }
        long ans=INF;
        for(int i=0;i<N;i++){
            if(t[i]<=T){
                ans=Math.min(ans,c[i]);
            }
        }
        if(ans==INF){
            System.out.println("TLE");
            return;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25300
#include <stdio.h>
#include <stdlib.h>
#define X 1000001

int main(void){
    int N,*a,i,max=-X,min=X,maxi,mini,count=0,**out;
    scanf("%d",&N);
    a = (int*)malloc(sizeof(int)*N);
    out = (int**)malloc(sizeof(int*)*(2*N));
    for(i=0;i<2*N;i++)    out[i] = (int*)malloc(sizeof(int)*2);
    for(i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(max<a[i]){
            max = a[i];
            maxi = i;
        }
        if(min>a[i]){
            min = a[i];
            mini = i;
        }
    }
    if(min<0&&max>0){
        if(max>=-min){
            for(i=0;i<N;i++){
                a[i] += max;
                out[count][0] = maxi + 1;
                out[count][1] = i + 1;
                count++;
            }
            max += max;
            min += max;
        }else{
            for(i=0;i<N;i++){
                a[i] += min;
                out[count][0] = mini + 1;
                out[count][1] = i + 1;
                count++;
            }
            max += min;
            min += min;
        }
    }
    if(min>=0){
        for(i=1;i<N;i++){
            if(a[i-1]>a[i]){
                a[i] += a[i-1];
                out[count][0] = i;
                out[count][1] = i + 1;
                count++;
            }
        }
    }else{
        for(i=N-2;i>=0;i--){
            if(a[i]>a[i+1]){
                a[i] += a[i+1];
                out[count][0] = i + 2;
                out[count][1] = i + 1;
                count++;
            }
        }
    }
    printf("%d\n",count);
    for(i=0;i<count;i++){
        printf("%d %d\n",out[i][0],out[i][1]);
    }
    return 0;
}

Measured memory_bytes: 128
# ARC061C - たくさんの数式 / Many Formulas (ABC045C)
from itertools import product


def main():
    S = input()
    ans = 0
    for ops in tuple(product(("", "+"), repeat=len(S) - 1)):
        ops = ops + ("",)  # operators
        exp = "".join(i + j for i, j in zip(S, ops))  # expression
        ans += eval(exp)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060