akhauriyash/Code-Regression huggingface dataset:
//By Tushar Gautam
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    int pre=0;
    forn(i,n){
        cin>>x;
        if(x==pre) y++,pre=0;
        else pre=x;
    }
    cout<<y;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<ll> L(N+1);
    L[0]=2;L[1]=1;
    for(int i=2;i<=N;i++){
        L[i]=L[i-1]+L[i-2];
    }
    cout << L[N] << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7
ans = 0
ni = 1

for i in range(60):
    x = sum([1 for j in range(N) if (A[j] >> i) & 1])
    buff = x * (N - x) * ni
    ans += buff
    ni = ni * 2

print(ans % mod)


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

typedef long long LL;
const int N=200010;
char s[N];
int nxt[N];
LL l,r;
LL f[100][27];
LL sum[100],ans[27];
int mx=90;

void getnext()
{
	int n=strlen(s+1)/2,j=0;
	for(int i=2;i<=n;i++)
	{
		while(j&&s[i]!=s[j+1]) j=nxt[j];
		if(s[i]==s[j+1]) j++;
		nxt[i]=j;
	}
}

void initfib()
{
	for(int i=2;i<=mx;i++)
	{
		for(int j=0;j<26;j++)
			f[i][j]=f[i-1][j]+f[i-2][j];
		sum[i]=sum[i-1]+sum[i-2];
		if(sum[i]>LL(1e18)){mx=i;break;}
	}
}

void gao(LL x,int fg)
{
	int p;
	for(p=0;p<=mx;p++)
		if(sum[p]>x) break;
	for(;p>=0;p--)
		if(x>=sum[p])
		{
			for(int i=0;i<26;i++)
				ans[i]+=fg*f[p][i];
			x-=sum[p];
		}
	for(int i=1;i<=x;i++) ans[s[i]-'a']+=fg;
}

int main()
{
	scanf("%s%lld%lld",s+1,&l,&r);
	int n=strlen(s+1);
	for(int i=1;i<=n/2;i++)
		f[0][s[i]-'a']++;
	getnext();
	sum[0]=n/2;sum[1]=n-nxt[n/2];
	for(int i=0;i<26;i++) f[1][i]=f[0][i];
	for(int i=1;i<=n/2-nxt[n/2];i++)
		f[1][s[i]-'a']++;
	initfib();gao(r,1);gao(l-1,-1);
	for(int i=0;i<26;i++) printf("%lld ",ans[i]);
	return 0;
}

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

using namespace std;

struct UnionFind {  // The range of node number is from 0 to n-1
	//'rank[x]' is a rank of the union find tree the root of which is x.
	//'parents[x]' is the parent of x
	vector<int> rank, size, parents;

	// constructor
	UnionFind() {}
	UnionFind(int n) {  // make n trees.
		size.resize(n, 0);
		rank.resize(n, 0);
		parents.resize(n, 0);
		for (int i = 0; i < n; i++) {
			makeTree(i);
		}
	}
	// make a union find tree
	void makeTree(int x) {
		parents[x] = x;  // the parent of x is x
		rank[x] = 0;
		size[x] = 1;
	}

	// check whether the root of x is the same as that of y
	bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }

	//uniteはどちらかを選ぶこと！！！！！

	// unite two tree (ランク（木の高さ）が低くなるように繋げる場合）
	bool unite(int x, int y) {
		x = findRoot(x);
		y = findRoot(y);
		if (x == y) return false;
		if (rank[x] > rank[y]) {
			parents[y] = x;
		}
		else {
			parents[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
		return true;
	}

	// unite two tree (サイズ（頂点の数）が大きい方に小さい方を繋げる場合）
	//bool unite(int x, int y) {
	//	x = findRoot(x);
	//	y = findRoot(y);
	//	if (x == y) return false;
	//	if (size[x] > size[y]) {
	//		parents[y] = x;
	//		size[x] += size[y];
	//	}
	//	else {
	//		parents[x] = y;
	//		size[y] += size[x];
	//	}
	//	return true;
	//}

	// 経路圧縮（全て根につなげる）する場合の根探しtravel the parents of tree recursivily to find root
	int findRoot(int x) {
		if (x != parents[x]) {
			parents[x] = findRoot(parents[x]);  // change the x's parent to the root of tree.
		}
		return parents[x];
	}
	//経路圧縮しない場合
	//int findRoot(int x) {
	//	if (x == parents[x])
	//		return x;
	//	return findRoot(parents[x]);
	//}

	int treeSize(int x) { return size[findRoot(x)]; }
};

int main() {

	int n, q;
	cin >> n >> q;

	UnionFind tree(n);

	int in1, in2,in3;
	for (int i = 0; i < q; i++) {
		cin >> in1 >> in2 >> in3;
		if (in1 == 0) {
			tree.unite(in2, in3);
		}
		else {
			cout << tree.isSame(in2, in3) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3216
d,n = map(int,input().split())
if d == 0:
  if n != 100:
    print(n)
  else:
    print(101)
elif d == 1:
  if n != 100:
    print(100*n)
  else:
    print(10100)
elif d == 2:
  if n != 100:
    print(10000*n)
  else:
    print(1010000)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define foreach(a,A) for(auto &a:A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    string S, T; cin >> S >> T;
    T.pop_back();
    cout << (S == T ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

ll n,ans;

int main() {
    scanf("%lld",&n);
    for (int i=1;i<=n;++i)
        ans=(ans+(n-i+1)*(1-i)+(i+n)*(n-i+1)/2);
    for (int i=1;i<n;++i){
        int u,v;scanf("%d%d",&u,&v);
        if (u>v) swap(u,v);
        ans-=(1ll*u*(n-v+1));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin >> s;
	int ans = 1000000;
	for(int i = 0; i < s.size()-2; i++){
		int x=0;
		x += (s[i]-'0')*100;
		x += (s[i+1]-'0')*10;
		x += (s[i+2]-'0');
		ans = min(ans,abs(753-x));
	}
	cout << ans << endl;

	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;
int n;
int dp[1'000'100][2];

int rec(int i, int c){
    if(i < 0){
        return c;
    }

    if(dp[i][c] != -1){
        return dp[i][c];
    }

    int x = c + (S[i] - '0'), y = x % 10, z = x / 10;
    
    // (1)
    dp[i][c] = rec(i - 1, z) + y;

    // (2)
    dp[i][c] = std::min(dp[i][c], rec(i - 1, z + 1) + (10 - y));

    return dp[i][c];
}

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

  std::cin >> S;

  n = S.size();

  memset(dp, -1, sizeof(dp));

  int mn = rec(n - 1, 0);
  std::cout << mn << std::endl;
}


Measured memory_bytes: 56092
from collections import Counter

N = int(input())
#S = [''.join(sorted(input())) for _ in range(N)]
S = [''.join(input())for _ in range (N)]
#print(S)
T=[''.join(sorted(S[x]))for x in range (N)]
#print(T)
count = Counter(T)
#print (count)
ans = sum(x*(x-1)//2 for x in count.values())
print(ans)

Measured memory_bytes: 26888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}


int main() {
  ll x;
  cin >> x;
  for(int i=-200; i<200; i++) {
      ll a=pow(i,5);
      for(int j=-200; j<200; j++) {
          ll b=pow(j,5);
          if(a-b==x) {
              cout << i << " " << j << endl;
              return 0;
          }
      }
  }
  return 0;
}


Measured memory_bytes: 4100
import java.util.ArrayList;
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        ArrayList<Integer> numbers = new ArrayList<>();
        int temp = 0;

        for (int i = 0; i < a; i++) {
            numbers.add(sc.nextInt());
        }

        int low = numbers.get(0);
        for (int i = 0; i < a; i++) {
            if (numbers.get(i) < low) {
                low = numbers.get(i);
            }
            if (numbers.get(i) <= low) {
                temp++;
            }
        }
        System.out.println(temp);
    }
}

Measured memory_bytes: 68960
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
    int n, a[105], i, j, t, ans = INF;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }

    for(i = -100; i <= 100; i++){
        t = 0;
        for(j = 0; j < n; j++){
            t += (i - a[j]) * (i - a[j]);
        }
        if(ans > t){
            ans = t;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

char G[1100][1100];
int dist[1100][1100];
queue<pair<int,int>> que;
// North, west, south, east
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};



int main(){
    int h, w;
    cin >> h >> w;
    int ans = 0;

    rep(i,h){
        rep(j,w){
            cin >> G[i][j];
            dist[i][j] = -1;
            if(G[i][j] == '#'){
                que.push(P(i,j));
                dist[i][j] = 0;
            }
        }
    }

    while(!que.empty()){
        P p = que.front();
        que.pop();

        rep(i,4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if(-1 < ny && ny < h && -1 < nx && nx < w && G[ny][nx] == '.' && dist[ny][nx] == -1 ){
                dist[ny][nx] = dist[p.first][p.second] + 1;
                que.push(P(ny,nx));
            }

        }

    }

    rep(i,h){
        rep(j,w){
            ans = max(ans, dist[i][j]);
        }
    }

    dunk(ans);
}

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

#define ll long long int
#define vi vector<int> 
ll prime(int i){

    int j=2;
    for(j=2;j<sqrt(i);j++){
        if(i%j==0)return 0;
        
    }
return 1;    
}




int main() {
  long long int a,b,c;
  cin >> a >>b >> c;
  if(a+b+c>=22)
  cout <<"bust";
  else cout <<"win";
    
}


Measured memory_bytes: 256
n, m = map(int, input().split())

a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    
check = [0 for i in range(m)]
for i,j in enumerate(a):
    for k in range(j[0]):
        check[a[i][k+1] - 1] += 1
        
print(check.count(n))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
#define ld long double
#define see(x) cout << (#x) << " " << x << endl;

const int N = 302;

int n, a[N];
ld dp[N][N][N];
				
int32_t main() {
	fast_cin();  
	cin >> n;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt1 += (a[i] == 1);
		cnt2 += (a[i] == 2);
		cnt3 += (a[i] == 3);
	}
	dp[0][0][0] = 0.0;
	for (int k = 0; k <= 300; k++) {
		for (int j = 0; j <= 300; j++) {
			for (int i = 0; i <= 300; i++) {
				if (i + j + k == 0) continue;
				ld &ans = dp[i][j][k];
				if (i > 0) ans += dp[i - 1][j][k] * i;
				if (j > 0) ans += dp[i + 1][j - 1][k] * j;
				if (k > 0) ans += dp[i][j + 1][k - 1] * k;
				ans += n;
				ans /= (i + j + k);
			}
		}
	}
	cout << fixed << setprecision(13);
	cout << dp[cnt1][cnt2][cnt3] << endl;
	return 0;
}

Measured memory_bytes: 430464
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - November 30
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int m1, d1, m2, d2;
  scanf("%d%d%d%d", &m1, &d1, &m2, &d2);

  printf("%d\n", (d2 == 1) ? 1 : 0);
  return 0;
}


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

typedef long long ll;
const int MAXN = 100010;

template<typename T> inline T read() {
	T x(0), f(1);
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, q, cnt;
ll x[MAXN], p[MAXN];
ll Min[MAXN], f[MAXN];
ll ans[MAXN];

void calc(ll len, ll times) {
	if(len == 0) return;
	int u = lower_bound(p+1, p+cnt+1, len)-p-1;
	if(u == 0) {
		ans[len] += times;
		return;
	}
	ll t = len/p[u];
	f[u] += t*times;
	calc(len%p[u], times);
}

int main() {
	n = read<int>(); q = read<int>();
	if(q == 0) {
		for(int i = 1; i <= n; i++) 
			printf("1\n");
		return 0;
	}
	for(int i = 1; i <= q; i++) x[i] = read<ll>();
	Min[q] = q;
	for(int i = q-1; i >= 1; i--) 
		Min[i] = x[Min[i+1]] < x[i] ? Min[i+1] : i;

	int t = Min[1];
	p[++cnt] = x[t];
	if(x[t] > n) t = 0, p[cnt] = n;
	while(t != q) {
		p[++cnt] = x[Min[t+1]];
		t = Min[t+1];
	}

	/*for(int i = 1; i <= cnt; i++)
		printf("%lld ", p[i]);
	printf("\n");
	int v = lower_bound(p+1, p+cnt+1, 4704325659258LL)-p-1;
	printf("%d\n", v);*/
	
	f[cnt] = 1;
	for(int i = cnt; i > 1; i--) {
		ll t = p[i]/p[i-1];
		f[i-1] += t*f[i];
		calc(p[i]%p[i-1], f[i]);
	}

	ans[p[1]] += f[1];
	for(int i = p[1]-1; i >= 1; i--) 
		ans[i] += ans[i+1];
	for(int i = 1; i <= n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int a,b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int [][] c = new int[3][3];
        
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                c[i][j] = Integer.parseInt(sc.next());
            }
        }
        int[] t = new int[6] ;
        t[0] = c[0][0] + c[1][1] + c[2][2];
        t[1] = c[0][1] + c[1][2] + c[2][0];
        t[2] = c[0][2] + c[1][0] + c[2][1];
        t[3] = c[0][2] + c[1][1] + c[2][0];
        t[4] = c[0][1] + c[1][0] + c[2][2];
        t[5] = c[0][0] + c[2][1] + c[1][2];
        
        String ans = "Yes";
        for(int i = 1;i<6;i++){
            if(t[i] != t[0]){
                ans = "No";
                break;
            }
        }
        System.out.println(ans);
    }
    
}

Measured memory_bytes: 22608
n = int(input())
l = list(map(int,input().split()))
ans = 0

for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
      if ((l[i] != l[j]) & (l[j] != l[k]) & (l[k] != l[i])):
        if(l[i]+l[j]>l[k]) & (l[j]+l[k] > l[i]) & (l[k] + l[i] > l[j]):
          ans += 1
        
print(ans)

Measured memory_bytes: 9212
#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 <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

bool field[25][25];

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string compass = "NESW";

int main(){
    int n, m;
    while(cin >> n, n){
        int ans = 0;
        int mx=10, my=10;
        for(int i=0; i < 25; i++)for(int j=0; j < 25; j++) field[i][j] = false;

        for(int i=0; i < n; i++){
            int p, q;
            cin >> p >> q;
            field[p][q] = true;
        }
        cin >> m;
        for(int i=0; i < m; i++){
            string p; int q;
            cin >> p >> q;
            int position;
            for(int j=0; j < 4; j++) if(compass.substr(j, 1) == p) position = j;

            for(int j=1; j <= q; j++){
                if(field[my+dy[position]*j][mx+dx[position]*j]){
                    ans++;
                    field[my+dy[position]*j][mx+dx[position]*j] = false;
                }
            }
            mx += dx[position]*q; my += dy[position]*q;
        }
        if(n == ans) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
//        long[] emp = new long[4001];
            

//        BufferedReader bReader =
//                new BufferedReader(new InputStreamReader(System.in));
        Scanner s = new Scanner(System.in); 

//        aryClear(emp);
        int empValue;
        while ((empValue = s.nextInt()) != 0) {
        	int overCount = 0, empID, n;
        	long price, quantitiy;
        	long total;

        	HashMap<Integer,Long> emp = new HashMap<Integer,Long>();
        	Queue<Integer> iQueue = new LinkedList<Integer>();

            n = 0;
            while (n < empValue) {
//                String str = bReader.readLine();
//                String[] editedstr = str.split(" ");
                empID = s.nextInt(); //Integer.parseInt(editedstr[0]);         //社員番号
                price = s.nextInt(); //Integer.parseInt(editedstr[1]);         //単価
                quantitiy = s.nextInt(); //Integer.parseInt(editedstr[2]);     //販売個数
                total = price * quantitiy;                      //実績

                if (!emp.containsKey(empID)) {                         //初めての入力
                    emp.put(empID, total);
                    iQueue.offer(empID);
                } else if (emp.get(empID) <= 1000000) {   //2回目以降の入力かつ100万を超えない値の場合
                    emp.put(empID, emp.get(empID) + total);
                    
                } else {
                }
                n++;
            }

//            for (int a : iQueue) {
            Integer a;
            while ((a = iQueue.poll()) != null) {
                //System.out.println(a);        //debug
                if (emp.get(a) >= 1000000) {
                    System.out.println(a);
                    overCount++;
                }
            }
            if (overCount == 0) {
                System.out.println("NA");
            }
            overCount = 0;
            iQueue.clear();
//            emp = new long[4001];
//            aryClear(emp);
            emp.clear();
        }
    }

    public static void aryClear(long[] ary) {
        for (int i = 0; i <= 4000; i++) {
            ary[i] = -1;
        }
    }
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    int *a = new int[n];

    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n, greater<int>());

    int A = 0, B = 0;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0)
            A += a[i];
        else 
            B += a[i];
    }

    cout << A - B << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

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

 	int t{},T{};
 	//cin>>t;T=t;
    t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        if(n<=2){
            cout<<0<<"\n";
            return 0;
        }
        F(i,0,n-2){
            F(j,i+1,n-1){
                F(p,j+1,n){
                    if(v[i]+v[j]>v[p]&&v[i]!=v[j]&&v[i]!=v[p]&&v[j]!=v[p])++ans;
                }
            }
        }
        cout<<ans<<"\n";
       
    }
    
    
	return 0;
}

Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String ns = String.valueOf(n);
            int a = 0;
            for (int i = 0; i < ns.length(); i++) {
                a += Integer.parseInt(ns.substring(i, i + 1));
            }

            String ans = n % a == 0 ? "Yes" : "No";
            out.println(ans);
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long i,j,t,a,b,n,c,y,m,prev,sum,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
       cin>>n;
       ans=0;
       long arr[n+1];
       for(i=1;i<=n;i++)
       cin>>arr[i];
       for(i=1;i<n;i++)
       {
           if(arr[i]==i)
           {
               swap(arr[i],arr[i+1]);
               ans++;
           }
       }
       if(arr[n]==n)ans++;
       cout<<ans;
    }
}

Measured memory_bytes: 1024
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int A = 100000, B = 100000, C = 100000;

int aa[A + B + C];

int main() {
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	c += b += a;
	for (int i = 0; i < c; i++)
		cin >> aa[i];
	sort(aa, aa + a);
	sort(aa + a, aa + b);
	for (int i = a - 1, j = b - y - 1; i >= a - x; i--, j--)
		aa[j] = aa[i];
	sort(aa + b - x - y, aa + c);
	long long ans = 0;
	for (int i = c - 1; i >= c - x - y; i--)
		ans += aa[i];
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4804
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	R := map[string]int{}
	for i := 0; i < N; i++ {
		R[sc.s()]++
	}

	fmt.Println("AC x ", R["AC"])
	fmt.Println("WA x ", R["WA"])
	fmt.Println("TLE x ", R["TLE"])
	fmt.Println("RE x ", R["RE"])

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<vector<int>> edges(n);
    for (int i = 0;i < n;++i) cin >> h[i];
    for (int i = 0;i < m;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    int ans = 0;
    for (int i = 0;i < n;++i) {
        bool f = true;
        for (int j : edges[i]) if (h[i] <= h[j]) f = false;
        ans += f;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8788
import java.util.*;
public class Main{
	public static int order(long a){
		int o=0;
		long d=1;
		while(d<=a){
			o++;d*=10;
		}
		return o;
	}
	public static int ABCNumber(char a){
		int num=-1;
		char[] abc= "abcdefghijklmnopqrstuvwxyz".toCharArray();
		for(int n=0;n<26;n++){
			if(a==abc[n])num=n;
		}
		return num;
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N =Integer.parseInt(sc.next());
		String[] S= new String[N];
		for(int i=0;i<N;i++){
			S[i]=sc.next();
		}
		
		int[] xmin= new int[26];
		for(int n=0;n<26;n++)xmin[n]=50;
		for(int i=0;i<N;i++){
			int[] x= new int[26];
			for(char a: S[i].toCharArray()){
				x[ABCNumber(a)]++;
			}
			for(int n=0;n<26;n++){
				xmin[n]=Math.min(xmin[n], x[n]);
			}
		}
		
		
		char[] abc= "abcdefghijklmnopqrstuvwxyz".toCharArray();
		StringBuilder sb= new StringBuilder();
		for(int n=0;n<26;n++){
			for(int cnt=0;cnt<xmin[n];cnt++)sb.append(abc[n]);
		}
		System.out.println(sb.toString());
		
		sc.close();
	}
}


Measured memory_bytes: 22604
<?php
	fscanf(STDIN,'%d',$x);
	$ans=1;
	for($i=2;$i*$i<=$x;$i++){
		$j=$i*$i;
		while($j<=$x){
			$ans=max($ans,$j);
			$j*=$i;
		}
	}
	echo $ans;
?>
   

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

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

    int n, ans = 0;

    cin >> n;

    n--;

    int arr[n][3];

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < 3; j++) {

            cin >> arr[i][j];
        }
    }

    for (int i = 0; i < n; i++) {

        ans = arr[i][1]+arr[i][0];

        for (int j = i+1; j < n; j++) {

            if (ans >= arr[j][1]) {

                if (ans%arr[j][2]) ans += arr[j][2]-(ans%arr[j][2]);

            } else {

                ans += arr[j][1]-ans;
            }

            ans += arr[j][0];
        }

        cout << ans << endl;
    }

    cout << 0;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        System.out.println(Math.min(k, n) * x + (n > k ? (n - k) * y : 0));
    }
}

Measured memory_bytes: 21716
x = int(input())
if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
elif 1800 <= x <= 1999:
    print(1)


Measured memory_bytes: 9040
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n, a[100];
	
	cin >> n;
	
	for (int i = 0; i < n; i++) cin >> a[i];
	
	sort(a, a + n);
	
	cout << a[n - 1] - a[0] << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int tmp;
    string s;
    cin >> n;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        tmp = s[i] - 'A';
        tmp += n;
        if(tmp>=26){
            tmp -= 26; 
        }
        s[i] = 'A' + tmp;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const long long m1=1e9+7;
long long  pow(long long a,long long n,long long m)
{
    long long ans=1;
    while(n){
        if(n&1){
            ans=(ans*a)%m;
        }
        a=(a*a)%m;
        n >>= 1;
    }
    return ans;
}
long long c(long long n,long long a)
{
	long long ans=1,ans1=1;
	for(long long i=n-a+1;i<=n;i++)
	{
		ans*=i%m1;ans%=m1;
	}
	
	for(long long i=2;i<=a;i++)
	ans1=(ans1*i)%m1;
	ans1=pow(ans1,m1-2,m1);
	return ((ans%m1)*ans1)%m1;
}

int main()
{
	long long n,a,b,ans2;
	cin>>n>>a>>b;
	ans2=pow(2,n,m1);
	ans2=(ans2-1+4*m1-c(n,a)-c(n,b))%m1;
	cout<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
v = [0 for i in range(n+1)]
v[0] = 1
r = [1]
p = a[0]
while v[p]==0:
  v[p] = 1
  r.append(p)
  if len(r)==k+1:
    break
  p = a[p-1]
if len(r)==k+1:
  print(p)
else:
  idx = r.index(p)
  k -= idx
  print(r[k%(len(r)-idx)+idx])


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

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

    int divX = X / 100;
    int modX = X % 100;
    
    if (divX >= 101) {
        cout << 1 << endl;
    }
    else if (modX <= divX * 5) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}

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

int main() {
  int n,x;
  cin>>n>>x;
  int d=0,count=1;
  int i=0,d_; 
  while(i<n){
    cin>>d_;
    d+=d_;
    //cout<<d<<endl;
    if(d<=x)count++;
    else{break;}
    i++;
  }
  cout<<count;
}
      

Measured memory_bytes: 256
n,k = map(int,input().split())
lis_tup = []
for _ in range(n):
  lis_tup.append(tuple(map(int,input().split())))
lis_tup.sort(key=lambda tup: tup[0])
i = 0
while(k>0):
  k -= lis_tup[i][1]
  i += 1
print(lis_tup[i-1][0])

Measured memory_bytes: 18192
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
int a[MN+5];
int main()
{
	int n,k,i,ans=1e9;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=1;i<=n-k+1;++i)
	{
		int l=max(-a[i],0),r=max(a[i+k-1],0);
		ans=min(ans,2*min(l,r)+max(l,r));
	}
	printf("%lld",ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n; 
    map<string,ll> s;
    rep(i,0,n)
    {
        string ss;
        cin >> ss;
        s[ss]++;
    }

    cout << "AC x " << s["AC"] << endl 
         << "WA x " << s["WA"] << endl
         << "TLE x " << s["TLE"] << endl 
         << "RE x " << s["RE"] << endl;

    return 0;
}


Measured memory_bytes: 3652
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int h1, w1, h2, w2;
  readf("%s %s\n%s %s\n", &h1, &w1, &h2, &w2);
  writeln(h1 * w1 - (h2 * w1 + w2 * h1 - w2 * h2));
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main(void){
    int x,h;
    while(true){
        cin>>x>>h;
        if(x==0&&h==0)
            break;
        double s=x*x;
        s+=x*2*(double)sqrt((double)x*x/4+h*h);
        cout<<fixed<<setprecision(6)<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    for (auto i : irange(1uL, s.size())) {
        if (s[i - 1] == s[i]) {
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/
ll const MAX = 1e5 + 5;
ll a[MAX];
ll dp[105][MAX] = {};
ll sumx[MAX];
ll const MOD = 1e9 + 7;

ll mod_p(ll x, ll y) {
	return (x + y + MOD) % MOD;
}

int main() {
	ll n, k;
	cin >> n >> k;
	REP(i, 1, n) {
		cin >> a[i];
	}

	dp[0][k] = 1;
	REP(i, 0, n - 1) {
		REP(j, 0, k) {
			dp[i + 1][j] = mod_p(dp[i + 1][j], dp[i][j]);
			if (j - a[i + 1] - 1 >= 0) {
				dp[i + 1][j - a[i + 1] - 1] = mod_p(dp[i + 1][j - a[i + 1] - 1], MOD - dp[i][j]);
			}
		}
		PER(j, k - 1, 0) {
			dp[i + 1][j] = mod_p(dp[i + 1][j], dp[i + 1][j + 1]);
		}
	}
	cout << dp[n][0] << endl;
}

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

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int dp[210];

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> n && n)
	{
		PArray arr;
		for (int i = 0; i < n; i++)
		{
			int h, r; cin >> h >> r;
			arr.emplace_back(h, r);
		}
		cin >> m;
		for (int i = 0; i < m; i++)
		{
			int h, r; cin >> h >> r;
			arr.emplace_back(h, r);
		}

		sort(ALL(arr), [&](const P& p1, const P& p2){
			return p1.first != p2.first ? p1.first < p2.first
				: p1.second != p2.second ? p1.second > p2.second
				: false;
		});
		fill(dp, dp + n + m, INF);
		for (int i = 0; i < n + m; i++)
		{
			*(lower_bound(dp, dp + n + m, arr[i].second)) = arr[i].second;
		}
		cout << (lower_bound(dp, dp + n + m, INF) - dp) << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	private static void print(String[] A){
		System.out.println(String.join(" ",A));
	}
	
	public static void selectionSort(String[] A){ // N??????????´??????????0-?????????????????????
		for(int i =0;i< A.length;i++){
			int mini = i;
			for(int j = i;j< A.length;j++){
				 if(Integer.parseInt(A[j].substring(1, 2))<Integer.parseInt(A[mini].substring(1, 2))){
					 mini = j;
				 }
			}
			if(mini!=i){
				String w=A[i];
				A[i]=A[mini];
				A[mini]=w;
			}
		}
		print(A);
	}
	
	private static void BubbleSort(String[] A){
		 for(int i = 0;i<=A.length-1;i++){
		     for(int j = A.length-1;j>=i+1;j--){
		    	 if(Integer.parseInt(A[j].substring(1, 2))<Integer.parseInt(A[j-1].substring(1, 2))){
		             String w=A[j];
		             A[j]=A[j-1];
		             A[j-1]=w;
		         }
		     }
		 }
		 print(A);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
       // System.out.println("0".compareTo("1"));
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
            	int[] A=new int[Integer.parseInt(line)];
            	line=br.readLine();
            	String[] str=line.split(" ");
            	String[] str2=line.split(" ");
            	BubbleSort(str);
            	System.out.println("Stable");
            	selectionSort(str2);
            	if(Arrays.equals(str,str2)){
            		System.out.println("Stable");
            	}else{
            		System.out.println("Not stable");
            	}
            	
            	break;
            }
        }
	}

}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

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

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

ll dp[105][4][2];

int main()
{
	ll K;
	string s;
	cin >> s >> K;
	ll n=s.size();
	dp[0][0][0]=1;
	rep(i,n){
		rep(j,4){
			rep(k,2){
				ll nd=s[i]-'0';
				rep(d,10){
					ll ni=i+1;
					ll nj=j;
					ll nk=k;
					if(d!=0) nj++;
					if(nj>K) continue;
					if(k==0){
						if(d>nd) continue;
						if(d<nd) nk=1;
					}
					dp[ni][nj][nk]+=dp[i][j][k];
				}
			}
		}
	}
	cout << dp[n][K][0]+dp[n][K][1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 100001
#define ll long long
using namespace std;

struct Node{
    ll a;
    ll b;
};

int main(){
    int n;
    ll g;
    cin>>n>>g;
    
    struct Node data[n];
    
    for (int i=0; i<n; i++){
        cin>>data[i].a>>data[i].b;
    }
    

    
    vector<ll> ans;
    for (int bit = 0; bit < (1<<n); ++bit){
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i))  S.push_back(1);
            else S.push_back(0);
        }
        
        ll memo=0;
        ll sum=0;
        ll max=0;
        
        for (int i=0; i<n; i++){
            if (S[i]==1){
                sum+=100*(i+1)*data[i].a+data[i].b;
                memo+=data[i].a;;
            }
            else max=i;
        }
        
        if (sum>=g) ans.push_back(memo);
        else{
            ll p=g-sum;
            ll q=(data[max].a-1)*100*(max+1);
            ll r=(max+1)*100;
            if (p<=q){
                if (p%r==0) memo+=p/r;
                else memo+=p/r+1;
                ans.push_back(memo);
            }
        }
    }
    sort(ans.begin(),ans.end());
    
    cout<<ans[0]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;
typedef pair<ll, ll> P;
typedef vector<P> VP;

int main() {
  ll a, b;
  ll res = 0;

  cin >> a >> b;
  while(true) {
    if(a & 3 != 0) {
      res ^= a;
      a++;
    } else {
      break;
    }
  }
  ll d = (b - a + 1) / 4;
  a += 4 * d;
  if(a <= b) {
    while(true) {
      res ^= a;
      if(a == b) break;
      a++;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi d(n);
	int jump = 0;
	bool can = true;
	rep(i, 0, n) {
		cin >> d[i];
		jump = max(jump, 10 * i + d[i]);
		if (jump < 10 * (i + 1)) can = false;
	}
	if (!can) {
		cout << "no\n";
		return 0;
	}
	jump = 0;
	reverse(all(d));
	rep(i, 0, n) {
		jump = max(jump, 10 * i + d[i]);
		if (jump < 10 * (i + 1)) {
			cout << "no\n";
			return 0;
		}
	}
	cout << "yes\n";
	return 0;
}


Measured memory_bytes: 3868