akhauriyash/Code-Regression huggingface dataset:
T=[(1,2),(2,5),(3,5),(4,4),(5,5),(6,6),(7,3),(8,7),(9,6)]
 
N,M=map(int, raw_input().split())
A=map(int, raw_input().split())
 
 
P=[]
for i in A:
	P.append(T[i-1])
 
 
dp=[ None for i in range(N+1) ]
dp[0]=""
 
 
for i in range(N):
	#print "i :::: ",i,dp
	if dp[i] is not None:
		for num, match in P:
			if i+match<=N:
 
				if dp[i+match] is None:
					dp[i+match]=dp[i]+str(num)
				else:
					l1=len(dp[i+match])
					l2=len(dp[i]+str(num))
					if l1>l2:
						pass
					elif l1<l2:
						dp[i+match]=dp[i]+str(num)
					else:
						dp[i+match]=max( dp[i+match] , dp[i]+str(num) )
 
 
print dp[N]

Measured memory_bytes: 57500
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
vector<pair<int,int> > G[100010];
int used[100010] = {0};
int ans[100010] = {0};
void dfs(int p,int d){
    if(d%2)ans[p] = 1;
    for(auto x:G[p]){
        if(used[x.fi] == 0){
            used[x.fi] = 1;
            dfs(x.fi,x.se+d);
        }
    }
}
signed main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        G[u-1].pb(MP(v-1,w));
        G[v-1].pb(MP(u-1,w));
    }
    used[0] = 1;
    dfs(0,0);
    rep(i,n) cout << ans[i] << endl;

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc126.contest.atcoder.jp/tasks/abc126_a

Measured memory_bytes: 10112
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n, x;

int a[400000];
int fl[400000];

void no() {
	cout << "No\n";
	exit(0);
}

int main() {
	cin >> n >> x;
	if (x == 1 || x == 2 * n - 1)
		no();
	if (n == 2) {
		if (x != 2)
			no();
		cout << "Yes\n";
		cout << "1\n2\n3\n";
		return 0;
	}
	for (int i = 0; i < 2 * n; ++i)
		a[i] = -1;
	a[n - 1] = x;
	a[n - 2] = x - 1;
	a[n] = x + 1;
	fl[x] = 1;
	fl[x - 1] = 1;
	fl[x + 1] = 1;
	if (x > 2) {
		a[n + 1] = x - 2;
		fl[x - 2] = 1;
	}
	else {
		a[n - 3] = x + 2;
		fl[x + 2] = 1;
	}
	int now = 1;
	for (int i = 0; i < 2 * n - 1; ++i) {
		if (a[i] == -1) {
			while (fl[now])
				++now;
			fl[now] = 1;
			a[i] = now;
		}
	}
	cout << "Yes\n";
	for (int i = 0; i < 2 * n - 1; ++i)
		cout << a[i] << "\n";
	return 0;
}




Measured memory_bytes: 3072
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    FOR(x,0,n){
        if ((x * 108) / 100 == n){
            cout << x << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


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



int main() {
    int h, a;
    cin >> h >> a;
    
    int cnt = 0;
    while(h > 0) {
        h -= a;
        cnt++;
    }
    
    cout << cnt << endl;
    
    
    return 0;
}




Measured memory_bytes: 3604
def main(s_list):
    if len(s_list) == 1 and s_list[0] == '#':
        print('Yes')
        return

    for i_row, s in enumerate(s_list):
        for j_col, char in enumerate(s):
            if char == '#':
                neighbor_list = []
                try:
                    neighbor_list.append(s_list[i_row-1][j_col])
                except:
                    pass
                try:
                    neighbor_list.append(s_list[i_row+1][j_col])
                except:
                    pass
                try:
                    neighbor_list.append(s_list[i_row][j_col-1])
                except:
                    pass
                try:
                    neighbor_list.append(s_list[i_row][j_col+1])
                except:
                    pass
                
                if neighbor_list.count('#') == 0:
                    print('No')
                    return

    print('Yes')

if __name__ == "__main__":
    H, W = [int(x) for x in input().split()]
    s_list = []
    for i in range(H):
        s_list.append(input())

    main(s_list)

def test1(capsys):
    inputs = ['.#.', '###', '.#.']
    out = 'Yes'
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == out + '\n'

def test2(capsys):
    inputs = ['#.#.#', '.#.#.', '#.#.#', '.#.#.', '#.#.#']
    out = 'No'
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == out + '\n'

def test3(capsys):
    inputs = ['...#####...', '.##.....##.', '#..##.##..#', '#..##.##..#', '#.........#', '#...###...#', '.#########.', '.#.#.#.#.#.', '##.#.#.#.##', '..##.#.##..', '.##..#..##.']
    out = 'Yes'
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == out + '\n'

def test4(capsys):
    inputs = ['#']
    out = 'Yes'
    main(inputs)
    captured = capsys.readouterr()    
    assert captured.out == out + '\n'

Measured memory_bytes: 3064
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

queue<pint> que;

int main(){

    int h,w; cin >> h >> w;
    Graph G(h,vi(w));
    rep(i,h){
        rep(j,w){
        int a; cin >>a;
        G.at(i).at(j) = a;
        }   
        if(i%2 == 0){
            rep(k,w){
                if(G.at(i).at(k)%2 == 1) que.push(make_pair(i,k));
            }
        }
        else{
            for(int k = w-1; k>=0; --k){
                if(G.at(i).at(k)%2 == 1) que.push(make_pair(i,k));
            }
        }
    }
    queue<pint> ans;
    while(que.size() > 1){
        int m = que.front().first;
        int n = que.front().second;
        que.pop();
        int mn = que.front().first;
        int nn = que.front().second;
        bool ok = false;
        ans.push(make_pair(m+1,n+1));
        for(int i = m; i < h; ++i){
            if(i%2 == 0){
                for(int j = n+1; j < w; ++j){
                    ans.push(make_pair(i+1,j+1));
                    if(i == mn && j == nn) ok = true;
                    else ans.push(make_pair(i+1,j+1));
                    if(ok) break;
                }
                n = w;
            }
            else{
                for(int j = n-1; j >= 0; --j){
                    ans.push(make_pair(i+1,j+1));
                    if(i == mn && j == nn) ok = true;
                    else ans.push(make_pair(i+1,j+1));
                    if(ok) break;
                }
                n = -1;
            }

            if(ok){
                que.pop();
                break;
            }
        }
    }
    cout << ans.size()/2 << endl;
    while(!ans.empty()){
        cout << ans.front().first sp ans.front().second << " ";
        ans.pop();
        cout << ans.front().first sp ans.front().second << endl;
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 105;
const int W = 1e5+5;
int n, w;
ll dp[W];

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> w;
  for (int i = 0; i < n; ++i) {
    int a, v; cin >> a >> v;
    for (int to = w; to > 0; --to) {
      int from = to - a;
      if (from < 0) break;
      dp[to] = max(dp[to], dp[from] + v);
    }
  }
  cout << *max_element(dp, dp+w+1) << nl;

  return 0;
}



Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> t(n), a(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];

    vector<ll> pat(n, 0);
    ll maxt = 0;
    vector<ll> decided(n, -1);
    rep(i, n){
        if(t[i] > maxt){
            pat[i] = 1;
            maxt = t[i];
            decided[i] = t[i];
        } else {
            pat[i] = t[i];
        }
    }
    ll maxa = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] > maxa){
            pat[i] = 1;
            maxa = a[i];
            if(decided[i] != -1 && a[i] != decided[i]){
                cout << 0 << endl;
                return 0;
            }
        } else {
            pat[i] = min(pat[i], a[i]);
            if(decided[i] != -1 && a[i] < decided[i]){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    ll ans = 1;
    rep(i,n){
        //cout << i << " " << pat[i] << endl;
        ans *= pat[i];
        ans %= MOD;
    }

    if(maxa != maxt){
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
N=int(input())
S=input()
hw=[]
i=0
while i<N:
  if i+1<N and S[i]==S[i+1]:
    hw.append(2)
    i+=2
  else:
    hw.append(1)
    i+=1
mod=10**9+7
ans=0
for i in range(len(hw)):
  if i==0:
    if hw[i]==1:
      ans=3
    else:
      ans=6
  if i!=0:
    if hw[i]==1 and hw[i-1]==1:
      ans*=2
      ans%=mod
    if hw[i]==1 and hw[i-1]==2:
      ans*=1
    if hw[i]==2 and hw[i-1]==1:
      ans*=2
      ans%=mod
    if hw[i]==2 and hw[i-1]==2:
      ans*=3
      ans%=mod

print(ans)      

Measured memory_bytes: 61980
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()

"""
無向グラフでdpできるのが非直感的だが（というのも普通dpをするのはDAGに限るから）、
まず無向グラフは各辺に対して向きの違う有向辺が２本走っていると思えば一応有向グラフではある。

ダイクストラ自体はacyclicityは要請しないので実行可能だが、このとき各頂点への最短距離を小さい順に並べる。
    （例） S--->A--->B--->C--->D--->E
すると実は元のグラフからA--->SやC--->Bといった上の順番と逆行するような辺を除いてもダイクストラの結果は同じになる。
（というのも負辺は無いので逆向きの辺を使うと経路長が長くなるから）

そもそもダイクストラで最小値を取って更新をかけているのはまさに上のような間引いたグラフを構築しているわけで、これは
まさにDAGになっている。なのでこの上でdpを走らせることも可能。

そしてダイクストラとdpを同時に実行できる点が奇跡なのであって、本問のような一般グラフ上でのDAG生成＆dpを俗に
「拡張ダイクストラ」とも言うらしい。
"""

def main():
    N, M, S = map(int, input().split())
    MAX_S = 50 * N + 1
    repn = [[] for _ in range(N)]
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        repn[u - 1].append((v - 1, a, b))
        repn[v - 1].append((u - 1, a, b))
    coin = []
    for _ in range(N):
        c, d = map(int, input().split())
        coin.append((c, d))

    """
    「最短路問題はダイクストラだが、実質それはdpと見れるらしい。」
    重要になるパラメーターは
        ・頂点　・お金　・時間
    なのでdp[v][s][x]が最初に思いつくが確実にTLE、
    ただし移動にかかるお金は制約が強いので
        dp[v][s] = (頂点vに手持ちs円でたどり着く最小の時間)
    とすればよい。
    このときお金sの状態数は上限50*(N-1)とすれば十分。
    (これだけあれば一切換金が不要なので)

    dpの遷移は「辺を移動」、「換金する」の２つあることに注意。
    この遷移を式にする際にダイクストラを用いる。
    """

    dp = [[float("inf")] * (MAX_S + 1) for _ in range(N)]
    S = min(S, MAX_S)
    q = []

    # heappushの再定義（x時間で頂点vにお金sで行けるかどうか）
    def push(x, v, s):
        if not (s < 0 or dp[v][s] <= x):
            dp[v][s] = x
            heappush(q, (x, v, s))
    
    # initialization
    push(0, 0, S)

    # dijkstra
    while q:
        x, v, s = heappop(q)
        if (dp[v][s] != x): continue # すでに別経路で同じ条件を探索済みの場合は除く。（必須ではないが高速化になる）
        # 両替するとき
        new_x = x + coin[v][1]
        new_s = min(s + coin[v][0], MAX_S)
        push(new_x, v, new_s)
        # 辺を移動するとき
        for u, a, b in repn[v]:
            push(x + b, u, s - a)
    
    # answer
    for v in range(1, N):
        ans = float("inf")
        for s in range(MAX_S):
            ans = min(ans, dp[v][s])
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 99112
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b) {
  if (a % b == 0) {
    return(b);
  } else {
    return(gcd(b, a % b));
  }
}
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int a = 1; a <= N; a++) {
    for (int b = 1; b <= N; b++) {
      for (int c = 1; c <= N; c++) {
        ans = ans +  gcd(gcd(a, b), c);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,k;
	cin>>k>>a>>b;
	b=b/k;
	b=b*k;
	if(b>=a){
		cout<<"OK";
	} else cout<<"NG";
	RE 0;
}




Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n,k; cin >> n >> k;
	int ans=0;
	rep(i,n) {
		int a; cin >> a;
		if(a>=k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define N 10005
using namespace std;

int n, s, a[N], b[N], c[N], d[N];
bool v[N];
struct st {
	int c1, c2, c3;
};
vector<st> e[N];
void pu(int p, int q) {
	e[p].push_back({q, 1, e[q].size()});
	e[q].push_back({p, 0, e[p].size() - 1});
}

int f(int p, int q) {
	int i, t2;
	st t;
	if (p == n * 2 + 1) return q;
	v[p] = 1;
	for (i = 0; i < e[p].size(); i++) {
		t = e[p][i];
		if (!v[t.c1] && t.c2 > 0) {
			t2 = f(t.c1, min(q, t.c2));
			if (t2 > 0) {
				e[p][i].c2 -= t2;
				e[t.c1][t.c3].c2 += t2;
				return t2;
			}
		}
	}
	return 0;
}
int main()
{
	int i, j, t;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%d %d", &a[i], &b[i]);
	}
	for (i = 1; i <= n; i++) {
		scanf ("%d %d", &c[i], &d[i]);
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (a[i] < c[j] && b[i] < d[j]) pu(i, n + j);
		}
	}
	for (i = 1; i <= n; i++) pu(0, i);
	for (i = 1; i <= n; i++) pu(n + i, n * 2 + 1);
	while (1) {
			memset(v, 0, sizeof(v));
		t = f(0, 2e9);
		if (t == 0) break;
		s += t;
	}
	cout << s;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int num = 0;
  int maxL = 0;
  for(int i = 0; i < N; i++){
    int p ;
    cin >> p;
    maxL = max(maxL,p);
    num += p;
  }
  int ans = num - (maxL / 2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

struct TRAMP{
	char mark;
	int number;
};

int main(){
	int n,min;
	char buf[3];
	scanf("%d",&n);

	TRAMP selectArray[n],bubbleArray[n];

	for(int i = 0; i < n; i++){
		scanf("%s",buf);
		selectArray[i].mark = buf[0];
		selectArray[i].number = buf[1] - '0';
		bubbleArray[i] = selectArray[i];
	}

	for(int i = n-1; i >= 0; i--){
		for(int j = 0; j < i; j++){
			if(bubbleArray[j].number > bubbleArray[j+1].number) swap(bubbleArray[j], bubbleArray[j+1]);
		}
	}

	for(int i = 0; i < n-1; i++){
		min = i;
		for(int j = i+1; j < n; j++){
			if(selectArray[j].number < selectArray[min].number){
				min = j;
			}
		}
		if(i != min){
			swap(selectArray[i],selectArray[min]);
		}
	}

	for(int i = 0; i < n-1; i++) printf("%c%d ",bubbleArray[i].mark,bubbleArray[i].number);
	printf("%c%d\n",bubbleArray[n-1].mark,bubbleArray[n-1].number);
	printf("Stable\n");
	for(int i = 0; i < n-1; i++) printf("%c%d ",selectArray[i].mark,selectArray[i].number);
	printf("%c%d\n",selectArray[n-1].mark,selectArray[n-1].number);

	int p;
	for(p=0; p < n; p++){
		if(selectArray[p].number != bubbleArray[p].number || selectArray[p].mark != bubbleArray[p].mark)
			break;
	}
	if(p == n){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}

	return 0;
}



Measured memory_bytes: 2760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 List<Integer> list = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toList());

        Map<Long, Long> map = new HashMap<>();
        map.put(0L, 1000L);
        for (int i = 0; i < n; i++) {
            final Map<Long, Long> tmp = new HashMap<>();
            final int stock = list.get(i);
            for (final Map.Entry<Long, Long> entry : map.entrySet()) {
                final long sell = entry.getValue() + entry.getKey() * stock;
                tmp.compute(0L, (k, v) -> v == null ? sell : Math.max(v, sell));
                final long buy = entry.getKey() + entry.getValue() / stock;
                final long rest = entry.getValue() % stock;
                tmp.compute(buy, (k, v) -> v == null ? rest : Math.max(v, rest));
            }

            for (final Map.Entry<Long, Long> entry : map.entrySet()) {
                tmp.compute(entry.getKey(), (k, v) -> v == null ? entry.getValue() : Math.max(v, entry.getValue()));
            }
            map = tmp;
        }

        map.values().stream()
            .mapToLong(Long::longValue)
            .max()
            .ifPresent(System.out::println);
    }

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


Measured memory_bytes: 36284
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

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

int n;
int main(void) {
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i,n) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
using namespace std;

int main () {
    int N, M, sum = 0;
    cin >> N >> M;

    vector<int> X(M);
    vector<int> dis(M-1);

    for(int i = 0; i < M; i++){
        cin >> X.at(i);
    }

    if(M == 1){
        cout << 0 << endl;
    }
    else{
        sort(X.begin(), X.end());

            for(int i = 0; i < M; i++){
                dis.at(i) = fabs(X.at(i) - X.at(i+1));
                if((i+2) == M){
                    break;
                }
            }

            sort(dis.begin(), dis.end(), greater<int>());

            for(int i = N-1; i < dis.size(); i++){
                sum += dis.at(i);
            }

            cout << sum << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue< long long > a;
    for (int i = 0; i < n; i++) {
        long long A;
        cin >> A;
        a.push(A);
    }
    for (int i = 0; i < m; i++) {
        long long A = a.top();
        a.pop();
        a.push(A / 2);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main(){
	long long n,a,b;
	cin >> n >> a >> b;
	if(a>b)cout << 0 << endl;
	else if(n==1){
		if(a==b)cout << 1 << endl;
		else cout << 0 << endl;
	}else{
		cout << (b-a)*(n-2)+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
while input = gets do
  n = input.to_i
  count = 0

  for i in 0..9
    for j in 0..9
      for k in 0..9
        for l in 0..9
          count += 1 if i + j + k + l == n
        end
      end
    end
  end

  puts count
end

Measured memory_bytes: 6084
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

string calc(int m, int f, int r) {
	if(m == -1 || f == -1) return "F";
	int s = m + f;
	if(s >= 80) return "A";
	if(s >= 65) return "B";
	if(s >= 50) return "C";
	if(s >= 30) {
		if(r >= 50) return "C";
		else return "D";
	}
	return "F";
}

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

	while(true) {
		int m, f, r;
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		cout << calc(m, f, r) << endl;
	}
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
long long a[100005];
long long b[2];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=0;i<2;i++)
	{
		long long s=0;
		b[i]=0;
		for(int j=0;j<n;j++)
		{
			s+=a[j];
			if((i+j)&1)
			{
				if(s<=0){b[i]+=(1-s);s=1;}
			}
			else
			{
				if(s>=0){b[i]+=(1+s);s=-1;}
			}
		}
	}
	printf("%lld\n",min(b[0],b[1]));
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
class Main{
  	public static void main(String arts[]){
      	Scanner sc =  new Scanner(System.in);
      	int X = 0;
      	int Y = 0;
      	int Rls = 0;
      	int N = sc.nextInt();
      	sc.nextLine();
      	String Vlist = sc.nextLine();
      	String[] Vs = Vlist.split(" ");
      	int[] V = new int[Vs.length];
        for(int n = 0;n < V.length;n++){
          	V[n] = Integer.parseInt(Vs[n]); 
        }
      	String Clist = sc.nextLine();
      	String[] Cs = Clist.split(" ");
      	int[] C = new int[Cs.length];
      	for(int n = 0;n < C.length;n++){
          	C[n] = Integer.parseInt(Cs[n]);
        }
      	int[] D = new int[C.length];
      	for(int x = 0;x < D.length;x++){
          	D[x] = V[x] - C[x];
        }
      	Arrays.sort(D);
      	for(int n = C.length-1;n>=0;n--){
          if(D[n]<=0){
            	break;
          }
          Rls = Rls + D[n];
        }
      	System.out.println(Rls);
    }
}
              	

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b);
	deque<ll> r(c);
	rep(i, a) cin >> p[i];
	rep(i, b) cin >> q[i];
	rep(i, c) cin >> r[i];
	sort(rall(p));
	sort(rall(q));
	sort(rall(r));
	
	vector<ll> res;
	rep(i, x) res.emplace_back(p[i]);
	rep(i, y) res.emplace_back(q[i]);
	rep(i, c) res.emplace_back(r[i]);
	sort(rall(res));
	ll ans = 0;
	rep(i, x + y) ans += res[i];
	dunk(ans);
	return 0;
}

Measured memory_bytes: 8436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  char s;
  cin>>s;
  bool j=false;
  for(int i=0;i<26;i++){
    if(s==alp[i]){
      j=true;
      break;
    }
  }
  if(j){
    cout<<'a'<<endl;
  }
  else{
    cout<<'A'<<endl;
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,b) for(ll i=a;i<=b;i++)
#define fr(i,n) for(ll i=n-1;i>=0;i--)
#define endl "\n"
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ms(array,value) memset(array,value,sizeof(array))
#define test(t) ll t;cin>>t;while(t--)
#define en cout<<endl;
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define pb push_back
#define all(a) a.begin(),a.end()
#define pi pair<int,int>
#define mod2  998,244,353

int main()
{
    int k; cin>>k;
    ll sum=0;
    fa(i,1,k)
    {
        fa(j,1,k)
        {
            int x=__gcd(i,j);
            fa(l,1,k)
            {
                int y=__gcd(j,l);
                sum+=__gcd(x,y);
            }
        }
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
string n;
int s = 0;
int main()
{
    cin >> n;
    reverse(n.begin(), n.end());
    for (int i = 0, k = 0; k || i < n.size(); ++ i)
    {
        if (i == n.size()) n.push_back('0');
        int w = (n[i] - '0') * 9 + k;
        n[i] = w % 10 + '0'; k = w / 10;
    }
    // reverse(n.begin(), n.end()); cout << n << endl;
    for (int i = 0; i < n.size(); ++ i) s += n[i] - '0';
    for (int w = 1; ; ++ w)
    {
        for (int i = 0, k = 9; k; ++ i)
        {
            if (i == n.size()) n.push_back('0');
            s -= n[i] - '0';
            int w = (n[i] - '0') + k;
            n[i] = w % 10 + '0'; k = w / 10;
            s += n[i] - '0';
        }
        if (s <= 9 * w) {cout << w << endl; break;}
    }
}


Measured memory_bytes: 900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

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

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

		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		UnionFind uft = new UnionFind(n);

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");

			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);

			uft.unite(a - 1, b - 1);
		}

		long max = 0;
		for (int i = 0; i < n; i++) {
			max = Math.max(max, uft.size(i));
		}

		System.out.println(max);
	}
}

class UnionFind {

	// 自身が親であれば、その集合に属する頂点数に-1を掛けたもの
	// そうでなければ親のid
	int r[];

	public UnionFind(int n) {
		r = new int[n];
		Arrays.fill(r, -1);
	}

	int root(int x) {
		if (r[x] < 0)
			return x;
		return r[x] = root(r[x]);
	}

	boolean unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)
			return false;
		if (r[x] > r[y]) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		r[x] += r[y];
		r[y] = x;
		return true;
	}

	int size(int x) {
		return -r[root(x)];
	}
}


Measured memory_bytes: 56376
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 1000001
char a[N];
int sum;
int main(){
    gets(a);
    int n=strlen(a);
    for (int i=1;i<n;i++){
        if (a[i]!=a[i-1]){
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 384
import math

n = int(raw_input())

def isPrime(a):
    if a==2 or a==3:
        return 1
    if a<2 or a%2==0:
        return 0
        
    i = int(math.sqrt(a))+1
    for x in xrange(3,i):
        if a%x==0:
            return 0
    return 1

cnt = 0
for _ in xrange(n):
    a = int(raw_input())
    cnt += isPrime(a)
print cnt

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

int main(){
  int N;cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++) cin>>H.at(i);
  int max=H.at(0);
  int count=1;
  for(int i=1;i<N;i++){
    if(H.at(i)>=max){
      count++;
      max=H.at(i);
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    long N;

    cin >> N;

    long long ans = 0;

    for (long i = 1; i <= N; i++)
    {
        if ((i % 3 == 0) or (i % 5 == 0))
        {
            continue;
        }
        // cout << i << endl;

        ans += i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int ary[n],i;
    for(i=0;i<n;i++)scanf("%d",&ary[i]);
    int l=ary[0],r=0,gt,min=214783647;
    for(i=1;i<n;i++)r+=ary[i];
    for(i=1;i<n;i++){
        gt=l-r;
        if(gt<0)gt=-gt;
        if(gt<min)min=gt;
        r-=ary[i];
        l+=ary[i];
    }
    printf("%d\n",min);
    return 0;
}

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

int
main (void)
{
  int a = 0;
  int b = 0;
  int n = 0;

  cin >> n >> a >> b;

  if ((b - a - 1) & 1)
    cout << "Alice";
  else
    cout << "Borys";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
	int i, j, k, n, x, count;
	count = 0, k = 1, i = 1, n = 1, x = 1, j = 1;
	while (1)
	{
		count = 0;
		scanf("%d %d", &n, &x);
		if ((n == 0) && (x == 0))
		{
			break;
		}
		for (i = 1;i <= n;i++)
		{
			
			for (j = i+1;j <= n;j++)
			{
				for (k = j+1;k <= n;k++)
				{
					if (x ==i + j + k)
					{
						count = count + 1;
					}
				}
			}

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

Measured memory_bytes: 600
from collections import deque
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,Q = LI()
ab = [LI() for _ in [None]*(N-1)]
px = [LI() for _ in [None]*(Q)]
ans = [0]*(N+1) #1_index
graph = [deque() for _ in [None]*(N+1)] #1_index
for a,b in ab:
        graph[a].append(b)
        graph[b].append(a)
for p,x in px:
    ans[p] += x
seen = [0]*(N+1) #1_index
stack = []
def dfs():
    seen[1] = 1
    stack.append(1)
    while stack:
        s = stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            g_NO = graph[s].popleft()
            if seen[g_NO]:
                continue
            seen[g_NO] = 1
            stack.append(g_NO)
            ans[g_NO] += ans[s]
dfs()
print(*ans[1:])


Measured memory_bytes: 244184
import Control.Monad

main :: IO ()
main = do
  ls <- replicateM 3 getLine
  let ls' = map (map read . words) ls
  mapM_ putStrLn $ map solve ls'

solve :: [Int] -> String
solve [h1,m1,s1,h2,m2,s2] = toTime (h2*3600 - h1*3600 + m2*60 - m1*60 + s2 -s1)
  where
    toTime :: Int -> String
    toTime i = (show hour) ++ " " ++ (show minu) ++ " " ++ (show sec)
      where
        hour = i `div` 3600
        minu = (i - 3600 * hour) `div` 60
        sec = i `mod` 60

Measured memory_bytes: 3696
# diverta 2019 Programming Contest
# https://atcoder.jp/contests/diverta2019
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, K = i2nn()
    print(N-K+1)

main()


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







int main(){ 
    Int N, M;
    cin >> N >> M;

    vector<vector<Int>> G(100010);
    vector<Int> sirube(100010,-1);
    vector<bool> visited(100010,false);

    rep(i,M) {
        Int A, B;
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    queue<Int> que;
    que.push(0);

    while(!que.empty()) {
        Int now = que.front();
        rep(j,G[now].size()) {
            if (visited[G[now][j]]) continue;
            else {
                que.push(G[now][j]);
                visited[G[now][j]] = true;
                sirube[G[now][j]] = now;
            }
        }
        que.pop();
    }

    bool flag = true;
    rep1(i,N-1) {
        if (!visited[i]) flag = false;
    }

    if (!flag) {
        cout << "No" << endl;
        return 0;
    }

    if (flag) {
        cout << "Yes" << endl;
        rep1(i,N-1) cout << sirube[i] + 1 << endl;
    }
    


}

Measured memory_bytes: 12864
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int m_day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, INF};

ll cSeireki(ll y, ll m,ll d){
  ll ret = 0;
  ret += (y-1)*365 + ((y-1)/4 - (y-1)/100 + (y-1)/400);
  for(int i = 1; i < m; i++) ret += m_day[i];
  ret += d;
  if(m > 2){
    if((y%4 == 0 && y%100)|| y%400 == 0) ret++;
  }
  return ret;
}

void to_mayan(ll y, ll m, ll d){
  ll day = cSeireki(y, m, d) - cSeireki(2012, 12, 21);

  ll b, ka, t, w, ki;
  b = (day/(20*20*18*20))%13; day = day%(20*20*18*20);
  ka = day/(20*18*20);   day = day%(20*18*20);
  t = day/(18*20);       day = day%(18*20);
  w = day/20;            day = day%20;
  ki = day;
  printf("%lld.%lld.%lld.%lld.%lld\n", b, ka, t, w, ki);
}

void to_seireki(ll b, ll ka, ll t, ll w, ll ki){
  ll day = 0;
  day += ki;
  day += w*20;
  day += t*18*20;
  day += ka*20*18*20;
  day += b*20*20*18*20;

  ll y = 2012 , m = 12, d = 21;
  while(day--){
    if(m == 12 && d == 31){
      y++;
      m = 1;
      d = 1;
    }else{
      int f = 0;
      if(((y%4 == 0 && y%100) || y%400 == 0) && m == 2 ) f = 1;
      d++;
      if(m_day[m]+f < d){
	d = 1;
	m++;
      }
    }
    //    printf("%lld.%lld.%lld\n", y, m, d);
  }

  printf("%lld.%lld.%lld\n", y, m, d);

  /*  ll lb = 0, ub = 10000001, mid, tmp;
    while(ub - lb > 1){
    mid = (lb + ub)/2;
    //    printf("%lld\n", mid);
    tmp = cSeireki(mid-1, 12, 31) - cSeireki(2012, 12, 21);
    //    printf("%lld %lld\n", day, tmp);
    if(day >= tmp && day - tmp <= 365){
      break;
    }
    if(day < tmp){
      ub = mid;
    }else{
      lb = mid;
    }
  }

  ll y = mid;
  if((y%4 == 0 && y%100) || y%400 == 0) m_day[2] = 29;
  day -= tmp;
  ll m = 1;
  while(day > m_day[m]){
    day -= m_day[m];
    m++;
  }
  m_day[2] = 28; */

  //  printf("%lld.%lld.%lld\n", y, m, day); 
}

int main(){
  char str[128];
  while(scanf("%s", str) && str[0] != '#'){
    int c = 0;
    rep(i, strlen(str)) if(str[i] == '.') c++;
    if(c == 2){
      ll y, m, d;
      sscanf(str, "%lld.%lld.%lld", &y, &m, &d);
      to_mayan(y, m, d);
    }else{
      ll b, ka, t, w, ki;
      sscanf(str, "%lld.%lld.%lld.%lld.%lld", &b, &ka, &t, &w, &ki);
      to_seireki(b, ka, t, w, ki);
    }
  }
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

typedef struct {
	LL l, r, s;
} query;

VLL lazy, seg;

void eval(LL k, LL l, LL r) {
	if (k >= seg.size())return;
	if (lazy[k] == 1e15)return;
	seg[k] += lazy[k];
	if (k < seg.size() / 2) {
		if (lazy[2 * k] == 1e15)lazy[2 * k] = lazy[k];
		else lazy[2 * k] += lazy[k];
		if (lazy[2 * k + 1] == 1e15)lazy[2 * k + 1] = lazy[k];
		else lazy[2 * k + 1] += lazy[k];
	}
	lazy[k] = 1e15;
}

void add(LL a, LL b, LL x, LL k = 1, LL l = 0, LL r = seg.size() / 2 - 1) {
	eval(k, l, r);
	if (r < a || b < l)return;
	if (a <= l && r <= b) {
		if (lazy[k] == 1e15)lazy[k] = x;
		else lazy[k] += x;
		eval(k, l, r);
	}
	else {
		add(a, b, x, 2 * k, l, (l + r) / 2);
		add(a, b, x, 2 * k + 1, (l + r) / 2+1, r);
		seg[k] = max(seg[2 * k], seg[2 * k + 1]);
	}
}

LL getmax(LL a, LL b, LL k = 1, LL l = 0, LL r = seg.size() / 2-1) {
	if (r < a || b < l)return 0;
	eval(k, l, r);
	if (a <= l && r <= b)return seg[k];
	else return max(
		getmax(a, b, 2 * k, l, (l + r) / 2),
		getmax(a, b, 2 * k + 1, (l + r) / 2 + 1, r)
	);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	LL M;
	cin >> M;
	vector<query> querys(M + 1);
	LL SUM = 0;
	for (LL m = 0; m < M; m++) {
		query& q = querys[m];
		cin >> q.l >> q.r >> q.s;
		q.s *= -1;
		SUM -= q.s;
	}
	querys.back() = { N + 1,N + 1,0 };
	VLL DP(N + 1, 0);
	LL RN = 1;
	while (RN < N+1)RN *= 2;
	seg.resize(2 * RN, 0);
	lazy.resize(2 * RN, 1e15);
	sort(querys.begin(), querys.end(), [](query a, query b) {
		return a.r < b.r;
	});
	LL look = 0;
	for (LL n = 1; n <= N; n++) {
		LL t = getmax(0, n - 1);
		DP[n] = t;
		add(n, n, t);
		while (querys[look].r == n) {
			add(0, querys[look].l - 1, querys[look].s);
			look++;
		}
	}
	for (LL n = 0; n < lazy.size(); n++)lazy[n] = 1e15;
	for (LL n = 0; n <= N; n++) seg[RN + n] = DP[n];
	for (LL n = RN - 1; n >= 1; n--) {
		seg[n] = max(seg[2 * n], seg[2 * n + 1]);
	}
	for (auto q : querys) {
		add(0, q.l - 1, q.s);
	}
	cout << SUM+getmax(0,N) << "\n";
	return 0;
}


Measured memory_bytes: 14720
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int n;
ll v[100005][3];
ll dp[100005][3];
ll solve(int i, int prev){
		if(dp[i][prev]!=-1)
	return dp[i][prev];
	ll ans=0;
	if(i==n){
		 for(int j=0;j<3;j++)
		 if(j!=prev)
		 ans=max(ans,v[n][j]);
	}

    else
     for(int j=0;j<3;j++)
     {
     	if(j!=prev)
     	ans=max(ans,solve(i+1,j)+v[i][j]);
	 }
	 return dp[i][prev]=ans;
}
int main(){
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>v[i][0]>>v[i][1]>>v[i][2];
	memset(dp, -1, sizeof(dp));
	cout<<solve(1,-1);
	
	
	}

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

ll gcd(ll a,ll b){return b==0 ? a:gcd(b,a%b);}
ll M,N,L;
ll a[100000];
ll cnt(ll a);

bool check(){
    ll num = cnt(a[0]);
    rep(i,N)if(num != cnt(a[i]))return false;
    return true;
}

ll cnt(ll a){
    ll i = 0;
    while(a%2==0){
        i++;
        a/=2;
    }
    return i;
}

int main(void){
    cin >> N >> M;
    rep(i,N){
        cin >> a[i];
        a[i] /=2;
    }
    if(!check()){cout << 0 << endl;return 0;}
    L =a[0];
    rep(i,N)L =   L / gcd(a[i],L) * a[i];
    if(M/L == 0)cout << M/L/2 <<endl;
    else cout << (M/L+1)/2 <<endl;
}


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

int main() {

  int N;
  cin >> N;

  for(int i = 1;i <= N;i++) {
    int n = i*1.08;
    if(n == N) {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;

}






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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, m, r;
        std::cin >> l >> m >> r;
        std::rotate(v.begin() + l, v.begin() + m, v.begin() + r);
    }
/*
rotate : rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);でmiddleに指定した要素が先頭、middle-1の要素が末尾に来るように回転
ex. 1 2 3 4 5 6
rotate(1,3,6)とかを指定するイメージ(middle=3,middle-1=2)
→3 4 5 6 1 2
*/

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define N 1000099
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define LL long long
using namespace std;
int n, cnt;
LL a, b;
bool is[N];
LL prime[N];
LL gcd(LL x, LL y)
{
    if (y == 0) return x;
    return gcd(y, x % y);
}
void getprime()
{
    is[1] = is[0] = 1;
    prime[0] = 1;
    for (int i = 2; i < N; i++)
    {
        if (!is[i]) prime[++cnt] = i;
        for (int j = 1; j <= cnt && prime[j] * i < N; j++)
        {
            is[prime[j] * i] = 1;
            if (i % prime[j] == 0) break;
        }
    }
}
bool check(LL x)
{
    for (LL i = 2; i * i <= x; i++)
    {
        if (x % i == 0) return 0;
    }
    return 1;
}
int cal(LL x)
{
    int res = 0;
    for (LL i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            if (check(i)) res++;
            if (x / i != i && check(x / i)) res++;
        }
    }
    return res;
}
int main()
{
    cin >> a >> b;
    getprime();
    cout << cal(gcd(a, b)) << endl;
    return 0;
}


Measured memory_bytes: 5232
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define SORT(t, a, n) qsort(a, n, sizeof(t), ({ int _f (const void *_a, const void *_b) { return *(t *)_a - *(t *)_b; } _f; }))
#define RSORT(t, a, n) qsort(a, n, sizeof(t), ({ int _f (const void *_a, const void *_b) { return *(t *)_b - *(t *)_a; } _f; }))
#define SUM(a, n) ({ ll _s = 0; REP(_i, n) _s += a[_i]; _s; })
#define CNT(x, a, n) ({ ll _c = 0; REP(_i, n) if (a[_i] == x) _c++; _c; })
#define MAXM(t, a, n) ({ t _m = a[0]; REP(_i, n) _m = MAX(_m, a[_i]); _m; })
#define MINM(t, a, n) ({ t _m = a[0]; REP(_i, n) _m = MIN(_m, a[_i]); _m; })
#define INF 1145141919
typedef long long ll;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    int g[50][50] = {};
    REP(i, m) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        g[a][b]++; g[b][a]++;
    }
    REP(i, n) printf("%lld\n", SUM(g[i], n));
    return 0;
}

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

int main(){
   int A, B, C, D;
   cin >> A >> B >> C >> D;
   int cnt = 0;
   while (!((A <= 0) || (C <= 0))){
      if (cnt % 2 == 0){
         C = C - B;
      } else{
         A = A - D;
      }
      //cout << "cnt: " << cnt << " " << "A: " << A << " " << "C: " << C << endl;
      cnt++;
   }
   if (cnt % 2 == 0)
      cout << "No" << endl;
   else
      cout << "Yes" << endl;
}



Measured memory_bytes: 3636