akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, p);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rrep(i, n) {
        //cout << i << endl;
        int sums = 0;
        for (int j = i; j < n; j += (i+1))
        {
            //cout << j << endl;
            sums += b[j];
        }
        if (sums % 2 != a[i]) {
            b[i] = 1;
            cnt++;
        }
        
    }
    cout << cnt << endl;
    rep(i, n) {
        if (b[i]) cout << i + 1 << ' ';
    }
    return 0;
}

Measured memory_bytes: 2432
import sys
sys.setrecursionlimit(10**6)

n, T, A = map(int, input().split())
T -= 1; A -= 1
g = [list() for i in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

dist_r = [0] * n
dist_t = [0] * n

def dfs(v, p, dist):
    dist_r[v] = dist
    ret = 0
    for nv in g[v]:
        if nv == p: continue
        ret = max(ret, dfs(nv, v, dist+1))
    dist_t[v] = ret
    return ret + 1

dfs(A, -1, 0)

init_dist = dist_r[T]
v = T
d1 = 0
d2 = init_dist
while init_dist - dist_r[v] < dist_r[v]:
    if d1 < dist_t[v]:
        d1 = dist_t[v]
        d2 = dist_r[v]
    for nv in g[v]:
        if dist_r[v] > dist_r[nv]:
            v = nv
            break

print(d1+d2-1)

Measured memory_bytes: 104492
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
  vb.resize(N);
  partial_sum(all(va), vb.begin());
}

int calc(int l, int m, int r) {
  if (0 <= l && l < m && m < r && r < N - 1) {
    int a1 = vb[l];
    int a2 = vb[m] - a1;
    int a3 = vb[r] - vb[m];
    int a4 = vb[N - 1] - vb[r];
    return (max({a1, a2, a3, a4}) - min({a1, a2, a3, a4}));
  } else
    return INF;
}
// int left(int i, int j) {
//   if (0 <= i && i < j && j < N - 2) {
//     int a1 = vb[i];
//     int a2 = vb[j] - a1;
//     return (max({a1, a2} - min({a1, a2})));
//   } else {
//     return INF;
//   }
// }
// int right(int mid, int r) {
//   if (0 < mid && mid < r && r < N - 1) {
//     int a1 = vb[N - 1] - vb[r];
//     int a2 = vb[r] - vb[mid];
//     return (max({a1, a2}) - min({a1, a2}));
//   } else {
//     return INF;
//   }
// }

void solve() {
  // 尺取法
  int l = 0;
  int mid = 1;
  int r = 2;
  int ans = INF;
  while (mid < N - 2) {  // midをきめる
    while (vb[mid] > vb[l] * 2) {
      ++l;
    }
    while (vb[N - 1] - vb[mid] > (vb[r] - vb[mid]) * 2) {
      ++r;
    }
    chmin(ans, calc(l, mid, r));
    chmin(ans, calc(l - 1, mid, r));
    chmin(ans, calc(l - 1, mid, r - 1));
    chmin(ans, calc(l, mid, r - 1));
    mid++;
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

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

typedef long long ll;
typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define pb push_back
#define mp make_pair
#define all(c) ((c).begin(), (c).end)
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = (c).begin();it!=(c).end();it++)
#define present(c,x) ((c).find(x)!=(c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end)
#define cp(s,c) copy(all(c),(s).begin())
// note that data is copied from C --> S's reference

void dfs(int n, int m, int pre_num, vi now, vvi &num)
{
    if (now.size() == n)
    {
        num.pb(now);
        return;
    }
    for (int i = pre_num; i <= m; i++)
    {
        auto tmp_now = now;
        tmp_now.pb(i);
        dfs(n, m, i, tmp_now, num);
    }
    return;
}

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m, q;
    cin >> n >> m >> q;
    vi a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i], a[i]--, b[i]--;
    vvi num;
    vi now;
    dfs(n, m, 1, now, num); // on which iteration are we .
    int ans = 0;
    for (int i = 0; i < num.size(); i++)
    {
        int sum = 0;
        for (int j = 0; j < q; j++)
        {
            if (num[i][b[j]] - num[i][a[j]] == c[j])
                sum += d[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13856
#include<stdio.h>
#include<string.h>
#define m 1000003
long long dna[m];
int zimu_to_num(char c){
	if (c=='A') return 1;
	if (c=='C') return 2;
	if (c=='G') return 3;
	if (c=='T') return 4;
	else return 0;
}
long long be_long(char str[]){
	long long sum=0;
	for(int i=0;i<strlen(str);i++){
		sum=sum*10+zimu_to_num(str[i]);
	}
	return sum;
}
long long h1(long long key){
	return key %m;
} 
long long h2(long long key){
	return 1+(key %(m-1));
} 
long long h(long long key,long long i){
	return (h1(key)+i*h2(key)) %m;
}
long long insert(long long t[],long long key){
	long long i=0;
	while(true){
		long long j=h(key,i);
		if(t[j]==-1){
			t[j]=key;
			return j;
		}
		else {
			i++;
		}
	}
}
long long find(long long t[],long long key){
	long long i=0;
	while(true){
		long long j=h(key,i);
		if (t[j]==key)
		{printf("yes\n");
		return j;}
		else if (t[j]==-1 || i>=m){
			printf("no\n");
			return 0;
		}
		else {
			i++;
		}
	}
}


int main(){
char order[10];
char zimu[15];
long long n,i;
long long long_num; 

memset(dna,-1,sizeof(dna));
scanf("%I64d",&n);
for(i=0;i<n;i++){
	scanf("%s %s",&order,&zimu);
	long_num=be_long(zimu);
	if(order[0]=='i') insert(dna,long_num);
	else find(dna,long_num);
}

}




Measured memory_bytes: 10440
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N;cin >> N;
    vector<int> T(N);
    int sum =0;
    for(int i=0;i<N;i++) {cin >> T[i]; sum+=T[i];}
    int M; cin >> M;

    for(int i=0;i<M;i++){
        int p,x; cin >> p >> x;
        int out = sum - T[p-1] + x;
        cout << out << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>cnt(n + 5);
    for(int i = 1; i < n; i++){
        int x;
        cin >> x;
        cnt[x]++;
    }
    for(int i = 1; i <= n; i++){
        cout << cnt[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const int INF=0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,x,num=INF;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>x;
        int temp=0;
        while(x%2==0) {
            x/=2;
            temp++;
        }
        num=min(num,temp);
    }
    cout<<num<<endl;
    return 0;
}


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


int main(){
    int n;
    cin >> n;
    int mi = n+1;
    int ans=0;
    for (int i=0; i<n; i++){
        int p;
        cin >> p;
        if (p <= mi){
            ans++;
            mi = p;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
string a,b;
char c[81];
int main(){
    while(getline(cin,a)){
        int flg=0;
        for(;;){
            if(flg==1)break;
            for(int i=0;i<26;i++){
                for(int j=0;j<a.size();j++){
                    if(a[j]>='a'&&a[j]<='z'){
                        if(a[j]-1>='a'){
                            a[j]-=1;
                        }else{
                            a[j]+=25;
                        }
                    }
                }
                for(int j=0;j<a.size()-3;j++){
                    b=a.substr(j,3);
                    if(b=="the")flg=1;
                    b=a.substr(j,4);
                    if(b=="that"||b=="this")flg=1;
                    if(flg==1)break;
                }
                if(flg==1)break;
            }
        }
    cout<<a<<endl;
    }
return 0;
}

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

int A[310][310];
bool required[310][310];

int main() {
    int N;
    cin >> N;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            cin >> A[i][j];
            required[i][j] = true;
        }
    }

    long long ans = 0;
    for (int k=0; k<N; k++) {
        for (int i=0; i<N; i++) {
            for (int j=0; j<N; j++) {
                if (A[i][j] > A[i][k] + A[k][j]) {
                    ans = -1;
                    goto END;
                }
                if (i != k && j != k && A[i][j] == A[i][k] + A[k][j]) {
                    required[i][j] = false;
                    required[j][i] = false;
                }
            }
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=i; j<N; j++) {
            if (required[i][j]) ans += A[i][j];
        }
    }

END:
    cout << ans << endl;

    return 0;
}


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

int main(){
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double x = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  cout << setprecision(20) << sqrt(x) << endl;
}


Measured memory_bytes: 3288
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int a, b, k;
  cin >> a >> b >> k;
  int tmp = 0;
  while (k--) {
    if (tmp % 2 == 0) {
      if (a % 2 == 1) a--;
      int A = a / 2;
      a /= 2;
      b += A;
    } else {
      if (b % 2 == 1) b--;
      int B = b / 2;
      b /= 2;
      a += B;
    }
    tmp++;
  }
  cout << a << ' ' << b << endl;
  return 0;
}


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


int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	if(a-b>=0)cout<<"delicious"<<endl;
	else if(b-a<=n)cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
	return 0;
}

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

int main() {
	// your code goes here
	long long A = 0;
	long long B = 0;
	long long C = 0;
	long long K = 0;
	cin>>A>>B>>C>>K;
	long long res = 0;
	if(K<=A)
	{
	    res = K;
	}
	else if(K<=A+B)
	{
	    res = A;
	}
	else
	{
	    res = 2*A + B - K;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 3588
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n; cin >> n;
  ll sumV=0;
  rep1(i,n){
    sumV+=i*(n-i+1);
  }
  ll sumE=0;
  rep(i,n-1){
    ll a,b; cin >> a >> b;
    if(a>b) swap(a,b);
    sumE+=a*(n-b+1);
  }
  ll ans=sumV-sumE;
  cout << ans << endl;
}

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

for i in range(n):
    x[i] -= a

x.sort()

if x[0] > 0 or x[-1] < 0:
    print(0)
    exit()

num_zero = x.count(0)

if x[0] == 0 or x[-1] == 0:
    print(pow(2, num_zero) - 1)
    exit()

xp = [i for i in x if i > 0]
xm = [-i for i in x if i < 0]

sum_xp = sum(xp) + 1
dp = [0] * sum_xp
dp[0] = 1
for i in xp:
    new_dp = [0] * sum_xp
    for j in range(sum_xp - i):
        new_dp[i + j] += dp[j]
    for j in range(sum_xp):
        dp[j] += new_dp[j]

for i in xm:
    new_dp = [0] * sum_xp
    for j in range(i, sum_xp):
        new_dp[j - i] += dp[j]
    for j in range(sum_xp):
        dp[j] += new_dp[j]

print(dp[0] * pow(2, num_zero) - 1)

Measured memory_bytes: 66380
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    lin a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a+3);
    lin res = a[2] * 10 + a[1] + a[0];

    cout << res << endl;

    return 0;
}


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

infty = 2**21

def dijkstra(n):
    d = [infty] * n
    color = [0] * n

    d[0] = 0
    PQ = [(0, 0)]
    heapq.heapify(PQ)
    color[0] = 1

    while PQ:
        f = heapq.heappop(PQ)
        u = f[1]
        color[u] = 2

        #最小値を取り出し、それが最短でなければ無視
        if d[u] < f[0]:
            continue

        for adj_u in adj[u]:
            v = adj_u[0]
            if color[v] == 2:
                continue
            if d[v] > d[u] + adj_u[1]:
                d[v] = d[u] + adj_u[1]
                heapq.heappush(PQ, (d[v], v))
                color[v] = 1


    for i in range(n):
        print(str(i) + ' ' + str(-1 if d[i] == infty else d[i]))


n = int(input())

adj = [0]*n

for _ in range(n):
    u, k, *vc = map(int, input().split())
    vx_tuple = [0] * k
    for i, (v, c) in enumerate(zip(vc[::2], vc[1::2])):
        #pythonにはvectorないので、tupleで代用
        vx_tuple[i] = (v, c)
    adj[u] = vx_tuple


dijkstra(n)



Measured memory_bytes: 67504
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	string s;
	cin >> s;
	for (char &c : s) {
		if (c == '?') c = 'D';
	}
	
	cout << s << '\n';
	
	return 0;
}

Measured memory_bytes: 3752
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const M = scan!int;
  const A = scan!int(N);

  string solve() {
    const votesCount = A.sum();
    
    int items;
    foreach(a; A) if (a*4*M >= votesCount) items++;

    return items >= M ? "Yes" : "No";
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int N,M,C,i,j,X=0,count=0;
  	int A[20][20], B[20];

    scanf("%d %d %d", &N, &M, &C);
  	for(j=0;j<M;j++){
      scanf("%d",&B[j]);
    }

  	for(i=0;i<N;i++){
      X=C;
      for(j=0;j<M;j++){
        scanf("%d",&A[i][j]);
        X=X+A[i][j]*B[j];
      }
      if(X>0){
        count++;
      }
    }

    printf("%d",count);
    return 0;
}

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



int main(){
    string cmd;
    int num;
    vector<int> q;
    while (cin >> cmd && cmd != "end") {
        if (cmd == "insert") {
            cin >> num;
            q.push_back(num);
            int n = q.size()-1;
            while(n > 0 && q[(n-1)/2] < q[n]){
                swap(q[(n-1)/2], q[n]);
                n = (n-1)/2;
            }
        }else if(cmd == "extract"){
            int ans = q[0];
            q[0] = q[q.size()-1];
            q.pop_back();
            int n = 0;
            int N = q.size();
            while(2*n+1 < N){
                int i;
                if(2*n+2 < N){
                    i = (q[2*n+1] > q[2*n+2] ? 2*n+1 : 2*n+2);
                }else{
                    i = 2*n+1;
                }
                if (q[i] > q[n]){
                    swap(q[i], q[n]);
                    n = i;
                }else{
                    break;
                }
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef unsigned long long ull;
const int N=1e4;
const double eps=1e-6;
const int MOD=1e5+3;
const int INF=0x3f3f3f3f;
int main()
{
    int n,y;
    while(cin>>n>>y)
    {
        for(int i=0;i<=n;i++)
        {
            for(int j=0;i+j<=n;j++)
            {
                int k=n-(i+j);
                if(i+j+k==n&&i*N+j*(N/2)+k*(N/10)==y)
                {
                    printf("%d %d %d\n",i,j,k);
                    return 0;
                }
            }
        }
        puts("-1 -1 -1");
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int H,W,i,j,k;

  while(1){
    scanf("%d %d",&H,&W);

    if(H==0 && W==0){
      break;
    }else if(H==1 & W==1){
      printf("#\n");
    }else{

      //???????????????
      for (i=0; i<W; i++){
	printf("#");
      }
      printf("\n");

      //???????????????
      for(k=0; k<H-2; k++){
	printf("#"); //??????????????????#
	for(j=0; j<W-2; j++){
	  printf(".");
	}
	printf("#\n"); //??????????????????#
      }
      
      //???????????????
      for(i=0; i<W; i++){
	printf("#");
      }

      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int tt,tp;
bool w[N];
int head[N],to[N*2],nxt[N*2],v[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool dfs(int x) {
    if(w[x]) return 0;
    w[x]=1,v[++tp]=x;
    for(int i=head[x];i;i=nxt[i])
	if(dfs(to[i])) return 1;
    return 1;
}
int main() {
    int n,m,x,y;
    cin>>n>>m;
    for(int i=1;i<=m;i++) {
	x=gi(),y=gi();
	to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
    }
    w[x]=1;
    for(int i=head[x],j=0;i;i=nxt[i])
	if(dfs(to[i])) {
	    if(!j) reverse(v+1,v+1+tp),v[++tp]=x,++j;
	    else break;
	}
    cout<<tp<<endl;
    for(int i=1;i<=tp;i++) printf("%d ",v[i]);
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if(a == b){
		cout << "a == b" << endl;
	}else if(a < b){
		cout << "a < b" << endl;
	}else{
		cout << "a > b" << endl;
	}

	/*
	a -= b;
	if(a){
		if(a < 0){
			cout << "a < b" << endl;
		}else{
			cout << "a > b" << endl;
		}
	}else{
		cout << "a == b" << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 3076
import java.io.*;
public class Main {
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line1 = reader.readLine();
			int n = Integer.parseInt(line1);//1stLine
			String line2 = reader.readLine();//2ndLine
			String[] sarray = line2.split(" ", -1);
			int[] num = new int[n];
			for(int i = 0; i < n; i++){
				num[i] = Integer.parseInt(sarray[i]);
			}
			
			int min = 0;//min number
			int p = 0;
			while(min < n - 1 && p < n - 1){
				p++;
				if(num[min] > num[p]){
					min = p;
				}
			}
			
			int max = 0;//max number
			int q = 0;
			while(max < n - 1 && q < n - 1){
				q++;
				if(num[max] < num[q]){
					max = q;
				}
			}
			
			long sum[] = new long[n + 1]; //sum long
			long value[] = new long[n];
			for(int j = 0; j < n; j++){
				value[j] = num[j]; //int to long
			}
			sum[0] = 0;
			for(int k = 1; k <= n; k++){
				sum[k] = value[k - 1] + sum[k - 1];
			}
			
			System.out.println(num[min] + " " + num[max] + " " + sum[n]);
		} catch (IOException e) {
          System.out.println(e);
        } catch (NumberFormatException e) {
          System.out.println("error");
        }
    }
}

Measured memory_bytes: 29088
from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			cnt += 1
			insort_left(keytbl, ki)
		elif dict[ki] == 0:
			dict[ki] = 1
			cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			if dict[keytbl[j]] == 1: print(keytbl[j])



Measured memory_bytes: 27680
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i += 2 {
		if totalDivisors(i) == 8 {
			ans++
		}

	}
	fmt.Println(ans)
}

func totalDivisors(n int) int {
	total := 0
	for i := 1; i <= n; i++ {
		if n%i == 0 {
			total++
		}
	}
	return total
}


Measured memory_bytes: 512
// F - Three Variables Game
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<string> s(n);
	vector<int> ab, ac, bc;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i] == "AB") ab.push_back(i);
		else if (s[i] == "AC") ac.push_back(i);
		else bc.push_back(i);
	}

	vector<char> ans(n);
	if (a + b + c == 0) {
		if (n > 0) ans.clear();
	} else if (a + b + c == 1) {
		for (int i = 0; i < n && ans.size() > 0; i++)
			if (s[i] == "AB") {
				if (a + b == 0) ans.clear();
				else {
					if (a) ans[i] = 'B', b++, a--;
					else ans[i] = 'A', a++, b--;
				}
			} else if (s[i] == "AC") {
				if (a + c == 0) ans.clear();
				else {
					if (a) ans[i] = 'C', c++, a--;
					else ans[i] = 'A', a++, c--;
				}
			} else {
				if (b + c == 0) ans.clear();
				else {
					if (b) ans[i] = 'C', c++, b--;
					else ans[i] = 'B', b++, c--;
				}
			}
	} else {
		for (int i = 0; i < n && ans.size() > 0; i++) {
			if (s[i] == "AB") {
				if (a + b == 0) {
					ans.clear();
				} else {
					if (a == 0) ans[i] = 'A', a++, b--;
					else if (b == 0) ans[i] = 'B', b++, a--;
					else if (i + 1 < n && s[i + 1] == "BC") ans[i] = 'B', b++, a--;
					else ans[i] = 'A', a++, b--;
				}
			} else if (s[i] == "AC") {
				if (a + c == 0) {
					ans.clear();
				} else {
					if (a == 0) ans[i] = 'A', a++, c--;
					else if (c == 0) ans[i] = 'C', c++, a--;
					else if (i + 1 < n && s[i + 1] == "AB") ans[i] = 'A', a++, c--;
					else ans[i] = 'C', c++, a--;
				}
			} else {
				if (b + c == 0) {
					ans.clear();
				} else {
					if (b == 0) ans[i] = 'B', b++, c--;
					else if (c == 0) ans[i] = 'C', c++, b--;
					else if (i + 1 < n && s[i + 1] == "AC") ans[i] = 'C', c++, b--;
					else ans[i] = 'B', b++, c--;
				}
			}
		}
	}

	if (ans.size() > 0) {
		cout << "Yes" << endl;
		for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 7264
k,n=input().split(" ")
k,n=int(k),int(n)

a=input().split(" ")
for i in range(n):
  a[i]=int(a[i])
cnt=0
for i in range(n-1):
  cnt=max(abs(a[i]-a[i+1]),cnt)
cnt=max(abs(k-a[-1]+a[0]),cnt)

print(k-cnt)

Measured memory_bytes: 24500
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
   // FI(); /// skip this line for compile
    int n;
    cin >> n;
    if(n>1999) {cout << 1 << endl; return 0;}
    else{
        int mx = n/100;
        int mn = n/105;
        for(int i=mn;i<=mx;i++){
            if(i*100<=n && i*105>=n){
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}



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

#define REP(i, n) for(int i = 0; i < (int)n; ++i)

using namespace std;

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

    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    if (K >= N) cout << X * N << '\n';
    else cout << X * K + Y * (N - K) << '\n';
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  int ret = a * b - (a + b - 1);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())

#graph = [[] for _ in range(n+1)]
graph = [set() for _ in range(n+1)]


for i in range(m):
    a, b = map(int, input().split())
#    graph[a].append(b)
#    graph[b].append(a)
    graph[a].add(b)
    graph[b].add(a)


dist = [-1] * (n+1)
dist[0] = 0


d = deque()
ans = 1
for j in range(len(dist)):
    if dist[j] != -1:
        continue
    d.append(j)
    cnt = 0
    while d:
        v = d.popleft()
        for i in graph[v]:
            if dist[i] != -1:
                continue
            dist[i] = dist[v] + 1
            d.append(i)
            cnt = cnt + 1
    ans = max(ans,cnt)

print(ans)


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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> zero(62,0),one=zero;

	for(long long i=0;i<n;i++){
		long long hoge;
		cin>>hoge;
		bitset<62> bit=hoge;

		for(long long i=0;i<62;i++){
			if(bit.test(i)) one.at(i)++;
			else zero.at(i)++;
		}
	}

	long long ans=0;
	long long two=1;

	for(long long i=0;i<62;i++){
		ans+=(two*zero.at(i))%inf*one.at(i);
		ans%=inf;
		two*=2;
		two%=inf;
	}

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

template<typename T>
bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return 1;
	}
	return 0;
}

template<typename T>
bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return 1;
	}
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//小数点以下　cout << fixed << setprecision(10) << num << endl;

int main(){
    int n,y; cin >> n >> y;
    for(int i=0;i<=y/10000;i++){
        for(int j=0;j<=y/5000;j++){
            int k = n-i-j;
            if(0<=k && 10000*i+5000*j+1000*k == y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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

int main() {

	int a, b;
	cin >> a >> b;

	int ans = b;

	if (a <= 12 && a >= 6) ans /= 2;
	if (a <= 5) ans = 0;


	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
string s;
int dp[30001][3];
int su[30001][10];
int l[30001];
int main(){
	cin>>n>>s;
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<10;j++)
		su[i][j]=su[i+1][j];
		su[i][s[i]-'0']++;
	}
	dp[n-1][0]=1;
	int a[10];
	for(int i=0;i<10;i++)
	a[i]=-1;
	for(int i=n-1;i>=0;i--){
		if(a[s[i]-'0']==-1){
			l[i]=i;
			a[s[i]-'0']=i;
		}else{
			l[i]=a[s[i]-'0'];
			a[s[i]-'0']=i;
		}
	}
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<=9;j++)
		if(su[i][j])
		dp[i][0]++;
		dp[i][1]=dp[i+1][0]+dp[i+1][1];
		if(l[i]!=i)
		dp[i][1]-=dp[l[i]+1][0];
		dp[i][2]=dp[i+1][1]+dp[i+1][2];
		if(l[i]!=i)
		dp[i][2]-=dp[l[i]+1][1];
	}
	cout<<dp[0][2];
	re 0;
}

Measured memory_bytes: 2048
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

def dijkstra(E, start): #最短経路のみ
	N_d = len(E)
	dist = [INF] * N_d
	dist[start] = 0
	q = [(0, start)]
	while q:
		dist_v, v = heappop(q)
		if dist[v] != dist_v:
			continue
		for u, dist_vu in E[v]:
			dist_u  = dist_v + dist_vu
			if dist[u] > dist_u:
				dist[u] = dist_u
				heappush(q, (dist_u, u))
	return dist	

N, X, Y = MAP()

graph = [[[1, 1]]] + [[[i-1, 1], [i+1, 1]] for i in range(1, N-1)] + [[[N-2, 1]]]
graph[X-1].append([Y-1, 1])
graph[Y-1].append([X-1, 1]) 

dic = defaultdict(int)

ans = 0
for i in range(N):
	ans = dijkstra(graph, i)
	for key in ans:
		dic[key] += 1

for i in range(1, N):
	print(dic[i]//2)


Measured memory_bytes: 84956
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
const int INF = 1001001001;
const ll LINF = 1e18;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}

ll A, B, C, X, Y;

int main(){
    cin >> A >> B >> C >> X >> Y;
    
    ll cost = LINF;
    for (ll i = 0; i <= 2 * max(X, Y); i++) {
        if(i % 2 != 0) continue;
        ll leftA = max(X - i / 2, (ll)0);
        ll leftB = max(Y - i / 2, (ll)0);
        ll tmp = leftA * A + leftB * B + i * C;
        cost = min(cost, tmp);
    }
    
    cout << cost << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const ll MOD = 1e9+7;

int main() {
  int n, k;
  cin >> n >> k;

  ll ldif = 0;
  ll rdif = 0;
  rep(i, k){
    ldif += (n - i) % MOD;
    rdif += i % MOD;
  }
  ll ans=0;
  for(ll i=k;i<n+2;i++){
    ll start = rdif;
    ll end = ldif;
    ans += (end - start + 1);
    ans %= MOD;
    ldif += (n - i) % MOD;
    rdif += i % MOD;
  }

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

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


int main () {
  int D;
  cin >> D;
  if (D == 25) cout << "Christmas" << endl;
  else if (D == 24) cout << "Christmas Eve" << endl;
  else if (D == 23) cout << "Christmas Eve Eve" << endl;
  else if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 3584
def is_anargam(s, t):
    if sorted(s.lower()) == sorted(t.lower()):
        return True
    else:
        return False


def string_rotate(s, t):
    """
    check if strings equal after roatation
    """
    if s==t:
        return True

    if not is_anargam(s, t):
        return False

    idx = s.index(t[0])
    f_part = s[idx:]
    l_part = s[:idx]

    if f_part + l_part == t:
        return True
    else:
        return False


s = raw_input()
t = raw_input()

if string_rotate(s, t):
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main() {

    int n,m;
    cin>>n>>m;

    vector<int> h;
    for(int i=0;i<n;i++){
        int hi;
        cin>>hi;
        h.push_back(hi);
    }

    vector<bool> v;
    v.resize(n,true);
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--; b--;
        if(h[a]>h[b]){
            v[b]=false;
        }
        else if(h[a]<h[b]){
            v[a]=false;
        }else{
            v[a]=false;
            v[b]=false;
        }
    }
    int cnt=0;
    for(int i=0;i<v.size();i++){
        if(v[i])
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3876
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	ll mx = 0;
	ll sumA = 0, sumB = 0;
	rep(i, n)
	{
		sumA += a[i];
		sumB += b[i];
		if (a[i] < b[i])mx += (b[i] - a[i] + 1) / 2;
	}
	if (mx <= sumB - sumA)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi a(m);
    rep(i,m)cin >> a[i];
    sort(all(a));
    vi d(m-1);
    rep(i,m-1)d[i] = a[i+1]-a[i];
    sort(all(d));
    int ans = 0;
    rep(i,m-n){
        ans += d[i];
    }
    cout << ans << endl;
}


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

int main() {
	int d,m;
	scanf(" %2d%2d", &d, &m);
	if( 1<=m&&m<=12 &&1<=d && d<=12 ) puts("AMBIGUOUS");
	else if( !(1<=m&&m<=12) && 1<=d && d<=12 ) puts("MMYY");
	else if( 1<=m&&m<=12 && !(1<=d && d<=12) ) puts("YYMM");
	else puts("NA");
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   if(s=="SUN") cout<<"7";
   else if(s=="MON") cout<<"6";
   else if(s=="TUE") cout<<"5";
   else if(s=="WED") cout<<"4";
   else if(s=="THU") cout<<"3";
   else if(s=="FRI") cout<<"2";
   else if(s=="SAT") cout<<"1";
   
   

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int dp[100010];
int a[1010], b[1010];
signed main()
{
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    vector<pair<double, double>> v(n);
    REP(i, n)
    cin >> a[i] >> b[i];
    
     vector<pair<double, double>> p(n);
  
    int cnt = 0;
    for (int i = 0; i <= 10000; i++)
    {
        dp[i] = INF;
    }
  //cerr << dp[0] << endl;
    for (int i = 0; i < n; i++)
    {
        dp[0] = min(dp[0], b[i]);
    }
   // cerr << dp[0] << endl;
   // dp[0] = 0;
    dp[0] = 0;
    for (int i = 0; i <= h; i++)
    {
        bool ok = false;
        for (int j = 0; j < n; j++)
        {
            dp[i+a[j]] = min(dp[i]+b[j], dp[i+a[j]]);
            ok = true;
            
        }
        }
  /*  for (int i = 0; i <= h; i++)
    {
        cerr << dp[i] << endl;
    }*/
        int ans = INF;
        for (int i = h; i <= 10000; i++)
        {
            ans = min(ans, dp[i]);
        }
        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 384
#include<cstdio>
int N,C[410][4],cnt;
long long id(int*a){
	long long v=-1;
	for(int d=0;d<4;d++){
		long long t=0;
		for(int i=0;i<4;i++)t|=1ll*a[d+i&3]<<i*10;
		t>v?v=t,cnt=1:t==v?++cnt:0;
	}
	return v;
}
const int mod=10007;
struct item{long long x;int cnt;item*next;}items[1610],*nit=items,*fir[mod];
void ins(long long x){
	int h=x%mod;
	for(item*it=fir[h];it;it=it->next)
		if(it->x==x){++it->cnt;return;}
	*nit=(item){x,1,fir[h]};
	fir[h]=nit++;
}
int fd(long long x,bool*suc){
	for(item*it=fir[x%mod];it;it=it->next)
		if(it->x==x)return*suc=1,it->cnt--;
	return*suc=0;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		for(int j=0;j<4;j++)scanf("%d",C[i]+j);
		ins(id(C[i]));
	}
	long long sum=0;
	bool tmp;
	for(int x=0;x<N;x++){
		fd(id(C[x]),&tmp);
		for(int y=x+1;y<N;y++){
			fd(id(C[y]),&tmp);
			for(int d=0;d<4;d++){
				long long t=1,z[4];
				bool suc[4]={0};
				for(int i=0;i<4&&t;i++){
					int a[4]={C[y][d-i&3],C[y][d-i-1&3],C[x][i+1&3],C[x][i&3]};
					z[i]=id(a);
					t*=fd(z[i],suc+i)*cnt;
				}
				for(int i=0;i<4;i++)if(suc[i])ins(z[i]);
				sum+=t;
			}
			ins(id(C[y]));
		}
		ins(id(C[x]));
	}
	printf("%lld\n",sum/3);
}

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

#define MAX_N 500000

int n, a, depth[MAX_N];
vector<int>x[MAX_N];
string p[MAX_N];

void print(int b) {
	for (int i = 0; i < x[b].size(); i++) {
		for (int j = 0; j < depth[x[b][i]]; j++) { cout << '.'; }
		cout << p[x[b][i]] << endl;
		print(x[b][i]);
	}
	return;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a >> p[i];
		if (a >= 1) { x[a].push_back(i); depth[i] = depth[a] + 1; }
		else { depth[i] = 0; }
	}
	cout << p[1] << endl;
	print(1);
	return 0;
}

Measured memory_bytes: 17780
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
-- end of templete


main = do
    [n,m,d] <- getInts
    f <- replicateM n getLine
    let g = sum . map (length . filter (>=d) . scanl (\t c -> if c=='.' then t+1 else 0) 0) in print $ sum $ map (($f) . (g.)) [id, transpose]


Measured memory_bytes: 4916
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define pb 	push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	int n,m;
	cin>>n>>m;
	vector<vector<int>>v(100005);
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
	}
	int sum=0;
	priority_queue<int>pq;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<v[i].size();j++)
			pq.push(v[i][j]);
		if(!pq.empty())
		{
			sum+=pq.top();
			pq.pop();
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 5632
N, A, B, C = map(int, input().split())
P = 10**9+7
fa = [1]
al = A * pow(A + B, P-2, P) % P
be = B * pow(A + B, P-2, P) % P
ga = C * pow(100, P-2, P) % P
for i in range(1, N*2+100):
    fa.append(fa[-1]*i%P)
ans = 0
for i in range(N):
    ans = (ans + fa[N+i-1] * pow((fa[N-1]*fa[i]), P-2, P) * (pow(al, N, P) * pow(be, i, P) + pow(al, i, P) * pow(be, N, P)) * (i+N)) % P
print(ans * pow(1-ga, P-2, P) % P)

Measured memory_bytes: 52464