akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using ll = long long;
using namespace std;

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

  for( int i=1;i<=9;i++ )
    {
      int c = i*(111);
      if( c>= N)
	{
	  cout << c << endl;
	  break;
	}
    }
}


Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(lambda:defaultdict(lambda:0))

N,C = map(int,input().split(" "))
for i in range(N):
    s,t,c = map(int,input().split(" "))
    d[s][c] += 1
    d[t][c] -= 1

using = [0]*C
ma = 0

for i in sorted(d.keys()):
    e = d[i]
    #print(e)
    ekeys = e.keys()
    for j in ekeys:
        if e[j] == 1:
            using[j-1] = 1
    ma = max(ma,sum(using))
    #print(ma)
    for j in ekeys:
        if e[j] == -1:
            using[j-1] = 0

print(ma)

#   時刻tに1個以上のイベントがあるならば
#       録画を開始する
#       録画しているデッキの数を数える
#       録画を終了する

Measured memory_bytes: 57796
N = int(input())
a = list(map(int, input().split()))
xCnt = dict()
ans = 0
for v in a:
    for i in range(-1,2):
        if v+i not in xCnt:
            xCnt[v+i] = 0
        xCnt[v+i] += 1
        ans = max(ans, xCnt[v+i])

print(ans)


Measured memory_bytes: 19680
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			String str = scanner.next();

			for (int i = 0; i < n; i++) {
				StringBuilder builder = new StringBuilder();
				int count = 1;
				for (int j = 1; j < str.length(); j++) {
					if (str.charAt(j) == str.charAt(j - 1))
						count++;
					else {
						builder.append(count);
						builder.append(str.charAt(j - 1));
						count = 1;
					}
				}
				builder.append(count);
				builder.append(str.charAt(str.length() - 1));
				str = builder.toString();
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 27100
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            3223372036854775807
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n, W;
int w[110];
ll v[110];
ll dp[2][100100];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> W;
	rep(i, n) cin >> w[i] >> v[i];
	dp[0][w[0]] = v[0];
	for(int i = 1; i < n; i++){
		int now = (i & 1);
		int last = (i - 1) & 1;
		dp[now][w[i]] = max(dp[now][w[i]], dp[last][0] + v[i]);
		for(int j = 1; j <= W; j++){
			if(dp[last][j] == 0) continue;
			if(j + w[i] <= W) dp[now][j + w[i]] = max(dp[now][j + w[i]], dp[last][j] + v[i]);
			dp[now][j] = max(dp[now][j], dp[last][j]);
		}
	}
	ll ans = 0ll;
	int index = (n - 1) & 1;
	for(int i = 0; i <= W; i++){
		ans = max(ans, dp[index][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char S[102];

int main()
{
	int k;
	scanf("%s",(S+1));
	scanf("%d",&k);
	int n = strlen(S+1);

	ll il[202];
	for(int i=1;i<=200;i++) il[i]=0;

	char c = S[1];
	int curr=1;
	for(int i=2;i<=n;i++)
	{
		if(c!=0 && S[i]!=c) c=0;
		if(S[i]==S[i-1]) curr++;
		else il[curr]+=k ,curr=1;
	}
	il[curr]+=k;

	if(c!=0)
	{
		printf("%lld\n",((ll)k * n)/2);
		return 0;
	}

	if(S[1] == S[n])
	{
		int j = 1;
		while(S[j+1]==S[1]) j++;

		int t = n;
		while(S[t-1]==S[n]) t--;
		t=n-t+1;

		il[j]-=(k-1);
		il[t]-=(k-1);
		il[j+t]+=(k-1);
	}

	ll res = 0;
	for(int i=2;i<=200;i++) res+=(ll)((i)/2) * il[i];
        printf("%lld\n",res);	
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e12+13;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
ll mpow(ll a, ll b){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
 
ll range(ll l, ll r){
	return l + mt()%(r-l+1);
}
 
ll rev(ll v){
	return mpow(v,MOD-2);
}

bool cmp(string& s1, string& s2){
	return (sz(s1) < sz(s2));
}

const ll p1 = 243;

void solve(){
	ll n;
	cin >> n;
	map<ll,v64> m;
	string s[n];
	forn(i,n) {
		cin >> s[i];
	}
	sort(s,s+n,cmp);
	ll ans = 0;
	forn(i,n){
		v64 c(26,0);
		for(auto k : s[i]) c[k-'a']++;
		ll val = 0;
		rforn(j,sz(s[i])-1){
			if(m.find(val) != m.end()){
				forn(k,26){
					if(c[k]) ans += m[val][k];
				}
			}
			c[s[i][j]-'a']--;
			if(j==0){
				if(m.find(val)==m.end()) m[val]=v64(26,0);
				m[val][s[i][j]-'a']++;
			}
			val *= p1;
			val += (s[i][j]-'a'+1);
			val %= MOD;
		}
	}
	cout << ans << ln;
}
 
int main()
{
	fast_cin();
	ll t=1;
    // cin >> t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 51020
import sys
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readints():return list(map(int,readline().split()))

from collections import deque

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

dist = [10**10]*(h*w)

dq = deque()
dq.append(start)
dist[start] = 0

while dq:
    p = dq.popleft()
    y = p//w
    x = p%w
    for dy in range(-2,3):
        for dx in range(-2,3):
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                q = (y+dy)*w + x+dx
                if abs(dy)+abs(dx)==1:
                    if dist[q]>dist[p]:
                        dq.appendleft(q)
                        dist[q] = dist[p]
                else:
                    if dist[q]>dist[p]+1:
                        dq.append(q)
                        dist[q] = dist[p] + 1

print(-1 if dist[goal]==10**10 else dist[goal])


Measured memory_bytes: 89924
# https://atcoder.jp/contests/abc084/tasks/abc084_d
# エラトステネスの篩を使う以外に考えられないが...
# あと高速化のために累積和も

import sys
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def ret_erators(N: int):
    # エラトステネスの篩
    is_prime = [True] * (N + 1)

    # 0と1は素数ではない
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(N**0.5) + 1):
        if is_prime[i]:
            j = i * 2  # iの倍数は素数ではない
            while j < N + 1:
                is_prime[j] = False
                j += i
    return is_prime


is_prime = ret_erators(10 ** 5)

# make is_like2017
is_like = [0] * (10**5 + 1)
for x in range((10 ** 5) // 2 + 1):
    if not is_prime[x]:
        continue
    n = 2 * x - 1
    if is_prime[n]:
        is_like[n] = 1

# make accum
from itertools import accumulate
is_like_accum = [0] + list(accumulate(is_like))

Q = int(input())
L, R = read_col(Q, 2)


for l, r in zip(L, R):
    print(is_like_accum[r + 1] - is_like_accum[l])


Measured memory_bytes: 60848
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int> stick(n*2);
	for(int i=0; i<n*2; i++){
		cin >> stick[i];
	}
	sort(stick.begin(),stick.end());
	int ans=0;
	for(int i=0; i<n*2; i+=2){
		ans+=stick[i];
	}
	cout << ans << endl;
	return 0;
}

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

string st[4] = {"A","B","AB","O"};

int main() {
	int n, b[4] = { 0 };
	char t;
	string s;
	while (cin >> n) {
		cin >> t >> s;

		for (int i = 0; i < 4; i++) {
			if (s == st[i]) {
				b[i]++;
				break;
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		cout << b[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n";
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v;
    vector<int> v1;
    int a, b, c, cnt=0, t, product = 1, p=0;
    string str;
    cin >> str;

    a = (str[0]-'0')*10 + (str[1]-'0');
    b = (str[2]-'0')*10 + (str[3]-'0');

    if(a>=1 && a<=12){
    	if(b>=1 && b <=12){
    		cout << "AMBIGUOUS" << "\n";
    	}else{
    		cout << "MMYY" << "\n";
    	}
    }else{
    	if(b>=1 && b<=12){
    		cout << "YYMM" << "\n";
    	}else{
    		cout << "NA" << "\n";
    	}
    }
    



   bye;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,k,vis[5005];
long long p[5005],c[5005],sum[5005],ans=-1e18;
int main(){
	cin >> n >> k;
	for(int i=1; i<=n; i++) cin >> p[i];
	for(int i=1; i<=n; i++) cin >> c[i];
	for(int i=1; i<=n; i++){
		long long s=c[i];
		vector<long long> t; t.push_back(s);
		for(int j=p[i]; j!=i; j=p[j]) s+=c[j],t.push_back(s);
		int len=t.size();
		for(int j=0; j<len; j++){
			long long rest=k-j-1;
			if(rest < 0) break;
			ans=max(ans,t[j]+(rest/len)*max(s,0LL));
		}		
	}
	cout << ans;
}

Measured memory_bytes: 3788
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

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

        // final String N = sc.next();

        final int N = sc.nextInt();
        // final int m = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        System.out.println("ABC" + N);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    int n;
    cin>>n;
    cout<<n*(n+1)/2<<endl;
}

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

int main() {
	int a = 0, b = 0, c = 0;
    std::string s;

	std::cin >> s;

	for (int i = 0; i < s.size(); i++) {
    	s.at(i) == '1' ? a++ : b++;
    }
  
    c = a < b ? a : b;

	std::cout << c * 2 << std::endl;
	
	return 0;
}

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

using namespace std;

int main(void)
{
    int rest;
    int A;
    int B;
    int C;

    scanf("%d %d %d", &A,&B,&C);

    int in = A-B;

    rest = C - in;

    if(rest <0){
        rest = 0;
    }

    cout << rest << endl;
}

Measured memory_bytes: 256
sizeI, sizeJ = map(int, input().split())
a = [input().strip() for _ in range(sizeI)]

rowVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for i in range(sizeI):
    for j in range(sizeJ):
        if j == 0:
            rowVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                rowVal[i][j] = rowVal[i][j - 1] + 1
            else:
                rowVal[i][j] = 0
    for j in range(sizeJ - 2, -1, -1):
        if rowVal[i][j] and rowVal[i][j + 1]:
            rowVal[i][j] = rowVal[i][j + 1]

colVal = [[0 for _ in range(sizeJ)] for _ in range(sizeI)]
for j in range(sizeJ):
    for i in range(sizeI):
        if i == 0:
            colVal[i][j] = 1 if a[i][j] == '.' else 0
        else:
            if a[i][j] == '.':
                colVal[i][j] = colVal[i - 1][j] + 1
            else:
                colVal[i][j] = 0
    for i in range(sizeI - 2, -1, -1):
        if colVal[i][j] and colVal[i + 1][j]:
            colVal[i][j] = colVal[i + 1][j]

ret = 0
for i in range(sizeI):
    for j in range(sizeJ):
        ret = max(ret, rowVal[i][j] + colVal[i][j] - 1)
print(ret)


Measured memory_bytes: 128984
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool vector_find(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) {
        return true;
    }
    else {
        return false;
    }
}


int main(void){
    ll result;
    string S;
    cin >> S;
    ll count0 = 0, count1 = 0;
    rep(i, S.size()){
        if(S[i] == '0'){
            count0 ++;
        }else{
            count1 ++;
        }
    }
    
    if(count0 < count1){
        result = count0 * 2;
    }else{
        result = count1 * 2;
    }
    
    cout << result << endl;
}


Measured memory_bytes: 512
def main():
    N, M = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    CD = [[int(i) for i in input().split()] for j in range(M)]

    for a, b in AB:
        cur = 10**12
        cur_ans = -1
        for i, cd in enumerate(CD):
            if cur > abs(a-cd[0])+abs(b-cd[1]):
                cur = abs(a-cd[0])+abs(b-cd[1])
                cur_ans = i
        print(cur_ans+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include <stdio.h>
#include <string.h>
#include <math.h>
 
int main(void){
 
    double a, b, c, d;
    double length;
    
    scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
    
    
    
    length = sqrt((a-c)*(a-c)+(b-d)*(b-d));
    
    printf("%f\n", length);
    
    return 0;
 
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n;
  cin >> n;
  double ans = 0;
  rep(i,n){
    double x;
    cin >> x;
    string u;
    cin >> u;
    if(u == "JPY"){
      ans += x;
    }
    else{
      ans += x * 380000.0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3820
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
signed main() {
	int n, k; cin >> n >> k;
	int sum = 0, ans = 0;
	while (sum < n) {
		int p = (sum + k - 1) / k;
		if (!sum)p = 1;
		if (sum + p > n)break;
		sum += p;
		ans++;
	}
	cout << ans << endl;
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int main()
{
	IOS;
	string s;
	cin >> s;
	int m1 = (s[0]-'0')*10 + (s[1]-'0');
	int m2 = (s[2]-'0')*10 + (s[3]-'0');
	if (m1 >= 1 && m1 <= 12 && (m2 == 0 || m2 > 12))
		cout << "MMYY" << endl;
	else if (m2 >= 1 && m2 <= 12 && (m1 == 0 || m1 > 12))
		cout << "YYMM" << endl;
	else if (m1 >= 1 && m1 <=12 && m2 >= 1 && m2 <= 12)
		cout << "AMBIGUOUS" << endl;
	else 
		cout << "NA" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int H,W,h,w,i=1,j;
  scanf("%d%d%d%d",&H,&W,&h,&w);
  if(H%h||W%w) for(puts("Yes");i<=H;++i,puts("")) for(j=0;j<W;++j,printf("%d ",(i%h||j%w)?999:-999*(h*w-1)-1));
  else puts("No");
  return 0;
}

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

int main(){
    string o, e;
    cin >> o >> e;
    int len = o.size() + e.size();
    vector<char> c(len);
    int i = 0, j = 1;
    for(char x : o){
        c[i] = x;
        i += 2;
    }
    for(char x : e){
        c[j] = x;
        j += 2;
    }
    for(char i : c)  cout << i;
    cout << '\n';
}


Measured memory_bytes: 256
import numpy as np
import numpy

N,K = map(int, input().split())
P = list(map(int,input().split()))

S = numpy.cumsum(P)
P.append(0)
M = S[K-1]

for i in range(0,N):
    if P[i+K] == 0:
        break
    A = S[i+K] - S[i]
    M = max(M, A)

ans = 0.5 * (M + K)

print(ans)

Measured memory_bytes: 34232
#include<iostream>
#include<vector>
using namespace std;
int main() {
    string s; cin >> s;
    for (int i = 1; i < s.size(); ++i)
    {
        int sz = s.size() - i;
        if (sz % 2 != 0)
            continue;
        if (s.substr(0, sz / 2) == s.substr(sz / 2, sz / 2)){
            cout << sz;
        break;
    }

    }
       
    return 0;
}

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

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

	long long ans = 0;
	if( N % 2 == 0 ) {
		long long n = 10;
		while( n <= N ) {
			ans += N / n;
			n *= 5;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *nodepointer;
nodepointer set;//格納していく

void insert(int);//代入
void delete(int);//削除
nodepointer nodesearch(int);//検索
void deleteFirst(void);//First削除
void deleteLast(void);//Last削除
void nodedelete(nodepointer);//nodeの入替
void initialize(void);//初期化
void nodeprint(void);//出力
int main(){

  int count; //命令回数
  char command[20];//命令
  int number;//数字
  int i=0;//ループカウンタ
  int flag;
  nodepointer setup;

  
  
  scanf("%d",&count);//命令数入力
  initialize();
  while(i < count){//命令と数字入力
    flag = 0;
    i++;
    scanf("%s",command);

    if(command[0]=='d'){
      if(strlen(command) > 6){//First Last
	flag = 1;
	if(command[6]=='F') deleteFirst();
	else if(command[6]=='L') deleteLast();
      }	
    }
      
    if(flag == 0){
      scanf("%d",&number);
     
      //命令の識別
      if(command[0]=='i') insert(number);//insert
      /*else if(command[0]=='d'){
	if(strlen(command) > 6){//First Last
	if(command[6]=='F') deleteFirst();
	else if(command[6]=='L') deleteLast();
	}	*/
      else delete(number);//derete
    }
  }
  nodeprint();
  return 0;
}

void nodeprint(){
  nodepointer setup = set->next;
  int count=1;
  while(1){
    if(setup==set)break;
    if(count==0)printf(" ");//数字の間の空白表示
    printf("%d",setup->key);
    setup = setup->next;
    count = 0;
  }
  printf("\n");
}
void initialize(){
  set = malloc(sizeof(struct node));
  set->next = set;
  set->prev = set;
}

void insert(int num){//格納
  nodepointer setup;
  setup = malloc(sizeof(struct node));
  setup->key = num;
  //setとnextの間にsetupを入れる
  setup->next = set->next;
  set->next->prev = setup;
  set->next = setup;
  setup->prev = set;
}
void delete(int num){
  nodepointer setup;
  setup = nodesearch(num);

  if(setup != NULL){//nodeの中に発見
    nodedelete(setup);
    }
}

nodepointer nodesearch(int num){
  nodepointer setup = set->next;
  //検索
  while(setup != set && num != setup->key){
    setup = setup->next;
  }
  if(setup == set) return NULL;
  return setup;
}

void deleteFirst(){
  nodepointer setup = set->next;
  if(setup == set) return;
  nodedelete(setup);
}

void deleteLast(){
  nodepointer setup = set->prev;
  if(setup == set) return;
  nodedelete(setup);
}

void nodedelete(nodepointer setup){
  setup->next->prev = setup->prev;//間を削除
  setup->prev->next = setup->next;
  free(setup);
}

Measured memory_bytes: 31656
#include <stdio.h>

int main(void){

    int a, b, i, a1, a2;
    
    scanf("%d%d",&a,&b);

    for(i=1;i<=1000;i++){

        a1 = i * 8 / 100;
        a2 = i * 10 / 100;

        if(a1 == a && a2 == b){
            printf("%d",i);
            return 0;
        }
    }

    printf("-1");
    return 0;
}

Measured memory_bytes: 1732
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    max_n = 100005
    is_prime = [True]*max_n
    is_prime[0], is_prime[1] = False, False
    i = 2
    while i*i < max_n:
        if is_prime[i]:
            k = 2
            while i*k < max_n:
                is_prime[i*k] = False
                k+= 1
        i+= 1
        
    table = [0]*max_n
    for i in range(3, max_n):
        table[i] = table[i-1]
        if is_prime[i] and is_prime[(i+1)//2]:
            table[i] += 1
    q = int(input())
    for i in range(q):
        l, r = map(int, input().split())
        tmp = table[r]-table[l]
        if is_prime[l] and is_prime[(l+1)//2]:
            tmp += 1
        print(tmp)



            



if __name__ == '__main__':
    main()

Measured memory_bytes: 10968
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, k;
  cin >> n >> k;
  if(n%k == 0) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int x;
    cin >> x;
    int ans = 0;
    
    if (x <= 99){
        cout << 0 << endl;
    }
    else {
        int s;
        if (x%105 == 0){
            s = x/105;
        }
        else {
            s = x/105 +1;
        }
        int e = x/100;
        for (int i = s;i <= e;i++){
            if (x-100*i >= 0 && x-100*i <= 5*i){
                ans = 1;
                break;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define endl "\n"
using namespace std;

void solve()
{
	//Enter code here Tanmay::
	int n;
	cin>>n;
	int b[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>b[i];
	}
	int arr[n];
	arr[0]=b[0];
	arr[n-1]=b[n-2];
	for(int i=0;i<n-2;i++)
	{
		if(b[i]<=b[i+1])
		arr[i+1]=b[i];
		else
		arr[i+1]=b[i+1];
	}
	int sum=0;
	for(int i=0;i<n;i++)
	sum=sum+arr[i];
	
	cout<<sum;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
void fastscan(int &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
  
    // extract current character from buffer 
    c = getchar(); 
    if (c=='-') 
    { 
        // number is negative 
        negative = true; 
  
        // extract the next character from the buffer 
        c = getchar(); 
    } 
  
    // Keep on extracting characters if they are integers 
    // i.e ASCII Value lies from '0'(48) to '9' (57) 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
  
    // if scanned input has a negative sign, negate the 
    // value of the input number 
    if (negative) 
        number *= -1; 
} 

Measured memory_bytes: 256
#coding:utf-8

if __name__ == "__main__":
    H, W = map(int, input().split(" "))
    sub = 10 ** 10

    #horizontal division
    for h in range(1, H):
        s_a = h * W

        #divide remain area vertically
        s_b = (H - h) * (W // 2)
        s_c = (H - h) * (W - (W // 2))
        sub_v = max(s_a, s_b, s_c) - min(s_a, s_b, s_c)

        #divide remain area horizontally
        s_b = ((H - h) // 2) * W
        s_c = ((H - h) - (H - h) // 2) * W
        sub_h = max(s_a, s_b, s_c) - min(s_a, s_b, s_c)

        min_sub = min(sub_v, sub_h)
        if min_sub < sub:
            sub = min_sub

    #vertical division
    for w in range(1, W):
        s_a = H * w
        #divide remain area vertically
        s_b = H * ((W - w) // 2)
        s_c = H * ((W - w) - (W - w) // 2)
        sub_v = max(s_a, s_b, s_c) - min(s_a, s_b, s_c)

        #divide remain area horizontally
        s_b = (H // 2) * (W - w)
        s_c = (H - (H // 2)) * (W - w)
        sub_h = max(s_a, s_b, s_c) - min(s_a, s_b, s_c)

        min_sub = min(sub_v, sub_h)
        if min_sub < sub:
            sub = min_sub

    print (sub)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	long long ans = 0;
	for (long long i = 1; i <= n; i++) {
		long long m = n / i;
		long long add = i * m * (m + 1) / 2;
		ans += add;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>
#define NIL NULL
#define TREE_VALUE INT_MAX

typedef struct Node* NodePointer;
typedef NodePointer Tree;

typedef struct Node {
  int key;
  NodePointer p, left, right;
} Node;

NodePointer makeNode(int key) {
  NodePointer node = (NodePointer)malloc(sizeof(Node));
  node->key = key;
  node->p = node->left = node->right = NIL;
  return node;
}

void treeInsert(Tree tree, NodePointer z) {
  NodePointer y = NIL;
  NodePointer x = tree->left;
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->p = y;
  if(y == NIL) {
    tree->left = z; // if T is empty
  } else if(z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void printInorder(NodePointer node) {
  if(node->left  != NIL) printInorder(node->left);
  if(node->key != TREE_VALUE) printf(" %d", node->key);
  if(node->right != NIL) printInorder(node->right);
}

void printPreorder(NodePointer node) {
  if(node->key != TREE_VALUE) printf(" %d", node->key);
  if(node->left  != NIL) printPreorder(node->left);
  if(node->right != NIL) printPreorder(node->right);
}

NodePointer find(NodePointer node, int key) {
  if(node == NIL) return NIL;
  if(node->key == key) return node;
  else if(key < node->key)
    return find(node->left, key);
  else
    return find(node->right, key);
}

NodePointer treeMinimum(NodePointer x) {
  while(x->left != NIL) {
    x = x->left;
  }
  return x;
}

NodePointer treeSuccessor(NodePointer x) {
  NodePointer y;
  if(x->right != NIL)
    return treeMinimum(x->right);
  y = x->p;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Tree T, NodePointer z) {
  NodePointer x, y;

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)
    x->p = y->p;

  if(y->p == NIL)
    T->left = x;
  else if(y == y->p->left)
    y->p->left = x;
  else
    y->p->right = x;

  if(y != z)
    z->key = y->key;

}

int main() {
  int N, key;
  char str[10];
  Tree tree;

  // initialize tree
  tree = makeNode(TREE_VALUE);

  scanf("%d", &N);
  while(N--) {
    scanf("%s", str);
    if(str[0] == 'i') {
      scanf("%d", &key);
      treeInsert(tree, makeNode(key));
    } else if(str[0] == 'p') {
      printInorder(tree);
      printf("\n");
      printPreorder(tree);
      printf("\n");
    } else if(str[0] == 'f') {
      scanf("%d", &key);
      printf(find(tree,key)?"yes\n":"no\n");
    } else {
      scanf("%d", &key);
      treeDelete(tree, find(tree,key));
    }
  }
  return 0;
}

Measured memory_bytes: 9836
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt = Integer.parseInt(s.nextLine());
		for(int i=0 ; i<cnt ; i++) {
			char[] a = s.next().toCharArray();
			char[] b = s.next().toCharArray();
			System.out.println(solve(a, b));
		}
	}

	public static int solve(char[] a, char[] b) {
		int[][] result = new int[a.length+1][b.length+1];
		for(int i=1 ; i<=b.length ; i++) {
			for(int j=1 ; j<=a.length ; j++) {
				if(a[j-1]==b[i-1]) {
					result[j][i] = result[j-1][i-1] + 1;
				}else {
					result[j][i] = Math.max(result[j][i-1], result[j-1][i]);
				}
			}
		}
		return result[a.length][b.length];
	}

}

Measured memory_bytes: 60776
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())

N = int(input())
B = [int(input()) for _ in range(N)]

def ok(a, b, c):
    return B.__contains__(a) and B.__contains__(b) and B.__contains__(c)

print("Yes" if ok(a11, a12, a13) or ok(a21, a22, a23) or ok(a31, a32, a33) or ok(a11, a21, a31) or ok(a12, a22, a23) or ok(a13, a23, a33) or ok(a11, a22, a33) or ok(a13, a22, a31) else "No")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> X(n), Y(m);
  rep(i, n) cin >> X[i];
  rep(i, m) cin >> Y[i];
  ll sumi = 0;
  REP(i, 1, n) {
    sumi += (((i * (n-i)) % mod) * ((X[i] - X[i-1]) % mod)) % mod;
    sumi %= mod;
  }
  ll sumj = 0;
  REP(j, 1, m) {
    sumj += (((j * (m-j)) % mod) * ((Y[j] - Y[j-1]) % mod)) % mod;
    sumj %= mod;
  }
  // sum_i i * (n-i) * dx[i] * sum_j j * (m-j) * dy[j]
  cout << (sumi * sumj) % mod << endl;
  return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int k , s , ans=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j >= 0 && s-i-j <= k){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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


int main(){
    int N,M; cin >> N >> M;
    int L[M], R[M];
    for (int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i];
    }
    sort(L,L+M); sort(R,R+M);
    if(R[0]-L[M-1]+1 > 0) cout << R[0]-L[M-1]+1 << endl;
    else cout << 0 <<  endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

constexpr int lim = 2*1e5;
int a[lim+1], b[lim+1];
int main(){
  int n, m; cin >> n >> m;
  string s; cin >> s;

  set<int> g[n];

  REP(i, m){
    int x, y; cin >> x >> y;
    x--; y--;
    g[x].insert(y);
    g[y].insert(x);
  }

  set<int> q;
  REP(i, n){
    for(auto x: g[i]){
      if(s[x] == 'A') a[i]++;
      else b[i]++;
    }
    if(a[i] == 0 || b[i] == 0) q.insert(i);
  }
  
  int cnt = 0;
  while(q.size()){
    int v = *q.begin(); 
    q.erase(q.begin());
    cnt++;
    for(auto x: g[v]){
      if(x == v) continue;

      g[x].erase(v);
      if(s[v] == 'A') a[x]--;
      else b[x]--;

      if(a[x] == 0 || b[x] == 0) q.insert(x);
    }
  }

  if(cnt == n) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

int main(){
    long long n;
    cin>>n;
    long long a[n+1],b[n+1];
    for(int i=0;i<=n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    long long c=0;
    //for(int i=0;i<n;i++) cout<<a[i]<<" "<<b[i];
    //cout<<a[n];
    for(int i=0;i<n;i++){
        if(a[i]+a[i+1]>b[i]){
            //cout<<"1.";
            c+=b[i];
            if(a[i]>=b[i]) continue;
            if(a[i+1]-b[i]+a[i]<0) a[i+1]=0;
            else a[i+1] -= b[i]-a[i];
            //cout<<c<<".";
        }
        else{
            c+=a[i]+a[i+1];
            a[i+1]=0;
            //cout<<c<<",";
        }
        //cout<<c<<" ";
    }
    cout<<c;
    return 0;
}

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

vector<int> v(3);

void solve(){
	sort(v.begin(),v.end());
	if((v[2] * v[2]) == (v[1] * v[1] + v[0] * v[0])) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main(){
	int n;
	cin >> n;
	for(int j=1;j<=n;j++){
		for(int i=0;i<3;i++){
		cin >> v[i];
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 3064
N,K = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort.reverse
wa = Array.new(N+1,0)
dp = Array.new(K,false)
b = -1
dp[0] = true
(N-1).downto(0) do |i|
  s = wa[i+1]+a[i]
  if s >= K
    wa[0..i] = Array.new(i+1,K)
    break
  else
    wa[i] = wa[i+1]+a[i]
  end
end
for i in 0..N-1
  (K-1).downto(K-wa[i]) do |j|
    if dp[j]
      if j+a[i] >= K
        b = i
        (K-1-a[i]).downto(K-wa[i]) do |k|
          if dp[k]
            dp[k+a[i]] = true
          end
        end
        break
      else
        dp[j+a[i]] = true
      end
    end
  end
end
puts N-b-1

Measured memory_bytes: 2424
import java.util.*;
public class Main
{
    public static void main(String args[]) 
    {
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      HashMap<Long,Integer> map=new HashMap<>();
      while(n-->0)
      {
          long a=sc.nextInt();
          if(map.containsKey(a))
          {
              int c=map.get(a);
              map.put(a,c+1);
          }
          else
          {
              map.put(a,1);
          }
      }
      long sum=0;
      for(Map.Entry<Long,Integer> entry:map.entrySet())
      {
          if(entry.getKey()!=(long)entry.getValue())
          {
             if((long)entry.getValue()>entry.getKey())
             {
                 sum+=(long)entry.getValue()-entry.getKey();
             }
             else
             {
                 sum+=(long)entry.getValue();
             }
          }
      }
      System.out.print(sum);
    }
}


Measured memory_bytes: 64796
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-26 20:59:23
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int h, a;
    cin >> h >> a;

    cout << ceil((float)h/a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//????????¢??°
int compare(char *a, char *b){
	return strcmp(a, b);
}

//??????
void sort_sub(char **origin, int left, int right, char **tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(char **origin, int N){
	char **tmp = (char **)malloc(sizeof(char *) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int main(){
	int N, L, i, j, k, l;
	scanf("%d%d", &N, &L);
	char **s = (char **)malloc(sizeof(char *) * N);
	int **is_reverse = (int **)malloc(sizeof(int *) * N);
	int *is_used = (int *)malloc(sizeof(int) * N);
	int *go = (int *)malloc(sizeof(int) * N);
	int *back = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		s[i] = (char *)malloc(sizeof(char) * (L + 1));
		scanf("%s", s[i]);
		is_reverse[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			is_reverse[i][j] = 1;
		}
		is_used[i] = 0;
	}
	sort(s, N);
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			for(k = 0; k < L; k++){
				if(s[i][k] != s[j][L - 1 - k]){
					is_reverse[i][j] = 0;
					is_reverse[j][i] = 0;
					break;
				}
			}
		}
	}
	l = 0;
	for(i = 0; i < N - 1; i++){
		if(is_used[i] == 0){
			for(j = i + 1; j < N; j++){
				if(is_used[j] == 0 && is_reverse[i][j] == 1){
					is_used[i] = 1;
					is_used[j] = 1;
					go[l] = i;
					back[l] = j;
					l++;
					break;
				}
			}
		}
	}
	for(i = 0; i < l; i++){
		for(k = 0; k < L; k++){
			printf("%c", s[go[i]][k]);
		}
	}
	for(i = 0; i < N; i++){
		if(is_reverse[i][i] == 1 && is_used[i] == 0){
			for(k = 0; k < L; k++){
				printf("%c", s[i][k]);
			}
			break;
		}
	}
	for(i = l - 1; i >= 0; i--){
		for(k = 0; k < L; k++){
			printf("%c", s[back[i]][k]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 5732
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int primax = 1500000;
		int[] pri = new int[primax+10000];
		for(int i=2;i<=primax;i++) pri[i] = i;
		for(int i=2;i<=primax+1;i++){
			for(int j=i+i;j<=primax;j+=i){
					pri[j]=0;
			}
		}

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			if(pri[n]>0){
				System.out.println("0");
			}else{
				int a = 0;
				int b = 0;
				for(int i=n;;i++){
					if(pri[i]>0){
						a = i;
						break;
					}
				}
				for(int i=n;;i--){
					if(pri[i]>0){
						b = i;
						break;
					}
				}
				System.out.println(a-b);
			}
		}
	}
	
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int ans = INF;
	int sum = 0;
	int n = s.size();
	REP(i, n) {
		if (s[i] - '0' != i % 2)sum++;
	}
	chmin(ans, sum);
	sum = 0;
	REP(i, n) {
		if (s[i] - '0' != 1 - i % 2)sum++;
	}
	chmin(ans, sum);
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 500*1000 + 7;
const int MAXSQ = 1000 + 10;
const int SS = 1<<20;
const int INF = 1000*1000*1000 + 7;

struct zap {
	int l, r, i;
};

int t[MAXN];
int cnt[MAXN];
vector<zap> zapytania[MAXSQ];
int wyn[MAXN];
int n, q;
int sq;

bool comp(zap a, zap b)
{
	if(a.r == b.r)
		return a.l < b.l;
	return a.r < b.r;
}

void dla_sq(int ind)
{
	int L = 1, R = 0, akt = 0;
	for(zap z: zapytania[ind])
	{
		while(R+1 <= z.r)
		{
			R++;
			cnt[ t[R] ]++;
			if(cnt[ t[R] ] == 1)
				akt++;
		}
		while(L-1 >= z.l)
		{
			L--;
			cnt[ t[L] ]++;
			if(cnt[ t[L] ] == 1)
				akt++;
		}
		while(L < z.l)
		{
			cnt[ t[L] ]--;
			if(cnt[ t[L] ] == 0)
				akt--;
			L++;
		}
		wyn[z.i] = akt;
	}
}

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

	int T;
	//cin >> T;
	T = 1;
	while(T--)
	{
		cin >> n >> q;
		for(int i=1; i<=n; i++)
			cin >> t[i];
		sq = sqrt(n)+1;
		for(int i=1; i<=q; i++)
		{
			int l, r;
			cin >> l >> r;
			zapytania[ (l+sq-1)/sq ].pb({l, r, i});
		}
		for(int i=1; i<=sq; i++)
		{
			sort(zapytania[i].begin(), zapytania[i].end(), comp);
			for(int i=1; i<=n; i++)
				cnt[i] = 0;
			dla_sq(i);
		}
		for(int i=1; i<=q; i++)
			cout << wyn[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 18580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"



  
  int main(){
	ios::sync_with_stdio(true);
	cin.tie(0);
    int a;
    string b;
    cin >> a >> b;
    if(b.length() > a){
		for(int i = 0; i<a; i++){
			cout << b[i];
		}
		cout << "...";
	}
    else{
		cout << b;
	}
	
 }


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

int main() {
  int n;
  cin >> n;
  ll num[n];
  ll sum = 0;
  rep(i,n) cin >> num[i];
  rep(i,n) sum += num[i];

  ll psum[n];
  psum[0] = 0;
  ll ans = INFTY;
  for (int i=1; i<n; i++) {
    psum[i] = psum[i-1]+num[i-1];
    ll res = sum - psum[i];
    ll tmp = max(psum[i]-res, res-psum[i]);
    if (tmp < ans) {
      ans = tmp;
    }
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

struct City {
    int year;
    int num;
    City(int year, int num): year(year), num(num) {}
    City() {}
    bool operator<(const City& o) const {
        return year < o.year;
    }
};

struct Prefect {
    int p;
    vector<City> cities;
    Prefect() {}
    Prefect(int p): p(p) {}
    void add_city(City c) {
        cities.push_back(c);
    }
    void assign_ids(vector<long long>& ids) {
        sort(cities.begin(), cities.end());
        for (int i = 0; i < (int) cities.size(); ++i) {
            auto& city = cities[i];
            ids[city.num] = 1000000LL * p + (i+1);
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<Prefect> prefects(n+1);
    for (int i = 0; i <= n; ++i) {
        prefects[i].p = i;
    }
    for (int i = 0; i < m; ++i) {
        int p, year;
        cin >> p >> year;
        prefects[p].add_city(City(year, i));
    }
    vector<long long> ids(m);
    for (auto prefect : prefects) {
        prefect.assign_ids(ids);
    }
    for (auto id : ids) {
        printf("%012lld\n", id);
        // cout << id << "\n";
    }
    return 0;
}


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


int main(void)
{
    int N;
    int a[101];
    cin>>N;
    REP(i, 0, N) cin>>a[i];

    int cnt=0;
    REP(i, 0, N){
        if(i%2==0 && a[i]%2!=0) cnt++;
    }

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

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int n;

int f(char c){
    return (int)(c - '0');
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        cin >> n;
        if(n == 0) break;
        vector<int> imos(60*60*24+100, 0);
        
        REP(i, n){
            string s1, s2;
            cin >> s1 >> s2;
            int t1 = 0, t2 = 0;
            t1 += f(s1[0]) * 36000 + f(s1[1]) * 3600 + f(s1[3]) * 600 + f(s1[4]) * 60 + f(s1[6]) * 10 + f(s1[7]);
            t2 += f(s2[0]) * 36000 + f(s2[1]) * 3600 + f(s2[3]) * 600 + f(s2[4]) * 60 + f(s2[6]) * 10 + f(s2[7]);
            imos[t1]++; imos[t2]--;
        }
        REP(i, 60*60*24+10) imos[i+1] += imos[i];
        int ans = 0;
        
        REP(i, 60*60*24+1) ans = max(ans, imos[i]);
        cout << ans << endl;
    }
}



Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORS(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define SORT(v,n) sort(v,v+n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,n,0)
#define si(n) scanf("%d",&n)
#define sc(s) scanf("%s",s)
#define EPS (1e-7)
#define INF (1e9)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

ll N;
ll A[100000];
int main(void){
    cin >> N;
    rep(i,N) cin >> A[i];

    ll total = 0;
    rep(i,N) total += A[i] * (((i+1)%2)-0.5) * 2;
    cout << total;
    for(int i=0;i<N-1;i++) {
        cout << ' ';
        total = A[i] * 2 - total;
        cout << total;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll sumv = 0;

    for (ll l = 1; l <= n; l++) {
        sumv += (n - l + 2) * (n - l + 1) / 2;
    }

    ll sume = 0;
    rep(i, n - 1) {
        ll u, v;
        cin >> u >> v;
        sume += min(u,v) * (n - max(u,v) + 1);
    }
    cout << sumv - sume << endl;
}


Measured memory_bytes: 3628