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

using namespace std;
typedef long long ll;

int H, W, K;
char c[6][6];
int cnt_black;

int calc(int i, int j){
    int ans = cnt_black;
    for(int h = 0; h < H; h++){
        for(int w = 0; w < W; w++){
            if((((1<<h)&i) || ((1<<w)&j)) && c[h][w] == '#') ans--;
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c[i][j];
            if(c[i][j] == '#') cnt_black++;
        }
    }
    int ans = 0;
    for(int i = 0; i < (1<<H); i++){
        for(int j = 0; j < (1<<W); j++){
            if(calc(i, j) == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
"use strict"
function main(arg) {
    if (arg.trim().split("\n")[0].split(" ").map(Number).sort((a,b) => a-b).join('') == '557') {
        console.log('YES')
    } else {
        console.log('NO')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
s = input()
n = len(s)
s1 = s[:n//2]
s2 = s[n//2 + 1:]
s1r = s1[::-1]
s2r = s2[::-1]
if s1 == s1r and s1 == s2 and s2 == s2r:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////
int p[100100], y[100100];
vector<pii>v[100100];
int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> p[i] >> y[i];
		v[p[i]].push_back({ y[i],i });
	}
	for (int i = 0; i < 100100; ++i) {
		sort(v[i].begin(), v[i].end());
	}
	vector<int>ans(m);
	for (int i = 0; i < 100100; ++i) {
		if (v[i].empty())continue;
		for (int j = 0; j < v[i].size(); ++j) {
			ans[v[i][j].second] = j + 1;
		}
	}
	for (int i = 0; i < m; ++i) {
		cout << setw(6) << setfill('0') << p[i]<< setw(6) << setfill('0') << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <stack>

using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))
#define QWERTYR(c) (c == 'y' || c == 'u' || (c >= 'h' && c <= 'p') ?	true : false)
typedef vector<int> Ivec;
typedef pair<int, int> pii;

int main() {
	int n, q;
	while (scanf("%d %d", &n, &q)) {
		array<int, 101> cou = {};
		if (n == 0 && q == 0)
			return 0;
		int max_day = 0;
		for (int i = 0; n > i; i++) {
			int a;
			scanf("%d", &a);
			for (int j = 0; a > j; j++) {
				int b;
				scanf("%d", &b);
				cou[b]++;
				max_day = max(max_day, b);
			}
		}
		int max_num = 0,max = -1;
		for (int i = 1; max_day >= i; i++) {
			if (max < cou[i]) {
				max = cou[i];
				max_num = i;
			}
		}
		if (max < q) max_num = 0;
		printf("%d\n",max_num);
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	SORT(a); SORT(b);
	if(n % 2){
		ll m = a[n/2];
		ll M = b[n/2];
		cout << M - m + 1 << endl;
	} else {
		ll m = a[n/2-1] + a[n/2];
		ll M = b[n/2-1] + b[n/2];
		cout << M - m + 1 << endl;
	}
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    string s;
    cin >> s;
    string t = s;
    reverse(t.begin(), t.end());
    for (auto &c: t) {
        if (c == 'b')
            c = 'd';
        else if (c == 'd')
            c = 'b';
        else if (c == 'p')
            c = 'q';
        else if (c == 'q')
            c = 'p';
    }
    cout << (t == s ? "Yes\n" : "No\n");
}


Measured memory_bytes: 512
H, W = map(int, input().split())

P = [ [ 0 if x == "#" else 0x00010001 for x in input()] for _ in range(H)]

class Union:
    def __init__(self):
        self.rx = 0
        self.ry = 0
        self.lx = 0
        self.ly = 0
    def init(self, y, x):
        value = P[y][x]
        if value == 0:
            return False

        self.lx = x
        self.ly = y
        w = value & 0xffff
        if w & 0x8000:
            self.ry = w ^ 0x8000
        else:
            self.ry = self.ly

        w = value >> 16
        if w & 0x8000:
            self.rx = w ^ 0x8000
        else:
            self.rx = self.lx

        return True

    def changeH(self, src, value):
        return (src ^ (src & 0xffff0000)) | (value << 16)
    def changeV(self, src, value):
        return (src ^ (src & 0xffff)) | value

    def changeHA(self, value):
        return self.changeH(value, self.rx | 0x8000)
    def changeVA(self, value):
        return self.changeV(value, self.ry | 0x8000)

    def getHC(self):
        return P[self.ly][self.rx] >> 16
    def setHC(self, value):
        P[self.ly][self.rx] = self.changeH(P[self.ly][self.rx], value)
    def getVC(self):
        return P[self.ry][self.lx] & 0xffff
    def setVC(self, value):
        P[self.ry][self.lx] = self.changeV(P[self.ry][self.lx], value)
        
uni = Union()

for i in range(H):
    for j in range(W):
        if P[i][j] != 0:
            if i > 0 and uni.init(i-1, j):
                uni.setVC(uni.getVC() + 1)
                P[i][j] = uni.changeVA(P[i][j])
            if j > 0 and uni.init(i, j-1):
                uni.setHC(uni.getHC() + 1)
                P[i][j] = uni.changeHA(P[i][j])


w = 0
for i in range(H):
    for j in range(W):
        if uni.init(i, j):
            w = max(w, uni.getHC() + uni.getVC() -1)

print(w)


Measured memory_bytes: 103644
#include<stdio.h>
#include<math.h>
int main(){
 int i,j,k;
 int N[1000];
 int S[1000];
 double A[1000],B[1000];
 double V[1000];

 for(i=1;i<1000;i++){
  scanf("%d",&N[i]);


  for(j=1;j<=N[i]-1;j++){
   scanf("%d ",&S[j]);
   A[i]+=pow(S[j],2);
   B[i]+=S[j];
  }
   scanf("%d\n",&S[N[i]]);
   A[i]+=pow(S[N[i]],2);
   B[i]+=S[N[i]];

   V[i]=sqrt(A[i]/N[i]-pow(B[i]/N[i],2));

  if(N[i]==0){
   k=i;
   break;
  }

 }

 for(i=1;i<k;i++){
  printf("%lf\n",V[i]);
 }



return 0;
}

Measured memory_bytes: 660
import sys
import numpy as np

read = sys.stdin.read
N, M, V, P, *A = map(int, read().split())

A = np.array(A + [10 ** 10], np.int64)
A.sort()
A = A[::-1]
left = P
right = N + 1
# i番目の問題が採用される可能性があるか否や
while right - left > 1:
    mid = (right + left) // 2
    score = A[mid] + M
    if score < A[P]:
        right = mid
        continue

    s = np.minimum(score - A[P:], M)
    if np.sum(s) >= M * (V - (P - 1)):
        left = mid
    else:
        right = mid

print(left)


Measured memory_bytes: 23112
#include <stdio.h>

int main(void)
{
  int cooking_time[5];
  int i;

  for(i = 0; i < 5; i++) {
    scanf("%d", &cooking_time[i]);
  }

  int min_time = 0;
  int subtractor = 10;
  for(i = 0; i < 5; i++) {
    if(subtractor > cooking_time[i] % 10
    && cooking_time[i] % 10 != 0) {
      subtractor = cooking_time[i] % 10;
    }

    min_time +=
      cooking_time[i] + (200 - cooking_time[i]) % 10;
  }
  min_time -= 10 - subtractor;

  printf("%d\n", min_time);
  return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	vector <char> abc;

	for(char c = 'A'; c <= 'Z'; c++){
		abc.push_back(c);
	}


	int n; cin >> n;

	string s; cin >> s;

	for(int i = 0; i < s.size(); i++){
		s[i] = abc[(s[i] - 'A' + n) % 26];
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define MAX_N 8

using namespace std;

int main() {
    int N,M,a,b,i,sum=0;
    scanf("%d %d",&N,&M);
    int perm[N];
    bool path[MAX_N][MAX_N] = {{0}};
    for (i=0; i<N; i++)
        perm[i] = i;
    for (i=0; i<M; i++) {
        scanf("%d %d",&a,&b);
        path[a-1][b-1] = true;
        path[b-1][a-1] = true;
    }
    do {
        for (i=0; i<N-1 && path[perm[i]][perm[i+1]]; i++);
        if (i == N-1) sum++;
    } while (next_permutation(perm+1,perm+N));
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,top;
	cin>>a;
	top=a+1;
	for(long long i=2;i<=sqrt(a);i++)
	{
		if(a%i==0){
			if(top>a/i+i)
			top=a/i+i;
		}
	}
	cout<<top-2;
} 

Measured memory_bytes: 256
public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(3);
    int[] l = na(n);
    
    System.out.println(dfs(0, 0, l, a));
  }
  
  private static int dfs(int i, int used, int[] l, int[] a) {
    int ret = Integer.MAX_VALUE / 10;
    int n = l.length;
    if (i == 3) return 0;
    
    if (i == ((1 << n) - 1)) return ret;

    for (int j = 1; j < (1 << n); j ++) {
      if ((j & used) != 0) continue;
      int now = 0;
      
      now += (Integer.bitCount(j) - 1) * 10;
      int len = 0;
      for (int k = 0; k < n; k ++) {
        if (((j >> k) & 1) != 0) {
          len += l[k];
        }
      }
      now += Math.abs(len - a[i]);
      now += dfs(i + 1, used | j, l, a);
      
      ret = Math.min(ret, now);
    }
    return ret;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
  
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N,Q;
//https://minus9d.hatenablog.com/entry/2014/07/05/215756
//vector<tuple<int,int,int>> に対しsort()を使うと
//自動的に第一要素、第二要素、…と順に比較した結果に基づいてソートされる
vector<tuple<int,int,int>> stx;
set<pair<int,int>> D;

int ans[200000];
 
void solve(){
	for(int i=0;i<Q;i++) ans[i] = -1;
    sort(stx.begin(),stx.end());

    for (int i=0;i<N;i++) {
    	int x = get<0>(stx[i]);
    	int s = get<1>(stx[i]);
    	int t = get<2>(stx[i]);
        auto first = D.lower_bound(make_pair(s-x,0));
        auto end = D.upper_bound(make_pair(t-x-1,Q));

        for(auto it=first;it!=end;it++) ans[it->second] = get<0>(stx[i]);

        D.erase(first, end);
    }
}
 
int main(){
	cin >> N >> Q;
	for(int i=0;i<N;i++){
		int s,t,x;
		cin >> s >> t >> x;
		stx.push_back(tuple<int,int,int>(x,s,t));
	}
	for(int i=0;i<Q;i++){
		int d;
		cin >> d;
		D.insert(make_pair(d,i));
	}
 
	solve();

	for(int i=0;i<Q;i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 15088
_, M = map(int, input().split())
PS = [tuple(input().split()) for _ in range(M)]
result = dict()
AC, WA = 0, 0
for p,s in PS:
    i = int(p)
    if not (i in result):
        if s == "WA":
            result[i] = 1
        elif s == "AC":
            AC += 1
            result [i] = "AC"
    else:
        if result[i] != "AC":
            if s == "WA":
                result[i] += 1
            if s == "AC":
                AC += 1
                WA += result[i]
                result[i] = s
print(AC, WA)

Measured memory_bytes: 33392
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll N,M;
  cin>>N>>M;
  putYN(N==M);
  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-8
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double pi = acos(-1);

struct edge{
	int u,v,w;
	edge(){u=v=w=0;}
	edge(int _u, int _v, int _w){
		u = _u;
		v = _v;
		w = _w;
	}
};

int n,i,j,k,t;
int coba[60];

int get(int val, int base){
	int i=0, j=1;
	while(base*j <= val){
		i++;
		j*=base;
	}
	return i;
}

int main(){
	scanf("%d", &n);
	if(n <=60){
		printf("%d %d\n", 2,n);
		for(i=0;i<n;++i)
			printf("%d %d %d\n", 1, 2, i);
	}
	else{
		vector<edge> e;
		vector<pii> sisa;
		int tmp = get(n, 2), manode = tmp+1;
		int wew = pow(2, tmp-1);
		for(i=1;i<=tmp;++i){
			e.pb({i, i+1, 0});
			e.pb({i, i+1, wew});
			wew /= 2;
			coba[tmp-i] = i+1;
		}
		int sum = 0;
		while(n){
			if(n == pow(2, tmp))
				break;
			int x = n - pow(2, tmp);
			e.pb({1, coba[get(x, 2)], sum+=pow(2, tmp)});
			n = x;
			tmp = get(n, 2);
			if(!tmp)
				break;
		}
		printf("%d %d\n", manode, (int) e.size());
		for(const edge &x : e){
			printf("%d %d %d\n", x.u, x.v, x.w);
		}
	}
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.abs
import kotlin.math.min

fun main() {
    val n = nextInt()
    val X = mutableListOf<Long>()
    val Y = mutableListOf<Long>()
    val P = mutableListOf<Long>()
    repeat(n) {
        val (x, y, p) = nextLongList()
        X.add(x)
        Y.add(y)
        P.add(p)
    }
    val xsel = Array(1 shl n) { Array(n) { 0L } }
    val ysel = Array(1 shl n) { Array(n) { 0L } }
    (0 until (1 shl n)).forEach { i ->
        (0 until n).forEach { j ->
            xsel[i][j] += abs(X[j])
            ysel[i][j] += abs(Y[j])
            (0 until n).forEach { k ->
                if ((i shr k) and 1 == 1) {
                    xsel[i][j] = min(xsel[i][j], abs(X[j] - X[k]))
                    ysel[i][j] = min(ysel[i][j], abs(Y[j] - Y[k]))
                }
            }
        }
    }
    (0 until (1 shl n)).forEach { i ->
        (0 until n).forEach { j ->
            xsel[i][j] *= P[j]
            ysel[i][j] *= P[j]
        }
    }

    val ans = sizedArray(n + 1, Long.MAX_VALUE)
    (0 until (1 shl n)).forEach { i ->
        val count = (0 until n).count {
            i shr it and 1 == 1
        }
        var j = i
        while (j >= 0) {
            j = j and i
            var cost = 0L
            (0 until n).forEach { k ->
                if ((i shr k) and 1 != 1) {
                    cost += min(xsel[j][k], ysel[i - j][k])
                }
            }
            ans[count] = min(ans[count], cost)
            j--
        }
//        ans.forEach(::println)
//        return
    }
    ans.forEach(::println)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

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

bool prime[1000001];

void era(){
	for(int i=2;i<1000000;i++)prime[i]=true;
	for(int i=2;i*i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=0;
			}
		}
	}
}

int main(){
	era();
	int n,ans;
	while(cin>>n){
		ans=0;
		for(int i=0;i<=n;i++){
			if(prime[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2132
//Name: Step Aerobics
//Level: 1
//Category: やるだけ
//Note:

/**
 * 以下の4パターンのみが正常な踏み台昇降である。
 * ・lu -> ru
 * ・ru -> lu
 * ・ld -> rd
 * ・rd -> ld
 * これらの出現数を数えればよい。
 *
 * オーダーは O(N)。
 */
#include <iostream>
#include <string>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    string prev = "";
    int ans = 0;
    for(int i = 0; i < N; ++i) {
        string cmd;
        cin >> cmd;
        if((prev == "lu" && cmd == "ru") ||
           (prev == "ru" && cmd == "lu") ||
           (prev == "ld" && cmd == "rd") ||
           (prev == "rd" && cmd == "ld")) {
            ++ans;
        }
        prev = cmd;
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1224
n = int(input())
dat = [None] * n

def su(x):
    print(x)
    r = input()
    if r == "Vacant":
        return True
    elif r == "Male":
        dat[x] = "M"
        return False
    elif r == "Female":
        dat[x] = "F"
        return False
def do():
    if su(0):
        return 0
    if su(n-1):
        return 0
    l = 0
    r = n-1
    while True:
        mid = (l+r) // 2
        if su(mid):
            return 0

        if (mid - l) % 2 == 1: #even個
            if dat[l] == dat[mid]: # ここが変
                r = mid
                continue
        else: # odd
            if dat[l] != dat[mid]: # koko
                r = mid
                continue

        if (r - mid) % 2 == 1: #even個
            if dat[r] == dat[mid]: # ここが変
                l = mid
                continue
        else: # odd
            if dat[r] != dat[mid]: # koko
                l = mid
                continue
do()


Measured memory_bytes: 63036
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7

ct=[0,0,0]
ans=1
for i in range(n):
  f=0
  ct2=0
  for j in range(3):
    if a[i]==ct[j]:
      if ct2==0:
        ct[j]+=1
      ct2+=1
  ans*=ct2
  ans%=mod
print(ans%mod)

Measured memory_bytes: 52952
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
long long sqr(long long a) {return a * a; }
int main() {
    long long a, b; cin >> a >> b;
    if (a == 1 || b == 1)   cout << 1;
    else {
        long long ans = 0;
        ans += (a / 2) * (b / 2);
        a++;    b++;
        ans += (a / 2) * (b / 2);
        cout << ans;
    }
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
D = int(input())
c = [0] + list(map(int,input().split()))
sum_c=sum(c)
s = [0] + [[0] + list(map(int,input().split())) for i in range(D)]

#print(s)

cs = 0 #満足度
last = [0]*(26+1) #前回開催日
for day in range(1,D+1):
  t=int(input()) #開催コンテストNo.
  cs+=s[day][t]

  for j in range(27):
    if j==t:
      continue
    cs-=c[j]*(day-last[j])
  last[t]=day #前回開催日に追加
  print(cs)
  

Measured memory_bytes: 9180
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let n = {
        let i = read::<isize>();
        (i[0])
    };

    let name;
    if n <= 999 {
        name = "ABC";
    } else {
        name = "ABD";
    }
    println!("{}", name);
}


Measured memory_bytes: 4352
<?php
fscanf(STDIN, "%d", $N);
$A = explode(' ',  trim(fgets(STDIN)));
$c = array_count_values($A);
$d = [];
foreach ($c as $k => $v) {
    $c[$k] = $v * ($v - 1) / 2;
    $d[$k] = ($v - 2) * ($v - 1) / 2;
}
// var_dump($c);
$sum = array_sum($c);
for ($i = 0; $i < $N; $i++) {
    printf("%d\n", $sum - ($c[$A[$i]] - $d[$A[$i]]));
}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

signed main() {
    int N;
    cin >> N;
    vector<int> ab;
    rep(i, 1, N + 1) rep(j, 1, N + 1) {
        ab.push_back(gcd(i, j));
    }

    int tot = 0;
    rep(i, 1, N + 1) {
        for (const auto& a : ab) {
            tot += gcd(i, a);
        }
    }
    cout << tot << "\n";
}


Measured memory_bytes: 3780
#include <iostream>

using namespace std;

int main(){
  int A, B, K;

  cin >> A >> B >> K;

  int count = 0;
  for(int i = 100; i >= 1; --i){
    if(A % i == 0 and B % i == 0) count++;
    if(count == K){
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
    s += l + i - 1
 
x = 1 - l
if x <= n and x >= 1:
    print(s)
else:
    a = l
    b = l + n - 1
    if abs(a) < abs(b):
        print(s - a)
    else:
        print(s - b)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

ll solve(ll ls, ll lt, ll rs, ll rt, ll x){

    ll d_ls, d_lt, d_rs, d_rt;
    d_ls = abs(ls-x);
    d_lt = abs(lt-x);
    d_rs = abs(rs-x);
    d_rt = abs(rt-x);
    
    ll ans = INF;
    
    chmin(ans, min(max(d_ls, d_lt), max(d_rs, d_rt)));
    chmin(ans, 2 * (d_ls + d_rt) - max(d_ls, d_rt));
    chmin(ans, 2 * (d_lt + d_rs) - max(d_lt, d_rs));

    return ans;

}

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

    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A);
    vector<ll> t(B);
    vector<ll> x(Q);

    for(int i = 0; i < A; i++) cin >> s[i];
    for(int i = 0; i < B; i++) cin >> t[i];
    for(int i = 0; i < Q; i++) cin >> x[i];

    s.insert(s.begin(), -INF);
    s.push_back(INF);
    t.insert(t.begin(), -INF);
    t.push_back(INF);
    

    ll ls_tmp;
    ll lt_tmp;
    ll rs_tmp;
    ll rt_tmp;

    for(int i = 0; i < Q; i++){
        rs_tmp = *lower_bound(s.begin(), s.end(), x[i]);
        rt_tmp = *lower_bound(t.begin(), t.end(), x[i]);
        ls_tmp = *(lower_bound(s.begin(), s.end(), x[i])-1);
        lt_tmp = *(lower_bound(t.begin(), t.end(), x[i])-1);

        cout << solve(ls_tmp, lt_tmp, rs_tmp, rt_tmp, x[i]) << endl;

    }

    return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>

#define Mod 998244353

int main()
{
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A == C && B == D) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}
	
	int i, j, k;
	long long dp[3002][2][3][3] = {};
	dp[0][0][0][0] = 1;
	dp[1][0][1][0] = B - 1;
	dp[1][0][1][1] = 1;
	for (i = 2; i <= C - A; i++) {
		dp[i][0][1][0] = dp[i-1][0][1][0] * (B - 1) % Mod;
		dp[i][0][1][1] = (dp[i-1][0][1][0] + dp[i-1][0][1][1] * (B - 1)) % Mod;
		dp[i][0][1][2] = (dp[i-1][0][1][1] + dp[i-1][0][1][2] * B) % Mod;
	}
	dp[0][1][0][1] = A - 1;
	dp[0][1][1][1] = 1;
	for (i = 1; i <= C - A; i++) {
		dp[i][1][1][0] = dp[i-1][1][1][0] * B % Mod;
		dp[i][1][1][2] = (dp[i-1][1][0][1] + dp[i-1][1][1][1] + dp[i-1][1][2][1] + dp[i-1][1][1][2] * (B + 1)) % Mod;
		dp[i][1][0][1] = dp[i][0][0][1] * (A + i - 1) % Mod;
		dp[i][1][2][1] = (dp[i][0][1][0] + dp[i][0][1][1] + dp[i][0][1][2] + dp[i][0][2][1] * (A + i)) % Mod;
		dp[i][1][1][1] = (dp[i-1][0][0][0] + dp[i-1][0][0][1] + dp[i-1][0][0][2] + dp[i-1][0][1][0] + dp[i-1][0][1][1] + dp[i-1][0][1][2] + dp[i-1][0][2][0] + dp[i-1][0][2][1] + dp[i-1][0][2][2]) * (A + i - 1) * B % Mod;
	}
	dp[0][0][0][0] = 0;
	for (j = 2; j <= D - B; j++) {
		dp[0][j%2][0][1] = dp[0][1-j%2][0][1] * (A - 1) % Mod;
		dp[0][j%2][1][1] = (dp[0][1-j%2][0][1] + dp[0][1-j%2][1][1] * (A - 1)) % Mod;
		dp[0][j%2][2][1] = (dp[0][1-j%2][1][1] + dp[0][1-j%2][2][1] * A) % Mod;
		for (i = 1; i <= C - A; i++) {
			dp[i][j%2][1][0] = dp[i-1][j%2][1][0] * (B + j - 1) % Mod;
			dp[i][j%2][1][2] = (dp[i-1][j%2][0][1] + dp[i-1][j%2][1][1] + dp[i-1][j%2][2][1] + dp[i-1][j%2][1][2] * (B + j)) % Mod;
			dp[i][j%2][0][1] = dp[i][1-j%2][0][1] * (A + i - 1) % Mod;
			dp[i][j%2][2][1] = (dp[i][1-j%2][1][0] + dp[i][1-j%2][1][1] + dp[i][1-j%2][1][2] + dp[i][1-j%2][2][1] * (A + i)) % Mod;
			dp[i][j%2][1][1] = (dp[i-1][1-j%2][0][0] + dp[i-1][1-j%2][0][1] + dp[i-1][1-j%2][0][2] + dp[i-1][1-j%2][1][0] + dp[i-1][1-j%2][1][1] + dp[i-1][1-j%2][1][2] + dp[i-1][1-j%2][2][0] + dp[i-1][1-j%2][2][1] + dp[i-1][1-j%2][2][2]) * (A + i - 1) * (B + j - 1) % Mod;
		}
	}
	
	
	printf("%lld\n", (dp[C-A][(D-B)%2][1][0] + dp[C-A][(D-B)%2][1][2] + dp[C-A][(D-B)%2][0][1] + dp[C-A][(D-B)%2][2][1] + dp[C-A][(D-B)%2][1][1]) % Mod);
	fflush(stdout);
	return 0;
}

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

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  long sum = a[n-1]-a[0];
  long head = 0;
  long tail = n-1;
  long generated_top = a[0];
  long generated_bottom = a[n-1];
  int flag;
  while (1) {
    head++;
    if (head >= tail) {
      break;
    }
    if (head+1 == tail) {
      if (labs(generated_top-a[head]) > labs(generated_bottom-a[head])) {
        sum += labs(generated_top-a[head]);
      } else {
        sum += labs(generated_bottom-a[head]);
      }
      break;
    }
    if (generated_top > generated_bottom) {
      sum += generated_top-a[head];
      generated_top = a[head];
      flag = 0;
    } else {
      sum += generated_bottom-a[head];
      generated_bottom = a[head];
      flag = 1;
    }
    tail--;
    if (head >= tail) {
      break;
    }
    if (flag == 0) {
      sum += a[tail]-generated_bottom;
      generated_bottom = a[tail];
    } else {
      sum += a[tail]-generated_top;
      generated_top = a[tail];
    }
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,p,n) for(int i=p;i<=n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

//貪欲法はクソ
int main() {

  int N; cin >> N ;

  vector<int> A(N); rep(i,N) cin >> A[i];

  set<int> S;

  bool can=true;

  rep(i,N){
    
    if(S.count(A[i])) can=false;
    else S.insert(A[i]);
  }

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

  return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9+1;

int main(){
    int n;
    cin>>n;
    int cnt[n]={};
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        cnt[a-1]++;
    }
    int ans[n];
    priority_queue<int> q;
    for(int i=0;i<n;i++){
        if(cnt[i]>0){
            q.push(-cnt[i]);
        }
    }
    for(int i=n;i>q.size();i--){
        ans[i-1]=0;
    }
    for(int i=q.size();i>=1;i--){
        ans[i-1]=-q.top();
        int p=-q.top();
        q.pop();
        if(i==1)break;
        while(p>0){
            p--;
            int r=q.top();
            q.pop();
            q.push(r-1);
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4336
S = input()
amari = [0]*2019
ans = 0
amari[0] = 1
A = 0
for i in range(len(S)):
    A += pow(10, i, 2019)*(int(S[len(S)-1-i]))
    amari[A % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(int(ans))
        
    

Measured memory_bytes: 68332
N = int(input())
h = list(map(int, input().split()))

dp = [-1] * N

dp[0] = 0
dp[1] = dp[0] + abs(h[1] - h[0])

for x in range(2, N):
    dp[x] = min(dp[x - 1] + abs(h[x] - h[x - 1]),
                dp[x - 2] + abs(h[x] - h[x - 2]))
print(dp[N - 1])

Measured memory_bytes: 20656
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=0;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	long long int a,b,x;
	cin >> a>> b>>x;
	if(a%x==0){
		ans = b/x-a/x+1;
	}else{
		ans = b/x-a/x;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

vector<ll> divisor(ll n) {
	vector<ll> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, M;
	cin >> N >> M;

	vector<ll> v = divisor(M);
	ll max_v = 1;

	rep(i, 0, v.size()) {
		if(v[i] * N <= M) max_v = max(max_v, v[i]);
	}
	
	cout << max_v << endl;
}


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

int main()
{

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

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

    int result = a.at(n/2) - a.at(n/2 - 1);

    cout << result << endl;
}

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

 using namespace std;

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

   int count_N = 0;
   int count_W = 0;
   int count_S = 0;
   int count_E = 0;

   for (int i = 0; i < S.length(); i++) {
     if (S.at(i) == 'N') count_N++;
     else if (S.at(i) == 'W') count_W++;
     else if (S.at(i) == 'S') count_S++;
     else count_E++;
   }

   string ans;
   if (count_N != 0 && count_W != 0 && count_S != 0 && count_E != 0) ans = "Yes";
   else if (count_N == 0 && count_W != 0 && count_S == 0 && count_E != 0) ans = "Yes";
   else if (count_N != 0 && count_W == 0 && count_S != 0 && count_E == 0) ans = "Yes";
   else ans = "No";

   cout << ans << endl;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

bool sort_fn(Pll &a, Pll &b) {
  return a.first+a.second > b.first+b.second;
}

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

  vector<Pll> ab(n);
  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    ab[i] = mkp(a, b);
  }
  sort(ab.begin(), ab.end(), sort_fn);

  ll tak = 0, aok = 0;
  for (ll i = 0; i < n; ++i) {
    if (i%2 == 0) tak += ab[i].first;
    else aok += ab[i].second;
  }

  cout << tak-aok << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const int N = 1<<18;
int total[N];
int id[N];
int score[N];

int nn;
void update(int i, int x){
	id[i+nn-1] = i;
	i += nn-1;
	score[i] += x;
	while(i > 0){
		i = (i-1)/2;
		int chl = i*2+1, chr = i*2+2;
		if(score[chl] >= score[chr]){
			score[i] = score[chl];
			id[i] = id[chl];
		}else{
			score[i] = score[chr];
			id[i] = id[chr];
		}
	}
}

void init(int n){
	nn = 1;
	while(nn < n) nn *= 2;
	rep(i, nn*2) score[i] = -1<<30;
	rep(i, n) update(i, 1<<30);
}

int main(){
	ios::sync_with_stdio(false);

	int n, r, l;
	cin >> n >> r >> l;
	init(n);
	int prev = 0;
	rep(i, r){
		int d, t, x;
		cin >> d >> t >> x;
		total[id[0]] += t-prev;
		update(d-1, x);
		prev = t;
		//cout << "score:"; rep(j, n) cout << (j?" ":"") << score[j+nn-1]; cout << endl;
		//cout << "time:";  rep(j, n) cout << (j?" ":"") << total[j]; cout << endl;
	}
	total[id[0]] += l-prev;

	cout << max_element(total, total+n)-total+1 << endl;

	return 0;
}

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

int main(void) {

    int Q; cin >> Q;
    string N;
    for (int i = 0; i < Q; i++) {
        cin >> N;

        set<int> hist;
        hist.insert(stoi(N));

        int cnt = 0;
        while (N.size() > 1) {
            int next_N = -1;
            for (int j = 1; j < N.size(); j++) {
                int n1 = stoi(string(N.begin(), N.begin()+j));
                int n2 = stoi(string(N.begin()+j, N.end()));
                next_N = max(next_N, n1*n2);
            }

            auto r = hist.insert(next_N);
            if (!r.second) {
                cnt = -1;
                break;
            }

            N = to_string(next_N);
            cnt++;
        }

        cout << cnt << endl;
    }


    return 0;
}

Measured memory_bytes: 3280
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    200010
#define   pb    push_back
#define   py    printf("Yes\n")
#define   pn    printf("No\n")

using namespace std;


int main()
{

    ll a,b,n,x,y,p,k,d,mn=100000000000000000;

    cin>>n;

    k=sqrt(n);

    for(ll i=1;i<=k;i++)
    {
        if(n%i==0)
        {
            a=i-1;
            b=n/i-1;

            d=a+b;
            mn=min(mn,d);
        }
    }

    cout<<mn<<endl;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Hello
{
    public static void Main()
    {
        Console.WriteLine(program(new string[] { Console.ReadLine(), Console.ReadLine() }));
    }

    private static string program(string[] args)
    {
        var n = int.Parse(args[0]);
        var s = args[1].ToCharArray();

        return (new String[] { "SS", "SW", "WS", "WW" }).Select(animals =>
            s.Aggregate(new StringBuilder(animals, n),
                (t, elem) => t.Append(isXor(t[t.Length - 1], elem) ? not(t[t.Length - 2]) : t[t.Length - 2]))
        )
        .Select(sb => sb.ToString())
        .FirstOrDefault(result => result.Substring(0, 2) == result.Substring(result.Length - 2, 2))?.Substring(1, n) ?? "-1";
    }

    private static bool isXor(char animal, char ans) => animal == 'S' && ans == 'x' || animal == 'W' && ans == 'o';

    private static char not(char animal) => animal == 'S' ? 'W' : 'S';
}

Measured memory_bytes: 13792
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int N,K;
        int x[100010];
        int Ans=0;

        cin >> N >> K;

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

        for(int i=0; i<=N-K; ++i){
                int Sum=abs(x[i+K-1]-x[i]), Near=min(abs(0-x[i]),abs(0-x[i+K-1]));

                Sum+=Near;

                if(i==0) Ans = Sum;
                else Ans = min(Ans,Sum);
        }

        cout << Ans << endl;

        return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  ll a, b, c;
  ll k;
  cin >> a >> b >> c >> k;
  
  if(k%2==0){
    cout << a-b << endl;
    return 0;
  }
  cout << b-a << endl;

  return 0;
}

Measured memory_bytes: 3616
str = gets.chomp
base = gets.chomp

str_size = str.size
base_size = base.size

match_max = 0
(str_size - base_size + 1).times do |i|
  tmp_match_sum = 0
  base_size.times do |j|
    tmp_match_sum += 1 if str[i + j] == base[j]
  end
  match_max = [match_max, tmp_match_sum].max
end



puts base_size - match_max

Measured memory_bytes: 14164
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str1,str2;
    ll h,w;
    ll n;
    ll a,b;
    cin>>n>>a>>b;
    if(b==0)cout<<n<<endl;
    else if(a==0) cout<<0<<endl;
    else{
        ll w=n/(a+b);
        ll j=n%(a+b);
        if(j>=a){
            sum+=a;
        }else{
            sum+=j;
        }
        sum+=a*w;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

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

struct edge{int to,cost;};

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

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

	if(n*2 >= m) cout << m/2 << "\n";
	else cout << n+(m-2*n)/4 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#define MAX 510
using namespace std;
int main(){
	int n,m,x,y;
	while(cin>>n>>m,n||m){
	set<int> box,pp;
	vector<int> tab[MAX];
	for(int i=0;i<m;i++){
		cin>>x>>y;
		tab[x].push_back(y);
		tab[y].push_back(x);
	}
	box.insert(1);
	for(int i=0;i<tab[1].size();i++)
		box.insert(tab[1][i]);
	set<int>::iterator ite=box.begin();
	while(ite!=box.end()){
		for(int i=0;i<tab[*ite].size();i++)
			pp.insert(tab[*ite][i]);
		ite++;
	}
	set<int>::iterator it=pp.begin();
	while(it!=pp.end()){
		box.insert(*it);
		it++;
	}
	cout<<box.size()-1<<endl;
	}
	return 0;
}

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

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 1 << 30;
    for (int z = 0; z <= max(x, y); z++)
    {
        ans = min(ans, max(0, a * (x - z)) + max(0, b * (y - z)) + 2 * c * z);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int A[N];
  int sum = 0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    sum += A[i];
  }
  sort(A, A+N);
  sum -= A[N-1];
  if(sum > A[N-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
    string right,left;
    int m,h;
while (1) {
    cin >> right;
    if(right == "-") break;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        cin >> h;
        left = right.substr(0, h);
        right.erase(0,h);
        right = right + left;
    }
    cout << right << endl;
}
    return 0;
}

Measured memory_bytes: 1232
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N, X = map(int, input().split())
x = list(map(int, input().split()))
x = list(map(lambda arg: abs(arg - X), x))

g = x[0]
for xx in x[1:]:
    g = gcd(g, xx)
print(g)


Measured memory_bytes: 15020