akhauriyash/Code-Regression huggingface dataset:
N=input()
a=int(N[:2])
b=int(N[2:])

if (a > 12 or a ==0) and (b > 12 or b ==0): 
    print("NA")
elif (1 <= a and a<=12) and (1 <= b and b<=12):
    print("AMBIGUOUS")
elif (1 <= a and a<=12):
    print("MMYY")
else:
    print("YYMM")

Measured memory_bytes: 3064
# Small and Large Integers
a, b, k = map(int, input().split())
s = {a, b}
for i in range(k):
    if a+i <= b:
        s.add(a+i)
    if b-i >= a:
        s.add(b-i)
s = sorted(s)
for i in s:
    print(i)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] str = br.readLine().split(" ");

		int old = Integer.parseInt(str[0]);
		int price = Integer.parseInt(str[1]);

		if(old >= 13) {
			System.out.println(price);
		}else if(old <= 12 && old >= 6) {
			System.out.println(price/2);
		}else {
			System.out.println(0);
		}


	}

}


Measured memory_bytes: 21844
from collections import *
from heapq import *
from itertools import *
#from fractions import gcd

from decimal import *
import copy
from bisect import *
import time
import sys
import math

input=lambda :sys.stdin.readline().rstrip()
K=int(input())
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))

sys.setrecursionlimit(10**7)
z=0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            z+=gcd(a,gcd(b,c))
print(z)


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

int N;

int A[1000002], B[1000001];

int main(){
	cin >> N;
	for(int i = 0; i <= N; i++ ) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	//--
	long long answer = 0;
	int subMin;
	for(int i = 0; i < N; i++){
		subMin = INT_MAX;
		subMin = min(B[i], A[i]);
		answer += subMin;
		B[i] -= subMin;
		A[i] -= subMin;
		//
		subMin = INT_MAX;
		subMin = min(B[i], A[i+1]);
		answer += subMin;
		B[i] -= subMin;
		A[i+1] -= subMin;
	}
	//
	cout << answer;
}

Measured memory_bytes: 4736
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define MX 100000
#define mod
#define ll long long
const double pi = acos(-1.0);

using namespace std;

int main()
{
	ll a,b;
	cin>>a>>b;
	if(a>b)
	cout<<a-b;
	else cout<<"0";
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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 qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N) if(A[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i,N) {
        double c = ans;
        ans *= A[i];
        c *= A[i];
        if(ans > INFL || c > INFL) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    ll n, m;
    cin >> n >> m;    
    
    vvl G(n);  // 辺の重みがすべて1のグラフ
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    // BFS。計算量はO(V+E)
    vl dist(n, -1);  // dist[v] : 頂点svから頂点vへの最短距離(-1のとき未訪問)
    queue<ll> Q;
    vl ans(n);
    const ll sv = 0;  // BFSを始める頂点
    dist[sv] = 0;
    Q.push(sv);
    while(!Q.empty()) {
        ll v = Q.front();
        Q.pop();
        for(auto u : G[v]) {
            if(dist[u] == -1) {
                dist[u] = dist[v] + 1;
                Q.push(u);
                ans[u] = v;
            }
        }
    }

    out("Yes");
    exrep(i, 1, n-1) {
        out(ans[i]+1);
    }

    re0;
}

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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

long long mod_pow(long long x, long long n, int M=1000000007) {
    long long ret = 1;
    while(n) {
        if(n & 1) (ret *= x) %= M;
        (x *= x) %= M;
        n >>= 1;
    }
    return ret;
}

int main(){
    int N, K;
    cin >> N >> K;

    vector<mint> D(K+1);
    D[K] = 1;
    repr(i, K) {
        if (i == 0) break;
        ll d = K / i;
        mint res = mod_pow(d, N);
        for (int j = 2; i * j <= K; ++j) {
            res -= D[i*j];
        }
        D[i] = res;
    }

    mint ans = 0;
    rep(i, K) ans += D[i+1] * (i+1);

    cout << ans << endl;
}

Measured memory_bytes: 4052
#define REP(i,n) for (int i=0;i<(n);i++)
#include <queue>
#include <iostream>
using namespace std;
const int MAX = 1000;
const int INF = 10000;
typedef pair<int,int> P; //??§?¨??????????

int N,M,c_num;
int sx,sy;
int gx,gy;
P C[9];
char field[MAX][MAX+1]; //field
int d[MAX][MAX+1]; //distance

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


void init(){
    // cout << "init ..." << endl;
	REP(i,N){
		REP(j,M){
			if (! (i == sx && j == sy)) d[i][j] = INF;
		}
	}
	// cout << "start: " << d[sx][sy] << endl;
}


void bfs(){
    
    init();

	queue <P> que;
	que.push(P(sx,sy));

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

		if (p.first == gx && p.second == gy) break; 

		// ??¨???4??????????????????
		for(int r = 0; r < 4; r++) {
	    	int nx = p.first + dx[r], ny = p.second + dy[r]; 
	    	if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != 'X' &&d[nx][ny] == INF){
	    		d[nx][ny] = d[p.first][p.second] + 1;
	    		que.push(P(nx,ny));
	    	}
		}
	}
	return ;
}


void solve(){
	REP(i,c_num){
		gx = C[i].first, gy = C[i].second;
		//cout <<???'goal :'<< gx << gy << endl;
		bfs();
		sx = gx, sy = gy;
	}
	cout << d[gx][gy] << endl;
}


int main(){
	cin >> N >> M >> c_num;
	REP(i,N){
		REP(j,M){
			cin >> field[i][j];
			if (field[i][j] == 'S') sx = i, sy = j;
			else if ('1' <= field[i][j] && field[i][j] <= '9'){
			    C [field[i][j]-'1'] = P(i,j);
			}
		}
	}
	solve();
}

Measured memory_bytes: 8032
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		char[] arr = s.toCharArray();
		for (int i = 0; i < arr.length; i++) {
			arr[i] = (char) ((arr[i] + n - 65) % 26 + 65);
		}

		String ans = new String(arr);
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23892
N = gets.to_i
A = gets.split.take(N).map(&:to_i)

a = [0] * 8
A.each{|n|
  a[n / 400] = 1 if n < 3200
}
sum = a.inject(0, :+)
top = A.count{|n| n >= 3200 }
# min = [sum, top].max
min = [sum, 1].max
# max = [sum + top, 8].min
max = sum + top
puts "#{min} #{max}"


Measured memory_bytes: 1788
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	if (n % 2) {
		cout << n / 2 + 1 << endl;
	}
	else {
		cout << n / 2 << endl;
	}

	return 0;
}

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

template <typename T>
class SaikyoSegmentTree {
	struct node {
		T val, add;
		node *l, *r;
		node(T val, T add, node *left = nullptr, node *right = nullptr) : val(val), add(add), l(left), r(right) {}
	};
	const ll n;
	const T id;
	int it, rit;
	vector<node*> root;
	T getval(node *x) {
		return x == nullptr ? id : x->val;
	}
	T getadd(node *x) {
		return x == nullptr ? id : x->add;
	}
	node* getl(node *x) {
		return x == nullptr ? nullptr : x->l;
	}
	node* getr(node *x) {
		return x == nullptr ? nullptr : x->r;
	}
	ll size(ll n) {
		assert(n < (1ll << 62ll));
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node *new_node(T val, T add, node *l = nullptr, node *r = nullptr) {
		return new node(val, add, l, r);
	}
	node *fix(node *x, ll l, ll r, T val, ll lb, ll ub) {
		if (r <= lb || ub <= l) return x;
		if (l <= lb && ub <= r) return new_node(getval(x), getadd(x) + val, getl(x), getr(x));
		ll c = (lb + ub) / 2;
		auto nl = fix(getl(x), l, r, val, lb, c);
		auto nr = fix(getr(x), l, r, val, c, ub);
		return new_node(getval(x) + val * (min(r, ub) - max(l, lb)), getadd(x), nl, nr);
	}
	T sub(node *x, ll l, ll r, ll lb, ll ub) {
		if (x == nullptr) return id;
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return x->val + x->add * (ub - lb);
		ll c = (lb + ub) / 2;
		return sub(getl(x), l, r, lb, c) + sub(getr(x), l, r, c, ub) + x->add * (min(r, ub) - max(l, lb));
	}
public:
	SaikyoSegmentTree(ll n_, T id_) : n(size(n_)), id(id_), it(0) {
		root.push_back(nullptr);
	}
	void add(ll l, ll r, T val, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		root.push_back(fix(root[rt], l, r + 1, val, 0, n));
	}
	T find(ll l, ll r, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		return sub(root[rt], l, r + 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll N, M, Q;
	cin >> N >> M >> Q;
	vector<tuple<int, int, int>> vab(M);
	for (int i = 0; i < M; i++) {
		cin >> get<1>(vab[i]) >> get<2>(vab[i]) >> get<0>(vab[i]); get<1>(vab[i])--; get<2>(vab[i])--;
	}
	sort(vab.begin(), vab.end());
	SaikyoSegmentTree<ll> sst(N, 0);
	for (int i = 0; i < M; i++) {
		sst.add(get<1>(vab[i]), get<2>(vab[i]), 1);
	}
	ll x, y, j;
	while (Q--) {
		cin >> x >> y >> j; x--; y--;
		ll l = 0, r = M;
		while(l + 1 < r) {
			ll c = (l + r) / 2;
			if (sst.find(x, y, c) >= j) {
				r = c;
			}
			else {
				l = c;
			}
		}
		printf("%d\n", get<0>(vab[r - 1]));
	}
	return 0;
}

Measured memory_bytes: 397404
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		try {
			String input = br.readLine();
			String[] splitInput = input.split(" ", 0);

			int a = Integer.parseInt(splitInput[0]);
			int b = Integer.parseInt(splitInput[1]);
			
			if (!(a >= 1 && b <= 100)) {
				throw new IllegalArgumentException();
			}
			
			System.out.println((a * b) + " " + (a * 2 + b * 2));
		
		} catch(NumberFormatException e) {
			e.printStackTrace();
		} catch(IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24220
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;
int32_t main(){
    int a, b;
    cin >>a >>b;
    cout <<a - min(a, 2* b) <<endl;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll MAX_N = 3e5;
vector<ll> G[MAX_N];
vector<ll> d(MAX_N,0);
void dfs(ll v,ll dep,ll pre){
  d[v] = dep;
  for(auto nv:G[v]){
    if(nv!=pre){
      dfs(nv,dep+1,v);
    }
  }
}
signed main(){
  init_io();
  ll n,oc=0,ec=0,idx=1;
  cin >> n;
  vector<ll> ans(n,0),ov,ev;
  vector<bool> used(n+1,0);
  vector<ll> a(n-1),b(n-1);
  for(int i=0;i<n-1;i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  dfs(0,0,0);
  for(int i=0;i<n;i++){
    if(d[i]%2){
      oc++;
      ov.push_back(i);
    }else{
      ec++;
      ev.push_back(i);
    }
  }
  if(ec<=n/3){
    ll ed=3;
    for(auto i:ev){
      used[ed] = true;
      ans[i] = ed;
      ed += 3;
    }
  }else if(oc<=n/3){
    ll ed=3;
    for(auto i:ov){
      used[ed] = true;
      ans[i] = ed;
      ed += 3;
    }
  }else{
    ll ed=1;
    for(auto i:ov){
      if(ed>n) break;
      used[ed] = true;
      ans[i] = ed;
      ed += 3;
    }
    ed=2;
    for(auto i:ev){
      if(ed>n) break;
      used[ed] = true;
      ans[i] = ed;
      ed += 3;
    }
  }
  for(int i=0;i<n;i++){
    if(ans[i]==0){
      while(used[idx]) idx++;
      ans[i] = idx;
      used[idx] = true;
    }
  }
  for(int i=0;i<n;i++){
    cout << ans[i]<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 27500
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		
		int[] point = new int[N];
		for(int i = 0; i < N; i++){
			point[i] = K - Q;
		}
		
		for(int i = 0; i < Q; i++){
			point[sc.nextInt() - 1]++;
		}

		for(int i = 0; i < N; i++){
			System.out.println((point[i]>0)?"Yes":"No");
		}
	}
}

Measured memory_bytes: 58044
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
 {  ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
            int n,m;
            cin>>n>>m;
            string s="";
            for(int i=0;i<n;i++) s+='a';
            //s[0]= 1;
            for(int i=0;i<m;i++){
                int si;
                char c;
                cin>>si>>c;
                if(s[si-1]!='a' && s[si-1]!=c){
                    cout<<"-1\n"; return 0;
                }
                s[si-1] = c;
            }
            for(int i=1;i<n;i++)
                if(s[i]=='a') s[i]='0';
            
            if(s.length()!=1 && s[0]=='a') s[0] = '1';
            else if(s.length()==1 && s[0]=='a') s[0] = '0';
            if(s.length()!=1&&s[0]=='0') cout<<"-1\n";
            else
            cout<<s<<"\n";
            
	return 0;
}


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

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things. 
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

int main(){
	
	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin>>n;


    vector<char> ans;
    while(n>0){
        n--;
        // cerr<<n<<" "<<n%26<<endl;
        ans.push_back('a'+(n%26));
        n/=26;
    }

    reverse(ans.begin(),ans.end());

    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
    }
    cout<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define method(name,res,...) function<res (__VA_ARGS__) > name = [&](__VA_ARGS__) -> res
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int str2int(string str){
  map<char,int> m;
  m['m'] = 1000;
  m['c'] = 100;
  m['x'] = 10;
  m['i'] = 1;
  int last = 0;
  int res = 0;
  foreach(i,str){
    if(m.count(i)){
      if(!last)last=1;
      res += last * m[i];
      last = 0;
    }else{
      last = i - '0';
    }
  }
  return res;
}

string int2str(int num){
  string res = "";
  string k="ixcm";
  foreach(i,k){
    int x = num % 10;
    if(x){
      res += i;
      if(x>1)res += '0' + x;
    }
    num/=10;
  }
  reverse(all(res));
  return res;
}

string func(){
  int sum = 0;
  sum += str2int(in<string>());
  sum += str2int(in<string>());
  return int2str(sum);
}

int main(){
  int n = in();
  rep(i,n){
    cout << func() << endl;
  }
  return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n)    for(int i = 0; i < (n) ; ++i)
#define orep(i,n)   for(int i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(int i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()   // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int n;
  cin >> n;
  vi a(n-1,0);
  vi b(n,0);
  rep(i,n-1) {
    cin >> a.at(i);
    b.at(a.at(i)-1)++;
  }

  rep(i,n) cout << b.at(i) << endl;



  return 0;
}


Measured memory_bytes: 4840
#!/usr/bin/python

import os
import sys
import itertools

if __name__ == '__main__':
    a = int(raw_input())
    l = map(int, raw_input().split())

    dp = [[ 0L for _ in xrange(21)] for _ in xrange(len(l))]
    dp[1][l[0]] = 1

    for j in xrange(1,len(l)-1):
        for i in xrange(21):
            if 0 <= i+l[j] <= 20: dp[j+1][i+l[j]] += dp[j][i]
            if 0 <= i-l[j] <= 20: dp[j+1][i-l[j]] += dp[j][i]

    print dp[-1][l[-1]]

Measured memory_bytes: 6504
//安利少歌
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 510, mod = 998244353;
int n,a[N],b[N],S;

inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}

int fac[N],ifac[N];
inline void init(){
	fac[0]=1;
	For(i,1,500) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[500]=power(fac[500],mod-2);
	Dow(i,499,0) ifac[i]=1ll*(i+1)*ifac[i+1]%mod;
}

int dp[N][N],Pow[N];
inline void solve(){
	dp[0][0]=mod-1;
	For(i,1,n) Dow(j,S-a[i],0) Dow(k,500,0) if (dp[j][k]){
		Pow[0]=1;
		FOR(l,1,b[i]) Pow[l]=1ll*Pow[l-1]*a[i]%mod;
		FOR(l,0,b[i]) if (k+l<=500){
			dp[j+a[i]][k+l]=(dp[j+a[i]][k+l]-1ll*Pow[l]*dp[j][k]%mod*ifac[l]%mod+mod)%mod;
		}
	}
}

int main(){
	n=read();
	For(i,1,n) a[i]=read(),b[i]=read(),S+=a[i];
	init(),solve();
	int ans=0;
	For(i,1,S){
		int inv=1ll*ifac[i]*fac[i-1]%mod,tmp=1ll*S*inv%mod;
		assert(inv==power(i,mod-2));
		For(j,0,500) ans=(ans+1ll*dp[i][j]*fac[j]%mod*tmp%mod*power(inv,j))%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<P> l = new ArrayList<>();
        for(int i=0; i<n; i++) {
            int a = sc.nextInt();
            l.add(new P(i + 1, a));
        }
        Collections.sort(l);
        for(int i=0; i<n; i++) {
            if(i > 0) System.out.print(" ");
            System.out.print(l.get(i).a);
        }
        System.out.println();
    }

    static class P implements Comparable<P>{
        int a;
        int b;
        public P(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override public int compareTo(P o) {
            return b - o.b;
        }
    }
}


Measured memory_bytes: 63116
#include <iostream>
using namespace std;
typedef long long ll;
ll n;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 1; i <= 3500; i++){
        for (ll j = 1; j <= 3500; j++){
            if (4 / (double)n <= 1 / (double)i + 1 / (double)j) continue;
            double w = 4 / (double)n - 1 / (double)i - 1 / (double)j;
            ll W = 1 / w;
            if (4 / (double)n == 1 / (double)i + 1 / (double)j + 1 / (double)W){
                cout << i << ' ' << j << ' ' << fixed << W << endl;
                return 0;
            }  if (4 / (double)n == 1 / (double)i + 1 / (double)j + 1 / (double)(W + 1)){
                cout << i << ' ' << j << ' ' << fixed << W + 1 << endl;
                return 0;
            }  if (4 / (double)n == 1 / (double)i + 1 / (double)j + 1 / (double)(W - 1)){
                cout << i << ' ' << j << ' ' << fixed << W - 1 << endl;
                return 0;
            } 
        }
    }
}


Measured memory_bytes: 256
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int n, k;
int dp[100005];
vector<int> hi;
int calc(int idx) {
	if (idx == n - 1)
		return 0;
	int &ret = dp[idx];
	if (ret != -1)
		return ret;
	ret = calc(idx + 1) + abs(hi[idx] - hi[idx + 1]);
	for (int i = 2; i <= k && idx + i < n; ++i)
		ret = min(ret, calc(idx + i) + abs(hi[idx] - hi[idx + i]));
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	hi.resize(n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &hi[i]);
	int ans = calc(1) + abs(hi[0] - hi[1]);
	for (int i = 2; i <= k && i < n; ++i)
		ans = min(ans, calc(i) + abs(hi[0] - hi[i]));
	cout << ans << endl;
	return 0;
}

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

signed main(){
	int n;
	cin >> n;
	int odd = 0;
	int even = 0;
	
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a % 2 == 0)even++;
		else odd++;
	}
	odd %= 2;
	cout << (odd == 0 ? "YES" : "NO") << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n, a,b,c,d,e;
void solve(){
	cin >> n >> a >> b >> c >> d >> e;
	
	cout << (n+min({a,b,c,d,e})-1)/min({a,b,c,d,e})+4 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

using namespace std;

int main(){
  int n,i,j,x,y;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  x=0;
  for(i=0;i<n;i++){
    if(i%2==0)x+=a[i];
    else x-=a[i];
  }
  cout << x << endl;
  return 0;
}


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

int arr[2000];

int GCD(int x, int y) {
	if (y == 0) return x;
	else if (x < y) return GCD(y, x);
	else return GCD(x % y, y);
}

int main() {
	int n, m;
	//freopen("input.in", "r", stdin);
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> arr[i];
	
	int  num = (n * m) / GCD(n, m);
	num /= m;
	//cout << num << endl;
	int sum = 0;
	for (int i = 0; i < num; i++) {
		int x = (m * i) % n;
		int y = (m * i + m-1) % n;
		int maxi = -INF;
		int mini = INF;
		//cout << x << " " << y << endl;
		while (x % n != (y+1) % n) {
			int j = x % n;
			maxi = max(maxi, arr[j]);
			mini = min(mini, arr[j]);
			x++;
			
		}
		//cout << "----"<< maxi - mini << " " << endl;
		
 		sum += maxi - mini;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3096
//#define _XCODE_DEBUG

#include <iostream>
#include <math.h>
#include <string>
#include <vector>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main() {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    
    std::string s;
    std::cin >> s;
    int length = (int)s.length()-1;
    
    long long ans = 0;
    for (int i=0; i<pow(2, length); ++i) {
        long long sum_v = 0;
        int ind = 0;
        for (int j=0; j<length; ++j) {
            if ((1 << j) & i) {
                sum_v += std::stoi(s.substr(ind, j+1-ind));
                ind = j+1;
            }
        }
        sum_v += std::stoll(s.substr(ind, length+1-ind));
        ans += sum_v;
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

void bfs(vector<vector<long>>& graph, vector<long>& res, vector<long>& pla , long par, long now) {

	if (par != -1) res[now] = res[par] + pla[now]; else res[now] = pla[now];//累積

	for (long e : graph[now]) {
		if (e != par) bfs(graph, res, pla, now, e);
	}
}

int main() {
	//操作は可換
    //BFS
	long N, Q; cin >> N >> Q;
	vector<vector<long>> graph(N);
	vector<long> res(N);

	for (int i = 0; i < N - 1; i++) {
		long a, b; cin >> a >> b; a--; b--;
	    graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<long> pla(N); for (int i = 0; i < N; i++) pla[i] = 0; 
    for (int i = 0; i < Q; i++) { long p, x; cin >> p >> x;p--; pla[p] += x; }

	bfs(graph, res, pla, -1, 0);

	for (int i = 0; i < N; i++) cout << res[i] << " ";
}

Measured memory_bytes: 32128
n = gets.to_i
cards = Array.new(n)
all_cards = Array.new(4).map{Array.new(13)}
4.times do |i|
	for j in 1..13 do
		if i == 0
			all_cards[i][j - 1] = ["S",j]
		elsif i == 1
			all_cards[i][j - 1] = ["H",j]
		elsif i == 2
			all_cards[i][j - 1] = ["C",j]
		else
			all_cards[i][j - 1] = ["D",j]
		end
	end
end
n.times do |i|
	cards[i] = gets
	cards[i] = cards[i].split(" ")
	cards[i][1] = cards[i][1].to_i
end
4.times do |i|
	n.times do |j|
		all_cards[i].delete(cards[j])
	end
end
4.times do |i|
	13.times do |j|
		if all_cards[i][j] != nil
			puts all_cards[i][j].join(" ")
		end
	end
end

Measured memory_bytes: 8688
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
int main(){
    fast;
    ll n,a[200000],s=0,sumleft=0,sumright=0,left,right;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    left=0;
    right=n-1;
    sumleft+=a[left];
    sumright+=a[right];
    while(left<right){
        if(left==right-1)
            break;
      //  cout<<sumleft<<" "<<sumright<<endl;
        if(sumleft<sumright){
            left++;
            if(left<right)
            sumleft+=a[left];
            continue;
        }
        if(sumright<sumleft){
            right--;
            if(left<right)
             sumright+=a[right];
            continue;
        }
        if(sumleft==sumright){
            left++;
            sumleft+=a[left];
            continue;
        }
        
    }
    cout<<abs(sumleft-sumright)<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N; long long X[1010],Y[1010]; int P[1010];
char A[1010][44];

int main()
{
	scanf ("%d",&N);
	for (int i=0;i<N;i++){
		scanf ("%lld %lld",&X[i],&Y[i]);
		P[i] = (X[i] % 2 + Y[i] % 2 + 2) % 2;
	}

	for (int i=0;i<N;i++) if (P[i] != P[0]){
		puts("-1");
		return 0;
	}

	vector<long long> mv;
	for (int i=0;i<6+P[0];i++) mv.push_back(1);
	for (int i=1;i<32;i++) mv.push_back(1ll << i);

	long long sum = 0;
	for (int j=0;j<mv.size();j++) sum += mv[j];
	for (int j=mv.size()-1;j>=0;j--){
		auto l = mv[j];
		sum -= l;

		int dx[4] = {0,1,0,-1};
		int dy[4] = {1,0,-1,0};
		char ch[6] = "URDL";
		for (int i=0;i<N;i++) for (int k=0;k<4;k++){
			long long px = X[i] - dx[k] * l;
			long long py = Y[i] - dy[k] * l;
			if (abs(px) + abs(py) <= sum){
				X[i] = px;
				Y[i] = py;
				A[i][j] = ch[k];
				break;
			}
		}
	}

	printf ("%d\n",mv.size());
	for (int j=0;j<mv.size();j++) printf ("%lld%c",mv[j],j+1<mv.size()?' ':'\n');
	for (int i=0;i<N;i++) puts(A[i]);

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod=1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define P pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main(){
  int n;
  cin>>n;
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vec dp(n+2,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
  }
  cout<<dp[n-1]<<endl;
}



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

int main() {
    auto n = 0;
    std::cin >> n;

    auto robots = std::vector<std::pair<std::int64_t, std::int64_t>>();
    for (auto i_ = 0; i_ < n; ++i_) {
        auto x = std::int64_t(0);
        auto l = std::int64_t(0);
        std::cin >> x >> l;
        robots.emplace_back(x, l);
    }

    std::sort(robots.begin(), robots.end(), [](const auto& a, const auto& b) { return a.first < b.first; });

    auto range = robots.front().first + robots.front().second;
    auto counter = -1;
    for (const auto& r : robots) {
        const auto x = r.first;
        const auto l = r.second;
        if (range <= (x - l)) {
            range = x + l;
        } else {
            counter++;

            if (range > (x + l)) {
                range = x + l;
            }
        }
    }

    std::cout << n - counter << std::endl;

    return 0;
}

Measured memory_bytes: 3052
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    m = 0
    k = 0
    ia, ib = 0, 0
    while ia < N:
        a = A[ia]
        if k + a > K:
            break
        k += a
        ia += 1

    while True:
        while ib < M:
            b = B[ib]
            if k + b > K:
                break
            k += b
            ib += 1
        m = max(m, ia + ib)
        if ia > 0:
            ia -= 1
            k -= A[ia]
        else:
            break

    return m

print(main())


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

int main(){
    int N;
    cin >> N;
    double v[N];
    for(int i = 0; i < N; i++)  cin >> v[i];
    
    sort(v, v+N);
    double ans = (v[0]+v[1])/2;
    for(int i = 2; i < N; i++){
        ans = (ans+v[i])/2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
int n;
long long m;

ll a[200000+10];
int v[200000+10];
int qz=0;

namespace solver
{
 // struct node
 // {
 //   int x,y;
 //	ll v;
  //};
  //queue<node> q;
  void solve()
  {
    //freopen("in","r",stdin);;
    //freopen("out","w",stdout);
	scanf("%d%lld",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%lld",&a[i]);
	ll all=0;
    for(int i=1; i<=n-1; ++i)
	  if(a[i] + a[i+1] >= m)
	  {
	    puts("Possible");
		for(int j=1; j<i; ++j) printf("%d\n",j);
		for(int j=n-1; j>=i; --j) printf("%d\n",j);
	    return;
	  }
    puts("Impossible");
  }
}
int main()
{
  solver::solve();
}

Measured memory_bytes: 1664
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 1200;

int n, m;
vector<pair<int, int> > ed;
vector<int> eds[MAXN];
vector<int> reds[MAXN];
int cc;
int cl[MAXN];

int was[MAXN];
vector<int> vv;

void dfs1(int v) {
	was[v] = 1;
	for (int u: eds[v]) {
		if (!was[u])
			dfs1(u);
	}
	vv.push_back(v);
}

void dfs2(int v, int c) {
	cl[v] = c;
	was[v] = 1;
	for (int u: reds[v]) {
		if (!was[u]) {
			dfs2(u, c);
		}
	}
}

vector<pair<int, int>> dd[MAXN];
int fl[MAXN][MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		ed.emplace_back(a, b);
		eds[a].push_back(b);
		reds[b].push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		if (was[i])
			continue;
		dfs1(i);
	}
	reverse(vv.begin(), vv.end());
	memset(was, 0, sizeof(was));
	for (int i: vv) {
		if (!was[i])
			dfs2(i, cc++);
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			dd[j].clear();
		queue<pair<int, int>> qu;
		for (int j: eds[i]) {
			dd[j].emplace_back(1, j);
			qu.emplace(j, 0);
		}
		while (!qu.empty()) {
			int x, y;
			tie(x, y) = qu.front();
			qu.pop();
			for (int u: eds[x]) {
				if (u == i)
					continue;
				if (dd[u].empty()) {
					dd[u].emplace_back(dd[x][y].first + 1, dd[x][y].second);
					qu.emplace(u, 0);
				}
				else if (dd[u].size() == 1) {
					if (dd[u][0].second != dd[x][y].second) {
						dd[u].emplace_back(dd[x][y].first + 1, dd[x][y].second);
						qu.emplace(u, 1);
					}
				}
				else
					continue;
			}
		}
		for (int j = 0; j < n; ++j) {
			for (auto k: dd[j])
				if (k.second != j)
					fl[i][j] = 1;
		}
	}
	for (auto e: ed) {
		int x, y;
		tie(x, y) = e;
		if (cl[x] == cl[y]) {
			if (fl[x][y])
				cout << "same\n";
			else
				cout << "diff\n";
		}
		else {
			if (fl[x][y])
				cout << "diff\n";
			else
				cout << "same\n";
		}
	}
	return 0;
}




Measured memory_bytes: 10480
import math
import itertools 
import collections

K = int(input())
result = 0
for v in itertools.combinations_with_replacement(range(1,K+1), 3):
    a,b,c = v
    count = collections.Counter(v)
    if 3 in count.values():
        result += math.gcd(math.gcd(a,b), c)
    elif 2 in count.values():
        result += math.gcd(math.gcd(a,b), c)*3
    else:
        result += math.gcd(math.gcd(a,b), c)*6
print(result)

Measured memory_bytes: 71680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();

        final int[] count = new int[13];
        final int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            final int d = scanner.nextInt();
            array[i] = d;
            count[d]++;
        }

        if (count[0] >= 1 || count[12] >= 2) {
            System.out.println(0);
            return;
        }

        final boolean isOverlapping = Arrays.stream(count)
            .anyMatch(i -> i >= 3);
        if (isOverlapping) {
            System.out.println(0);
            return;
        }

        Arrays.sort(array);
        final boolean[] location = new boolean[25];
        location[0] = true;
        boolean flag = true;
        for (final int d : array) {
            if (flag) {
                location[d] = true;
            } else {
                location[24 - d] = true;
            }

            flag = !flag;
        }

        final List<Integer> list = IntStream.rangeClosed(0, 24)
            .filter(i -> location[i])
            .boxed()
            .collect(Collectors.toList());

        int min = 24 - list.get(list.size() - 1);
        for (int i = 0; i < list.size() - 1; i++) {
            min = Math.min(min, list.get(i + 1) - list.get(i));
        }

        System.out.println(min);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

Measured memory_bytes: 27984
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		map<int, int> sum, in;
		int day = -1, god = -1;
		while (n--)
		{
			int m, d, hour, minute, prog;
			char io;
			scanf("%d/%d %d:%d %c %d", &m, &d, &hour, &minute, &io, &prog);
			d += m*100;
			minute += hour*60;
			if (d != day)
			{
				if (god != -1)
				{
					foreach (it, in)
						sum[it->first] += 24*60 - it->second;
				}

				in.clear();
				day = d;
				god = -1;
			}

			if (prog == 0)
			{
				if (io == 'I')
				{
					god = minute;
					foreach (it, in)
						it->second = minute;
				}
				else
				{
					foreach (it, in)
						sum[it->first] += minute - it->second;
					god = -1;
				}
			}
			else
			{
				if (io == 'I')
					in[prog] = minute;
				else
				{
					if (god != -1)
						sum[prog] += minute - in[prog];
					in.erase(prog);
				}
			}
		}

		int res = 0;
		foreach (it, sum)
			res = max(res, it->second);
		printf("%d\n", res);
	}
}

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

using ll = long long int;
using P = std::pair<int, int>;

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

ll n;

ll cnt(ll x)
{
    ll res = 0;
    for (ll y = 1; y <= n / x; y *= x)
    {
        res += n / (y * x);
    }

    return res;
}

int main()
{

    std::cin >> n;

    if (n % 2)
    {
        std::cout << 0 << std::endl;
        return 0;
    }

    n /= 2;

    std::cout << std::min(cnt(2) + n, cnt(5)) << std::endl;

    return 0;
}

Measured memory_bytes: 3644