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

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();
		int xor = 0;
		TreeSet<Integer> hs = new TreeSet<Integer>();
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			xor ^= x;
			hs.add(x ^ (x - 1));
		}
		ArrayList<Integer> all = new ArrayList<Integer>();
		for (int x : hs) {
			all.add(x);
		}
		int res = 0;
		for (int i = all.size() - 1; i >= 0; i--) {
			int cur = all.get(i);
			int maxBit = (cur + 1) >> 1;
			if (0 != (xor & maxBit)) {
				res++;
				xor ^= cur;
			}
		}
		out.println(xor != 0 ? -1 : res);
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().runIO();
			}
		}, "1", 1 << 26).start();
	}
}

Measured memory_bytes: 25060
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<cstring>
#include<set>
#include<queue>
#include<map>
#include<math.h>

#define FASTREAD      ios_base::sync_with_stdio(0);cin.tie(nullptr);
#define ll long long
#define dd double
#define scl(n)        scanf("%lld",&n)
#define scd(n)        scanf("%lf",&n)
#define scc(n)        scanf("%c",&n)
#define scs(n)        scanf("%s",&n)
#define ptl(n)        printf("%lld",n)
#define ptd(n)        printf("%f",n)
#define ptc(n)        printf("%c",n)
#define pts(n)        printf("%s",n)
#define nline         printf("\n")
#define pb            push_back
#define FOR(i,a,b)    for(ll i=a;i<=b;i++)
#define FORr(i,a,b)   for(ll i=a;i>=b;i--)
#define pi            2*acos(0.0)
#define pii           pair<ll,ll>
#define uu            first
#define vv            second

using namespace std;

int main()
{
    ll n,h[100005],dp[100005];
    scl(n);
    FOR(i,1,n)
    {
        scl(h[i]);
    }
    dp[n]=0;
    dp[n-1]=abs(h[n-1]-h[n]);
    FORr(i,n-1,1)
    {
        if(i+2<=n){
        dp[i]=min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]));
      //  cout<<i<<" "<<dp[i]<<endl;
        }
    }
    ptl(dp[1]);
    nline;
    return 0;
}


Measured memory_bytes: 5280
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,Z,W; cin >> N >> Z >> W;
    int a[N]; REP(i,N) cin >> a[i];
    if(N==1) cout << abs(W-a[0]) << endl;
    else cout << max(abs(a[N-1]-W), abs(a[N-1]-a[N-2])) << endl;
    return 0;
}

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

int main(){
    ll X,ans=0;cin>>X;
    ans += X/500*1000;
    X -= X/500*500;
    ans += X/5*5;
    cout<<ans<<endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> t(n, vector<int>());
    vector<int> d(n, 0);
    int a, b;
    REP(i, n - 1 + m) {
        cin >> a >> b;
        a--; b--;
        t[a].push_back(b);
        d[b]++;
    }

    vector<int> ans(n);
    deque<int> q;
    REP(i, n) if (d[i] == 0) {
        ans[i] = -1;
        q.emplace_back(i);
    }

    while (!q.empty()) {
        int x = q.front(); q.pop_front();
        for (int y : t[x]) {
            d[y]--;
            if (d[y] == 0) {
                ans[y] = x;
                q.push_back(y);
            }
        }
    }
    for (int i : ans) cout << i + 1 << endl;
}


Measured memory_bytes: 7040
#include<iostream>
using namespace std;
int main(void){
  int a,b;
  cin>>a>>b;
  if(a<b){
    if(a==1){
      cout<<"Alice"<<endl;
    }else{
      cout<<"Bob"<<endl;
    }
  }else if(a>b){
    if(b==1){
      cout<<"Bob"<<endl;
    }else{
      cout<<"Alice"<<endl;
    }
  }else{
    cout<<"Draw"<<endl;
  }
  return 0;
}

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

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

ll digit(ll n){
    ll d = 0;
    while(n != 0){
        d++;
        n /= 10;
    }
    return d;
}

int main(){
    ll n, ans = 9999; cin >> n;
    for(ll i = 1; i * i <= n; ++i){
        if(n%i != 0) continue;
        ll ii = n/i;
        ans = min(ans, max(digit(i), digit(ii)));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {

	int n,k;
	cin >> n >> k ;

	vector<int> a(200002, 0);
	int x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		a[x]++;
	}

	sort(a.begin(), a.end(), greater<int>());

	int counter = 0;
	for (int i = 0; i < a.size(); i++) {
		if (i >= k && a[i] != 0) {
			counter += a[i];
		}
		if (a[i] == 0) { break; }
	}
	cout << counter << endl;

}

Measured memory_bytes: 1024
from itertools import accumulate
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
b = [0]
for i in range(n + 1):
    b.append(abs(a[i] - a[i + 1]))
c = list(accumulate(b))
# print(n, a, b, c)
ans = 0
for i in range(0, n):
    ans = 0
    ans += c[i] - c[0]
    ans += abs(a[i] - a[i + 2])
    ans += c[n + 1] - c[i + 2]
    # print(c[i] - c[0], abs(a[i] - a[i + 2]), c[n + 1] - c[i + 2])
    print(ans)


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

#define rep(i, k) for (int i = 0; i < k; i++)
#define pair(x, y) make_pair((x), (y))

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll solve(ll n) {
    if (n == 1) return 1;
    return (2 * solve(n / 2) + 1);
}

int main() {
    ll h;
    cin >> h;
    cout << solve(h);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b; cin>>a>>b;
    string s; cin>>s;
    bool ok=true;
    rep(i,a){
        if(s[i]-'0'>=0 && s[i]-'0'<=9){

        }else{
            ok=false;
        }
    }
    if(s[a]!='-') ok=false;
    for(int i=a+1; i<a+b+1; ++i) {
        if(s[i]-'0'>=0 && s[i]-'0'<=9){

        }else{
            ok=false;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  string s;
  cin >> s;
  int q;
  cin >> q;
  bool boo = true;
  for(int i=0; i<q; i++){
    int a;
    cin >> a;
    if(a == 1){
      if(boo){
        boo = false;
      }
      else{
        boo = true;
      }
    }
    if(a == 2){
      int b;
      cin >> b;
      string c;
      cin >> c;
      if(b == 1){
        if(boo){
          s.insert(0,c);
        }
        else{
          s += c;
        }
      }
      if(b == 2){
        if(!boo){
          s.insert(0,c);
          //cout << c << endl;
        }
        else{
          s += c;
          //cout << c << endl;
        } 
      }
    }
  }
  if(!boo){
    reverse(s.begin(),s.end());
  }
  cout << s << endl;
}

Measured memory_bytes: 900
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
    int a, b, c;
    while (cin >> a >> b >> c) {
        int count = 0;
        for (int i = a; i <= b; i++) {
            if (c % i == 0) {
                count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	ll ans = 0;
	rep(b,1,n+1){
		ll ans1 = 0;
		if(b<=k)continue;
		ll c = (n+1)/b;
		ll d = (n+1)%b;
		ans1 += (b-k)*c;
		ans1 += max(d-k,0LL);
		if(k==0)ans1--;
		ans += ans1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define ll long long
using namespace std;
ll weight[100005]{};
ll value[100005]{};
ll mem[105][100005]{};
ll N,W;

ll maxVal(ll i , ll currWeight)
{
    if(i==N)
    {
        return 0;
    }
    ll &ret = mem[i][currWeight];
    if(ret!=-1)
        return ret;
    ret = 0;
    ll choice1 = maxVal(i+1 , currWeight);
    ll choice2 = 0;
    if(currWeight>=weight[i])
        choice2 = value[i] + maxVal(i+1 , currWeight-weight[i]);

    ret = max(ret , choice1);
    ret = max(ret , choice2);

    return ret;

}


int main()
{
    for(int i = 0 ; i<105 ; i++)
        for(int j = 0 ; j < 100005 ; j++) mem[i][j] = -1;

    cin>>N>>W;
    for(int i = 0 ; i<N ; i++)
    {
        cin>>weight[i]>>value[i];
    }

    cout<<maxVal(0 , W)<<endl;
    return 0;
}


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

struct Node {
  int val;
  Node *left;
  Node *right;

  Node(int val) : val(val), left(NULL), right(NULL) {};
};

Node *insert(Node *node, int val) {
  if (node == NULL) {
    return new Node(val);
  }

  if (val < node->val) {
    node->left = insert(node->left, val);
  } else {
    node->right = insert(node->right, val);
  }

  return node;
}

void generatePreorder(Node *node, vector<int> &vec) {
  vec.push_back(node->val);
  if (node->left) {
    generatePreorder(node->left, vec);
  }
  if (node->right) {
    generatePreorder(node->right, vec);
  }
}

void generateInorder(Node *node, vector<int> &vec) {
  if (node->left) {
    generateInorder(node->left, vec);
  }
  vec.push_back(node->val);
  if (node->right) {
    generateInorder(node->right, vec);
  }
}

void printVec(vector<int> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << " " << *it;
  }
  cout << endl;
}

void print(Node *root) {
  vector<int> inorder;
  generateInorder(root, inorder);
  printVec(inorder);

  vector<int> preorder;
  generatePreorder(root, preorder);
  printVec(preorder);
}

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

  Node *root = NULL;

  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string command;
    cin >> command;
    if (command == "insert") {
      int val;
      cin >> val;
      root = insert(root, val);
    } else if (command == "print") {
      print(root);
    }
  }

  delete root;

  return 0;
}



Measured memory_bytes: 23472
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  int x=0,ans=0;

  rep(i, s.size()){
    if(s[i]=='I') x++;
    else x--;

    ans = max(x,ans);
  }

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

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	FIO();
	int n; cin >> n;
	vi a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	int t[100005];
	t[0] = 0, t[1] = abs(a[0] - a[1]);

	for (int i = 2; i < n; ++i)
	{
		t[i] = min(t[i - 1] + abs(a[i] - a[i - 1]), t[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << t[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 4756
n,m,l = map(int,input().split())
A = [[0 for i in range(m)] for j in range(n)]
B = [[0 for i in range(l)] for j in range(m)]
C = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    S1 = input().strip().split()
    S1 = [int(s) for s in S1]
    for j in range(m):
        A[i][j] = S1[j]
        #if j == m-1:
        #    print(S1[j])
        #else:
        #    print(S1[j],end=' ')
    
    
for i in range(m):
    S2 = input().strip().split()
    S2 = [int(s) for s in S2]
    for j in range(l):
        B[i][j] = S2[j]
        #if j == m-1:
        #    print(S2[j])
        #else:
        #    print(S2[j],end=' ')    

for x in range(n):
    for y in range(l):
        for z in range(m):
            C[x][y] += A[x][z]*B[z][y]
        if y == l-1:
            print(C[x][y])
        else:
            print(C[x][y],end=' ')    
    
    


Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    ll a = 1,b = 1;
    rep(i,n){
        ll c,d;
        cin >> c >> d;
        ll N = max((a+c-1)/c,(b+d-1)/d);
        a = c * N;
        b = d * N;
        //cout << a << " " << b << endl;
    }
    cout << a + b << endl;
}

Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())

lanes = [deque() for i in range(N + 1)]

for i in range(M):
    info = list(map(int, input().split()))
    if info[0] == 0:
        print(lanes[info[1]].popleft())
    else:
        lane = -1
        count = 10001
        for j in range(1, N + 1):
            if len(lanes[j]) < count:
                lane = j
                count = len(lanes[j])
        lanes[lane].append(info[1])



Measured memory_bytes: 6312
--AOJ Simple Print a Rectangle

import Control.Applicative

rInt :: String -> Int
rInt str = read str :: Int

strRectangle :: Int -> Int -> Char -> String
strRectangle h w c = (concat $ replicate h $ replicate w c ++ ['\n']) ++ "\n" 

main :: IO ()
main = do
  xs <- pure (map rInt . words) <*> getLine
  let h = head xs 
      w = last xs      
  if h == 0 && w == 0
    then return ()
    else do
    putStr $ strRectangle h w '#' 
    main

Measured memory_bytes: 4092
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

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



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		final int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);

		if(N<=K) {
			// 全部必殺技
			out.println(0);
			return;
		}
		long sum = 0;
		for(int i=0;i<N-K;i++) {
			sum += A[i];
		}
		out.println(sum);
	}
}


Measured memory_bytes: 89240
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,a,b;
	string s;
	while(cin>>N) {
		ll ans = 0;
		REP(i, N) {
			cin>>a>>b;
			ans += b-a+1;
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a != t:
      i = min(d[a], d[t])
    else:
      i = d[a] // 2
    if i == 0:
      break
    result += i
    d[a] -= i
    d[t] -= i
    if d[a] == 0:
      break
print(result)


Measured memory_bytes: 44560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

struct bipartite {
    vector<int> color;
    vector<vector<int>> g;
    bipartite(int n) {
        color.assign(n,-1);
        g.resize(n);
    }
    void add_edge(int a, int b) {
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool is_bipartite(int v, int cur = 0) {
        color[v] = cur;
        for (int n_v : g[v]) {
            if (color[n_v] != -1) {
                if (color[n_v] == cur) return false;
                continue;
            }
            if (!is_bipartite(n_v,1-cur)) return false;
        }
        return true;
    }
};

// warshall_floyd
template<class T>
struct warshall_floyd {
    vector<vector<T>> dis;
    int n;
    T init_v;
    warshall_floyd(int n, T init_v) :init_v(init_v), n(n) {init(n);}

    void init(int n) {
        dis.assign(n,vector<T>(n,init_v));
        rep(i,n) dis[i][i] = 0;
    }

    void add_dis(int s, int t, T cost) {
        dis[s][t] = dis[t][s] = cost;
    }

    void run() {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (dis[j][i] == init_v || dis[i][k] == init_v) continue;
                    dis[j][k] = min(dis[j][k],dis[j][i]+dis[i][k]);
                }
            }
        }
    }
};

int main() {
    int n; cin >> n;
    vector<string> data(n);
    rep(i,n) cin >> data[i];
    bipartite bp(n);
    warshall_floyd<int> wf(n,inf);
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (data[i][j] == '1') {
                bp.add_edge(i,j);
                wf.add_dis(i,j,1);
            }
        }
    }
    if (!bp.is_bipartite(0)) cout << -1 << endl;
    else {
        wf.run();
        int ans = 0;
        rep(i,n) {
            int mx = 0;
            rep(j,n) chmax(mx,wf.dis[i][j]);
            ans = max(ans,mx+1);
        }
        cout << ans << endl;
    }
}

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

int main()
{
  int n, mx = 0, mn = 100, sum = 0;
  cin >> n;
  vector<int> x(n);
  rep(i, n)
  {
    cin >> x[i];
    mx = max(mx, x[i]);
    mn = min(mn, x[i]);
    sum += x[i];
  }
  int p = (double)sum / n + 0.5;
  int ans = 0;
  rep(i, n) ans += (x[i] - p) * (x[i] - p);
  cout << ans << endl;
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

bool p[55556];
vector<int> num;

void prime() {
  rep(i, 55556) p[i] = true;
  p[0] = p[1] = false;
  repl(i, 2, 55556) if(p[i]) {
    int j = i + i;
    while(j < 55556) {
      p[j] = false;
      j += i;
    }
  }
  rep(i, 55556) if(p[i] && i % 5 == 1) num.pb(i);
}

int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  prime();
  rep(i, n) cout << num[i] << ((i == n - 1) ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 384
from collections import namedtuple
Line = namedtuple('Line', ['lowest', 'end'])


def main():
    N = int(input())
    up_lines = []
    down_lines = []
    for i in range(N):
        s = input()
        now = 0
        lowest = 0
        for c in s:
            if c == "(":
                now += 1
            else:
                now -= 1
                lowest = min(lowest, now)
        if now > 0:
            up_lines.append(Line(lowest, now))
        else:
            down_lines.append(Line(lowest-now, -now))
    up_lines.sort(key=lambda line: -line.lowest)
    down_lines.sort(key=lambda line: -line.lowest)
    left = 0
    for line in up_lines:
        if left + line.lowest < 0:
            print("No")
            return
        left += line.end
        if left < 0:
            print("No")
            break
    right = 0
    for line in down_lines:
        if right + line.lowest < 0:
            print("No")
            return
        right += line.end
        if right < 0:
            print("No")
            break
    if left == right:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 242880
#include<stdio.h>

int main(void){

	int input;
	
	scanf("%d",&input);

	switch(input){
	
	case 22:
		printf("Christmas Eve Eve Eve");
		break;
	case 23:
		printf("Christmas Eve Eve");
		break;	
	case 24:
		printf("Christmas Eve");
		break;
	case 25:
		printf("Christmas");
		break;
	default:
		break;
	}
	
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;


int main(){

    int h, w;
    vector<int> cnt(26, 0);
    cin >> h >> w;
    rep(i, h) {
        string a; cin >> a;
        for(auto c : a){
            ++cnt[c-'a'];
        }
    }

    int c1 = (int)(h%2 and w%2), c2 = (h/2)*(w%2)+(w/2)*(h%2), c4 = (h/2)*(w/2);
    rep(i, c1){
        for(auto& x : cnt){
            if((x%4 == 1 or x%4 == 3) and x > 0) {--x; break;}
        }
        ++c2;
    }
    rep(i, c2){
        for(auto& x : cnt){
            if((x%4 == 2) and x > 0) {x -= 2; break;}
        }
        ++c4;
    }
    rep(i, c4){
        for(auto& x : cnt){
            if(x%4 == 0 and x > 0) {x -= 4; break;}
        }
    }
    Judge(all_of(cnt.begin(), cnt.end(), [](int x){return x == 0;}));

    return 0;
}


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

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	int N;
	cin >> N;
	int a = N / 1000 + (N % 1000 != 0);
	cout << a*1000 - N << endl;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
}



Measured memory_bytes: 3616
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
#include <limits>
using namespace std;
typedef pair<pair<int, int>, int> P;
typedef long long ll;
const int INF = 100000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;



int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, N, Y, Z, K, x, y, z;
	sum = 0;
	ll ans = 0;
	ll minus;
	minus = 0;
	cin >> N >> K;
	vector<ll>V(N);
	vector<ll>ruiseki(N);
	REP(i, 0, N) {
		ruiseki[i] = 0;
	}
	REP(i, 0, N) {
		cin >> V[i];
	}
	ruiseki[0] = V[0];
	REP(i, 1, N) {
		ruiseki[i] = ruiseki[i - 1] + V[i];
	}
	ll re,cnt,ans1;
	cnt = 0;
	vector<ll>hu;
	REP(l, 0, K+1) {
		if (l > N) {
			break;
		}
		else {
			re = K - l;//戻せる数
			for (i = N - l; i <= N; i++) {
				ans1 = 0;
				cnt = 0;
				hu.clear();
				for (j = i; j < i + l; j++) {
					ans1 += V[j%N];
					if (V[j%N] < 0) {
						hu.push_back(V[j%N]);
					}
				}
				sort(hu.begin(), hu.end());
				for (k = 0; k < fmin(hu.size(), re); k++) {
					cnt += hu[k];
				}
				ans1 -= cnt;
				
				if (ans1 > ans) {
					ans = ans1;
				}
			}
		}
	}
	output(ans);
	return 0;
}








Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <set>
#include <map>
#include <iostream>
#pragma warning(disable:4996)
using namespace std;


int main()
{
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (n != 0) {
		ans += 1;
		n /= k;
	}
	cout << ans;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
warzones = [[] for i in range(M)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -=1
    warzones[i] = [a,b]
warzones = sorted(warzones,key=lambda x:x[0])
#print(warzones)
shaku = warzones[0]
cnt = 1
for i in range(1,M):
    #print(shaku)
    #尺継続条件
    if(warzones[i][0] < shaku[1]):
        shaku[0] = max(warzones[i][0],shaku[0])
        shaku[1] = min(warzones[i][1],shaku[1])
    else:
        cnt += 1
        shaku = warzones[i]

print(cnt)

'''尺取法の初期化
最初に配列のlists[0]で初期化
for i in range(1,M):でまわして
okの場合lists[i]を代入
ngのときはカウントを増やしてngで再初期化
'''

Measured memory_bytes: 26288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);
        
		String[] str = scan.nextLine().split(" ");
		int[] x = new int[str.length];
		
        for(int i = 0; i < str.length; i++){
            x[i] = Integer.parseInt(str[i]);
        }
        
        if(x[0] > x[1]){
            System.out.println("safe");
        }else{
            System.out.println("unsafe");
        }
        
    }
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll num = 0;
    if(N==1){
        if(S[0] == '0'){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }
    rep(i,N){
        if(S[i] == '1') num++;
    }
    if(num == 0){
        cout << 0 << endl;
        return 0;
    }
    vector<ll> dp(200010);
    rep(i,200010){
        ll n = i;
        ll cnt = 0;
        while(n != 0){
            ll d = __builtin_popcountll(n);
            n = n % d;
            cnt++;
        }
        dp[i] = cnt;
    }
    vector<ll> bm(N+1), bp(N+1);
    ll mem=0;
    ll mep=0;
    bool flag = 0;
    if(num == 1){
        flag = 1;
        num += 2;
    }

    bm[N] = 1%(num-1);
    bp[N] = 1%(num+1);
    rep(i,N){
        mem *= 2;
        mep *= 2;
        if(S[i] == '1'){
            mem++;
            mep++;
            mem %= num-1;
            mep %= num+1;
        }
        mem %= num-1;
        mep %= num+1;
        bm[N-i-1] = (bm[N-i]*2) % (num-1);
        bp[N-i-1] = (bp[N-i]*2) % (num+1);
    }
    //cout << mem << " " << mep << endl;
    //PR(bm, N+1);
    //PR(bp, N+1);
    vector<ll> ans(N);
    if(flag){
        rep(i,N){
            if(S[i] == '1'){
                cout << 0 << endl;
            }else{
                ll tm = (mem + bm[i+1]) % (num-1); 
                cout << dp[tm] + 1 << endl;
            }
        }
        return 0;
    }
    rep(i,N){
        if(S[i] == '1'){
            ans[i] = ((mem - bm[i+1]) + num - 1) % (num-1); 
        }else{
            ans[i] = (mep + bp[i+1]) % (num+1);
        }
    }
    rep(i,N){
        cout << dp[ans[i]]+1 << endl;
    }
}

Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct S {
    string s;
    ll p;
    ll id;
    
    bool operator<(const S &b) {
        if (s == b.s) return p > b.p;
        return s < b.s;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<S> sp(n);
    rep(i, n) {
        cin >> sp[i].s >> sp[i].p;
        sp[i].id = i + 1;
    }
    sort(all(sp));
    rep(i, n) {
        cout << sp[i].id << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<int> eratosthenes(const int &n) {
  vector<int> v(n);
  fill(v.begin() + 2, v.end(), true);
  for (int i = 2; i * i < n; i++) {
    if (v[i]) {
      for (int j = i * 2; j < n; j += i) {
        v[j] = false;
      }
    }
  }
  return v;
}

void solve() {
  vi v = eratosthenes(1000000);
  int n;
  while (cin >> n, n) {
    int s = 0, i = 0;
    while (n--) {
      while (!v[i]) i++;
      s += i++;
    }
    cout << s << endl;
  }
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int dp[11][401010];
int main(){
    int d,g;
    cin>>d>>g;
    g/=100;
    V p(11),c(11);
    rep(i,d){cin>>p[i]>>c[i];c[i]/=100;}
    //dpの初期化
    int m=201010;
    rep(i,d+1){
        rep(j,m){
            dp[i][j]=inf;
        }
    }//1-index
    //dp[i][k]:i-1行目の問題までで，100ｋ点とる問題数のmin
    dp[0][0]=0;
    rep(i,d){
        int pos_P=p[i];
        int bonus=c[i];
        for(int j=0;j<=pos_P;j++){
            int add=(i+1)*j;
            rep(k,m){
                if(j==pos_P){
                    int addd=add+bonus;
                    dp[i+1][k+addd]=min(dp[i+1][k+addd],dp[i][k]+j);
                }else{
                    dp[i+1][k+add]=min(dp[i+1][k+add],dp[i][k]+j);
                }
            }
        }
    }
    int ans=inf;
    for(int k=g;k<m;k++){
        ans=min(ans,dp[d][k]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi rui(111111);
bool isprime(ll n){
  if(n == 1)return false;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i == 0)return false;
  }
  return true;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  for(ll i=1;i<=110000;i++){
    if(i%2 == 0){rui[i] += rui[i-1];continue;}
    if(isprime(i) && isprime((i+1)/2))rui[i] += rui[i-1]+1;
    else rui[i] += rui[i-1];
  }
  ll q;cin>>q;
  while(q--){
    ll l,r;cin>>l>>r;
    cout<<rui[r]-rui[l-1]<<endl;
  }
  return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i,m){
    cin >> s[i] >> c[i];
    s[i]--;
  }

  vector<int> res(n, -1);
  rep(i,m) {
    if(res[s[i]] >= 0) {
      if(res[s[i]] != c[i] ) {
	cout << -1 << "\n";
	return 0;
      }
    }
    else {
      res[s[i]] = c[i];
    }
  }

  if(n >= 2) {
    if(res[0] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    else if(res[0] == -1) {
      res[0] = 1;
    }
  }

  rep(i,n) if(res[i] == -1) res[i] = 0;

  rep(i,n) cout << res[i];
  cout  << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;

ll a[210000];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int l = 0;
	int r = n + 1;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		vector<pair<ll, int>> vv;
		int fl = 0;
		for (int i = 1; i < n; ++i) {
			if (a[i] <= a[i - 1]) {
				if (mid == 1) {
					fl = 1;
					break;
				}
				while (!vv.empty() && vv.back().first >= a[i])
					vv.pop_back();
				int cur = a[i] - 1;
				while (cur >= 0 && (vv.size() && vv.back().first == cur && vv.back().second == mid - 1))
					vv.pop_back(), --cur;
				if (cur < 0) {
					fl = 1;
					break;
				}
				if (vv.empty() || vv.back().first < cur)
					vv.emplace_back(cur, 1);
				else
					vv.back().second += 1;
			}
		}
		if (!fl)
			r = mid;
		else
			l = mid;
	}
	cout << r << "\n";
	return 0;
}




Measured memory_bytes: 1792