akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int score[3];

int getScore(char a) {
    if (a=='s') return score[0];
    if (a=='p') return score[1];
    if (a=='r') return score[2];
    return 0;
}

int main(){
    int n, k;
    cin >> n >> k;
    cin >> score[0] >> score[1] >> score[2];
    string s;
    cin >> s;
    int ans = 0;
    
    rep(i, k) {
        int num = 0;
        for (int j=i; j<n; j+=k) {
            if (j==i) {
                ans += getScore(s[j]);
                num++;
                continue;
            }
            if (s[j]==s[j-k]) {
                num++;
                if (num%2) ans += getScore(s[j]);
            }
            else {
                ans += getScore(s[j]);
                num = 1;
            }
        }
    }
    
    
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<char,char> pcc;
int h,w;
char s[20][20];
char sr[20][20];
int used[20];
int usedr[20];
bool same(char s[20][20], int n, int x, int y){
    vector<pcc> a,b;
    for(int i=0;i<n;i++){
        a.emplace_back(s[x][i], s[y][i]);
        b.emplace_back(s[y][i], s[x][i]);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    return a==b;
}
int main(){
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
        for(int j=0;j<w;j++){
            sr[j][i] = s[i][j];
        }
    }

    vector<int> rowf,rowb;
    vector<int> colf,colb;

    for(int i=0;i<h;i++){
        for(int j=i+1;j<h;j++){
            if(used[i] == 0 && used[j] == 0) {
                if (same(s,w,i,j)) {
                    used[i] = 1;
                    used[j] = 1;
                    rowf.push_back(i);
                    rowb.push_back(j);
                }
            }
        }
    }
    for(int i=0;i<w;i++){
        for(int j=i+1;j<w;j++){
            if(usedr[i] == 0 && usedr[j] == 0) {
                if (same(sr,h,i,j)) {
                    usedr[i] = 1;
                    usedr[j] = 1;
                    colf.push_back(i);
                    colb.push_back(j);
                }
            }
        }
    }
    if (count(used,used+h, 0) > 1 || count(usedr, usedr+w, 0) > 1) {
        printf("NO\n");
        return 0;
    }

    for(int i=0;i<h;i++){
        if (used[i] == 0){
            rowf.push_back(i);
        }
    }
    for(int i=0;i<w;i++){
        if (usedr[i] == 0){
            colf.push_back(i);
        }
    }
    rowf.insert(rowf.end(), rowb.rbegin(), rowb.rend());
    colf.insert(colf.end(), colb.rbegin(), colb.rend());
    int flag = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int x = rowf[i];
            int y = colf[j];
            int rx = rowf[h-i-1];
            int ry = colf[w-j-1];
            if (s[x][y] != s[rx][ry])flag = 1;
        }
    }
    printf("%s\n", flag ? "NO" : "YES");
}




Measured memory_bytes: 256
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a - 1
let rec loop acc i =
  if acc > n then -1
  else if i = 1 then acc
  else loop (acc + 1) a_s.(i)
let _ = loop 0 0 |> Printf.printf "%d\n"

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N,K;
  long long int mod = (long long int )(pow(10,9)+7);
  cin >> N >> K;
  vector<int> inp;
  int temp;
  long long int dp[N][K+1];
  for(int i=0;i<N;i++){
    
    cin >> temp;
    inp.push_back(temp);
    
  }
  sort(inp.begin(),inp.end());
  for(int i=0;i<N;i++){
    for(int j=0;j<=K;j++){
      if(j==0){
       	dp[i][j]=1;
        continue;
      }
      if(i==0){
       	 
        if(j<=inp[i]) dp[i][j]=1;
        else dp[i][j]=0;
        continue;
      }
     else{
       if(j-inp[i]-1>=0) dp[i][j] = (mod+(dp[i][j-1]+dp[i-1][j])%mod-dp[i-1][j-inp[i]-1])%mod;
       else dp[i][j] = (dp[i][j-1]+dp[i-1][j])%mod;
       
     }
    }
  }
  cout << dp[N-1][K];
  return 0;
  
  
}

Measured memory_bytes: 81540
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

long long int a[4], n, ans;
typedef pair<long long int, int> P;
vector<P> b;

int main(){
	for(int i=0; i<4; ++i) scanf("%lld", &a[i]);
	scanf("%lld", &n);
	for(int i=0; i<4; ++i){
		int t = 1;
		for(int j=0; j<4-i; ++j) t *= 2;
		b.push_back(P(a[i] * t, 16/t));
	}
	sort(b.begin(), b.end());
//	for(int i=0; i<4; ++i) printf("%lld %d\n", b[i].first, b[i].second);
	n *= 4;
	for(int i=0; i<4; ++i){
		ans += n/b[i].second*b[i].second*b[i].first/16;
		n %= b[i].second;
		if(n == 0) break;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  int h[n], hm[n];
  int minh;
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }

  for (int i = 0; i < n-1; i++){
    if (i == 0){
      hm[i+1] = abs(h[i]-h[i+1]);
      hm[i+2] = abs(h[i]-h[i+2]);
      minh = min(hm[i+1], hm[i+2]);
    }else if(i == n-2){
      hm[i+1] = min(abs(h[i]-h[i+1])+hm[i], hm[i+1]);
      minh =  hm[i+1];
    }else{
      hm[i+1] = min(abs(h[i]-h[i+1])+hm[i], hm[i+1]);
      hm[i+2] = abs(h[i]-h[i+2])+hm[i];
      minh =  min(hm[i+1], hm[i+2]);
    }
  }
  cout << minh;
  return 0;
}


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

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define UB upper_bound

const int MAXN = 2000 + 10;
int n;
int ind[5][MAXN],
    mx_ind[MAXN][MAXN], 
    dp[MAXN][MAXN],
    dis1[MAXN][MAXN],
    dis2[MAXN][MAXN];


void dp_base()
{
	for (int i = 1; i <= n; i ++)
	{
		dp[i][0] = dp[i - 1][0];
		for (int j = i; j >= 1; j --)
			if (ind[0][i] < ind[0][j])
				dp[i][0] ++;
	}

	for (int i = 1; i <= n; i ++)
	{
		dp[0][i] = dp[0][i - 1];
		for (int j = i; j >= 1; j --)
			if (ind[1][i] < ind[1][j])
				dp[0][i] ++;
	}
}

void dp_update()
{
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= n; j ++)
			dp[i][j] = min(dp[i - 1][j] + dis1[i][j], dp[i][j - 1] + dis2[i][j]);
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> n;
	for (int i = 0; i < 2 * n; i ++)
	{
		char c;
		int a;
		cin >> c >> a;
		ind[c == 'B'][a] = i;
	}

	for (int i = 1; i <= n; i ++)
	{
		int cnt = 0;
		for (int j = 1; j < i; j ++)
			if (ind[0][i] < ind[0][j])
				cnt ++;
		dis1[i][0] = cnt;
		for (int j = 1; j <= n; j ++)
		{
			dis1[i][j] = dis1[i][j - 1];
			if (ind[0][i] < ind[1][j])
				dis1[i][j] ++;
		}
	}

	for (int i = 1; i <= n; i ++)
	{
		int cnt = 0;
		for (int j = 1; j < i; j ++)
			if (ind[1][i] < ind[1][j])
				cnt ++;
		dis2[0][i] = cnt;
		for (int j = 1; j <= n; j ++)
		{
			dis2[j][i] = dis2[j - 1][i];
			if (ind[1][i] < ind[0][j])
				dis2[j][i] ++;
		}
	}

	dp_base();
	dp_update();
	cout << dp[n][n] << endl;

	return 0;
}


Measured memory_bytes: 96512
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793


int main(){
 int n,m;
 cin >> n >>m;
 VI k(m),p(m);
 vector<VI> s(m,VI(n));
 rep(i,m){
     cin >> k.at(i);
     rep(j,k.at(i)){
         cin >> s.at(i).at(j);
     }
 }
 rep(i,m)cin >> p.at(i);
 int cnt=0;
 for(int bit=0;bit < (1<<n);bit++){
        set<int> chk;
      rep(k,n){
         if(bit & (1<<k)){
            chk.insert(k+1);
         }
      }
      bool a=true;
      rep(i,m){
          int cntt=0;
          rep(j,k.at(i)){
              if(chk.count(s.at(i).at(j)))cntt++;
          }
          if(cntt%2!=p.at(i)){
              a=false;
              break;
          }
      }
      if(a)cnt++;
 }
 cout << cnt << endl;
}

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

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n + 1);
    rep(i, n)
    {
        if (s[i] == '<')
        {
            a[i + 1] = max(a[i + 1], a[i] + 1);
        }
    }
    per(i, n)
    {
        if (s[i] == '>')
        {
            a[i] = max(a[i], a[i + 1] + 1);
        }
    }
    ll ans = 0;
    rep(i, n + 1) ans += a[i];
    cout << ans << endl;
}

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

Measured memory_bytes: 5808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  vector<ll> a(5);
  ll answer = 0;
  ll minppl = 10000000000000000;
  ll ppl;
  cin >> ppl;
  for(int i = 0;i < 5;i++){
    cin >> a[i];
    if(a[i] < minppl)minppl = a[i];
  }
  answer = (ppl+minppl-1)/minppl + 4;
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
vint connect[200001];
int irovertex[200001][2]={0};
int iro[200001];
bool kindsmallerthan1flag[200001];
int main(){
	int N,M;
	string s;
	vpint edge;
	vint kindsmallerthan1;
	scan(N);scan(M);
	scan(s);
	rep1(i,N){
		if(s[i-1]=='A') iro[i]=0;
		else iro[i]=1;
	}
	rep(i,M){
		int a,b;
		scan(a);scan(b);
		connect[a].push_back(b);
		connect[b].push_back(a);
		irovertex[a][iro[b]]++;
		irovertex[b][iro[a]]++;
	}
	rep1(i,N){
		if(irovertex[i][0]==0||irovertex[i][1]==0){
			kindsmallerthan1flag[i]=true;
			kindsmallerthan1.push_back(i);
		}
		else{
			kindsmallerthan1flag[i]=false;
		}
	}
	while(kindsmallerthan1.size()!=0){
		int moto=kindsmallerthan1.back();
		kindsmallerthan1.pop_back();
		rep(i,connect[moto].size()){
			int saki=connect[moto][i];
			if(kindsmallerthan1flag[saki]==0){
				irovertex[saki][iro[moto]]--;
				if(irovertex[saki][iro[moto]]==0){
					kindsmallerthan1flag[saki]=true;
					kindsmallerthan1.push_back(saki);
				}
			}
		}
	}
	bool flag=1;
	rep1(i,N){
		flag=(flag&&kindsmallerthan1flag[i]);
	}
	if(!flag) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 13444
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

    int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

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

int main()
{
    string S;
    cin >> S;
    ll K;
    cin >> K;
    int ans = 0;
    int count = 0;
    for (int i = 0; i < S.size(); i++)
    {
        count++;
        if (S[i] != '1')
        {
            cout << S[i] << endl;
            return 0;
        }
        else if(count == K){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  map<string,int>mp;
  cin>>n;
  for(int i=0;i<n;i++){
    string str;
    cin>>str;
    if(mp.find(str)==mp.end()){
      mp.insert(make_pair(str,1));
    }else{
      mp[str]+=1;
    }
  }
  
  int maxim=0;
  for(map<string,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    maxim=max(maxim,itr->second);
  }

  for(map<string,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    if(itr->second==maxim){
      cout<<itr->first<<endl;
    }
  }
  return(0);
}

Measured memory_bytes: 25216
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
//141-D

int main() {
	int N;
	int i;
	cin >> N;
	vector<int> A(N);
	vector<int>B(N);
	vector<int>C(N - 1);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (i = 0; i < N-1; i++) {
		cin >> C[i];
	}
	int ans = 0;

	for (i = 0; i < N; i++) {
		ans += B[A[i]-1];
		if (i>0&&(A[i] - A[i - 1]) == 1) {
			ans += C[A[i]-2];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    int A, B;
    cin >> A >> B;
    if (A % 2 == 1 && B % 2 == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
S = raw_input().split(" ")
Stack = list()

def push(x):
    Stack.append(x)

def pop():
    return Stack.pop(-1)

a = 0
b = 0
for i in range(len(S)):
    if S[i] == "+":
        a = pop()
        b = pop()
        push(b + a)
    elif S[i] == "-":
        a = pop()
        b = pop()
        push(b - a)
    elif S[i] == "*":
        a = pop()
        b = pop()
        push(b * a)
    elif S[i] == "/":
        a = pop()
        b = pop()
        push(b / a)
    else:
        push(int(S[i]))

print Stack.pop(-1)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	
	vvl a;
	map<ll,ll> m;
	FOR(i,0,n) {
		ll x; cin >> x;
		if (has(m,x-1)) {
			ll j = m[x-1];
			a[j].pb(x);
			m.erase(x-1);
			m[x] = j;
		} else {
			m[x] = sz(a);
			a.pb({x});
		}
	}

	ll res = n;
	for (vl v: a) res = min(res,n-sz(v));
	cout << res << endl;
}



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

int main()
{
    int a,b,h,m;
    double hu,zi,kaku;
    double ans;
    cin>>a>>b>>h>>m;

    hu=m*6;
    zi=h*30+m*0.5;
    if(hu==0 || zi==0)kaku=360-fabs(hu-zi);
    else kaku=fabs(hu-zi);
    kaku=kaku*M_PI/180;
    ans=a*a+b*b-2*a*b*cos(kaku);
    ans=sqrt(ans);
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
	
int32_t main(){
	boost;
	int a;
	cin>>a;
	cout<<a+a*a+ a*a*a<<endl;		
}



Measured memory_bytes: 3648
n = int(input())
a = list(map(int, input().split()))

S = a[0] + a[1]
C = 0
for i in range(2, n):
    C ^= a[i]

D = S - C

if D < 0 or D % 2 == 1:
    print(-1)
    exit()

D //= 2

ans = 0

free_keta = []

for i in range(100):
    if (C & (1 << i)) != 0:
        free_keta.append(i)
        if (D & (1 << i)) != 0:
            print(-1)
            exit()
    else:
        ans += (D & (1 << i))

if ans > a[0]:
    print(-1)
    exit()
        
for keta in free_keta[::-1]:
    if ans + (1 << keta) <= a[0]:
        ans += (1 << keta)

if ans == 0:
    print(-1)
    exit()
    
print(a[0] - ans)

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_in_out;
    int a,b,uncover;
    cin >> a >> b;
    uncover =  a - (2 * b);
    if(uncover < 0)
    {
        cout << "0";
    }
    else
    {
        cout << uncover;
    }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  string s, t;
  cin >> s >> t;
  int ans = INF;
  int ns = s.size(), nt = t.size();
  rep(i, ns-nt+1) {
    int c = 0;
    rep(j, nt) if (t[j] != s[i+j]) ++c;
    chmin(ans, c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

const int kSize = 25;

struct Node {
    int parent = -1;
    int left, right;

    int depth;
    int height;
    int sibling;
    int degree;
};

Node tree[kSize];

void GetDepth(int node) {
    int ans = 0;
    int var = node;
    while (tree[var].parent != -1) {
        var = tree[var].parent;
        ans++;
    }

    tree[node].depth = ans;
}

int GetHeight(int node) {
    if (node == -1) {
        return 0;
    }

    return max(GetHeight(tree[node].left), GetHeight(tree[node].right)) + 1;
}

void GetSibling(int node) {
    int parent = tree[node].parent;

    if (parent == -1 || tree[parent].degree == 1) {
        tree[node].sibling = -1;
    } else {
        int left = tree[parent].left;
        int right = tree[parent].right;
        tree[node].sibling = node == left ? right : left;
    }
}

void GetDegree(int node) {
    if (tree[node].left == -1 && tree[node].right == -1) {
        tree[node].degree = 0;
    } else if (tree[node].left != -1 && tree[node].right != -1) {
        tree[node].degree = 2;
    } else {
        tree[node].degree = 1;
    }
}

void Print(int node) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", node, tree[node].parent,
            tree[node].sibling, tree[node].degree, tree[node].depth, tree[node].height);

    if (tree[node].parent == -1) {
        printf("root");
    } else if (tree[node].degree == 0) {
        printf("leaf");
    } else {
        printf("internal node");
    }
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        tree[id].left = left;
        tree[id].right = right;
        if (left != -1) {
            tree[left].parent = id;
        }
        if (right != -1) {
            tree[right].parent = id;
        }
    }

    for (int i = 0; i < n; ++i) {
        GetDegree(i);
        GetDepth(i);
        tree[i].height = GetHeight(i) - 1;
        GetSibling(i);
    }

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



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

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 long long INF = 1LL << 60;

int main(void){
	ll k;cin >> k;
	ll i=1,count=9;
	queue<ll> que;
	for(int i=1;i<=9;i++){
		que.push(i);
		if(i==k){cout << i << endl;return 0;}
	}
	while(1){
		ll x = que.front();que.pop();
		int a = x % 10;
		if(a != 0){
			que.push(x*10+a-1);
			count++;
			if(count==k){cout << x*10+a-1 << endl;return 0;}
		}
		que.push(x*10+a);
		count++;
		if(count==k){cout << x*10+a << endl;return 0;}
		if(a != 9){
			que.push(x*10+a+1);
			count++;
			if(count==k){cout << x*10+a+1 << endl;return 0;}
		}
	}
	return 0;
}



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

const ll N = 3*MAX5;
// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, l;
string s, t, d, c;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> s;
	bool c1,c2;
	c1 = (stoll(s.substr(0,2)) > 0 && stoll(s.substr(0,2)) < 13);
	c2 = (stoll(s.substr(2,2)) > 0 && stoll(s.substr(2,2)) < 13); 

	if(c1 && c2) cout<<"AMBIGUOUS";
	else if(c1) cout<<"MMYY";
	else if(c2) cout<<"YYMM";
	else cout<<"NA";
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3604
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
MOD = 10**9+7
INF = MOD-1
dp = [INF]*(n+1)
if n == 1:
    if 1 in a:
        print(0)
    else:
        print(1)
    exit()

dp[0] = dp[1] = 1

if 0 in a:
    dp[0] = INF
if 1 in a:
    dp[1] = INF

for x in a:
    dp[x] = 0

for i in range(2, n+1):
    if dp[i] == 0:
        continue

    if dp[i-1] == INF and dp[i-2] == INF:
        break
    elif dp[i-1] == INF or dp[i-2] == INF:
        dp[i] = max(dp[i-1], dp[i-2])
    else:
        dp[i] = dp[i-1]+dp[i-2]
    dp[i] %= MOD


print(dp[n] if dp[n] != INF else 0)


Measured memory_bytes: 7848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+50;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    cout<<"bust";
    else cout<<"win";
    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> values(N + 1);
    vector<int> ruisekiValues(N + 2);
    vector<int> revRuisekiValues(N + 2);
    //value, index
    vector<pair<int, int>> minusValues(0);
    for (int i = 1; i <= N; i++)
    {
        int v;
        cin >> v;
        values[i] = v;
        if (values[i] < 0)
        {
            minusValues.push_back(make_pair(values[i], i));
        }
    }
    sort(minusValues.begin(), minusValues.end());
    ruisekiValues[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        ruisekiValues[i] = values[i] + ruisekiValues[i - 1];
    }
    revRuisekiValues[N + 1] = 0;
    for (int i = N; i >= 1; i--)
    {
        revRuisekiValues[i] = values[i] + revRuisekiValues[i + 1];
    }
    int answer = 0;

    int maxAddMove = min(K, N);
    for (int i = 1; i <= maxAddMove; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            int left = j;
            int right = N + 1 - (i - j);
            int count = ruisekiValues[left] + revRuisekiValues[right];
            int removeCount = K - i;
            for (pair<int, int> minusValue : minusValues)
            {
                if(removeCount == 0){
                    break;
                }
                if (minusValue.second <= left || right <= minusValue.second){
                    count -= minusValue.first;
                    removeCount--;
                }
            }
            answer = max(answer, count);
        }
    }
    cout << answer << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  map<int,int> mp;
  if(s=="zyxwvutsrqponmlkjihgfedcba")cout<<-1<<endl;
  else if(s.size()!=26){
    r(i,s.size()){
      mp[s[i]-'a']++;
    }
    cout<<s;
    r(i,26){
      if(mp[i]==0){
        cout<<char('a'+i)<<endl;
        break;
      }
    }
  }
  else{
    int p;
    for(int i=25;i>=0;i--){
        if(s[i-1]<s[i]){
          p=i;
          break;
        }
    }
    next_permutation(s.begin()+p-1,s.end());
    s=s.substr(0,p);
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
char s[N];
int main() {
	scanf("%s", s);
	int n = 0;
	for (int i = 0; s[i]; i++)n += (s[i] - '0');
	puts(n % 9 == 0 ? "Yes" : "No");
	return 0;
}

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

int dfs(int i, int a0, int b0, int c0, int n, int a, int b, int c, int* l){
    int l0, l1, l2, l3;
    if(i == n){
        if(a0==0 || b0==0 || c0==0){
            return 99999999;
        }
        return abs(a0-a)+abs(b0-b)+abs(c0-c)-30;
    }
    l0 = dfs(i+1, a0, b0, c0, n, a, b, c, l);
    l1 = dfs(i+1, a0+l[i], b0, c0, n, a, b, c, l) + 10;
    l2 = dfs(i+1, a0, b0+l[i], c0, n, a, b, c, l) + 10;
    l3 = dfs(i+1, a0, b0, c0+l[i], n, a, b, c, l) + 10;
    return min(min(l0, l1), min(l2, l3));
}

int main(){
    int n, a, b, c, i;
    cin >> n >> a >> b >> c;
    int l[n];
    for(i=0; i<n; i++){
        cin >> l[i];
    }
    cout << dfs(0,0,0,0,n,a,b,c,l);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,cnt=0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i=a;i<=b;++i){
        if(c%i==0)++cnt;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String[] inputs = new Scanner(System.in).nextLine().split(" ");
		int w =  Integer.parseInt(inputs[0]);
		int a  = Integer.parseInt(inputs[1]);
		int b = Integer.parseInt(inputs[2]);
		
		int redRightEdge = a + w;
		int greenRightEdge = b + w;
		
		if (redRightEdge >= b && redRightEdge <= greenRightEdge) {
			System.out.println("0");
			return;
		}
		System.out.println(Math.min(Math.abs(redRightEdge - b), Math.abs(greenRightEdge - a)));
	}
}

Measured memory_bytes: 22996
// https://atcoder.jp/contests/abc080/tasks/abc080_b
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
  int N;
  cin >> N;

  int tmp, sum = 0;
  tmp = N;
  while (tmp > 0){
    sum += tmp % 10;
    tmp /= 10;
  }

  if (N%sum==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
    int X; cin >> X;
    int ans = X / 500 * 1000;
    X %= 500;
    ans += X / 5 * 5;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
fn = lambda: map(int, input().split())
W, H, N = fn()
min_x, max_x = 0, W
min_y, max_y = 0, H
for i in range(N):
    xi, yi, ai = fn()
    if ai == 1:
        min_x = max(xi, min_x)
    elif ai == 2:
        max_x = min(xi, max_x)
    elif ai == 3:
        min_y = max(yi, min_y)
    elif ai == 4:
        max_y = min(yi, max_y)
    else:
        print('Something wrong')

print(max(max_x - min_x, 0) * max(max_y - min_y, 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std ;
using V_2 = vector<vector<int>> ;
using Gragh = vector<vector<char>> ;
using P = pair<int,int> ;
using ll = long long ;

int main(){
  int n ; 
  int count = 0 ;
  cin >> n ;

  for(int a = 1 ; a < n ; a++){
    for(int b = 1 ; b < n ; b++){
      if(a * b < n){
        count++ ;
      }
      else break ;
    }
  }

  cout << count << endl ;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N), sum(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    sum[0] = A[0];
    for(int i=1;i<N;i++){
        sum[i] = sum[i-1] + A[i];
    }

    int t = -1;
    for(int i=0;i<N-1;i++){
        if(2*sum[i] < A[i+1]){
            t = i;
        }
    }
    if(t == -1){
        cout << N << endl;
    }else{
        cout << N - t - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
#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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
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;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 700;
    rep(i,3){
        if(s[i]=='o') ans += 100;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# AGC041A - Table Tennis Training
def main():
    N, A, B = map(int, input().split())
    if A % 2 == B % 2:
        ans = (B - A) // 2
    else:
        ans = min(A - 1, N - B) + 1 + (B - A - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int l;
    cin>>l;
    int ans = 0;
    int sum = 0;
    rep(i,n){
        int x;
        cin>>x;
        sum += x;
        if(sum<=l)++ans;
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<sstream>
#include<stdio.h>
#include <functional>
#include<set>

using namespace std;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			if (n == i * j)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N=parse(Int,readline())
A=parse.(Int,split(readline()))

function solve(N,A)
    a=A[1]
    res=0
    for i=2:N
        x=a-A[i]
        y=x<0 ? 0 : x
        a=A[i]+y
        res+=y
#         println(y)
    end
    println(res)
end

solve(N,A)

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

bool possible(int N, vi arr) {
	sort(arr.begin(), arr.end());
	if (arr[N-1] - arr[0] > 1) {
		return false;
	} else if (arr[0] == arr[N-1]) {
		return (N >= 2 * arr[0] || N-1 == arr[0]);
	} else {
		int s = 0;
		int b = 0;
		F0R(i, N) {
			if (arr[i] == arr[0])
				++s;
			else
				++b;
		}
		return (s < arr[N-1] && b >= 2 * (arr[N-1] - s));
	}
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	if (possible(N, arr)) {
		print("Yes");
	} else {
		print("No");
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <utility>
#include <time.h>
#include <set>
#include <unordered_set>
#include <list>
#include <iterator>
#include <time.h>
#include <chrono>
#include <deque>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
#include <tuple>
using namespace std;

#define ll long long
#define ldb long double

ll mod(ll a, ll b)
{
	return (b + (a % b)) % b;
}

ll subMod(ll a, ll b, ll M)
{
	return mod((mod(a, M) - mod(b, M)), M);
}

ll dayofweek(ll d, ll m, ll y)
{
	static ll t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
	y -= m < 3;
	return (y + y / 4 - y / 100 +
		y / 400 + t[m - 1] + d) % 7;
}

void test()
{

}

void solve()
{
	ll a, b, c;

	cin >> a >> b >> c;

	if (a == b)
	{
		if (c != a)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
	}
	else if (a == c)
	{
		if (b != a)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
	}
	else if (b == c)
	{
		if (b != a)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
	}
	else
	{
		cout << "No\n";
	}
}

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

	//test();

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int N,T,a[1000],c[1000],b=0,d=1001;
  cin >> N >> T;
  for(int i=0; i<N; i++){
      cin >> a[i];
      cin >> c[i];
  }for(int j=0; j<N; j++){
          if(c[j]<=T){
              b=a[j];
              if(b<=d){
                  d=b;
          }
      }
  }if(d==1001){
      cout << "TLE" << endl;
}else{cout << d << endl;
}
}

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

typedef long long ll;
int main() {
  ll a;
  string b;
  
  cin>>a>>b;
  int bi = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] -'0');
  //cout<<bi<<endl;
  //cout<<a<<"\n"<<b<<endl;
  cout<<(a * bi) / 100;
  return 0;
}

Measured memory_bytes: 3608
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2000 + 20 , mod = 1e9 + 7 ;
int n , k , dp[N][N] , fac[N * N]  ;

inline int pw (int a , int b) {
	int res = 1 ;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod ;
		a = 1ll * a * a % mod ;
		b >>= 1 ;
	}
	return res ;
}

inline int inv (int x) { return pw(x , mod - 2) ; }

void pre () {
	fac[0] = 1 ;
	for (int i = 1 ; i < N * N ; i ++) fac[i] = 1ll * fac[i - 1] * i % mod ;
}

inline bool ok (int x) { return 0 <= x && x < mod ; }

inline int Comb (int n , int k) {
	if (k < 0 || k > n) return 0 ;
	assert(ok(inv(fac[k]))) ;
	assert(ok(inv(fac[n - k]))) ;
	return 1ll * fac[n] * inv(fac[k]) % mod * inv(fac[n - k]) % mod ;
}

inline void add (int &a , int b) {
	a += b ;
	if (a >= mod) a -= mod ;
	if (a < 0) a += mod ;
}

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

	pre() ;

	cin >> n >> k ;

	if (k == 1) return cout << "1\n" , 0 ;

	dp[n][n] = 1 ;

	for (int i = n ; ~i ; i --)
		for (int j = i ; ~j ; j --) {
			if (j == n) continue ;

			if (i < n) add(dp[i][j] , 1ll * (n - i) * dp[i + 1][j] % mod) ;
			if (j < i) add(dp[i][j] , 1ll * Comb(n * k - (i + j * (k - 1) + 1) , k - 2) * dp[i][j + 1] % mod) ; 
		}

	cout << dp[0][0] << '\n' ;
}


Measured memory_bytes: 32000
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
      	String D = s.next(), m = D.substring(5,7);
      	if(m.equals("01") || m.equals("02") || m.equals("03") || m.equals("04")){
          System.out.println("Heisei");
        } else System.out.println("TBD");
	}
}


Measured memory_bytes: 22100
S = input()

cnd0 = 0
cnd1 = 0

target = '01' * (len(S) // 2)
if len(S) % 2 == 1:
    target = target + '0'
for idx, ch in enumerate(S):
    if ch != target[idx]:
        cnd0 += 1

target = '10' * (len(S) // 2)
if len(S) % 2 == 1:
    target = target + '1'
for idx, ch in enumerate(S):
    if ch != target[idx]:
        cnd1 += 1

print(min(cnd0, cnd1))


Measured memory_bytes: 3316
import sys
readline = sys.stdin.readline

def main():
    H, W = map(int, readline().rstrip().split())
    A = [list(map(int, readline().rstrip().split())) for _ in range(H)]
    res = []
    cnt = 0
    for h in range(H):
        for w in range(W-1):
            if A[h][w] % 2 == 1:
                A[h][w+1] += 1
                cnt += 1
                res.append('{} {} {} {}'.format(h+1, w+1, h+1, w+2))

    for h in range(H-1):
        if A[h][W-1] % 2 == 1:
            A[h+1][W-1] += 1
            cnt += 1
            res.append('{} {} {} {}'.format(h+1, W, h+2, W))
    
    print(cnt)
    print(*res, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 18396
#include <algorithm>
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, p;
  cin >> a >> p;
  p += a * 3;
  cout << p / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
    ll n, k, sum = 0;
    cin >> n >> k;
    vector<ll> s(n);
    REP(i,n){
        cin >> s[i];
    }
    REP(i, k){
        sum += s[i];
    }
    FOR(i, k, n){
        
        cout << (s[i - k] < s[i] ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 4840
S = input()
O = ['R','U','D']
E = ['L','U','D']
ans = 'Yes'
for i in range(len(S)):
    if ((i+1)%2 != 0) and (S[i] not in O):
        ans = 'No'
    elif ((i+1)%2 == 0) and (S[i] not in E):
        ans = 'No'
print(ans)

Measured memory_bytes: 3060
n = int(input())
s = input()
 
res = 0
dp = [[0]* (1+n) for _ in range(n+1)]
for i in range(n-1, -1, -1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + (j - i > dp[i+1][j+1])
            res = max(res, dp[i][j])
print(res)

Measured memory_bytes: 229640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

char a[333][333];
int b[333][333];

int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i != h; ++i)
        for (int j = 0; j != w; ++j)
            cin >> a[i][j];
    int color = 0, highest = -1;
    vector<bool> used(h);
    for (int i = 0; i != h; ++i) {
        int met = 0;
        for (int j = 0; j != w; ++j) {
            if (a[i][j] == '#') {
                ++color;
                if (met == 0) {
                    met = color;
                    used[i] = true;
                    if (highest < 0)
                        highest = i;
                }
            }
            if (met)
                b[i][j] = color;
        }
        for (int j = 0; j != w && a[i][j] == '.'; ++j)
            b[i][j] = met;
    }
    for (int i = 0; i != highest; ++i)
        for (int j = 0; j != w; ++j)
            b[i][j] = b[highest][j];
    int cur = highest;
    for (int i = highest + 1; i != h; ++i) {
        if (!used[i])
            for (int j = 0; j != w; ++j)
                b[i][j] = b[cur][j];
        else
            cur = i;
    }
    for (int i = 0; i != h; ++i) {
        for (int j = 0; j != w; ++j)
            cout << b[i][j] << ' ';
        cout << '\n';
    }
    return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k;
    cin >> k;
    set<int> st;
    int x = 7%k;
    rep1(i, k) {
        if (x == 0) {
            cout << i << endl;
            return 0;
        }
        if (st.count(x)!=0) break;
        st.insert(x);
        x = (x * 10 + 7) % k;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 50476
"""
@ 凸包をつくる
    > 凸包内部の点に属する領域は、半径Rの円からするともはやないものとして考えて良い
    > というかこの多角形自体点として考えていい！
@ 凸包の頂点vについて
    > vの両隣との傾きだけあればよい
    > その間の角度 / 360が答え
"""

from math import gcd, atan, pi, degrees

def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])

def convex_hull(ps):
    qs = []
    N = len(ps)
    for p in ps:
        # 一直線上で高々2点にする場合は ">=" にする
        while len(qs) > 1 and cross3(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(N-2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross3(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

def tup_to_key(tup):
    x, y = tup
    x += 10 ** 7
    y += 10 ** 7
    x *= 10 ** 8
    return x + y

def key_to_tup(key):
    x, y = divmod(key, 10 ** 8)
    x -= 10 ** 7
    y -= 10 ** 7
    return x, y

def angle(x1, y1, x2, y2):
    if y1 == y2:
        return pi / 2
    return atan(-(x1 - x2) / (y1 - y2))

def on_line(ps):
    st = set()
    for p, q in zip(ps, ps[1:]):
        px, py = p
        qx, qy = q
        dx, dy = qx - px, qy - py
        g = gcd(dx, dy)
        dx //= g
        dy //= g
        st.add(tup_to_key((dx, dy)))
    return len(st) == 1

if __name__ == "__main__":
    N = int(input())
    if N == 2:
        print(0.5)
        print(0.5)
        exit(0)

    res = dict()
    points = [list(map(int,input().split())) for _ in range(N)]

    # ps = sorted(points)
    # for a, b in zip(ps, ps[1:]):
    #     x1, y1 = a
    #     x2, y2 = b
    #     x, y = x2 - x1, y2 - y1
    #     print(x, y)

    if on_line(sorted(points)):
        mn = min(points)
        mx = max(points)
        res[tup_to_key(mn)] = 0.5
        res[tup_to_key(mx)] = 0.5
    else:
        ps = convex_hull(sorted(points))[:-1]
        sz = len(ps)
        for i, (x, y) in enumerate(ps):
            key = tup_to_key((x, y))
            lx, ly = ps[i - 1]
            rx, ry = ps[(i + 1) % sz]
            la = angle(x, y, lx, ly)
            ra = angle(x, y, rx, ry)
            a = ra - la
            # a = min(a, 2 * pi - a)
            # print(x, y)
            # print(degrees(la), degrees(ra))
            if a < 0:
                a += pi
            # print(la, ra)
            res[key] = a / (2 * pi)

    for tup in points:
        key = tup_to_key(tup)
        if key in res:
            print(res[key])
        else:
            print(0)


Measured memory_bytes: 64472
#include <stdio.h>
int main(){
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h == 0 && w == 0) break;;
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				if((i == 0 || i == h-1) || (j == 0 || j == w-1))
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
sa=list(input())
sb=list(input())
sc=list(input())

ans={"a":"A","b":"B","c":"C"}
card={"a":sa,"b":sb,"c":sc}

turn="a"

while True:
        if len(card[turn])==0:
                break

        next_turn=card[turn][0]

        card[turn]=card[turn][1:]

        turn=next_turn

print(ans[turn])


Measured memory_bytes: 3060