akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
using namespace std;

int main()
{
    long long int N, i, max_add = -99999999999999, min_add = 99999999999999, max_diff = -99999999999999, min_diff = 99999999999999, ans, x, y;
    cin>>N;
    for(i=0;i<N;i+=1)
    {
        cin>>x>>y;
        max_add = max(max_add, x+y);
        min_add = min(min_add, x+y);
        max_diff = max(max_diff, x-y);
        min_diff = min(min_diff, x-y);
    }
    ans = max(abs(max_add - min_add), abs(max_diff - min_diff));
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  long long u=0,v=0;
  for(int i=0;i<n-1;i++){
    if(a[i]<b[i]){
      u+=(b[i]-a[i])/2;
    }
    if(a[i]>b[i]){
      v+=a[i]-b[i];
    }
  }
  if(u<=v){
    if(a[n-1]+2*(v-u)<=b[n-1]){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    if(a[n-1]<=b[n-1]+u-v){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)

const ll INF = 100000000000000000LL;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
	int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    ll ret = INF;

    int f=1;
    ll sum=0, now=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(f==1&&sum<=0){
            now+=-sum+1LL;
            sum=1LL;
        }
        else if(f==-1&&sum>=0){
            now+=sum+1LL;
            sum=-1LL;
        }
        f*=-1;
    }
    ret=min(ret,now);

    f=-1;
    sum=0;
    now=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(f==1&&sum<=0){
            now+=-sum+1LL;
            sum=1LL;
        }
        else if(f==-1&&sum>=0){
            now+=sum+1LL;
            sum=-1LL;
        }
        f*=-1;
    }
    ret=min(ret,now);

    cout<<ret<<endl;

	return 0;
}

Measured memory_bytes: 768
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        k: i32,
        board: [Chars; h], // h*wのグリッドを Vec<Vec<char>> として読み込む
    }

    let mut ans = 0;

    let black: i32 = {
        let mut black = 0;
        for i in 0..h {
            for j in 0..w {
                if board[i][j] == '#' {
                    black += 1;
                }
            }
        }
        black
    };

    for hi in 0..2u32.pow(h as u32) {
        for we in 0..2u32.pow(w as u32) {
            let mut count = black;
            let mut fff = vec![vec![true; w]; h];
            for i in (0..h).filter(|i| (hi >> i) & 1 == 1) {
                for j in 0..w {
                    if fff[i][j] && board[i][j] == '#' {
                        count -= 1;
                    }
                    fff[i][j] = false;
                }
            }
            for j in (0..w).filter(|j| (we >> j) & 1 == 1) {
                for i in 0..h {
                    if fff[i][j] && board[i][j] == '#' {
                        count -= 1;
                    }
                    fff[i][j] = false;
                }
            }
            if count == k {
                ans += 1;
            }
        }
    }

    println!("{}",ans)
}


Measured memory_bytes: 2132
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0123
"""
import sys


def solve(r500, r1000):
    criteria = [(35.50,  71.0, 'AAA'),
                (37.50,  77.0, 'AA'),
                (40.0,   83.0, 'A'),
                (43.0,   89.0, 'B'),
                (50.0,  105.0, 'C'),
                (55.0,  116.0, 'D'),
                (70.0,  148.0, 'E')]
    rank = None
    for c500, c1000, r in criteria:
        if r500 < c500 and r1000 < c1000:
            rank = r
            break
    if rank == None:
        rank = 'NA'
    return rank


def main(args):
    for line in sys.stdin:
        r500, r1000 = [float(x) for x in line.strip().split()]
        result = solve(r500, r1000)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7544
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
	int n, k, p[1000], ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
	return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  vector<int> v(4,0);
  cin >> v[0] >> v[1] >> v[2] >> v[3];
  sort(v.begin(), v.end());

  if(v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3] == 1479){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;

  }
}


Measured memory_bytes: 3624
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stdio.h>
#define ll long long
#define maxn 100001
using namespace std;
ll n;
ll q;
ll cnt[maxn];
ll ans;
ll b,c;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		ll tmp;
		cin>>tmp;
		cnt[tmp]++;
		ans+=tmp;
	}
	cin>>q;
	for(int i=0;i<q;i++)
	{
		cin>>b>>c;
		ans-=(b*cnt[b]);
		cnt[c]+=cnt[b];
		ans+=(c*cnt[b]);
		cnt[b]=0;
		cnt[c]+=cnt[b];
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4384
#include <map>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    int C[100100] = {};
    while (n--) { int x; cin >> x; C[x]++; }
    int sum = 0, ans = 0;
    for (int a = 0; a <= 100000; a += m) sum += C[a];
    ans += sum/2;
    if (m%2==0) {
        sum = 0;
        for (int a = m/2; a <= 100000; a += m) sum += C[a];
        ans += sum/2;
    }
    for (int a = 1, b = m-1; a < b; a++, b--) {
        int c1 = 0, c2 = 0, d1 = 0, d2 = 0;
        for (int x = a; x <= 100000; x += m) { c1 += C[x]%2; d1 += C[x]/2*2; }
        for (int x = b; x <= 100000; x += m) { c2 += C[x]%2; d2 += C[x]/2*2; }
        int c0 = min(c1, c2);
        ans += c0; c1 -= c0; c2 -= c0;
        if (c1 > 0) ans += min(c1, d2), d2 -= min(c1, d2);
        if (c2 > 0) ans += min(c2, d1), d1 -= min(c2, d1);
        ans += d1/2 + d2/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

#define SQ(x) ((x) * (x))

int main(void)
{
	int a, b, c;
	int t, h;
	char buf[256];
	
	t = h = 0;
	while (fgets(buf, 256, stdin) != NULL){
		sscanf(buf, "%d,%d,%d", &a, &b, &c);
		
		if (SQ(a) + SQ(b) == SQ(c)){
			t++;
		}
		if (a == b){
			h++;
		}
	}
	
	printf("%d\n%d\n", t, h);
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
int main() {
    int x, y; cin>>x>>y;
    cout<<x+y/2<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        long s = 0;

        for (int i = 0; i < n; i++) {
            s += a[i];
        }

        System.out.println(a[0] + " " + a[n - 1] + " " + s);
    }
}

    



Measured memory_bytes: 41644
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(c,b/a)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void)
{
	int a1, a2, a3, min, a[6], i;

	scanf("%d %d %d", &a1, &a2, &a3);

	a[0] = fabs(a2-a1) + fabs(a3 - a2);
	a[1] = fabs(a3-a1) + fabs(a2 - a3);
	a[2] = fabs(a1-a2) + fabs(a3 - a1);
	a[3] = fabs(a3-a2) + fabs(a1 - a3);
	a[4] = fabs(a2-a3) + fabs(a1 - a2);
	a[5] = fabs(a1-a3) + fabs(a2 - a1);

	min = a[0];

	for(i=1; i<6; i++){
		if(min > a[i]){
			min = a[i];
		}
	}

	printf("%d", min);

	return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3

INVALID = -1


def compute(n, bs):
    # zero-based
    cs = [b - 1 for b in bs]
    num_breaks = 0
    cur_pos = 0
    for c in cs:
        if c == cur_pos:
            cur_pos += 1
        else:
            num_breaks += 1
    if num_breaks == n:
        return None
    else:
        return num_breaks


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(n, bs)
    if res is None:
        print(-1)
    else:
        print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24744
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
       
    int n = scan.nextInt();
    
    int[] p = new int[n];
    
    for (int i = 0; i < n; i++) {
      p[i] = scan.nextInt();
    }
    
    for (int k = 0; k < n - 1; k++) {
    	if (p[k] > p[k+1]) {
    		break;
    	} else if (k == (n - 2)) {
    		System.out.print("YES");
    		return;
    	}
    }
    
    int tmp = 0;
    int[] q = new int[n];
    
    for (int i = 0; i < n - 1; i++) {    
      for (int j = i + 1; j < n; j++) {
    	  
		for (int k = 0; k < n; k++) {
			 q[k] = p[k];
		}
		q[i] = p[j];
		q[j] = p[i];
		
		for (int k = 0; k < n - 1; k++) {
			if (q[k] > q[k+1]) {
				break;
			} else if (k == (n - 2)) {
				System.out.print("YES");
				return;
			}
		}
      }
    }
    
    System.out.print("NO");
    return;
  }
}


Measured memory_bytes: 21844
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
using VS = vector<string>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  ll n, m;
  cin >> n;
  VS s(n, "");
  REP(i, n) cin >> s[i];
  cin >> m;
  VS t(m, "");
  REP(i, m) cin >> t[i];
  ll max = 0;
  REP(i, n)
  if (count(s.begin(), s.end(), s[i]) - count(t.begin(), t.end(), s[i]) > max)
    max = count(s.begin(), s.end(), s[i]) - count(t.begin(), t.end(), s[i]);
  // REP(i, n) cout << s[i] << endl;
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
//Pradeep_7
//double tt = clock();
//if((clock()-tt)/CLOCKS_PER_SEC > 1) break;
#include<bits/stdc++.h>
#define mp make_pair 
#define pb push_back
#define fi first
#define se second 
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
#define tcc int tc;	cin>>tc; while(tc--)
#define arr(a,n)	for(int i=0;i<n;i++)		cin>>a[i]
#define all(a)	a.begin(),a.end()
#define rall(a)	a.rbegin(),a.rend()
using namespace std;     
int main()
{
	string a;
	cin>>a;
	map<char,int> mp;
	for(char c : a)
	{
		mp[c]++;
	}
	for(int i=0;i<a.size();i++)
	{
		if(mp[a[i]]% 2!=0)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 3620
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(int i = x; i < n; i++)
#define rrep(i, x, n) for(int i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
double PI=3.14159265358979323846;
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;
#define endl '\n'

int main() {
	boost
	ll n, m;
	cin >> n >> m;
	vvi dp(n + 1, vi (m + 1, 0));
	vector<string> v(n + 1, "");
	rep(i, 1, (n + 1)) cin >> v[i];
	rep(i, 1, (n + 1)) rep(j, 1, (m + 1)) {
		dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
		if(v[i][j-1] == '#') dp[i][j] = 0;
		if(i == 1 and j == 1) dp[i][j] = 1;
	}
	cout << dp[n][m] << endl;
}


Measured memory_bytes: 9216
N=int(input())
C=[[0]*9  for i in range(9)]
count=0

for n in range(1,N+1):
   if str(n)[-1]!="0":
      left=int(str(n)[0])-1
      right=int(str(n)[-1])-1
      C[left][right]+=1
      
for i in range(1,10):
   for j in range(1,10):
      count+=C[i-1][j-1]*C[j-1][i-1]

print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
  int x,y,z;
  int a;
  
  scanf("%d",&x); 
  scanf("%d",&y); 
  scanf("%d",&z);
  
  a=x;
  x=y;
  y=a;
  
  a=z;
  z=x;
  x=a;
  
  printf("%d ",x);
  printf("%d ",y);
  printf("%d ",z);
  
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,t,a,res=0;
  	float minn=99999999999;
  	long long h[n];
  	cin>>n;
  	cin>>t>>a;
  	for (long long i=1;i<=n;i++){
    	cin>>h[i];
    	if (abs(a-(t-h[i]*0.006))<minn){
        	res=i;
          	minn=abs(a-(t-h[i]*0.006));
        }
    }
    cout<<res;
}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;

int dp[3005][3005];
string s1, s2;

int kil(int idx1, int idx2) {
    if (idx1 == s1.length() || idx2 == s2.length())
        return 0;

    if (dp[idx1][idx2] != -1)
        return dp[idx1][idx2];

    if (s1[idx1] == s2[idx2])
        dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1 + 1, idx2 + 1) + 1);
    else {
        dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1, idx2 + 1));
        dp[idx1][idx2] = max(dp[idx1][idx2], kil(idx1 + 1, idx2));
    }
    return dp[idx1][idx2];
}

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

    string res = "";

    memset(dp, -1, sizeof dp);
    cin >> s1 >> s2;

    // recursive
    // kil(0, 0);

    // iterative
    memset(dp, 0, sizeof dp);

    for (int idx1 = s1.length() - 1; idx1 >= 0; idx1--)
        for (int idx2 = s2.length() - 1; idx2 >= 0; idx2--) {
            if (s1[idx1] == s2[idx2])
                dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1 + 1][idx2 + 1] + 1);
            else {
                dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1][idx2 + 1]);
                dp[idx1][idx2] = max(dp[idx1][idx2], dp[idx1 + 1][idx2]);
            }
        }

    int idx1 = 0, idx2 = 0;

    while (idx1 != s1.length() && idx2 != s2.length()) {
        if (s1[idx1] == s2[idx2]) {
            res += s1[idx1];
            idx1 += 1;
            idx2 += 1;
        } else {
            if (dp[idx1][idx2] == dp[idx1 + 1][idx2] && dp[idx1][idx2] != -1)
                idx1 += 1;
            else
                idx2 += 1;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main(){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v) cin >> i;

    int mi = inf, ans = 0;
    REP(i, n){
        if(v[i] <= mi){
            ans++;
            mi = v[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b=0,f,i;
	char c[101],d[101],e[101];
	scanf("%d %s %s %s",&a,&c,&d,&e);
	for(i=0;i<a;i++){
		if(c[i]==d[i]&&d[i]==e[i]){
			b=b;
		}else if(c[i]!=d[i]&&d[i]!=e[i]&&c[i]!=e[i]){
			b=b+2;
		}else if(c[i]==d[i]){
			b=b+1;
		}else if(d[i]==e[i]){
			b=b+1;
		}else{
			b=b+1;
		}
	}
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 7)

# ----------

INF = float("inf")
MOD = 10 ** 9 + 7

N, A, B, C = map(int, input().split())
num = [A, B, C]
S = []
for i in range(N):
    S.append(input().strip())
S.append('AB')

ans = []
for i in range(N):
    s1 = S[i][0]
    s2 = S[i][1]
    n1 = num["ABC".index(s1)]
    n2 = num["ABC".index(s2)]

    if n1 == n2 == 0:
        print("No")
        exit()

    s_add = ""
    s_sub = ""
    if n1 == 0:
        s_add = s1
        s_sub = s2
    elif n2 == 0:
        s_add = s2
        s_sub = s1
    elif s1 in S[i + 1]:
        s_add = s1
        s_sub = s2
    else:
        s_add = s2
        s_sub = s1

    num["ABC".index(s_add)] += 1
    num["ABC".index(s_sub)] -= 1
    ans.append(s_add)

print('Yes')
for a in ans:
    print(a)


Measured memory_bytes: 17112
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

string S, T;

bool check(string a, string b) {
   if (a.size() != b.size()) return false;
   int len = a.size();
   for (int i = 0; i < len; i++) {
      if (a[i] != '?' && a[i] != b[i]) return false;
   }
   return true;
}

int main() {
   cin >> S >> T;
   string ans;
   if (S.size() < T.size()) {
      cout << "UNRESTORABLE" << endl;
      return 0;
   }
   for (int i = 0; i < S.size(); i++) {
      ans += 'z';
   }
   bool updated = false;
   for (int i = 0; i <= S.size() - T.size(); i++) {
      if (check(S.substr(i, T.size()), T)) {
         string tmp = S;
         updated = true;
         for (int j = i; j < i + T.size(); j++) {
            tmp[j] = T[j - i];
         }
         for (int j = 0; j < S.size(); j++) {
            if (tmp[j] == '?') tmp[j] = 'a';
         }
         if (tmp < ans) ans = tmp;
      }
   }
   if (!updated) cout << "UNRESTORABLE" << endl;
   else cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



n = I()
A = LI()
dp = [-INF] * n
dp[0] = 1000
for i in range(1, n):
    ret = dp[i - 1]
    for j in range(i):
        ret = max(dp[j] // A[j] * A[i] + dp[j] % A[j], ret)
    dp[i] = ret


print(dp[n - 1])



Measured memory_bytes: 83472
#ABC081C
import collections
N, K =map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
NumA = list(c.values())
NumA.sort()
ans = 0
#print(NumA)
for i in range(len(set(A))-K):
    ans += NumA[i]
print(ans)

Measured memory_bytes: 41392
#include <bits/stdc++.h>
#include <vector>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;
 
using namespace std;
 
int main() {

	int x;
	cin >> x;

	int i = 0;
	int kx = 0;

	while(kx < x) {
		i++;
		kx += i;
	}

	cout << i << endl;
}

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

string S;

int main() {
    cin >> S;
    if (S == "SUN") cout << "7";
    if (S == "MON") cout << "6";
    if (S == "TUE") cout << "5";
    if (S == "WED") cout << "4";
    if (S == "THU") cout << "3";
    if (S == "FRI") cout << "2";
    if (S == "SAT") cout << "1";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
int main(){
	char s[200000];
	int start,end;
	int length;
	int input_length;

	scanf("%s",s);
	input_length = strlen(s);

	for(int i=0;i<input_length;i++){
		if(s[i] == 'A'){
			start = i;
			break;
		}
	}
	for(int i=start;i<input_length;i++){
		if(s[i] == 'Z'){
			end = i;
		}
	}
	length = end - start + 1;
	printf("%d\n",length);
	return 0;
}


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

using namespace std;
const int INF = 1e9;

int main() {
  int h, w;
  cin >> h >> w;
  vector< vector<int> > dist(10, vector<int>(10));
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> dist[i][j];
    }
  }

  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
	dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int a;
      cin >> a;
      if (a != -1) 
	ans += dist[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

// 未証明

LL n;

int main() {
	cin >> n;
	
	cout << n * (n - 1) / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        int n,x;
        n = in.nextInt();
        x = in.nextInt();
        int ans = 1;
        int cs = 0;
        for (int i = 0; i < n; i++){
            cs += in.nextInt();
            if (cs<=x){
                ans++;
            }
        }
        out.pl(ans);

        out.close();
    }
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32992
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define mp(a, b) make_pair(a, b)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;

int main(){
    ll A, B, C; cin >> A >> B >> C;
    if(B >= C-1){prt(B)+C;}
    else{
        prt(B + min(A+B+1, C));
    }
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N, M, P;
  while(cin >> N >> M >> P, N||M||P){
    vector<int> X(N);
    int X_sum = 0;
    for(int i = 0; i < N; i++){
      cin >> X[i];
      X_sum += X[i];
    }
    int ans = X_sum * (100-P);
    if(X[M-1]==0) cout << 0 << endl;
    else cout << ans / X[M - 1] << endl;
  }
}

Measured memory_bytes: 3064
#この実装は割とクソ
h,w = gets.split.map(&:to_i)
infos = h.times.map{ gets.chomp.split("") }

#白いマスからなる行を削除する
def calc(length, infos)
  isBreak = false

  length.times {|_|
    infos.each_with_index do |info,i|
      if info.all? {|item| item == "."}
        infos.slice!(i)
        break
      end
      isBreak = true if i == length
    end
    break if isBreak
  }
  infos
end

calc_infos = calc(h,infos)
calc_infos2 = calc(w, calc_infos.transpose)
calc_infos2.transpose.each{|info| puts info.join('') }

Measured memory_bytes: 2812
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  	ios::sync_with_stdio(0);
	cin.tie(0);
	string S;
  	getline(cin, S);
  	cout << ( (S[2]==S[3]) && (S[4] == S[5]) ? "Yes" : "No"); 
}

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

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

using namespace std;

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

int main(){
	rep(i, 7){
		int a, b;
		cin >> a >> b;
		cout << a-b << endl;
	}

	return 0;
}

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

using namespace std;
using int64 = long long;
using int8 = int8_t;

constexpr int DEBUG = 0;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
    s << v[i];
  }
  s << "]";
  return s;
}

template<typename T>
vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

// Returns a vector of cumulative sums.
// Let c_sums be the return value.
// - c_sums[k] is the sum of xs over [0, k).
// - c_sums[r] - c_sums[l] is the sum of xs over [l, r).
template<class T> vector<T> CumulativeSumVector(const vector<T>& xs) {
  int n = xs.size(); vector<T> c_sums(n + 1);
  for (int i = 0; i < n; i++) c_sums[i + 1] = c_sums[i] + xs[i];
  return c_sums;
}

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

  int n, k;
  cin >> n >> k;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  auto dp1 = MakeVector2D<int8>(n + 1, 2 * k + 1, 0);
  dp1[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 2 * k; j++) {
      dp1[i + 1][j] |= dp1[i][j];
      dp1[i + 1][min(j + xs[i], 2 * k)] |= dp1[i][j];
    }
  }

  auto dp2 = MakeVector2D<int8>(n + 2, 2 * k + 1, 0);
  dp2[n][0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= 2 * k; j++) {
      dp2[i][j] |= dp2[i + 1][j];
      dp2[i][min(j + xs[i], 2 * k)] |= dp2[i + 1][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (xs[i] >= k) continue;
    vector<int> as;
    for (int j = 0; j <= 2 * k; j++) {
      if (dp1[i][j]) {
        as.push_back(j);
      }
    }

    vector<int> b_bits(2 * k + 1);
    for (int j = 0; j <= 2 * k; j++) {
      if (dp2[i + 1][j]) {
        b_bits[j] = 1;
      }
    }
    
    vector<int> b_bit_cum_sum = CumulativeSumVector(b_bits);

    if (DEBUG) {
      cout << "i: " << i << endl;
      cout << "as: " << as << endl;
      // cout << "bs: " << bs << endl;
    }

    bool required = false;
    for (int a : as) {
      if (b_bit_cum_sum[max(k - xs[i] - a, 0)] != b_bit_cum_sum[max(k - a, 0)]) {
        required = true;
      }
    }

    if (!required) {
      if (DEBUG) cout << "not required! i: " << i << endl;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 98584
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

bool compare_by_b(tuple<int, string, int> a, tuple<int, string, int> b) {
    if(get<2>(a) != get<2>(b)){
        return get<2>(a) > get<2>(b);
    }
}

bool compare_by_string(tuple<int, string, int> a, tuple<int, string, int> b) {
    if(get<1>(a) != get<1>(b)){
        return get<1>(a) < get<1>(b);
    }else{
      	return get<2>(a) > get<2>(b);
    }
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
  	cin >> N >> M;
  	vector<vector<int>> ks(M);
  	for (int i=0;i<M;i++)
    {
      int num;
      cin >> num;
      ks[i].resize(num);
      for(int s=0;s<num;s++)
      {
        int ss;
        cin >> ss;
        ks[i][s] = ss-1;
      }
    }
  	vector<int> p(M);
  	for(int i=0;i<M;i++) cin >> p[i];
  	int ans = 0;
  	for (int i=0;i<(1 << N);i++){
        bool ok = true;
        for (int j=0;j<M;j++) {
            int t=0;
            for (int k=0;k<ks[j].size();k++) {
              	t ^= (i >> ks[j][k]) & 1;
            }
            if (t % 2 != p[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans++;
        }
    }
 
    cout << ans << endl;
  	return 0;
}


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

int main(void)
{
	char str[1000];
	int len;
	int i;
	
	fgets(str, 1000, stdin);
	
	len = strlen(str);
	
	for (i = 0; i < len; i++){
		if (str[i] == 'a'){
			if (str[i + 1] == 'p'){
				if (str[i + 2] == 'p'){
					if (str[i + 3] == 'l'){
						if (str[i + 4] == 'e'){
							str[i] = 'p';
							str[i + 1] = 'e';
							str[i + 2] = 'a';
							str[i + 3] = 'c';
							str[i + 4] = 'h';
						}
					}
				}
			}
		}
		else if (str[i] == 'p'){
			if (str[i + 1] == 'e'){
				if (str[i + 2] == 'a'){
					if (str[i + 3] == 'c'){
						if (str[i + 4] == 'h'){
							str[i] = 'a';
							str[i + 1] = 'p';
							str[i + 2] = 'p';
							str[i + 3] = 'l';
							str[i + 4] = 'e';
						}
					}
				}
			}
		}
	}
	
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 524
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	int q;
	cin >> q;
	vector<int>V;
	int ib;
	int ib2;
	rep(i, q) {
		cin >> ib;
		if (ib == 0) {
			cin >> ib2;
			V.push_back(ib2);
		}
		else if (ib == 1) {
			cin >> ib2;
			cout << V[ib2] << endl;
		}
		else if(ib==2) {
			V.pop_back();
		}
	}
}


Measured memory_bytes: 3848
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(X, A, B),
    abs(X - A) < abs(X - B) -> writeln("A") ; writeln("B").


Measured memory_bytes: 8088
#include <stdio.h>
#include <math.h>
int main(){
	int n,i,j,d=0,count=0,a[10000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++) {
		if(a[i]==2||a[i]==3){
			count++;
		continue;
	}
		for(j=2;j<=sqrt(a[i]);j++){
			d=0;
			if(a[i]%j==0){ 
				d=1;
			break;
		}
		}
		if(d==0)
			count++;
	}
	printf("%d\n",count);
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

ll solve(ll A) {
	switch (A % 4) {
		case 0:
			return A;
		case 1:
			return 1;
		case 2:
			return A ^ 1;
		case 3:
			return 0;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A, B;
	cin >> A >> B;
	ll ans = solve(B);
	if (A != 0) {
		ans ^= solve(A - 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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 () {
  int n, k;
  cin >> n >> k;

  int ans = 0;
  while(n != 0) {
    n /= k;
    ans++;
  }

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

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define M 200010
#define inf 2000000010
using namespace std;
int n,a[M];
long long ans,t,sum;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        sum = 0; ans = inf; t = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
       for (int i = 0; i < n-1; i++)
       {
            t += a[i];
            if(ans > abs(2 * t - sum))
                ans = abs(2 * t - sum);
       }
        printf("%lld\n",ans);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

#define pll pair<ll,ll>


int N;
int a[2000001];
int b[2000001];
vector<int> ans;
int main(){
    cin>>N;
    FILL(b,N+1,0);
    for(int i=1;i<=N;++i){
        cin >> a[i];
    }
    for(int i=N;i>=1;--i){
        int s = 0;
        for(int j=i*2;j<=N;j+=i){
            s += b[j];
        }
        if( (s+a[i])%2==1 ){
            b[i] = 1;
            ans.push_back(i);
        }
    }
    
    cout << ans.size() << "\n";
    for(int x:ans){
        cout << x << " ";
    }
    cout << "\n";

}


Measured memory_bytes: 6520