akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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; }

// ダブリング
const int D = 60;
const int MAX_N = 200200;
// 2^i個辿った先を記録していく
int to[D][MAX_N];

int main() {
    int n; long long k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> to[0][i];
        to[0][i]--;
    }

    for(int i = 0; i < D-1; ++i) {
        for(int j = 0; j < n; ++j) {
            to[i+1][j] = to[i][to[i][j]];
        }
    }

    int v = 0;
    for(int i = D-1; i >= 0; --i) {
        long long l = 1LL<<i;
        if(l <= k) {
            v = to[i][v];
            k -= l;
        }
    }

    cout << v+1 << endl;
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    string s[4];
    s[0]="AC";
    s[1]="WA";
    s[2]="TLE";
    s[3]="RE";
    
    int c0=0,c1=0,c2=0,c3=0;
    
    for(int i=0;i<n;i++)
    {
        string t;
        cin>>t;
        if(t[0]=='A')
            c0++;
        else if(t[0]=='W')
            c1++;
            else if(t[0]=='T')
            c2++;
            else if(t[0]=='R')
            c3++;
            }
    cout<<s[0]<<" x  "<<c0<<"\n";
    cout<<s[1]<<" x  "<<c1<<"\n";
    cout<<s[2]<<" x  "<<c2<<"\n";
    cout<<s[3]<<" x  "<<c3<<"\n";
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <deque>
using namespace std;
#define rep(i,n) for (ll i=0;i<n;i++)
typedef long long ll;

string S;
ll Q;
ll F[210000];
char C[210000];
ll q[210000];

int main() {
	cin >> S;
	cin >> Q;
	ll nobi = 0;
	rep(i, Q) {
		cin >> q[i];
		if (q[i] == 2) {
			cin >> F[i] >> C[i];
			nobi++;
		}
		else F[i] = 0;
	}
	vector<char> dq(S.size());
	rep(i, S.size()) dq[i] = S[i];
	bool now = true;
	rep(i, Q) {
		if (now) {
			if (F[i]==0) {
				now = false;
			}
			else if (F[i] ==1) dq.insert(dq.begin(), C[i]);
			else dq.insert(dq.end(), C[i]);
		}
		else {
			if (F[i] == 0) {
				now = true;
			}
			else if (F[i] == 1) {
				dq.insert(dq.end(), C[i]);
			}
			else {
				dq.insert(dq.begin(), C[i]);
			}
		}
	}
	if (!now) reverse(dq.begin(), dq.end());
	rep(i, dq.size()) cout << dq[i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 4412
s = input().split()  # s[0]は敵の数, s[1]は必殺技が使える数
s2 = list(map(int, input().split()))  # 敵の体力
s2_n = sorted(s2, reverse=True)[int(s[1]):]
# print(sum(s2))
print(sum(s2_n))


#
# if sum(s2) >= int(s[0]):
#     print("Yes")
# else:
#     print("No")


Measured memory_bytes: 26180
#include <stdio.h>

#define NMAX 25
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[NMAX];

int n,Depth[NMAX],Height[NMAX];

void Setdepth(int,int);
int Setheight(int);
int Getsib(int);
void print(int);

int main(void){
  int i,value,l,r,root = 0;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    T[i].parent = NIL;
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&value,&l,&r);
    T[value].left = l;
    T[value].right = r;
    if(l != NIL) T[l].parent = value;
    if(r != NIL) T[r].parent = value;
  }

  for(i = 0;i < n;i++){
    if(T[i].parent == NIL){
      root = i;
    }
  }
  Setdepth(root,0);
  Setheight(root);

  for(i = 0;i < n;i++){
    print(i);
  }

  return 0;
}

void Setdepth(int u,int d){
  if(u == NIL) return;
  Depth[u] = d;
  Setdepth(T[u].left,d + 1);
  Setdepth(T[u].right,d + 1);
}

int Setheight(int u){
  int h1 = 0,h2 = 0;
  if(T[u].left != NIL){
    h1 = Setheight(T[u].left) + 1;
  }
  if(T[u].right != NIL){
    h2 = Setheight(T[u].right) + 1;
  }
  return Height[u] = (h1 > h2 ? h1 : h2);
}

int Getsib(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,Getsib(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, depth = %d, height = %d, ",deg,Depth[u],Height[u]);
  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}
							       



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

void solve(float a, float b, float c, float d, float e, float f, float* x, float* y) {
  *y = (c * d - a * f) / (b * d - a * e);
  *x = (c * e - b * f) / (a * e - b * d);
}

float zero(float x) {
  if (fabsf(x) < 0.0001) {
    return 0;
  } else {
    return x;
  }
}

int main() {
  float a, b, c, d, e, f;
  while (scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF) {
    float x, y;
    solve(a, b, c, d, e, f, &x, &y);
    printf("%.3f %.3f\n", zero(x), zero(y));
  }
  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define sum(x,y) que(1,1,n,x,y)
#define change(x,y,z) chan(1,1,n,x,y,z)
#define add(x,y,z) Plus(1,1,n,x,y,z)
#define mid (l+r>>1)
using namespace std;
long long sum[400000],fg[400000],ad[400000];
long long n,m,a,b; 
void down(int now,int l,int r)
{
    if(fg[now])
    {
        fg[now]+=ad[now];
        fg[now<<1]=fg[now];
        fg[now<<1|1]=fg[now];
        ad[now]=ad[now<<1]=ad[now<<1|1]=fg[now]=0;
        sum[now<<1]=fg[now<<1]*(mid-l+1);
        sum[now<<1|1]=fg[now<<1|1]*(r-mid);
    }
    if(ad[now])
    {
        ad[now<<1]+=ad[now];
        ad[now<<1|1]+=ad[now];
        sum[now<<1]+=ad[now]*(mid-l+1);
        sum[now<<1|1]+=ad[now]*(r-mid);
        ad[now]=0; 
    }
}
void updata(int now)
{
    sum[now]=sum[now<<1]+sum[now<<1|1];
}
void chan(int now,int l,int r,int x,int y,long long z)
{
    if(l==x && r==y)
    {
        fg[now]=z;
        ad[now]=0;
        sum[now]=z*(r-l+1);
        return;
    }
    down(now,l,r);
    if(x<=mid)
        chan(now<<1,l,mid,x,min(mid,y),z);
    if(y>mid)
        chan(now<<1|1,mid+1,r,max(mid+1,x),y,z);
    updata(now);
}
void Plus(int now,int l,int r,int x,int y,long long z)
{
    if(l==x && r==y)
    {
        ad[now]+=z;
        sum[now]+=z*(r-l+1);
        return;
    }
    down(now,l,r);
    if(x<=mid)
        Plus(now<<1,l,mid,x,min(mid,y),z);
    if(y>mid)
        Plus(now<<1|1,mid+1,r,max(mid+1,x),y,z);
    updata(now);
}
long long que(int now,int l,int r,int x,int y)
{
    if(l==x && r==y)
        return sum[now];
    down(now,l,r);
    long long ret=0;
    if(x<=mid)
        ret+=que(now<<1,l,mid,x,min(y,mid));
    if(y>mid)
        ret+=que(now<<1|1,mid+1,r,max(x,mid+1),y);
    return ret;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%lld",&a,&b);
        int l=1,r=a;
        for(;l<r;)
            if(sum(mid,mid)*(a-mid+1)-sum(mid,a)<=b)
                r=mid;
            else
                l=mid+1;
        b-=sum(l,l)*(a-l+1)-sum(l,a);
        change(l,a,sum(l,l));
        add(l,a,b/(a-l+1));
        if(b%(a-l+1))
        add(l,l+b%(a-l+1)-1,1);
    }
    for(int i=1;i<=n;i++)
        printf("%lld\n",sum(i,i));
    return 0;
}

Measured memory_bytes: 9856
#include<stdio.h>
int main()
{
    char S[4],t[4];
    int i,c=0;
   scanf("%s",S);
   scanf("%s",t);
    for(i=0;i<3;i++)
    {
        if(S[i]==t[i])
            c++;
    }
    printf("%d\n",c);
    return 0;

}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define MAX 999999999

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

typedef long long ll;

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

    string s;
    cin >> s;

    cout << s[0] << s.end() - s.begin() - 2 << *(s.end()-1) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main() {
  
  int x,y,t;
  int i;
  
  while(1) {
  scanf("%d %d",&x,&y);
  if(x*y == 0) break;
  
  if(y >=x) {
    t = y;
    y = x;
    x = t;
  }
  
  i= 0;
  while(1) {
    i++;
    x = x % y;
  
    t =x;
    x = y;
    y = t;
  
    if(y == 0) break;
  
  }
  
  printf("%d %d\n",x,i);

  }
  
  return 0;
  
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
unsigned long long i,j,n,m,x,k,y,a,b;
int main()
{
    std::cin.sync_with_stdio(false);
    cin >> n;
    i=1;
    while (i<=n&&i<10)
    {
        cout << i <<endl;   
        i++;
    }
    m=9;
    x=10;
    while (i<=n)
    {
        m+=x;
        cout << m << endl;
        k=m+x;
        y=0;
        while (k>0)
        {
            y+=k%10;
            k/=10;
        }
        a=m+x*10;
        b=0;
        while (a>0)
        {
            b+=a%10;
            a/=10;
        }
        if ((m+x*10)*y<=(m+x)*b)
        {
            x*=10;
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*; 
 
public class Main{  
  public static void main (String [] args){    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int d[] = new int [N];
    for(int i=0; i<N; i++){
      d[i]=sc.nextInt();
    }
    Arrays.sort(d);
    for(int i=0; i<N; i++){
      System.out.println(d[N/2]-d[N/2-1]);
      break;
    }
  }
}
    
    


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

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1
    r[y - 1] = r[x - 1] | r[y - 1]
    if not l[x - 1]:
        r[x - 1] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)


Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int mod = 1000000007;
int a[200006], b[200006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i] >> b[i];

	vector<int>A, B;
	rep(i, n) { A.push_back(a[i]); B.push_back(b[i]); }
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	if (n & 1) {
		cout << B[n / 2] - A[n / 2] + 1 << endl;
	}
	else {
		cout << -A[n / 2] + B[n / 2] - A[n / 2 - 1] + B[n / 2 - 1] + 1 << endl;
	}
}

Measured memory_bytes: 9704
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var output = new System.Text.StringBuilder(200000);
            int count = 0;
            for(string input; (input = Console.ReadLine()) != "0"; output.AppendLine("Case " + ++count + ": " + input));
            Console.Write(output.ToString());
        }
    }
}

Measured memory_bytes: 6492
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include<string>
using namespace std;
long long a[100004];
 long long yueshuo(long long x,long long y)
 {
     long long a,b,t;
     a=x,b=y;
     if(x>y)
     {
         t=x;
         x=y;
         y=t;
     }
     while(b)
     {
         t=a%b;
         a=b;
         b=t;
     }
     return a;
 }
int main()
{
    long long  n,x,t,maxs,mins;
    int i,j,k,step;
    cin>>n>>x;
    a[0]=x;
    for(i=1; i<=n; i++)
    {
           cin>>a[i];
    }
    sort(a,a+n+1);
    t=a[1]-a[0];
    for(j=1;j<=n;j++)
    {
        t=yueshuo(t,a[j]-a[j-1]);
    }
    cout<<t<<endl;
    return 0;
    }


Measured memory_bytes: 1024
#include <iostream>

#define int long long

using namespace std;

const int N = 20, K = 20;

int a[N][N], c[N];

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 0; i < n; ++i)
    {
        cin >> c[i];
        for (int j = 0; j < m; ++j) cin >> a[i][j];
    }
    int ans = 1e18;
    for (int mask = 0; mask < (1 << n); ++mask)
    {
        int lvl[m] = {0};
        int cost = 0;
        for (int i = 0; i < n; ++i)
        {
            if (mask & (1 << i))
            {
                cost += c[i];
                for (int j = 0; j < m; ++j) lvl[j] += a[i][j];
            }
        }
        bool b = 0;
        for (int i = 0; i < m; ++i)
        {
            if (lvl[i] < x)
            {
                b = 1;
                break;
            }
        }
        if (b) continue;
        ans = min(ans, cost);
    }
    if (ans == 1e18) cout << -1;
    else cout << ans;
    return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9 + 7
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    for(int i =0;i<n;i++){
        cin>>h[i];
    }
    vector<int> dp (n, INF);
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i = 2;i<n;i++){
        for(int j = max(0,i-k);j<i;j++){
            dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

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

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

int main() {
    int N, M;
    cin >> N >> M;
    if(N == M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,i,a[100];
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;--i){
		printf("%d",a[i]);
		if(i>0){
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<pair<ll, ll>> XY;
map<pair<ll, ll>, ll> M;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll x, y;
        cin >> x >> y;
        XY.push_back(make_pair(x, y));
    }
    sort(XY.begin(), XY.end());
    for(int i=0;i<N-1;i++) {
        for(int j=i+1;j<N;j++) {            
            ll dx = XY[j].first-XY[i].first;
            ll dy = XY[j].second-XY[i].second;
            M[make_pair(dx, dy)]++;
        }
    }
    for(map<pair<ll, ll>, ll>::iterator itr=M.begin();itr!=M.end();itr++) {
        pair<pair<ll, ll>, ll> tmp = *itr;
        ans = max(ans, tmp.second);
    }
    cout << N-ans << endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<long long> fizzbuzz(n+1);

    for (size_t i = 1; i <= n; i++) fizzbuzz[i] = i;
    for (size_t i = 1; i <= 5; i++) {
        if (i != 3 && i != 5) continue;
        int m = i;
        while (m <= n) {
            fizzbuzz[m] = -1;
            m += i;
        }
    }

    long long ans = 0;
    for (size_t i = 1; i <= n; i++) {
        if (fizzbuzz[i] != -1) {
            ans += fizzbuzz[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11052
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int a[100010], b[100010];
ll c[100010], n, m;


template <typename T>
struct UnionFind{
    vector<T> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool connected(T x, T y){
        x = find(x), y = find(y);
        if (x == y) return true;
        else return false;
    }

    bool unite(T x, T y){
        x = find(x), y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int find(T k){
        if (data[k] < 0) return k;
        return (data[k] = find(data[k]));
    }

    T size(T k){
        return (-data[find(k)]);
    }
};

int main(){
    cin >> n >> m;
    UnionFind<ll> uf(n);
    for (int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    c[m] = n * (n - 1) / 2;
    for (int i = m - 1; i > 0; i--){
        if (uf.connected(a[i], b[i])){
            c[i] = c[i + 1];
        }
        else{
            c[i] = c[i + 1] - uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }
    for (int i = 1; i <= m; i++){
        cout << c[i] << endl;
    }
}


Measured memory_bytes: 3712
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end



def dfs(i, p=-1, c=-1)
  color = 1
  @g[i].each do |j|
    next if j == p
    color += 1 if c == color
    a, b = i, j
    a, b = a, b if a > b
    
    @edge[[a,b]] = color
    dfs(j, i, color)
    color += 1
  end
end

N=gets.to_i
AB=(N-1).times.map{gets.split.map(&:to_i)}

=begin
N = 10**5
ab=[]
(N-1).times do |i|
  ab << [i+1, i+2]
end
AB=ab
=end

@g = Array.new(N){[]}
g_n = Array.new(N, 0)
edge_i = Array.new(N-1)
(N-1).times do |i|
  a, b = AB[i][0]-1, AB[i][1]-1
  @g[a] << b
  @g[b] << a
  g_n[a] += 1
  g_n[b] += 1
  edge_i[i] = [a,b]
end

@edge = Hash.new()
dfs(0)

puts g_n.max
edge_i.each do |a,b|
  puts @edge[[a,b]]
end

Measured memory_bytes: 144712
N = int(input())
a = []
a = list(map(int,input().split()))
index = 0
count = 0
searchNum = 1
if not 1 in a:
    count = -1
else:
    for j in range(N):

        if a[j] ==searchNum:
            searchNum += 1
            continue
        else:
            count +=1
print(count)



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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  bool ok = false;
  REP(i, 0, N) {
    if (A[i] % 2 == 1) ok = true;
  }
  cout << (ok ? "first" : "second") << endl;
}

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

int main () {
	cin.sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
		
	// do this q times.
	for (int q = 0; q < k; q++) {
		bool maxed = true;
		vector<int> p(n+1, 0);
		for (int i = 0; i < n; i++){
			if (a[i] < n) maxed = false;

			int s = i - a[i];
			int e = i + a[i] + 1;
			if (s < 0) s = 0;
			if (e >= n) e = n;
			p[s]++;
			p[e]--;
		}
		if (maxed) break;
		
		for (int i = 0; i < n; i++) {
			a[i] = 0;
			a[i] += p[i];
			if (i > 0) a[i] += a[i-1];
		}
	}

	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i < n-1) cout << " ";
	}
	cout << endl;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 500 + 10;
const int M = (int) 1e6 + 10;
const int K = (int) 500 + 10;
const int INF = (int) 1e9 + 7;
//const int mod = (int) 1e9 + 7;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, k, mod;
int c[N][N], dp[N][N], suff[N][N];

void add(int &x, int y) {
	x += y;
	if (x >= mod)
		x -= mod;
	if (x < 0)
		x += mod;
}

int mult(int x, int y) {
	return x * 1ll * y % mod;
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output1.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n >> k >> mod;
	for (int i = 0; i <= n; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			add(c[i][j] = c[i - 1][j], c[i - 1][j - 1]);
		}
	}
	//cout << "Hello, World!\n";
	for (int cnt = 1; cnt <= n + 1; cnt++) {
		for (int x = 0; x <= k; x++) {
			if (cnt == 1) {
				dp[cnt][x] = 1;
				continue;
			}
			int cur = 0;
			for (int sub_tree = 1; sub_tree < cnt; sub_tree++) {
				add(cur, mult(suff[sub_tree][x + 1], mult(dp[cnt - sub_tree][x], c[cnt - 2][sub_tree - 1])));	
			}
			dp[cnt][x] = cur;
		}
		for (int x = k; x >= 0; x--) {
			add(suff[cnt][x] = suff[cnt][x + 1], dp[cnt][x]);
		}
	}
	cout << dp[n + 1][0];
	return 0;
}

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


int pow(int a, int b) {
	int q = 1 ;
	if (b == 0)
		return q ;
	else {
		for (int i = 0; i < b; i++)
			q *= a ;
		return q ;
	}
}

int main(void) {
	int D, N ;

	cin >> D >> N ;

	if (N == 100)
		N = 101 ;
	int q = pow(100, D) * N ;

	cout << q << endl ;

	return 0 ;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N;
    Scll(N);

    char s[13131];
    Scs(s);

    ll ans = 0;

    // A & ~B
    Repe(d,N,1) Rep(i,N){
        if( i+d+d >= N ) break;
        if( s[i] != s[i+d] && s[i] != s[i+d+d] && s[i+d] != s[i+d+d] ){
            ans++;
        }
    }

    int cti[1231];
    cti['R'] = 0;
    cti['G'] = 1;
    cti['B'] = 2;
    // A
    ll a2 = 0;
    vector<vi> v(3,vi(N+1));
    Rep(i,N){
        v[cti[s[i]]][i]++;
    }
    Rep(si,3) RRep(i,N){
        v[si][i] += v[si][i+1];
    }
    Rep(i,N){
        if( s[i] == 'R' ){
            Repe(j,N,i+1){
                if( s[j] == 'G' ) a2 += v[2][j+1];
                if( s[j] == 'B' ) a2 += v[1][j+1];
            }
        }
        if( s[i] == 'G' ){
            Repe(j,N,i+1){
                if( s[j] == 'R' ) a2 += v[2][j+1];
                if( s[j] == 'B' ) a2 += v[0][j+1];
            }
        }
        if( s[i] == 'B' ){
            Repe(j,N,i+1){
                if( s[j] == 'G' ) a2 += v[0][j+1];
                if( s[j] == 'R' ) a2 += v[1][j+1];
            }
        }
    }

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


    return 0;
}



Measured memory_bytes: 3856
def main():
    N = int(input())
    S = input().split()

    kind_set = set()
    for s in S:
        kind_set.add(s)

    length = len(kind_set)
    if length == 3:
        print("Three")
    elif length == 4:
        print("Four")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
using System;

namespace AOJ.ITP
{
    public class Transformation
    {
        public static void Main()
        {
            string test = Console.ReadLine();
            int cnt = int.Parse(Console.ReadLine());
            for (int i = 0; i < cnt; i++)
            {
                var order = Console.ReadLine().Split(' ');
                int from = int.Parse(order[1]);
                int to = int.Parse(order[2]);
                if (order[0] == "print")
                {
                    Console.WriteLine(test.Substring(from, to - from + 1));
                }
                else if (order[0] == "reverse")
                {
                    // ループ回数
                    int loop = to - from + 1;
                    
                    string new_test = test.Substring(0, from);
                    for (int j = 0; j < loop; j++)
                    {
                        new_test += test.Substring(to - j, 1);
                    }
                    new_test += test.Substring(to + 1);
                    test = new_test;
                }
                else
                {
                    string after = order[3];
                    string new_test;
                    if (from == 0) { new_test = ""; }
                    else { new_test = test.Substring(0, from); }
                    new_test += after;
                    new_test += test.Substring(to + 1);
                    test = new_test;
                }
            }
        }
    }
}

Measured memory_bytes: 17580
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n"  // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (int i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*printf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (int i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (int i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long true_rand(long long n)
{
	// Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<long long> uid(0, n - 1);
    return uid(rng);
}

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b>>1);
	res = (res*res)%mod;
	if (b&1LL)
		res = (res*a)%mod;
	
	return res;
}

const int N = 1e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int h, w;
	cin >> h >> w;
	char a[h + 5][w + 5] = {};

	int vis[h + 5][w + 5] = {};
	queue<pair<int, int> > q;
	
	forl(i, 0, h)
	{
		forl(j, 0, w)
		{
			cin >> a[i][j];
			if (a[i][j] == '.')
				continue;
			q.push({i, j});
			vis[i][j] = 1;
		}
	}
	int dx[] = {1, -1, 0, 0};
	int dy[] = {0, 0, 1, -1};


	while (!q.empty())
	{
		pr u = q.front();
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int tx = u.ff + dx[i];
			int ty = u.ss + dy[i];
			if (tx < 0 || tx >= h)
				continue;
			if (ty < 0 || ty >= w)
				continue;
			if (vis[tx][ty])
				continue;

			vis[tx][ty] = vis[u.ff][u.ss] + 1;
			q.push({tx, ty});
		}
	}
	int ans = 0;
	forl(i, 0, h)
	{
		forl(j, 0, w)
		{
			ans = max(ans, vis[i][j]);
		}
	}
	--ans;
	cout << ans << "\n";

	return 0;
}

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

int n, k;
long long A[100000];

int V(long long P){
    int s = 0;
    for(int i = 0; i < k; i++){
        long long t = 0;
        while(t + A[s] <= P){
            t += A[s];
            s++;
            if(s == n) return n;
        }
    }
    return s;
}

int ans(){
    long long left = 0;
    long long right = 100000 * 10000;
    long long mid;
    while(right > left + 1 ){
        mid = (right + left)/2;
        int v = V(mid);
        if(v >= n) right = mid;
        else left = mid;
    }
    
    return right;
}



int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> A[i];
    long long ans1 = ans();
    cout << ans1 << endl;
    
    return 0;
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}


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

int main () {
  int a , b , k ;
  cin >> a >> b >> k ;
  int pre = 0 ;
  int ans = 0 ;
  for(int i = max(a,b) ; i > 0 ; i-- ){
    if( a % i == 0 && b % i == 0 ) pre++ ;
    if(pre == k ) {
      ans = i ;
      break ;
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8-*-
if __name__ == '__main__':
    A, B = map(int ,input().split(" "))
    if A % 2 == 0:
        if B % 2 == 1:
            t = (B-A+1)//2
            print(t%2)
        else:
            t = (B-A)//2
            print((t%2)^B)
    else:
        if B % 2 == 1:
            t = (B-A)//2
            print((t%2)^A)
        else:
            t = (B-A-1)//2
            print((t%2)^A^B)


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

signed main(void)
{
	string s;
	int ans_i, ans_j;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'A')
		{
			ans_i = i;
			break;
		}
	}
	for (int i = s.size() - 1; i >= 0; i--)
	{
		if (s[i] == 'Z')
		{
			ans_j = i;
			break;
		}
	}
	cout << ans_j - ans_i + 1 << endl;
	return 0;
}


Measured memory_bytes: 640
# include "iostream"
# include "cstdio"
# include "cstring"

using namespace std;

const int maxm=100+10; 
char s[maxm];
int tot; 
int main(){
	register int i,j; 
	int k;
	scanf("%s%lld",s+1,&k);
	tot=strlen(s+1); 
	for(i=1;i<=tot;i++){
		if(s[i]=='1'){ 
			k--;
			if(k==0){
				printf("1");
				return 0; 
			}
			continue; 
		}else{
			printf("%c",s[i]);
			return 0; 
		}
	} 
	return 0;
} 

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

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

    int len = S.length();
    int count=0;
    rep(i,len){
        if(S.at(i)!=T.at(i)) {++count;}
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    map<int,int> cnt;
    ll ans = 0;
    rep(i,N){
        ans+=cnt[i-A[i]];
        cnt[A[i] + i]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 21860
S=input()
N=len(S)

T=[]
T.append(0)
tmp=""
d=[0 for _ in range(2019)]
d[0]=1
r=0
t=1
for i in range(N):
    s=S[N-1-i]
    r+=int(s)*t
    r%=2019
    t*=10
    t%=2019
    d[r]+=1

ans=0
for i in d:
    ans+=((i*(i-1))//2)

print(ans)

Measured memory_bytes: 9368
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
using T = tuple<int,int,int>;

#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
#define endl '\n'
#define int long long
#define INF 1e18
#define ss second
#define ff first

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;

int a[up],b[up];

void solve()
{
    int m=2019;
    string s;
    cin>>s;
    map<int,int>mp;
    int pw=1,ans=0,now=0;
    mp[0]++;
    revn(i,sz(s)-1,0)
    {
        now+=(s[i]-'0')*pw;
        now%=m;
        pw*=10 ;
        pw%=m;
        ans+=mp[now];
        mp[now]++;
    }
    cout<<ans<<endl;
}


int32_t main()
{
    fast_cin();
    int t;
    // memset(prime, true, sizeof(prime)); 
    // sieve();
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    //cout<<ans<<endl;
}



Measured memory_bytes: 3604
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

    int n; cin>>n;

    ll ans = 0;
    vi a(n);
    for(int &x : a)cin>>x;

    if(n == 1){
        cout<<0<<"\n";
        return 0;
    }
    
    
    sort(all(a), greater<int>());
    if(n == 2){
        cout<<a[0]<<"\n";
        return 0;
    }

    ans = a[0];

    priority_queue<pii> pq;

    pq.push({a[1], a[0]});
    pq.push({a[1], a[0]});

    for(int i = 2; i < n; i++){
        auto pr = pq.top(); pq.pop();
        ans += pr.first;
        //cout<<pr.first<<" "<<pr.second<<"\n";
        pq.push({a[i], pr.first});
        pq.push({a[i], pr.second});
    }
    cout<<ans<<"\n";
}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

ll dp[1005][1005],fac[1005][1005],inv[1005][1005];
int a,b,c,d;
ll nck(int n,int y){
  return fac[n][1]*inv[y][1]%mod*inv[n-y][1]%mod;
}
ll get(int tot,int mx){
  if(tot==0){
    return 1;
  }
 // printf("zz%d %d\n",tot,mx);
  if(mx<a) return 0;
  if(dp[tot][mx]!=-1) return dp[tot][mx];
  ll &ret=dp[tot][mx]; ret=0;

  ret=get(tot,mx-1);
  if(mx<=b){
    REPP(i,c,d+1){
      if(tot-mx*i<0) break;
      ret+=nck(tot,mx*i)*fac[mx*i][1]%mod*inv[mx][i]%mod*inv[i][1]%mod*get(tot-mx*i,mx-1)%mod;
 //     printf("%d %d %lld \n",tot,mx,ret);//,nck(tot,mx*i),fac[mx*i][1],inv[mx][i],get(tot-mx*i,mx-1),nck(tot,mx*i)*fac[mx*i][1]%mod*inv[mx][i]%mod*get(tot-mx*i,mx-1)%mod);
    }
  }
  ret%=mod;
//  printf("gg%d %d %lld\n",tot,mx,ret);
  return ret;
}
int main(){
  REP(i,1005){
    ll x; if(i==0) x=1; else x=fac[i-1][1]*i%mod;
    ll z=power(x,mod-2);
    ll y =1;
    REP(j,1005) fac[i][j]=y,y=y*x%mod;
    y=1;
    REP(j,1005) inv[i][j]=y,y=y*z%mod;
  }
  FILL(dp,-1);
  int n;
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  ll ans=get(n,b);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 24064
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define vii vector<int>
#define vip vector<pair<int,int> >
#define pb push_back

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //#endif
/*     int tc;
 *     cin>>tc;
 *     while(tc--)
 *     {
 *
 *     }
 */

    int n;bool f=1;
    cin>>n;
    vii v(n);
    for(int i=0;i<n;++i)
    {
        cin>>v[i];
        if(v[i]%2==0)
        if(v[i]%3!=0&&v[i]%5!=0)
            f=0;
    }
    cout<<(f?"APPROVED\n":"DENIED\n");

    return 0;
}


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

using namespace std;

long long int patty[51]={0,};
long long int l[51]={0,};

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

	patty[0] = 1;
	l[0] = 1;
	for(int i=1;i<=50;i++)
	{
		patty[i] = 2*patty[i-1] + 1;
		l[i] = 2*l[i-1] + 3;
	}

	long long int n,x;
	long long int res = 0;

	cin >> n >> x;

	while(1)
	{
		if(n==0)
		{
			res += 1;
			break;
		}
		//cout << n << ' ' << x << '\n';
		if(x<=1 || x>l[n])
		{
			break;
		}
		else if(x>1 && x<l[n-1]+2)
		{
			n-=1;
			x-=1;
		}
		else if(x==l[n-1]+2)
		{
			res += (patty[n-1] + 1);
			break;
		}
		else if(x>l[n-1]+2 && x<l[n])
		{

			res += (patty[n-1] + 1);
			x-=(l[n-1]+2);
			n-=1;
		}
		else if(x==l[n])
		{
			res += 2*patty[n-1] + 1;
			break;
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int n,mn,cnt[55][30];
string s;

int main() {
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		for(int j=0;j<s.size();j++) cnt[i][s[j]-'a']++;
	}
	s.clear();
	for(int i=0;i<26;i++){
		mn = 1e9;
		for(int j=0;j<n;j++){
			mn = min(mn, cnt[j][i]);
		}
		string ss="";
		for(int j=0;j<mn;j++){
			s.pb(char(i+'a'));
		}
		s += ss;
	}
	sort(s.begin(), s.end());
	cout<<s<<endl;
	return 0;
}

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

void init_dp(string a, string b, vector<vector<int> > &dp){
    dp[0][0] = a[0] == b[0] ? 1 : 0;
    for(int i=1; i<b.size();i++)
        if(a[0] == b[i])
            dp[0][i] = 1;
        else
            dp[0][i] = dp[0][i-1];
    
    for(int i=1; i<a.size();i++)
        if(b[0] == a[i])
            dp[i][0] = 1;
        else
            dp[i][0] = dp[i-1][0];
}

int LCS(string a, string b, vector<vector<int> > &dp){
    for(int i=1;i<a.size();i++)
        for(int j=1;j<b.size();j++)
            if(a[i] == b[j])
                dp[i][j] = 1+dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    
    return dp[a.size()-1][b.size()-1];
}

string getstring(string a, string b, vector<vector<int> > &dp, int lcssize){
    if(lcssize == 0)
        return "";

    int i,j;
    i = a.size()-1;
    j = b.size()-1;
    string ans;

    while(lcssize){
        if(a[i] == b[j]){
            ans += a[i];
            i--;
            j--;
            lcssize--;
        }
        else if(i > 0 && dp[i-1][j] > dp[i][j-1])
            i--;
        else if(j == 0)
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main(){
    
    string s, t;
    int asize, bsize, lcssize;
    cin >> s >> t;
    asize = s.size();
    bsize = t.size();
    vector<vector<int> > dp(asize, vector<int> (bsize));
    init_dp(s,t,dp);
    lcssize = LCS(s, t, dp);
    cout << getstring(s, t, dp, lcssize) << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  if (s[0] != s[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            String line = br.readLine();
            
            int a = Integer.parseInt(line.substring(0, line.indexOf(" ")));
            int b = Integer.parseInt(line.substring(line.indexOf(" ")+1));
            
            if(a<b){
            	System.out.println("a < b");
            }else if(a>b){
            	System.out.println("a > b");
            }else{
            	System.out.println("a == b");
            }
   
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 24432
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] alpabetDict = new int[26];
	while (scan.hasNext()) {
	    String input = scan.nextLine();
	    char[] inputArray = input.toCharArray();
	    int count = 0;
	    for (int i = 0; i < inputArray.length; i++) {
		if (Character.isLetter(inputArray[i])) {
		    alpabetDict[(int)Character.toLowerCase(inputArray[i]) - 'a']++;
		}
	    }
	}
	for (int i = 0; i < 26; i++) {
	    System.out.println((char)(i+'a') + " : " + alpabetDict[i]);
	}
    }
}

Measured memory_bytes: 26104
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if(a+b <= 2*c) {
        out(a*x + b*y);
        re0;
    }

    if(x <= y) {
        if(b < 2*c) {
            out(2*c*x + b*(y-x));
        }
        else {
            out(2*c*y);
        }
    }
    else {
        if(a < 2*c) {
            out(2*c*y + a*(x-y));
        }
        else {
            out(2*c*x);
        }
    }

    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
typedef long long ll;

int main()
{
    ll N,O;
    cin>>N;
    O=N;
    int dig=0;
    int s=0;
    while(N)
    {
        dig=N%10;
        s+=dig;
        N/=10;
    }
    if(O%s==0)cout<<"Yes"<<endl; else cout<<"No"<<endl;   
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {
  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp, stk;
  vector<bool> used, added;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false), added.assign(V, false);
    G.resize(V), rG.resize(V);
    stk.resize(4*V), cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int s) {
    int sp = 0;
    stk[sp++] = s;
    while (sp) {
      int v = stk[sp-1];
      used[v] = true;
      bool pushed = false;
      for (int c : G[v]) if (not used[c]) stk[sp++] = c, pushed = true;
      if (not pushed) {
        if (not added[v]) added[v] = true, vs.push_back(v);
        sp--;
      }
    }
  }

  void rdfs(int s, int k) {
    int sp = 0;
    stk[sp++] = s;
    while (sp) {
      int v = stk[sp-1]; sp--;
      used[v] = true;
      cmp[v] = k;
      for (int c : rG[v]) if (not used[c]) stk[sp++] = c;
    }
  }

  int run() {
    fill(used.begin(), used.end(), false);
    fill(added.begin(), added.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++) if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) if (not used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};

int main() {
  int V, E; scanf("%d %d", &V, &E);
  StronglyConnectedComponents scc(V);
  REP(_, E) {
    int f, t; scanf("%d %d", &f, &t);
    scc.add_edge(f, t);
  }
  scc.run();
  int Q; scanf("%d", &Q);
  REP(_, Q) {
    int x, y; scanf("%d %d", &x, &y);
    printf("%d\n", (scc.cmp[x] == scc.cmp[y]));
  }
  return 0;
}

Measured memory_bytes: 4300
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class BCommonRaccoonVsMonster
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var h = int.Parse(input[0]);
            var n = int.Parse(input[1]);
            var aList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

            Console.WriteLine(h - aList.Sum() > 0 ? "No" : "Yes");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 19680
#include<bits/stdc++.h>
#define INF (1e9)
#define R 10000
#define N 20
using namespace std;
typedef pair<double,int> P;
typedef pair<int,int> P1;
typedef pair<P,P1> P2;
vector<P> e[N][N];
double d[R][N][N];
int n,x[N],y[N];
double r,sita;

bool check(int a,int b,int c){
  int Y=y[a]-y[b],X=x[a]-x[b];
  double A=sqrt(Y*Y+X*X);
  Y=y[b]-y[c],X=x[b]-x[c];
  double B=sqrt(Y*Y+X*X);
  Y=y[c]-y[a],X=x[c]-x[a];
  double C=sqrt(Y*Y+X*X);
  return M_PI-acos((A*A+B*B-C*C)/(2*A*B))<=sita/180*M_PI;
}

int dijkstra(){
  priority_queue<P2,vector<P2>,greater<P2> > q;
  int res=0;
  for(int k=0;k<r;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
      	d[k][i][j]=INF;
  for(int i=1;i<n;i++){
    int Y=y[0]-y[i],X=x[0]-x[i];
    if(sqrt(Y*Y+X*X)<=r){
      q.push(P2(P(sqrt(Y*Y+X*X),1),P1(0,i)));
      d[1][0][i]=sqrt(Y*Y+X*X);
      res=1;
    }
  }
  while(!q.empty()){
    P2 t=q.top(); q.pop();
    int prevu=t.second.first;
    int u=t.second.second;
    int c=t.first.second;
    double cost=t.first.first;
    if(d[c][prevu][u]<cost)continue;
    for(int i=0;i<e[prevu][u].size();i++){
      double ncost=cost+e[prevu][u][i].first;
      int nu=e[prevu][u][i].second;
      if(ncost<=r&&d[c+1][u][nu]>ncost){
	res=max(res,c+1);
	d[c+1][u][nu]=ncost;
	q.push(P2(P(ncost,c+1),P1(u,nu)));
      }
    }
  }
  return res;
}

int main(){
  cin>>n>>r>>sita;
  for(int i=0;i<n;i++)
    cin>>x[i]>>y[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      if(i==j)continue;
      for(int k=0;k<n;k++){
	if(i==k||j==k)continue;
	if(check(i,j,k)){
	  int Y=y[j]-y[k],X=x[j]-x[k];
	  e[i][j].push_back(P(sqrt(Y*Y+X*X),k));
	}
      }
    }
  cout<<dijkstra()<<endl;
  return 0;
}

Measured memory_bytes: 34872