akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define INF (1<<29)
#define max_n 10000

using namespace std;

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

struct node_t{

  node_t *pp,*lp,*rp;
  int id,val,mini,minId,lazy;
  edge *e;

  node_t(int id,int v):id(id),val(v){
    pp=lp=rp=NULL; lazy=0; update();
  }
   
  inline void update(){
    mini=val,minId=id;
    if(lp && mini>lp->mini)mini=lp->mini,minId=lp->minId;
    if(rp && mini>=rp->mini)mini=rp->mini,minId=rp->minId;
  }
   
  inline void apply(int v){ lazy+=v, val+=v, mini+=v; }
   
  inline void push(){
    if(lp)lp->apply(lazy);
    if(rp)rp->apply(lazy);
    lazy=0;
  }
 
  bool is_root(){
    return !pp || (pp->lp != this && pp->rp != this);
  }
  
  void rotr(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->lp=rp))rp->pp=q;
    rp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void rotl(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->rp=lp))lp->pp=q;
    lp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void splay(){
    while(!is_root()){
      node_t *q=pp;
      if(q->is_root()){
	if(q->lp==this)rotr();
	else rotl();
      } else {
	node_t *r=q->pp;
	if(r->lp==q){
	  if(q->lp==this){q->rotr();rotr();}
	  else {rotl();rotr();}
	} else {
	  if(q->rp==this){q->rotl();rotl();}
	  else {rotr();rotl();}
	}
      }
    }
    push();
    update();
  }
};

node_t *expose(node_t *x){
  node_t *rp=NULL;
  for(node_t *p=x;p;p=p->pp){
    p->splay();
    p->rp=rp;
    p->update();
    rp=p;
  }
  x->splay();
  return x;
}

node_t *find_root(node_t *x){
  expose(x);
  while(x->lp)x=x->lp;
  return x;
}

void cut(node_t *c){
  expose(c);
  node_t *p=c->lp;
  c->lp=NULL;
  p->pp=NULL;
  c->val=INF;
}

void link(node_t *c,node_t *p){
  expose(c);
  expose(p);
  c->pp=p;
  p->rp=c;
}

void link(node_t *c,node_t *p,int val,edge *e){
  link(c,p);
  c->val=val;
  c->update();
  c->e=e;
}

int minId(node_t *x){expose(x); return x->minId;}
void add(node_t *x,int val){ expose(x); x->apply(val); }

node_t *lowestCommonAncestor(node_t *x,node_t* y){
  expose(x);
  node_t *rp=NULL;
  for(node_t *p=y;p;p=p->pp){
    p->splay();
    p->rp=rp;
    p->update();
    rp=p;
  }
  return rp;
}

node_t *node[100001];

int main(void){
  int n;
  cin >> n;
  
  for(int i=0;i<n;i++)node[i]=new node_t(i,0);
  for(int i=0;i<n;i++){
    int k,t;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      link(node[t],node[i]);
    }
  }

  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int u,v;
    cin >> u >> v;
    cout << lowestCommonAncestor(node[u],node[v])->id << endl;
  }
  
  return 0;
}

Measured memory_bytes: 8220
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

int main(){
  long  n;unsigned long tmp; long m=0;
  std::vector<std::pair<unsigned long,unsigned long> > ls;
  std::cin >> n;
  std::vector<unsigned long long> ans(n);
  ls.reserve(n+1);
  for(long i=0; i<n; ++i) {std::cin >> tmp;ls.emplace_back(std::make_pair(tmp,i));}
  ls.emplace_back(std::make_pair(0,n));
  std::sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
  auto target=ls.begin()->second;
  for(auto it=ls.begin();it!=ls.cend()-1;){
    if(target>it->second)target=it->second;
    ans[target]+=(it->first-(++it)->first)*(++m);
  }
  for(auto x : ans) std::cout<< x <<'\n';
  std::cout.flush();
  return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define dbg(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define dbg(x...)
#endif
#define endl "\n"
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define ROF(i, a, n) for (ll i = a; i >= n; i--)
#define all(x) (x).begin(), (x).end()
#define dline cout << "///REACHED///\n";

typedef long long ll;

const ll MOD = 1e+9 + 7;
const ll INF = 1e9+5;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 4e+5 + 7;


ll n,k;
vector<ll> h;
void solve(){
	cin>>n>>k;
	h.resize(n);
	for(ll&x:h)cin>>x;
	vector<ll> dp(n,INF);
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	FOR(i,2,k){
		FOR(j,0,i){
			if(i<n){

			dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
			}
		}
	}
	// dbg(dp);
	FOR(i,k,n){
		FOR(j,i-k,i){
			if(i<n){

		dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
			}
		}
	}
	// dbg(dp);
	cout<<dp[n-1]<<endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4728
package main

import (
    "fmt"
    "sort"
)

func nextPerm(a []int) int {
    n := len(a)
    besti := -1
    for i := 1; i < n; i++ {
        if a[i] > a[i-1] {
            besti = i
        }
    }

    if besti == -1 {
        return 0
    }

    bestj := besti
    for j := besti; j < n; j++ {
        if a[j] > a[besti-1] {
            bestj = j
        }
    }

    a[bestj], a[besti-1] = a[besti-1], a[bestj]

    for i := besti; i < n; i++ {
        j := n-1+besti - i
        if j < i {
            break
        }

        a[i], a[j] = a[j], a[i]
    }

    return 1
}

func main() {
    INF := 100000000
    var n,m,R int
    var g [][]int
    var r []int


    fmt.Scanf("%d %d %d", &n, &m, &R)

    r = make([]int, R)
    g = make([][]int, n)
    for i := 0; i < n; i++ {
        g[i] = make([]int, n)
    }

    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            g[i][j] = INF
        }
    }

    for i := 0; i < n; i++ {
        g[i][i] = 0
    }

    for i := 0; i < R; i++ {
        fmt.Scanf("%d", &r[i])
        r[i]--
    }

    sort.Ints(r)

    for i := 0; i < m; i++ {
        var a,b,c int
        fmt.Scanf("%d %d %d", &a, &b, &c)
        a--
        b--

        g[a][b] = c
        g[b][a] = c
    }

    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            for k := 0; k < n; k++ {
                if g[j][k] > g[j][i] + g[i][k] {
                    g[j][k] = g[j][i] + g[i][k]
                }
            }
        }
    }

    bestres := INF
    for  {
        res := 0
        for i := 0; i < R-1; i++ {
            res += g[r[i]][r[i+1]]
        }
        if res < bestres {
            bestres = res
        }
        if nextPerm(r) == 0 {
            break
        }
    }

    fmt.Println(bestres)


}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

struct UnionFind{
	vector<int> parent, rank;
	UnionFind(int n){ parent = vector<int>(n, -1); rank = vector<int>(n, 0); }
	int find(int x){
		if(parent[x] == -1) return x;
		else return (parent[x] = find(parent[x]));
	}
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(rank[x] < rank[y])
			parent[x] = y;
		else
			parent[y] = x;
		if(rank[x] == rank[y])
		++rank[x];
		return true;
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	for(int i = 0; i < N; ++i) {
		cin >> p[i];
		p[i]--;
	}
	vector<int> x(M), y(M);
	for(int i = 0; i < M; ++i) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}
	UnionFind uf(N);
	for(int i = 0; i < M; ++i) {
		uf.unite(x[i], y[i]);
	}
	vector<set<int>> a(N), b(N);
	for(int i = 0; i < N; ++i) {
		int f = uf.find(i);
		a[f].insert(i);
		b[f].insert(p[i]);
	}
	int ret = 0; 
	for(int i = 0; i < N; ++i) {
		for(int j: a[i]) {
			if(b[i].find(j) != b[i].end()) {
				ret ++ ;
			}
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 20992
H,W = map(int,input().split())
S = [input() for i in range(H)]

U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
L = [[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            U[i][j] = 0
        elif i == 0 and S[i][j] == '.':
            U[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
            
    for j in range(W):
        if S[i][j] == '#':
            L[i][j] = 0
        elif j == 0 and S[i][j] == '.':
            L[i][j] = 1
        else:
            L[i][j] = L[i][j-1] + 1
            
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            D[i][j] = 0
        elif i == H-1 and S[i][j] == '.':
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1
            
    for j in range(W-1,-1,-1):
        if S[i][j] == '#':
            R[i][j] = 0
        elif j == W-1 and S[i][j] == '.':
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1
            
ans = 0 

for i in range(H):
    for j in range(W):
        ans = max(ans,U[i][j]+R[i][j]+D[i][j]+L[i][j]-3)        
print(ans)    

Measured memory_bytes: 206028
def gcd(a, b):
    x, y = [a, b] if a > b else [b, a]
    while y:
        x, y = y, x%y
    return x

def solve(a, b):
    if b == 1:
        return 0, 1
    elif a == 1:
        return 1, 0

    A, B, Q, R = [a], [b], [b//a], [b%a]
    i = 0
    while R[i] != 0:
        B.append(A[i])
        A.append(R[i])
        Q.append(B[i+1]//A[i+1])
        R.append(B[i+1]%A[i+1])
        i += 1

    x, y = -1*Q[len(Q)-2], 1
    for i in range(len(A)-3, -1, -1):
        x, y = y - x*Q[i], x

    return x, y

a, b = list(map(int, input().split(' ')))
c = gcd(a, b)
a, b = a//c, b//c

x, y = solve(a,b)
print(x, y)


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    string a, b;
    cin >> a >> b;
    int n = sz(a), m = sz(b);
    int ca[n + 1], cb[m + 1];
    ca[0] = cb[0] = 0;
    rep(i, 0, n)
        ca[i + 1] = ca[i] + (a[i] == 'A');
    rep(i, 0, m)
        cb[i + 1] = cb[i] + (b[i] == 'A');
    int q;
    cin >> q;
    rep(i, 0, q)
    {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int cnt1 = ca[r1] - ca[l1 - 1], cnt2 = cb[r2] - cb[l2 - 1];
        cnt1 += ((r1 - l1 + 1) - cnt1) * 2;
        cnt2 += ((r2 - l2 + 1) - cnt2) * 2;
        cout << (cnt1 % 3 == cnt2 % 3 ? "YES\n" : "NO\n");
    }
    return 0;
}


Measured memory_bytes: 1744
from fractions import Fraction
def prime(num):
    prime_list = []
    temp = num
    div = 2
    while temp > 1 and temp >= div ** 2:
        if temp % div == 0:
            prime_list.append(div)
            temp //= div
        else:
            div += 1
    if temp != 1:
        prime_list.append(temp)
    return prime_list

target = int(input())
prime_list = prime(target)
answer = target
# print(prime_list)
for p in set(prime_list):
    answer *= (1 - Fraction(1, p))
print(answer)


Measured memory_bytes: 6912
inLst = list(map(int, input().split()))

anslst = []
anslst.append(inLst[2] - (inLst[3] - inLst[1]))
anslst.append(inLst[3] + (inLst[2] - inLst[0]))
anslst.append(anslst[0] - (inLst[2] - inLst[0]))
anslst.append(anslst[1] - (inLst[3] - inLst[1]))

for i in anslst:
    print(i, end=' ')

Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    val keyword = Set("the", "this", "that")

    def decrementString(line: String): String = line.map {
      case ch if 'b' to 'z' contains ch => (ch - 1).toChar
      case ch if ch == 'a' => 'z'
      case ch => ch
    }

//    @tailrec
    def go(line: String): String = {
      if (line.split(" ").exists(keyword.contains)) {
        line
      } else {
        go(decrementString(line))
      }
    }

    val sc = new java.util.Scanner(System.in)
    while (sc.hasNextLine) {
      println(go(sc.nextLine))
    }
  }
}

Measured memory_bytes: 48196
#include <iostream>


using namespace std;

bool isGood(char number[])
{
	for(int i = 0; i < 4; ++i)
	{
		if(number[i] == number[i + 1])
		{
			return false;
		}
	}
	return true;
}

int main()
{
	char number[5];
	cin >> number;
	if(isGood(number))
	{
		cout << "Good" << endl;
	}
	else
	{
		cout << "Bad" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[300001],f[300001][2][2],mem[300001][2];
pair<int,int>b[300001];
set<int>s;
int main(){
  r(i,300001)a[i]=1;
  cin>>n>>m;
  r(i,m)cin>>b[i].first>>b[i].second;
  sort(b,b+m);
  r(i,m){
    int x=b[i].second;
    if(!s.count(x)){
      s.insert(x);
      int x1=a[x],x2=a[x-1];
      a[x]+=x2,a[x-1]+=x1;
      if(f[x][0][0]){f[x][1][0]++;}
      else{
        mem[x][0]=a[x];
        f[x][0][0]++;
      }
      if(f[x-1][0][1])f[x-1][1][1]++;
      else{
        mem[x-1][1]=a[x-1];
        f[x-1][0][1]++;
      }
    }
    else{
      if(f[x][1]&&f[x-1][1]){
        int x1=a[x]-mem[x][0],x2=a[x-1]-mem[x-1][1];
        a[x]+=x2,a[x-1]+=x1;
        mem[x][0]=a[x],mem[x-1][1]=a[x-1];
        f[x][1][0]=f[x-1][1][1]=0;
      }
      else if(f[x][1]){
        a[x-1]+=a[x]-a[x-1];
        mem[x-1][1]=a[x-1];
        f[x][1][0]==0;
      }
      else if(f[x-1][1]){
        a[x]+=a[x-1]-a[x];
        mem[x][1]=a[x];
        f[x-1][1][1]=0;
      }
    }
  }
  r(i,n){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
}

Measured memory_bytes: 14992
#include<bits/stdc++.h>
#include <unordered_map>
#define int long long int
#define double long double
#define endl "\n"
#define PI 3.141592653589793238462643383279502884
#define sum_up(x)  (x*(x+1))/2
#define sp(x)   setprecision(x)
#define ceil(a,b)   (a+(b-1))/b
#define LCM(a,b)    (a*b)/__gcd(a,b)
#define all(v)  v.begin(),v.end()
#define alls(s,v)  s.begin(),s.end(),v
#define gena(arr,n,nxt)  generate(arr,arr+n, nxt)
#define genv(v,nxt)  generate(v.begin(),v.end(), nxt)
#define BSv(v,a) binary_search(v.begin(),v.end(), a)
#define BSa(v,n,a) binary_search(v,v+n, a)
#define base ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
unsigned int N=1000000;
bool prime[100001];
void sieve(int n)
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int power(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x*x;
    }
    return res;
}

int nxt()
{
    int x;
    cin >> x;
    return x;
}

bool comp(const pair<pair<int,int>,pair<int,int>>&a,
          const pair<pair<int,int>,pair<int,int>>&b)
{
    if(a.second.first==b.second.first)
        return a.first.first<b.first.first;
    return a.second.first>b.second.first;
}

int32_t main()
{
    base;
    int n=nxt();
    cout<<sp(20)<<2*PI*n;
    return 0;
}


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

using ll=long long;



void solve(){
    int a,b;
    int x;
    cin>>a>>b;
    cin>>x;
    if(a<=x && x<=a+b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    ans = 0
elif a < c and c < b and b < d:
    ans = abs(b-c)
elif c < a and a < d and d < b:
    ans = abs(d-a)
elif a <= c and d <= b:
    ans = abs(d-c)
else:
    ans = b-a

print(ans)

Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  
  ll ans = B-1;
  
  ans = min(ans, N);
  
  cout << ans*A/B - A*(ans/B) << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>

using namespace std;

short dp[4001][4001];

int main()
{
	for(;;){
		string s, t;
		
		if(!(cin >> s >> t)){
			break;
		}
		
		for(int i = 0; i <= s.size(); i++){
			dp[i][0] = 0;
		}
		
		for(int j = 0; j <= t.size(); j++){
			dp[0][j] = 0;
		}
		
		for(int i = 1; i <= s.size(); i++){
			for(int j = 1; j <= t.size(); j++){
				if(s[i-1] == t[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}
				else{
					dp[i][j] = 0;
				}
			}
		}
		int ans = 0;
		
		for(int i = 0; i <= s.size(); i++){
			for(int j = 0; j <= t.size(); j++){
				if(dp[i][j] > ans){
					ans = dp[i][j];
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}
	

Measured memory_bytes: 31000
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();

    if(a < b) System.out.println("a < b");
    else if(a > b) System.out.println("a > b");
    else if(a == b) System.out.println("a == b");
  }
}

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

flag = True
for i in range(len(a)):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            pass
        else:
            flag = False

if flag:
    print('APPROVED')
else:
    print('DENIED')


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

const long long mod = 998244353;
int main() {
    int n, s;
    cin >> n >> s;
    int a[3030];
    long long dp[3030][3030][3];
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= s; j++) {
            (dp[i+1][j][0] += dp[i][j][0]) %= mod;
            (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
            (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= mod;
            if(j + a[i] <= s){
                (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
                (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= mod;
            }
        }
    }
    cout << dp[n][s][2] << endl;
}

Measured memory_bytes: 214784
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    ans=A[0]
    for x in A[1:]:
        ans=gcd(ans,x)
    print(ans)
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 88428
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int, int> mp[5];
typedef map<int, int>::iterator iter;
int A[200005][2];
int n, m, mm;
int Read() {
	int x = 0, f = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-')  f = -1;
		ch = getchar();
	}
	while(isdigit(ch))  x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
	return x * f;
}
int query() {
    int res = 0;
    for(int i = 0; i < mm; i++){
        iter l = mp[i].begin();
        iter r = mp[i].end();
        --r;
        int tmp = abs((l -> first) - (r -> first));
        res = max(tmp, res);
    }
    return res;
}
void Dfs(int dep, int val, int root, int pos) {
    if(dep >= m) {
        ++mp[root][val];
        return ;
    }
    Dfs(dep + 1, val + A[pos][dep], root << 1, pos);
    Dfs(dep + 1, val - A[pos][dep], root << 1 | 1, pos);
    return ;
}
signed main() {
    m = 2, mm = 4;
    for(int i = 0; i < mm; i++)
        mp[i].clear();
    n = Read();
    for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= 2; j++)
			A[i][j - 1] = Read();
        Dfs(0, 0, 0, i);
    }
	printf("%d\n", query());
    return 0;
}

Measured memory_bytes: 56864
n,m = [int(v) for v in input().split()]
sc = [[int(v) for v in input().split()] for _ in range(m)]

ans = [-1 for _ in range(n+1)]
flag = True

for (s,c) in sc:
    if s > n: flag = False
    elif ans[s] != -1 and ans[s] != c: flag = False
    else: ans[s] = c

if ans[1] == -1: ans[1] = 1
elif ans[1] == 0 and n != 1: flag = False

if m == 0:
    if n == 1:
        print(0)
    else:
        print(1,end='')
        for _ in range(n-1):
            print(0,end='')
    exit()

if flag:
    for v in ans[1:]:
        if v == -1:
            print(0,end='')
        else:
            print(v,end='')
else:
    print(-1)


Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void)
{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}



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

using namespace std;

typedef long long ll;

const ll INF = 20000000000;

int Szukaj1(vector<ll>& a, ll x)
{
    int l = 0, p = a.size() - 1, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (a[s] <= x)
        {
            r = s;
            l = s + 1;
        }
        else
            p = s - 1;
    }
    return r;
}

int Szukaj2(vector<ll>& a, ll x)
{
    int l = 0, p = a.size() - 1, s, r = -1;
    while (l <= p)
    {
        s = (l + p) / 2;
        if (a[s] >= x)
        {
            r = s;
            p = s - 1;
        }
        else
            l = s + 1;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<ll> a(n), b(m);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i];
    for (int i = 0; i < q; ++i)
    {
        ll x;
        cin >> x;
        ll aL = Szukaj1(a, x);
        ll bL = Szukaj1(b, x);
        ll aP = Szukaj2(a, x);
        ll bP = Szukaj2(b, x);
        ll odp = INF;
        if (aL != -1 && bL != -1)
            odp = min(odp, x - min(a[aL], b[bL]));
        if (aP != -1 && bP != -1)
            odp = min(odp, max(a[aP], b[bP]) - x);
        if (aL != -1 && bP != -1)
            odp = min(odp, min(2 * (b[bP] - x) + (x - a[aL]), 2 * (x - a[aL]) + (b[bP] - x)));
        if (bL != -1 && aP != -1)
            odp = min(odp, min(2 * (a[aP] - x) + (x - b[bL]), 2 * (x - b[bL]) + (a[aP] - x)));
        cout << odp << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,c,d,i,x,y;
bool check() {
	return b>=(i*c-(n-1-i)*d)&&b<=(i*d-(n-1-i)*c);
}
int main() {
	cin>>n>>a>>b>>c>>d;
	b-=a;
	for(i=0;i<n;i++)
	if(check()) return puts("YES"),0;
	puts("NO");
}

Measured memory_bytes: 256
"""
tuple
"""
n,Y = map(int,input().split())
ans = -1,-1,-1
for x in range(n+1):
    for y in range(n-x+1):
        z = n - x - y 
        if 0 <= z <=2000 and (10000*x+5000*y+z*1000)==Y:
            ans = x,y,z
            break
        else :
            continue
        break
print(*ans)



Measured memory_bytes: 9148
#include <iostream>

int main(int argc, char **argv) {
  int a, b;
  
  std::cin >> a >> b;
  if (a < b) {
    std::cout << "a < b" << std::endl;
  }else if (a > b) {
    std::cout << "a > b" << std::endl;
  }else {
    std::cout << "a == b" << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[200005];
int cnt[200005];
int32_t main(){
	int n,k;cin>>n>>k;
	set<int> distinct;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		cnt[ar[i]]++;
		distinct.insert(ar[i]);
	}
	sort(ar+1,ar+n+1,[](int a,int b){return cnt[a]<cnt[b]||(cnt[a]==cnt[b]&&a<b);});
	int c = distinct.size();
	int ans = 0;
	int i=1;
	/*for(int i=1;i<=n;i++,cout<<i-1<<" "<<ar[i-1]<<"\n");
	cout<<"\n";*/
	while(c>k){
		if(ar[i]!=ar[i+1]){
			c--;
		}
		ans++;
		//cout<<i<<" "<<ar[i]<<" "<<c<<" "<<ans<<"\n";
		i++;
	}
	cout<<ans;
}


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

int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    priority_queue<ll, vector<ll>, greater<ll> > ma;
    for(int i = 1; i < n; i++) ma.push(t[i] - t[i - 1] - 1);
    ll ans = n, kx = n;
    while(kx > k){
        kx--;
        ans += ma.top();
        ma.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4624
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll power(ll a, ll b){
  ll ans = 1;
  if(b%2==0){
    REP(i, b/2){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans;
  }else{
    b = b/2;
    REP(i, b){
      ans *= a;
      if(ans>1000000000){
        return -1;
      }
    }
    return ans * ans* a;
  }
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main(void){

  ll n;
  cin>>n;
  if(n%1000==0) cout<<0<<endl;
  else cout<<1000-n%1000<<endl;
  return 0;
  
}

Measured memory_bytes: 3620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine());
        HashSet<long> reses = new HashSet<long>();
        long res = 0;
        for (long b = 2; b * b <= n; b++)
        {
            for (long pow = 1; n % pow == 0; pow *= b)
            {
                if (((n / pow) - 1) % b == 0)
                {
                    reses.Add(b);
                    res++;
                    break;
                }
            }
        }
        //b^n(mb+1)
        res++;//k=6
        long i;
        for (i = 1; i * i <= n - 1; i++)
        {
            if ((n - 1) % i != 0) continue;
            reses.Add((n - 1) / i);
            reses.Add(i);
            res += 2;
        }
        Console.WriteLine(reses.Count);
    }
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){
    long long N,sum;
    sum = 0;
    cin >> N;
    for (int i = 1; i < N+1; i++){
        if(i % 3 == 0 || i % 5 == 0)continue;
        else sum += i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define rev(N) 	for (int i = N - 1; i >= 0; --i)
#define all(v) v.begin(), v.end()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v; rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << endl;
}

int main() {
	int N, A;
	cin >> N >> A;
	if (N % 500 <= A)say("Yes");
	else say("No");
}


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[] a = new int[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }

        int count = 0;
        Set<Integer> ignore = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            if (ignore.contains(i)) continue;
            if (i == a[a[i]]) {
                count++;
                ignore.add(a[i]);
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 50800
//xの3乗
(stdin => {
  // Define Function
  const xCubic = x => x*x*x

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  
  const n = parseInt(inputs[0],10) 
  console.log(xCubic(n))

})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15392
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[1]+x[0])

ans = 0
for i,(a,b) in enumerate(AB[::-1]):
    if i%2:
        ans -= b
    else:
        ans += a
print(ans)

Measured memory_bytes: 21364
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N;

//３番目以降を埋める
void fillc(bool *animal,string &s){
    for(int i=2;i<N;i++) {
        if (animal[i - 1]) {
            if(s[i - 1] == 'o')animal[i]=animal[i - 2];
            else animal[i]=!animal[i - 2];
        } else {
            if(s[i - 1] == 'o')animal[i]=!animal[i - 2];
            else animal[i]=animal[i - 2];
        }
    }
}

bool chk(bool *animal,string &s){
    if(animal[0]){
        if(s[0]=='o'){
            return animal[1]==animal[N-1];
        }else{
            return animal[1]!=animal[N-1];
        }
    }else{
        if(s[0]=='o') {
            return animal[1] != animal[N - 1];
        }else{
            return animal[1]==animal[N-1];
        }
    }
}

bool chk2(bool *animal,string &s){
    if(animal[N-1]){
        if(s[N-1]=='o'){
            return animal[N-2]==animal[0];
        }else{
            return animal[N-2]!=animal[0];
        }
    }else{
        if(s[N-1]=='o')return animal[N-2]!=animal[0];
        else return animal[N-2]==animal[0];
    }
}

void set_bool(bool *animal,bool a,bool b){
    animal[0]=a;animal[1]=b;
}

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

    bool animal[N];

    REP(i,4){
        set_bool(animal,i%2==0,i<2);
        fillc(animal,s);
        if(chk(animal,s)&&chk2(animal,s)){
            REP(i,N){
                char c = animal[i]?'S':'W';
                cout<<c;
            }
            cout<<endl;
            break;
        }
        if(i==3){
            cout<<-1<<endl;
        }
    }






    return 0;
}

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

int main() {
  long int n, m, l;
  cin >> n >> m >> l;
  long int a[n][m] = {}, b[m][l] = {}, c[n][l] = {};
  for (int i = 0; i < n; i ++) {
      for (int j = 0; j < m; j++) {
          cin >> a[i][j];
      }
  }
  
  for(int i = 0; i < m; i ++){
      for(int j = 0; j < l; j++) {
          cin >> b[i][j];
      }
  }
  
  for(int k = 0; k < l; k++) {
  for(int i = 0; i < n; i ++) {
      for(int j = 0; j < m; j++) {
          c[i][k] = c[i][k] + a[i][j]*b[j][k];
      }
  }
  }
  
  for(int i = 0; i < n; i++) {
      for(int j = 0; j < l; j ++) {
          cout << c[i][j];
          if(j == l-1) {
              cout << endl;
          } else {
              cout << " ";
          }
      }
  }
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    cout<<!n;
}


Measured memory_bytes: 3600
#include <iostream>
#include <complex>
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

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

const double EPS = 1e-8;
const double INF = 1e12;

typedef complex<double> P;
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

// ??????
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

// ??????
double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}

// ???p2?????????p0, p1???????????´???????°???±?????????
P projection(const P& p0, const P& p1, const P& p2) {
    // ???????????????????????´???
    P vec1 = p1 - p0;
    P vec2 = p2 - p0;
    return p0 + vec1 * dot(vec1, vec2) / dot(vec1, vec1);
}

// ???p0, p1???????????´??????????§°?????¨????????????p2??¨????§°??????
P reflection(const P& p0, const P& p1, const P& p2) {
    P proj = projection(p0, p1, p2);
    return proj - (p2 - proj);
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;                               // a--c--b on line
}

// 2??´?????????????????????
bool is_parallel(const L& l1, const L& l2) {
    P p1 = l1[1] - l1[0];
    P p2 = l2[1] - l2[0];
    auto res = ccw(p1, p2, P(0,0));
    return (res == 2 || res == -2 || res == 0);
}

// 2??´???????????´?????????
bool is_ortho(const L& l1, const L& l2) {
    P p1 = l1[1] - l1[0];
    P p2 = l2[1] - l2[0];
    return dot(p1, p2) == 0;
}

// l: line(??´???)
// s: segment(??????)
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}


// // ????????¨???P??¨??????????????????????????¢
// double norm(const P& a, const P& b) {
//     return dot(
//     return real(conj(a)*b);
// }

int main(){
    int Q;
    cin >> Q;
    REP(q, Q) {
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        P p0(x0, y0);
        P p1(x1, y1);
        P p2(x2, y2);
        P p3(x3, y3);
        L s0(p0, p1);
        L s1(p2, p3);
        cout << intersectSS(s0, s1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#include <cstdint>
using namespace std;
typedef long long ll;
int main() {
  int cnt[4] = {0, 0, 0, 0};
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char in[3];
    cin >> in;
    switch (in[0]) {
    case 'A':
      cnt[0]++;
      break;
    case 'W':
      cnt[1]++;
      break;
    case 'T':
      cnt[2]++;
      break;
    default:
      cnt[3]++;
    }
  }
  cout << "AC x " << cnt[0] << endl
       << "WA x " << cnt[1] << endl
       << "TLE x " << cnt[2] << endl
       << "RE x " << cnt[3] << endl;
}


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

using namespace std;

typedef long long ll;

#define MAX_VAL 55
#define MAX_N 55


ll dp[MAX_N * MAX_VAL][MAX_N][MAX_N];
bool used[MAX_N * MAX_VAL][MAX_N][MAX_N];
int n;
vector<int> x;

ll getdp(int sum, int last, int num) {
    if (sum < 0)
        return 0;

    if (used[sum][last][num])
        return dp[sum][last][num];

    ll& cur = dp[sum][last][num];

    if (num == 0) {
        cur = 0;
        used[sum][last][num] = true;
        if (sum == x[last]) {
            cur = 1;
        }
        return cur;
    }

    for (int i = 0; i < last; ++i) {
        cur += getdp(sum-x[last], i, num - 1);
    }
    used[sum][last][num] = true;
    return cur;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans += getdp(a * i, j, i-1);
        }
    }
    cout << ans << endl;
}



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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int m = (s[0]-'0')*10 + (s[1]-'0');
    int y = (s[2]-'0')*10 + (s[3]-'0');

    if((y == 0 || y > 12)&&(m == 0 || m > 12)){
        cout << "NA" << endl;
    }else if(m == 0 || m > 12){
        cout << "YYMM" << endl;
    } else if(y == 0 || y > 12){
        cout << "MMYY" << endl;
    } else {
        cout << "AMBIGUOUS" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)

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

    for(int i=0; i<s.size()-8; i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m;
  cin>>n>>m;
  int c[n+1][n+1],d[m+1][m+1];
  vector<vector<int>> k(3,vector<int>(m+1,0));
  for(int i=1;i<=m;i++){
    for(int j=1;j<=m;j++){
      cin>>d[i][j];
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cin>>c[i][j];
      k[(i+j)%3][c[i][j]]++;
    }
  }
  vector<P> a[3];
  for(int i=0;i<3;i++){
    for(int j=1;j<=m;j++){
      int t=0;
      for(int r=1;r<=m;r++){
        t+=k[i][r]*d[r][j];
      }
      a[i].push_back(P(t,j));
    }
    sort(a[i].begin(),a[i].end());
  }
  int ma=1000000000,cnt,x,y;
  cnt=a[0][0].first,x=a[0][0].second;
  if(x==a[1][0].second){
    cnt+=a[1][1].first,y=a[1][1].second;
  }else{
    cnt+=a[1][0].first,y=a[1][0].second;
  }
  if(x==a[2][0].second||y==a[2][0].second){
    if(x==a[2][1].second||y==a[2][1].second){
      cnt+=a[2][2].first;
    }else{
      cnt+=a[2][1].first;
    }
  }else{
    cnt+=a[2][0].first;
  }
  ma=min(ma,cnt);
  cnt=a[0][0].first,x=a[0][0].second;
  if(x==a[2][0].second){
    cnt+=a[2][1].first,y=a[2][1].second;
  }else{
    cnt+=a[2][0].first,y=a[2][0].second;
  }
  if(x==a[1][0].second||y==a[1][0].second){
    if(x==a[1][1].second||y==a[1][1].second){
      cnt+=a[1][2].first;
    }else{
      cnt+=a[1][1].first;
    }
  }else{
    cnt+=a[1][0].first;
  }
  ma=min(ma,cnt);
  cnt=a[1][0].first,x=a[1][0].second;
  if(x==a[0][0].second){
    cnt+=a[0][1].first,y=a[0][1].second;
  }else{
    cnt+=a[0][0].first,y=a[0][0].second;
  }
  if(x==a[2][0].second||y==a[2][0].second){
    if(x==a[2][1].second||y==a[2][1].second){
      cnt+=a[2][2].first;
    }else{
      cnt+=a[2][1].first;
    }
  }else{
    cnt+=a[2][0].first;
  }
  ma=min(ma,cnt);
  cnt=a[1][0].first,x=a[1][0].second;
  if(x==a[2][0].second){
    cnt+=a[2][1].first,y=a[2][1].second;
  }else{
    cnt+=a[2][0].first,y=a[2][0].second;
  }
  if(x==a[0][0].second||y==a[0][0].second){
    if(x==a[0][1].second||y==a[0][1].second){
      cnt+=a[0][2].first;
    }else{
      cnt+=a[0][1].first;
    }
  }else{
    cnt+=a[0][0].first;
  }
  ma=min(ma,cnt);
  cnt=a[2][0].first,x=a[2][0].second;
  if(x==a[0][0].second){
    cnt+=a[0][1].first,y=a[0][1].second;
  }else{
    cnt+=a[0][0].first,y=a[0][0].second;
  }
  if(x==a[1][0].second||y==a[1][0].second){
    if(x==a[1][1].second||y==a[1][1].second){
      cnt+=a[1][2].first;
    }else{
      cnt+=a[1][1].first;
    }
  }else{
    cnt+=a[1][0].first;
  }
  ma=min(ma,cnt);
  cnt=a[2][0].first,x=a[2][0].second;
  if(x==a[1][0].second){
    cnt+=a[1][1].first,y=a[1][1].second;
  }else{
    cnt+=a[1][0].first,y=a[1][0].second;
  }
  if(x==a[0][0].second||y==a[0][0].second){
    if(x==a[0][1].second||y==a[0][1].second){
      cnt+=a[0][2].first;
    }else{
      cnt+=a[0][1].first;
    }
  }else{
    cnt+=a[0][0].first;
  }
  ma=min(ma,cnt);
  cout<<ma;
}

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

int main(){
	string s;
	cin >> s;
	if(s == "Sunny"){
		cout << "Cloudy" << endl;
	}
	else if(s == "Cloudy"){
		cout << "Rainy" << endl;
	}
	else{
		cout << "Sunny" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, c, d, e, f;

signed main() {
	cin >> a >> b >> c >> d >> e >> f;
	if (a*c + b * d == a * e + b * f) {
		cout << "infinity" << endl;
		return 0;
	}
	if ((c <= e && d <= f) || (c >= e && d >= f)) {
		cout << 0 << endl;
		return 0;
	}
	int n = a * c + b * d;
	int m = a * e + b * f;
	int s = a * (max(c, e) - min(c, e));
	int w = max(n, m) - min(n, m);
	if ((c < e&&n < m) || (c > e&&n > m)) {
		cout << 0 << endl;
		return 0;
	}
	if (!(s%w))cout << s / w * 2 << endl;
	else cout << s / w * 2 + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
string s;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>s;
    string ss="CODEFESTIVAL2016";
    int cunt=0;
    for(int i=0;i<ss.size();i++){
        if(s[i]!=ss[i]) cunt++;
    }
    cout<<cunt<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int n,m,k,x,y,cnt[maxn],fa[maxn],sum[maxn];
int findd(int x){
    if(x==fa[x])
        return x;
    return fa[x]=findd(fa[x]);
}
int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++){//初始化
        sum[i]=1,fa[i]=i;
    }
    for(int i=1;i<=m;i++){
        scanf("%d %d",&x,&y);
        cnt[x]++,cnt[y]++;
        if(findd(x)!=findd(y)){
            sum[findd(y)]+=sum[findd(x)];
            fa[findd(x)]=findd(y);
        }
    }
//    for(int i=1;i<=n;i++){
//        printf("%d ",sum[findd(i)]);
//    }
//    printf("\n");
    for(int i=1;i<=k;i++){
        scanf("%d %d",&x,&y);
        if(findd(x)==findd(y)){
            cnt[x]++,cnt[y]++;
        }
    }
    for(int i=1;i<=n;i++){
        int ans=sum[findd(i)]-cnt[i]-1;
        printf("%d%c",ans,i==n?'\n':' ');
    }
    return 0;
}



Measured memory_bytes: 2560
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Buffer(make([]byte, 500000), 500000)
	sc.Split(bufio.ScanWords)

	n := nextInt()

	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n-1)
		for j := 0; j < n-1; j++ {
			a[i][j] = nextInt() - 1
		}
	}

	allMatches := n * (n - 1) / 2

	queue := make([]int, 0)
	for i := 0; i < n; i++ {
		queue = append(queue, i)
	}

	for day := 1; ; day++ {
		flags := make([]bool, n)
		nextQueue := make([]int, 0)
		for _, i := range queue {
			if len(a[i]) == 0 {
				continue
			}
			j := a[i][0]
			if len(a[j]) == 0 {
				continue
			}
			if flags[i] || flags[j] || a[j][0] != i {
				continue
			}
			flags[i] = true
			flags[j] = true
			a[i] = a[i][1:]
			a[j] = a[j][1:]
			nextQueue = append(nextQueue, i, j)
			allMatches--
		}
		queue = nextQueue
		if len(queue) == 0 {
			fmt.Println(-1)
			break
		}
		if allMatches == 0 {
			fmt.Println(day)
			break
		}
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}


Measured memory_bytes: 18432