akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N=0;
 int count=0;
 string S;
 cin >> N >> S;
 vector<int> vec(N);
  
  for(int i=0; i<N ;i++){
  vec.at(i)=S.at(i);
  }
  
  for(int i=0; i<N-2 ;i++){
  if(vec.at(i)=='A'){
   if(vec.at(i+1)=='B'){
     if(vec.at(i+2)=='C'){
       count++;
     }
   }
  else{
  }
  }
 }
  cout<< count <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
typedef long long ll;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n), f(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int i = 0; i < n; i++)  cin >> f[i];
    if(accumulate(a.begin(), a.end(), 0ll) <= k){
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll l = 0, r = 1ll<<60;
    while(r-l > 1){
        ll mid = (l+r)/2;
        ll tmp = 0;
        for(int i = 0; i < n; i++){
            tmp += max(0ll, (ll)a[i]-(mid/f[i]));
        }
        if(tmp > k) l = mid;
        else        r = mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << 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;
}

const int MAX_N = 200050; // 要素数の最大

int par[MAX_N]; // 親
int rk[MAX_N];  // 木の深さ(rank)

// n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        rk[i] = 0;
    }
}

// 木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
    {
        return;
    }

    if (rk[x] < rk[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (rk[x] == rk[y])
        {
            rk[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int main()
{
    int n, m;
    cin >> n >> m;
    init(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        unite(a, b);
    }
    // 根の数を把握
    map<ll, ll> mp;
    for (int i = 0; i < n; i++)
    {
        mp[find(i)]++;
    }
    ll maxi = 0;
    for (auto m : mp)
    {
        maxi = max(maxi, m.second);
    }
    cout << maxi << endl;
    return 0;
}


Measured memory_bytes: 17368
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto s = readln.chomp.to!(char[]);

  int sum = 0;
  foreach (c; s[1 .. $]) {
    if (c == 'E')
      sum++;
  }
  auto mn = sum;
  foreach (i; 1 .. n) {
    if (s[i - 1] == 'W')
      sum++;
    if (s[i] == 'E')
      sum--;
    mn = min(mn, sum);
  }
  writeln(mn);

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 3028
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

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

  rep(i, 51){
    rep(j, 26){
      if(i+j == X && 2*i+j*4 == Y){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define MOD DEKAI
#define DEKAI (int)(1e9+7)
#define rep(i,n) lps(i,0,n)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i = j; i < n; i++)


int K;
double P, E, T;

long double foo(long double R,long  double L, int count){//cout<<count<<" "<<L<<" "<<R<<endl;
  long double H = (R+L)/2, r = (R+H)/2, l = (H+L)/2, d = l - H;
  long double ansr = 0, ansl = 0;

  if(count == K){
    if(fabs((H-T)) <= E){
      return 1;
    } else return 0;
  }
  
  
  
  if(H >= T){
    if(r+d <= T - E) ansr = 0;
    else if(T-E < r-d && r+d< T+E) ansr = (1-P);
    else ansr = foo(R,H, count+1)*(1-P);
    
    if( l-d >= T + E) ansl = 0;
    else if(T-E < l-d && l+d< T+E) ansl =  P;
    else ansl = foo(H,L,count+1)*P;
  } else {
     if(r+d <= T - E) ansr = 0;
    else if(T-E < r-d && r+d< T+E) ansr = P;
    else ansr = foo(R,H, count+1)*P;
    
    if( l-d >= T + E) ansl = 0;
    else if(T-E < l-d && l+d< T+E) ansl =  (1-P);
    else ansl = foo(H,L,count+1)*(1-P);
  }
  return ansr+ansl;
  /*
  if(count == K){
    if(fabs((H-T)) <= E){
      return 1;
    } else return 0;
  }
  

  else {
   
    if(H >= T){
      return foo(R,H, count+1)*(1-P) + foo(H,L,count+1)*P;
    } else {
      return foo(R,H, count+1)*P + foo(H,L,count+1)*(1-P);
    }
  }
  */
}

int main(){
  cout<<fixed<<setprecision(6);
  double R, L;

  cin>>K>>R>>L;

  cin>>P>>E>>T;


  cout<<foo(R,L,0)<<endl;
 

  return 0;
}



Measured memory_bytes: 3288
#!/usr/bin/env python

N, x = map(int, input().strip().split())
an = list(map(int, input().strip().split()))
an.sort()

cnt = 0
if x < an[0]:
    cnt = 0
elif sum(an) < x:
    cnt = len(an) - 1
elif sum(an) == x:
    cnt = len(an)
else:
    cnt = 0
    for a in an:
        if a <= x:
            x -= a
            cnt += 1

print(cnt)


Measured memory_bytes: 3060
N = int(input())
S0 = input()
S1 = input()

tate = []
ikkome = True
S = ''
for i in range(N):
  if S0[i] == S1[i]:
    tate.append(i)
    S = S + 'T'
  else:
    if ikkome:
      S = S + 'Y'
      ikkome = False
    else:
      ikkome = True

now = S[0]
if now == 'T':
  ans = 3
else:
  ans = 6
  
if len(S) == 1:
  print(ans)
  exit()
  
S = S[1:]
MOD = 1000000007
for si in S:
  if now == 'T':
    if si == 'T':
      ans = ans * 2 % MOD
    else:
      ans = ans * 2 % MOD
      now = 'Y'
  else:
    if si == 'Y':
      ans = ans * 3 % MOD
    else:
      now = 'T'
print(ans)



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

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

  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == '1')
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
   int a,n,m=0;
   double i;
   scanf("%d",&n);
   if(n!=1){
   for(a=1;a<=n;a++)
   {
       if(a%2!=0)
        m++;
   }
      i=(double)m/n;
   }else{
       i=(double)(m+1)/n;
   }
   printf("%.10f",i);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#define INF 10000000000000000LL

using namespace std;

struct edge {int to; long long int cap; int rev;} ;

vector<edge> G[102];
int level[102];
int iter[102];

void add_edge(int from, int to, long long int cap){
	edge e;
	e.to=to, e.cap=cap, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=0, e.rev=G[from].size()-1;
	G[to].push_back(e);
}

void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0; i<G[v].size(); i++){
			edge e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

long long int dfs(int v, int t, long long int f){
	if(v==t) return f;
	for(int &i=iter[v]; i<G[v].size(); i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			long long int d=dfs(e.to, t, min(f, e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

long long int max_flow(int s, int t){
	long long int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter, 0, sizeof(iter));
		long long int f;
		while((f=dfs(s, t, INF))>0){
			flow+=f;
		}
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	long long int a[101], psum=0;
	for(int i=1; i<=n; i++){
		scanf("%lld", &a[i]);
		if(a[i]>0){
			psum+=a[i];
			add_edge(0, i, a[i]);
		}else{
			add_edge(i, n+1, -a[i]);
		}
	}
	for(int d=1; d<n; d++){
		for(int k=d+1; k<=n; k++){
			if(k%d==0) add_edge(k, d, INF);
		}
	}
	printf("%lld\n", psum-max_flow(0, n+1));	
	return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N;
    cin >> N;
    multiset<int> pbs;
    REP(i,N) {
        int d;
        cin >> d;
        pbs.insert(d);
    }

    int M;
    cin >> M;
    REP(_,M) {
        int t;
        cin >> t;
        if (pbs.count(t) == 0) {
            cout << "NO" << endl;
            return;
        }
        pbs.erase(pbs.find(t));
    }
    cout << "YES" << endl;
}

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


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int res=0;
	for (int i=0;i<s.size();i++){
		for (int j=1;j+i<=s.size();j++){
			string ss;
			bool ok=1;
			ss=s.substr(i,j);
			for (int k=0;k<ss.size();k++)
				if (ss[k]!='A' && ss[k]!='C' && ss[k]!='G' && ss[k]!='T'){
					ok=0;
					break;
				}
			if (ok) res=max(res,(int)ss.size());
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop, heapify

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


# 最小全域木 O(ElogV)
def prims_algorithm(N, cost):

    used = [False] * N
    used[0] = True
    que = [(c, w) for c, w in cost[0]]
    heapify(que)

    ret = 0
    while que:
        cv, v = heappop(que)
        if used[v]:
            continue
        used[v] = True
        ret += cv
        for c, w in cost[v]:
            if used[w]:
                continue
            heappush(que, (c, w))

    return ret


def main():

    N = in_n()
    x = [0] * N
    y = [0] * N

    for i in range(N):
        x[i], y[i] = in_nn()

    sort_ind_x = sorted(range(N), key=lambda i: x[i])
    sort_ind_y = sorted(range(N), key=lambda i: y[i])

    cost = [[] for _ in range(N)]
    for i in range(N - 1):
        j1, j2 = sort_ind_x[i], sort_ind_x[i + 1]
        c = abs(x[j1] - x[j2])
        cost[j1].append((c, j2))
        cost[j2].append((c, j1))

        j1, j2 = sort_ind_y[i], sort_ind_y[i + 1]
        c = abs(y[j1] - y[j2])
        cost[j1].append((c, j2))
        cost[j2].append((c, j1))

    ans = prims_algorithm(N, cost)
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin>>N;
  string s;
  map<string,int> poll;
  for(int i=0; i<N; i++){
    cin>>s;
    poll[s]++;
  }
  int mv=0;
  for(auto x : poll){
    auto v=x.second;
    if(v>mv) mv=v;
  }
  for(auto x : poll){
    if(x.second==mv){
      cout<<x.first<<endl;
    }
  }
}

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

using namespace std;

int solve(const vector<int>& times){
	if(times[0] >= 2 || times[12] >= 2) return 0;
	for(int i=1;i<12;i++) if(times[i] >= 3) return 0;
	int res = 0;
	for(int i=0;i<(1<<11);i++){
		vector<int> exist(25, 0);
		if(times[0] > 0) exist[0] = exist[24] = 1;
		if(times[12] > 0) exist[12] = 1;
		for(int j=1;j<12;j++){
			if(times[j] == 0) continue;
			if(times[j] == 1) exist[(i&(1<<(j-1))) ? j : 24-j] = 1;
			if(times[j] == 2) exist[j] = exist[24-j] = 1;
		}
		int pre = 0;
		int cur_res = 100;
		for(int j=1;j<=24;j++){
			if(exist[j]){
				cur_res = min(cur_res, j-pre);
				pre = j;
			}
		}
		res = max(res, cur_res);		
	}
	return res;
}

int main(){
	int N;
	while(cin >> N){
		vector<int> cnt(13, 0);
		cnt[0] = 1;
		for(int i=0;i<N;i++){
			int t; cin >> t;
			cnt[t]++;			
		}
		cout << solve(cnt) << endl;
	}
}


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

using namespace std;

const int N_ = int(1.1e5);

using lint = long long;

int N, M;

class SegmentTree{
	lint tree[530000], lazy[530000];
	void init(int s, int e, int p, int *x){
		if(s == e){
			tree[p] = x[s];
			return;
		}
		int m = (s+e)/2;
		init(s, m, 2*p, x);
		init(m+1, e, 2*p+1, x);
		tree[p] = max(tree[2*p], tree[2*p+1]);
	}
	void lazydown(int p){
		tree[2*p] += lazy[p];
		tree[2*p+1] += lazy[p];
		lazy[2*p] += lazy[p];
		lazy[2*p+1] += lazy[p];
		lazy[p] = 0;
	}
	void add(int s, int e, int ps, int pe, int p, lint v){
		if(e < ps || pe < s) return;
		if(s <= ps && pe <= e){
			tree[p] += v;
			lazy[p] += v;
			return;
		}
		lazydown(p);
		int pm = (ps + pe) / 2;
		add(s, e, ps, pm, 2*p, v);
		add(s, e, pm+1, pe, 2*p+1, v);
		tree[p] = max(tree[2*p], tree[2*p+1]);
	}
	lint query(int s, int e, int ps, int pe, int p){
		if(e < ps || pe < s) return -1e18;
		if(s <= ps && pe <= e) return tree[p];
		lazydown(p);
		int pm = (ps + pe) / 2;
		return max(query(s, e, ps, pm, 2*p), query(s, e, pm+1, pe, 2*p+1));
	}
public:
  void add(int s, int e, lint v) {
    add(s, e, 0, M+1, 1, v);
  }
  lint query(int s, int e) {
    return query(s, e, 0, M+1, 1);
  }
}seg;


const int M_ = int(2.1e5);
vector<int> points[M_];

int main() {
#ifdef IN_MY_COMPUTER
  freopen("f.in", "r", stdin);
#endif

  scanf("%d%d", &N, &M);

  int maxl = -1, minr = 1e9;
  for(int i = 1; i <= N; i++) {
    int l, r; scanf("%d%d", &l, &r);
    maxl = max(l, maxl);
    minr = min(r, minr);
    points[l].push_back(r);
  }

  lint ans = 0;

  if(maxl >= minr || minr - maxl == 1) {
    ans = max(ans, (lint)N - M);
  }

  for(int i = 1; i <= M+1; i++) {
    seg.add(i, M+1, +1);
  }

  for(int a = 0; a < M; a++) {
    for(int b : points[a]) {
      seg.add(1, b, +1);
    }
    ans = max(ans, seg.query(a+1, M+1) - (a + M + 1));
  }

  printf("%lld\n", ans);

  return 0;
}

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

int main(){
    ll A,B;cin>>A>>B;
    if(A<B)swap(A,B);
    ll C=1;
    while(C){
        C=A%B;
        A=B;B=C;
    }
    int count=0;
    ll P=A;
    for(ll i=2;i<=A;i++){
        if(A%i==0){
            count++;
            while(A%i==0)A/=i;
        }
        else if(i>sqrt(A)+1){
            count++;
            break;
        }
    }
    cout<<count+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
  int a;
   int b;
 // int c;
 // int d;
 // int e;
 // int f;
   cin>>a>>b ;
   if (a>b){ cout<<"a > b"<<endl;
   }
   else if (a<b){ cout<<"a < b"<<endl;}
   else if (a==b){ cout<<"a == b"<<endl;}
 return 0;
}
 



Measured memory_bytes: 3080
#include <iostream>
using namespace std;
int main(void){
    int n, h[105];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    
    int ans = 0;
    while (1) {
        int min = 1000;
        for (int j = 0; j < n; j++) {
            if (h[j] > 0 && min > h[j]) min = h[j];
        }
        if (min == 1000) {
            cout << ans << endl;
            return 0;
        }
        
        int block = 1; 
        bool st = true;
        for (int j = 0; j < n; j++) {
            if (h[j] == 0 && !st) {
                block++;
                st = true;
            }
            else if (h[j] != 0) st = false;
        }
        if (st) block--;
        ans += min * block;
        
        for (int j = 0; j < n; j++) {
            h[j] = max(0, h[j] - min);
        }
        
    }
}


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

int N, K, A[1 << 18], cnt;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] >= K) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

def get_alphadic(string):
    dic = defaultdict(lambda: 0)
    for c in string:
        dic[c] += 1
    return dic


def get_newstring(dic):
    string = ''
    for item in sorted(dic.items(), key=lambda x: x[0]):
        string += item[0]*item[1]
    return string


def main():
    s = input()
    t = input()
    s_dic = get_alphadic(s)
    t_dic = get_alphadic(t)
    s_ = get_newstring(s_dic)
    t_ = get_newstring(t_dic)[::-1]

    if s_ < t_:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d, t, s; cin >> d >> t >> s;
  cout << (s*t>=d ? "Yes" : "No") << endk;
  return 0;
}


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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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 long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
int main () {
    int A,B;
    cin >> A >>B;
 
    for(int i = 1; i <=10000; i++){
        if(int (i*0.08) == A &&  int (i*0.1) == B){
            cout << i << endl;
            return 0;
        }
    }
    cout <<"-1" << endl;
    
 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define sqr(x) (x)*(x)
using namespace std;
vector<pair<int,int> > bi[800005];
vector<pair<int,pair<int,int> > >bi2[200005];
int n,m,i,j,x,y,z,cnt,used[800005];
long long dis[800005];
priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > pq;
void dijkstra(int st)
{
	pq.push(make_pair(0,st));
	//pq.push(make_pair(1,cnt+1));
	int i;
	for (i=1;i<=cnt;i++) dis[i]=1e8;
	used[st]=1;
	dis[st]=0;
	while (!pq.empty())
	{
		x=pq.top().second,y=pq.top().first;
		pq.pop();
		for (i=0;i<bi[x].size();i++)
		{
			if (!used[bi[x][i].first]&&dis[bi[x][i].first]>dis[x]+bi[x][i].second)
			{
				dis[bi[x][i].first]=dis[x]+bi[x][i].second;
				pq.push(make_pair(dis[bi[x][i].first],bi[x][i].first));
			}
		}
		used[x]=1;
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;cnt=m;
	for (i=1;i<=m;i++)
	{
		cin>>x>>y>>z;
		bi2[x].push_back(make_pair(y,make_pair(z,i)));
		bi2[y].push_back(make_pair(x,make_pair(z,i)));
	}
	for (i=1;i<=n;i++)
	{
		cnt++;
		for (j=0;j<bi2[i].size();j++)
		{
			bi[cnt].push_back(make_pair(bi2[i][j].second.second,1));
			bi[bi2[i][j].second.second].push_back(make_pair(cnt,0));
		}
		map<int,int> mp;
		for (j=0;j<bi2[i].size();j++)
		{
			if (!mp[bi2[i][j].second.first]) mp[bi2[i][j].second.first]=++cnt;
//			if (cnt==9)
//			{
//				cerr<<mp[bi2[i][j].second.second]<<' '<<bi2[i][j].second.second<<endl;
//			}
			bi[mp[bi2[i][j].second.first]].push_back(make_pair(bi2[i][j].second.second,0));
			bi[bi2[i][j].second.second].push_back(make_pair(mp[bi2[i][j].second.first],0));
		}
	}
	//cerr<<bi[9].size()<<endl;
	cnt++;
	for (i=0;i<bi2[1].size();i++)
	{
		bi[cnt].push_back(make_pair(bi2[1][i].second.second,0));
		bi[bi2[1][i].second.second].push_back(make_pair(cnt,0));
	}
	cnt++;
	for (i=0;i<bi2[n].size();i++)
	{
		bi[cnt].push_back(make_pair(bi2[n][i].second.second,0));
		bi[bi2[n][i].second.second].push_back(make_pair(cnt,0));
	}
	dijkstra(cnt-1);
	if (dis[cnt]<1e8) cout<<dis[cnt]+1<<endl;
		else puts("-1");
	return 0;
}

Measured memory_bytes: 75696
mod = 998244353
omega = pow(3,119,mod)
rev_omega = pow(omega,mod-2,mod)

N = 2*10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inv = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inv[i]=( ( -inv[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inv[i]) % mod )
inv[0]=0

def _ntt(f,L,reverse=False):
    F=[f[i] for i in range(L)]
    n = L.bit_length() - 1
    base = omega
    if reverse:
        base = rev_omega

    if not n:
        return F

    size = 2**n
    wj = pow(base,2**22,mod)
    res = [0]*2**n

    for i in range(n,0,-1):
        use_omega = pow(base,2**(22+i-n),mod)
        res = [0]*2**n
        size //= 2
        w = 1
        for j in range(0,L//2,size):
            for a in range(size):
                res[a+j] = (F[a+2*j] + w * F[a+size+2*j]) % mod
                t = (w * wj) % mod
                res[L//2+a+j] = (F[a+2*j] + t * F[a+size+2*j]) % mod
            w = (w * use_omega) % mod
        F = res

    return res

def ntt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L)
    return F

def intt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L,reverse=True)
    inv = pow(L,mod-2,mod)
    for i in range(L):
        F[i] *= inv
        F[i] %= mod
    return F

def convolve(f,g,limit):
    l = len(f)+len(g)-1
    L = 1<<((l-1).bit_length())

    F = ntt(f,L)
    G = ntt(g,L)

    H = [(F[i] * G[i]) % mod for i in range(L)]

    h = intt(H,L)

    return h[:limit]

N,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

print(*convolve(a,b,N+M-1))

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

const int inf=1e9;
int dp[10000010][2];

int main(){
    string s; cin >> s;
    reverse(s.begin(),s.end());
    s+='0';
    int N=s.size();
    dp[0][1]=inf;
    for(int i=0;i<N;i++){
        int d=s[i]-'0';
        dp[i+1][0]=min(dp[i][0],dp[i][1]+1)+d;
        dp[i+1][1]=min(dp[i][0]+(10-d),dp[i][1]+(10-(d+1)));
    }
    cout << dp[N][0] << endl;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

// const int mxN = 1e9 + 7;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

string s[6];

int main()
{
	fast;
	int h, w, k, ans = 0;
	cin >> h >> w >> k;
	FOR(h)
	cin >> s[i];
	FOR(1 << h)
	{
		FOR(j, 1 << w)
		{
			int c = 0;
			FOR(i2, h)
			{
				FOR(j2, w)
				{
					if (i >> i2 & 1 && j >> j2 & 1 && s[i2][j2] == '#')
						++c;
				}
			}
			ans += c == k;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3560
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static int SuitToInt(char s)
		{
			switch (s)
			{
				case 'S' : return 0;
				case 'H' : return 1;
				case 'C' : return 2;
				case 'D' : return 3;
				default : throw new ApplicationException();
			}
		}
		public static char IntToSuit(int i)
		{
			switch (i / 13)
			{
				case 0 : return 'S';
				case 1 : return 'H';
				case 2 : return 'C';
				case 3 : return 'D';
				default : throw new ApplicationException();
			}
		}
		public static void Compute(TextReader reader, TextWriter writer)
		{
			var cards = new bool[13 * 4];
			
			reader.ReadLine();
			string line = null;
			while (null != (line = reader.ReadLine()))
			{
				var values = line.Split(' ');
				var i = int.Parse(values[1]) + 13 * SuitToInt(values[0][0]) - 1;
				cards[i] = true;
			}
			for (int i = 0; i < cards.Length; i++)
			{
				if (!cards[i])
				{
					writer.Write(IntToSuit(i));
					writer.Write(' ');
					writer.WriteLine((i % 13) + 1);
				}
			}
		}
	}
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <string.h>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <sstream>
#include <stack>
#include <iomanip>
#include <climits>
#include <complex>
#include <cmath>
#define fi first
#define se second
#define th second

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, int> di;
typedef vector<int> vi;
typedef multiset<ll, greater<ll>>::iterator iit;
typedef pair<iit, iit> pvi;
typedef complex<double> cd;

const int maxN = 1e5 + 3, MOD = 1e9 + 9, LG = 21;
//NOTE: maxN>2^LG must be held, remember maxN is twice ur biggest polynom
/*
 HAB
 G C
 FE
 D*/
ll tot, C;
int n;

ll place[maxN], cost[maxN], best[maxN];

void solve(){
    ll sum = 0;
    for(int i = n - 1; i >= 0; i--){
        sum += cost[i];
        best[i] = sum - (C - place[i]);
        if(i < n - 1) best[i] = max(best[i], best[i + 1]);
    }
    
    sum = 0;
    
    for(int i = 0; i < n; i++){
        sum += cost[i];
        
        if(i + 1 < n) tot = max(tot, sum + best[i + 1] - place[i] * 2);
        tot = max(tot, sum - place[i]);
        
    }
    
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    cin >> n >> C;
    
    for(int i = 0; i < n; i++) cin >> place[i] >> cost[i];
    
    solve();
    reverse(place, place + n), reverse(cost, cost + n);
    
    for(int i = 0; i < n; i++)
        place[i] = C - place[i];
    
    solve();
    
    cout << tot << '\n';
    
}


Measured memory_bytes: 2560
import java.io.*;
import java.util.Arrays;
class Main{
	public static void main(String[] args) throws IOException {
		int i,j;
		int[] n = new int[990];
		String[] str = new String[990];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for(;;){
			str = in.readLine().split(" ");
			for(i=0;i<2;i++){
				n[i] = Integer.parseInt(str[i]);
			}
			if(n[0]+n[1]==0) break;
			for(i=0;i<n[0];i++){
				for(j=0;j<n[1];j++){
					if(i==0 || i==n[0]-1 || j==0 || j==n[1]-1)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 32256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ii;
typedef pair<int64, int64> int64int64;
typedef vector<int> vint;
typedef vector<int64> vint64;
typedef vector<uint64> vuint64;
typedef vector<vint> vvint;
typedef vector<vint64> vvint64;
typedef vector<vuint64> vvuint64;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;

#define mp make_pair
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define fori(n) for(int i = 0; i < n; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define INF9 (int64)(1e9)
#define INF18 (int64)(1e18)

template<typename T>
struct compF{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.first < b.first;
	}
};

template<typename T>
struct compS{
	bool operator()(const pair<T, T> &a, const pair<T, T> &b){
		return a.second < b.second;
	}
};

template<typename T>
void printMatrix(const string &txt, vector<vector<T>> &a){
	cout << txt;
	fori(a.size()){
		forj(a[i].size())
			cout << a[i][j] << ' ';

		cout << endl;
	}
}

template<typename T>
void printVector(const string &txt, vector<T> &a){
	cout << txt;
	for (int i = 0; i < a.size(); ++i)
		cout << a[i] << ' ';
	cout << endl;
}

template<typename T>
void readVector(int n, vector<T> &a){
	if (a.size() < n)
		a.resize(n);

	fori(n) cin >> a[i];
}

template<typename T1, typename T2>
bool exist(map<T1, T2> &m, T1 x){
	if (m.find(x) == m.end())
		return false;

	return true;
}

int64 gcd(int64 a, int64 b){
	while (a != 0 && b != 0){
		if (b > a)
			b %= a;
		else
			a %= b;
	}

	return a + b;
}

int64 minFactor(int64 x){
	for (int64 i = 2; i * i <= x; ++i)
		if (x % i == 0)
			return i;

	return x;
}

int64 allFactors(int64 x, vint64 &prms, vint64 &prm_cnt){
	prms.clear();
	prm_cnt.clear();
	while (x > 1){
		int64 t = minFactor(x);
		prms.push_back(t);
		int s = prms.size() - 1;
		prm_cnt.push_back(0);
		while (x % t == 0){
			x /= t;
			++prm_cnt[s];
		}
	}

	return 0;
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie();
	
	int n;
	cin >> n;
	vint a(n);
	readVector(n, a);
	int64 s = 0;
	fori(n) s ^= a[i];

	fori(n) cout << (s ^ a[i]) << ' ';

	return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;
    
#define EPS (1e-7)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    cout<<(1+n-1)*(n-1)/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  long long x;
  long long money = 100;
  int answer = 0;
  cin >> x;
  
  for(answer = 0; money < x; answer++){
    money = money * 1.01;
  }
  
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 3652
# Library
import bisect

alp = "abcdefghijklmnopqrstuvwxyz"
#

s = input()
t = input()
ss = s * 2
index = -1
cir = 0
letter = []
res = 0

for i in range(len(ss)):
    letter.append([ss[i], i])

# Sort出来る.
letter.sort()

for i in range(len(t)):
    search = [t[i], index]
    tmp_ind = bisect.bisect(letter, search)
    # print("now searching " + str(search))
    # print("find: " + str(tmp_ind))
    # print("found: " + str(letter[tmp_ind]))
    if tmp_ind == len(ss):
        res = -1
        break
    if t[i] != letter[tmp_ind][0]:
        # Not exist
        res = -1
        break
    index += (letter[tmp_ind][1] - index)
    if index >= len(s):
        cir += 1
        index -= len(s)
    # print("cir,index : " + str(cir) + " " + str(index))
    res = cir * len(s) + index + 1

print(res)


Measured memory_bytes: 81264
#include <iostream>
using namespace std;
int main(void){
    
    int  h1,h2;
    int k1,k2;
    int a,b,c,d;
    int n,m;
    cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
    
    n = h1 * a + h2 * b + (h1 / 10) * c + (h2/20)*d;
    
    m =k1*a+k2*b+(k1/10)*c+(k2/20)*d;
    
    if(n<m){
        cout<<"kenjiro"<<endl;
    }
     else if(n>m){
        cout<<"hiroshi"<<endl;
    }
    else if(n==m){
        cout<<"even"<<endl;
    }
    
    
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc054_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<string> a(N);
  vector<string> b(M);
  rep(i, N) { cin >> a[i]; }
  rep(i, M) { cin >> b[i]; }

  rep(i, N - M + 1) {
    rep(j, N - M + 1) {
      bool ok = true;
      rep(l, M) {
        string ai = a[i + l].substr(j, M);
        string bi = b[l];
        ok &= ai == bi;
        if (!ok) break;
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,n):
    l = []
    for j in range(1,min(len(dp),k)+1):
        l.append(dp[i-j] + abs(h[i]-h[i-j]))
    dp.append(min(l))
print(dp[n-1])

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b == c || b+c == a || c+a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

    string C[200001];
    int Tsum[200002];
int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<int> stocker[2];
    int ptr = 0;

    Tsum[0] = 0;
    rep(i, Q){
        int T, F;
        
        cin >> T;
        if (T == 1){
            //reverse(ALL(S));
            ptr = 1 - ptr;
            Tsum[i + 1] = Tsum[i] + 1;
        } else {
            Tsum[i + 1] = Tsum[i];
            cin >> F >> C[i];
            if (F == 1){
                stocker[ptr].push_back(i);
                //S = C + S;
            } else {
                stocker[1 - ptr].push_back(i);
                //S = S + C;
            }
        }
        //cout << i << " " << Tsum[i] << endl;
    }
    //cout << stocker[0].size() << " " << stocker[1].size() << endl;
    //cout << stocker[0][0] << " " << stocker[0][1] << endl;
    //cout << C[0] << C[2] << endl;
    for (int ii = stocker[ptr].size() - 1; ii >= 0; ii--){
        int i = stocker[ptr][ii];
        if ((Tsum[Q] - Tsum[i])%2 == 1){
            reverse(ALL(C[i]));
        }
        cout << C[i];
    }
    if (Tsum[Q]%2 == 1){
        reverse(ALL(S));
    }
    cout << S;
        
    rep(ii, stocker[1 - ptr].size()){
        int i = stocker[1 - ptr][ii];
        if ((Tsum[Q] - Tsum[i])%2 == 1){
            reverse(ALL(C[i]));
        }
        cout << C[i];
    }
    return 0;
}


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

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

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

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


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

  ll n;
  cin >> n;

  vector<pair<ll, pll>> p(n);
  REP(i, n){
    cin >> p[i].SE.FI >> p[i].SE.SE;
    p[i].FI = p[i].SE.FI + p[i].SE.SE;
  }

  sort(p.begin(), p.end(), greater<pair<ll, pll>>());
  ll ans = 0;
  REP(i, n){
    pll now = p[i].SE;
    if(i%2 == 0)
      ans += now.FI;
    else
      ans -= now.SE;
  }

  cout << ans << endl;




}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=10101;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll mod=n%k;
    if(mod<=k/2)
    {
        cout<<mod;
    }
    else
    {
        cout<<abs(k-mod);
    }
    
}

Measured memory_bytes: 256
r, c = list(map(int,input().split()))
S = [map(int,input().split()) for i in range(r)]
col_sum = [0 for i in range(c)];
for row in S:
    row = list(row)
    print(' '.join(map(str,row)) + ' {}'.format(sum(row)))
    col_sum = [x + y for (x,y) in zip(col_sum,row)]
print(' '.join(map(str,col_sum)) + ' {}'.format(sum(col_sum)))

Measured memory_bytes: 8220
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

prime_list = sieve(200000)
while 1:
    a = input()
    if a == 0:
        break
    print sum(prime_list[:a])

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int m,n;
    m=c/b;
    n=a/d;
    if(c%b!=0) m++;
    if(a%d!=0) n++;
    if(m<=n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3616
#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 <list>

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 clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define prll(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll d[26];
  clr(d,0);
  ll n,k;
  cin>>n>>k;
  rep(i,0,n){
    string s;
    cin>>s;
    d[s[0]-'A']++;
  }
  priority_queue<ll> q;
  rep(i,0,26){
    if(d[i]!=0){
      q.push(d[i]);
    }
  }
  ll c = 0;
  while(1){
    vector<ll> v;
    if(q.sz<k)break;
    c++;
    rep(i,0,k){
      ll a = q.top();
      if(a>1)v.pb(a-1);
      q.pop();
    }
    rep(i,0,v.sz){
      q.push(v[i]);
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())
x0, y0, x1, y1 = 0, 0, w, h

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x0 = max(x0, x)
  if a == 2:
    x1 = min(x1, x)
  if a == 3:
    y0 = max(y0, y)
  if a == 4:
    y1 = min(y1, y)

print(max(x1 - x0, 0) * max(y1 - y0, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 1000000007
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
typedef long long tint;
using namespace std;

bool anda(int a, int b, string s) {
	if((int)s.size()!=a+b+1) return false;
	if(s[a] != '-') return false;
	forn(i, a) if(s[i] < '0' || s[i] > '9') return false;
	forn(i, b) if(s[i+a+1] < '0' || s[i+a+1] > '9') return false;
	return true;
}

int main()
{
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	if(anda(a,b,s)) cout << "Yes" << endl; else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long i,j,k,N,A,B,C,K;

int main()
{
  cin>>A>>B>>C>>K;
  
  if(K<=A)
  {
    cout <<K;
  }
  else if(K<=A+B)
  {
    cout <<A;
  }
  else
  {
    N=A-(K-A-B);
    cout <<N;
  }
  
  
}

Measured memory_bytes: 3460
## main

n = gets.strip.to_i

pls = []
n.times do
  pls << gets.strip.split(' ').map{|s| s.to_i}
end

scores = n.times.map{0}

for i in (0..2)
  cards = 101.times.map{0}

  for j in (0...n)
    cards[pls[j][i]] += 1
  end

  for j in (0...n)
    if cards[pls[j][i]] == 1
      scores[j] += pls[j][i]
    end
  end
end

puts scores

Measured memory_bytes: 6120
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
ll dp[3001][3001];
int n;

ll solve(int i, int j, int A[]){
    if(i>j) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    ll op1=A[i]+min(solve(i+2,j,A),solve(i+1,j-1,A));
    ll op2=A[j]+min(solve(i,j-2,A),solve(i+1,j-1,A));
    return dp[i][j]=max(op1,op2);
    
}

int main(){
    cin>>n;
    int A[n];
     ll sum=0;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){ cin>>A[i]; sum+=A[i]; }
    ll x=solve(0,n-1, A);
    ll y=sum-x;
    cout<<x-y;
}//

Measured memory_bytes: 74152
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    Xstr = []
    Ystr = []
    for j in range(len(X)):
        Xstr.append(X[j])
    for j in range(len(Y)):
        Ystr.append(Y[j])
    Xstr = list(set(Xstr))
    Ystr = list(set(Ystr))
    anstemp = 0
    for x in Xstr:
        if x in Ystr:
            anstemp += 1
    if ans < anstemp:
        ans = anstemp
print(ans)


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

int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++) cin >> a[i];
  int cnt=0;
  for(int i=0;i<N;i++){
    while(i+1<N&&a[i]==a[i+1]) i++;
    if(i+1<N&&a[i]<a[i+1]){
      while(i+1<N&&a[i]<=a[i+1]) i++;
    }
    else if(i+1<N&&a[i+1]<a[i]){
      while(i+1<N&&a[i+1]<=a[i]) i++;
    }
    cnt++;
  }
  cout << cnt << endl;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  string s;
  cin >> s;
  bool ok = false;
  if(s[0]=='7'||s[1]=='7'||s[2]=='7') ok = true;
  cout << (ok?"Yes":"No") << endl;
}


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

using namespace std;

int n,i,j;
double odp;
double dp[3003][3003];
double szansa[3003];

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> szansa[i];
    }
    dp[0][0] = 1;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=i;j++)
        {
            if(j==0)
            {
                dp[i][j]=dp[i-1][j]*(1-szansa[i]);
            }
            else
            {
                dp[i][j]=dp[i-1][j]*(1-szansa[i])+dp[i-1][j-1]*szansa[i];
            }
        }
    }
    for(i=(n/2)+1;i<=n;i++){
        odp+=dp[n][i];
    }
    cout << fixed << setprecision(10) << odp;
    return 0;
}


Measured memory_bytes: 68992
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<tapu, Vtapu, greater<tapu> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;
ut N, M, K, L, Q, D, H, W,R;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
int A[SIZE],B[SIZE];string s[SIZE];
LL BASE=200;
LL additions[SIZE];
VI ans;
LL DP[SIZE][10];
LL solve(){
  cin >> K;
  string FESTIVAL="FESTIVAL";
  LL siz=FESTIVAL.size();
  REP(i,siz-1){
  //  int c=K%BASE;
    FOR(j,i,FESTIVAL.size()-1) ans.pb(j);
    FOR(j,0,BASE)
      ans.pb(i);
   // K/=BASE;
  }
  DP[0][0]=1;
  REP(i,ans.size()){
    REP(j,FESTIVAL.size()+1) DP[i+1][j]=DP[i][j];
    DP[i+1][ans[i]+1]+=DP[i][ans[i]];
  }
  RREP(i,ans.size()-1){
  //  cout << i<< " " <<  K <<" " <<  DP[i][FESTIVAL.size()-1] << endl;
    additions[i]=K/DP[i][FESTIVAL.size()-1];
    K%=DP[i][FESTIVAL.size()-1];  
    if(K==0) break;
  }
  REP(i,ans.size()){
    REP(j,additions[i]){
      cout << 'L';
    }
    cout << FESTIVAL[ans[i]];
  }
	return 0;
} 
 
//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	string s;
	solve();
	 
 
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 14208