akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    int cnt = 0;
    for (int i = min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a, b;
    vector<vector<ll>> g(n, vector<ll>());
    for (ll i = 0; i < m; i++)
    {
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }
    // BFS のためのデータ構造
    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    vector<ll> sirusi(n, -1);
    sirusi[0] = 0;
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty())
    {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : g[v])
        {
            if (dist[nv] != -1)
                continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            sirusi[nv] = v;
            que.push(nv);
        }
    }
    bool flag = true;
    for (auto f : sirusi)
    {
        if (f == -1)
        {
            flag = false;
        }
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (ll i = 1; i < n; i++)
    {
        cout << sirusi[i] + 1 << endl;
    }
}


Measured memory_bytes: 13200
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //get string
        String O = sc.next();
        String E = sc.next();
        String password = constructPassWord(O, E);
        System.out.println(password);
    }
    private static String constructPassWord(String O, String E) {
        StringBuilder res = new StringBuilder();
        int len = Math.min(O.length(), E.length());

        for(int i = 0; i < len; i++) {
            res.append(O.charAt(i));
            res.append(E.charAt(i));
        }

        if(O.length() > len) {
            res.append(O.charAt(len));
        } else if(E.length() > len) {
            res.append(E.charAt(len));
        }

        return res.toString();
    }
}


Measured memory_bytes: 21588
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

vector<ll> prime;
void init(void) {
    prime.push_back(2);
    prime.push_back(3);
    for (ll i=5; i<=100100; i++) {
        bool flag = false;
        for (ll j=2;j*j <= i && !flag; j++) {
            if (i%j == 0) flag = true;
        }
        if (!flag) prime.push_back(i);
    }
}

int main(void) {
    init();
    ll X;
    cin >> X;
    ll Y = *lower_bound(prime.begin(), prime.end(), X);
    cout << Y << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int i, j, k, n, a, b, dice[7],
    side[5] = {2,3,5,4,2};
    char order[7][3] = {"","","N","W","E","S","NN"};
    
    for (i=1; i<7; i++)
        scanf("%d", &dice[i]);
    
    scanf("%d", &n);
    
    //上面を合わせる
    for (i=0; i<n ;i++) {
        scanf("%d %d",&a,&b);
        
        for (j=1; dice[j]!=a; j++);
        
        //回転
        
        for(k=0;order[j][k]!='\0';k++) {
            
            dice[0] = dice[1];
            
            switch(order[j][k]) {
                    
                case 'E':
                    dice[1] = dice[4];
                    dice[4] = dice[6];
                    dice[6] = dice[3];
                    dice[3] = dice[0];
                    break;
                    
                case 'N':
                    dice[1] = dice[2];
                    dice[2] = dice[6];
                    dice[6] = dice[5];
                    dice[5] = dice[0];
                    break;
                    
                case 'S':
                    dice[1] = dice[5];
                    dice[5] = dice[6];
                    dice[6] = dice[2];
                    dice[2] = dice[0];
                    break;
                    
                case 'W':
                    dice[1] = dice[3];
                    dice[3] = dice[6];
                    dice[6] = dice[4];
                    dice[4] = dice[0];
                    break;
                    
            }
        }
        
        for(j=0; b!=dice[side[j]]; j++);
        
        printf("%d\n", dice[side[j+1]]);
        
    }
    
    return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = 1e18;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL N, A, B, C, D;
int ddig;
LL res, t;
map<LL, LL> mp;

int Dig(LL num) {
    int dig = 0;
    while(num > 0) {
        num /= 10;
        ++dig;
    }

    return dig;
}

void dfs(LL n, LL cost) {
    if(n == 1) {
        if(cost == -1) cost = 0;
        res = min(res, cost + D);
        return;
    }
    if(res <= cost || (mp[n] != 0 && mp[n] <= cost)) return;
    mp[n] = cost;
    if(cost == -1) cost = 0;

    for(LL i = max(2ll, n - 4); i <= n + 4; ++i) {
        if(i % 5 == 0) {
            t = LINF;
            if(Dig(i - (i / 5)) + ddig < 10) t = (i - i / 5) * D;
            dfs(i / 5, cost + min(C, t) + D * llabs(i - n));
        }
    }
    for(LL i = max(2ll, n - 2); i <= n + 2; ++i) {
        if(i % 3 == 0) {
            t = LINF;
            if(Dig(i - (i / 3)) + ddig < 10) t = (i - i / 3) * D;
            dfs(i / 3, cost + min(B, t) + D * llabs(i - n));
        }
    }
    for(LL i = max(2ll, n - 1); i <= n + 1; ++i) {
        if(i % 2 == 0) {
            t = LINF;
            if(Dig(i - (i / 2)) + ddig < 10) t = (i - i / 2) * D;
            dfs(i / 2, cost + min(A, t) + D * llabs(i - n));
        }
    }

    if(Dig(n) + ddig < 16) res = min(res, cost + n * D);

    return;
}

void solve() {
    cin >> N >> A >> B >> C >> D;

    mp.clear();
    res = LINF;
    ddig = Dig(D);
    dfs(N, -1);

    cout << res << endl;
    return;
}

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

    int T;
    cin >> T;
    while(T--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4460
package main

import (
  "fmt"
  "sort"
)

func main() {
  x := make([]int, 5)
  for i := 0; i < 5; i++ {
    fmt.Scan(&x[i])
  }
  var k int
  fmt.Scan(&k)
  sort.Ints(x)
  ans := ":("
  if x[4] - x[0] <= k {
    ans = "Yay!"
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.next();
		String result = "";
		for(char c: in.toCharArray()) {
			switch(c){
			case '1':
				result += "9";
				break;
			case '9':
				result += "1";
				break;
			}
		}
		System.out.println(result);

	}

}


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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long x, y, z;
        cin >> x >> y >> z;

        swap(x, y);
        swap(x, z);
        printf("%lld %lld %lld\n", x, y, z);
    }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
vector < int  > adj[100010];
int d[100010]={0};
int vis[100010] ={0} ;
 void  dfs(int u)
    {
    	int mx=0;
    	  vis[u] = true;
    	  
    	   loop(i,0,adj[u].size())
    	    {  int v = adj[u][i] ;
    	      
    	       
				if(!vis[v])
				 {
				 	 dfs(v);
			
				 }
				 	 mx= max(mx,d[v]+1);
				  
			}
			
			d[u]=mx;
	}
int main()
{    SPEED;

      int n,m;cin>>n>>m;
      
       loop(i,0,m)
        {
        	  int x,y; cin>>x>>y; 
        	   adj[x].pb(y); 
		}
		
		loop(i,1,n+1)
		 {
		 	 if(!vis[i])
		 	  {
		 	  	 
		 	  	 dfs(i) ;
			   }
		 }
		 
		int sm =-1; 
		 
		 loop(i,1,n+1) 
		 {
		 	 sm=max(d[i],sm);
		 }cout<<sm;
}



Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define LOOP(i,x,n) for(int i=(x);i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;


signed main(){
  int n,ans=0,min_b;
  cin>>n;
  bool same=true;
  vector<int> a(n),b(n);
  REP(i,n){
    cin>>a[i]>>b[i];
    if(a[i]!=b[i])same=false;
    ans+=a[i];
  }
  if(same){
    cout<<0<<endl;
    return  0;
  }
  REP(i,n)if(a[i]>b[i])min_b=min(min_b,b[i]);
  cout<<ans-min_b<<endl;
  return 0;
}


Measured memory_bytes: 512
from sys import stdin

li = [int(stdin.readline().rstrip()) for _ in range(5)]
lin = []

for i in range(5):
    amari = li[i]%10
    if amari == 0:
        amari = 10
    lin.append(amari)

sai = lin.index(min(lin))
point = 0
for i in range(5):
    if i == sai:
        point += li[i]
    else:
        if lin[i] == 10:
            point += li[i]
        else:
            point += li[i] + (10-lin[i])
print(point)

Measured memory_bytes: 3064
n = gets.to_i
nums = gets.split(' ').map(&:to_i)

count = 0
counts = []
(n-1).times do |i|
  if nums[i] >= nums[i+1]
    count += 1
  else
    counts << count
    count = 0
  end
end

counts << count

puts counts.max


Measured memory_bytes: 8964
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(0, (min(b, d)-max(a, c))) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int sub[5];
	int sum[2];
	int i;

	for(i=-0;i<2;i++){
		scanf("%d %d %d %d",&sub[0],&sub[1],&sub[2],&sub[3]);
		sum[0]=sub[0]+sub[1]+sub[2]+sub[3];
	}
	
	if(sum[0]>sum[1]){
		printf("%d\n",sum[0]);
	}
	else{
		printf("%d\n",sum[1]);
	}
	
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	var Alice, Bob int
	for index, val := range a {
		if index%2 == 0 {
			Alice += val
		} else {
			Bob += val
		}
	}
	fmt.Println(Alice - Bob)
}


Measured memory_bytes: 1844
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;
long long int gcd(long long int a,long long int b);
int main(){
    int n;
    cin >> n;
    // vector<long long int> a(n);
    long long int aps;
    // vector<long long int> gcdm(n);
    long long int sum=0;
    pair<int ,long long int> maxminus=make_pair(-1000000001,-1);
    int minusnum=0;
    pair<int ,long long int> minnm= make_pair(1000000001,-1);
    long long int a;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a<0){
            minusnum++;
            sum-=a;
            if(a>maxminus.first)maxminus=make_pair(a,i);
        }else{
            sum+=a;
            if(a<minnm.first)minnm=make_pair(a,i);
        }
    }
    
    if(minusnum&1){
        if(minusnum==n){
            sum += 2*(maxminus.first);
        }else if(minnm.first+maxminus.first>0)sum += 2*(maxminus.first);
        else if(minnm.first+maxminus.first<=0)sum -= 2*(minnm.first);
    }
    cout << sum << endl;
    return 0;
}
long long int gcd(long long int a,long long int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

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

//minagara
int main() {

    int a, b;
    cin >> a >> b;
    int count = 0;
    for(int i = a; a <= b; a++){
        if(a / 10000 == (a % 10) && (a / 1000) % 10  == (a % 100) / 10 ) count++;
    }
    cout << count << endl;

}

Measured memory_bytes: 256
NM = input().split()

N = int(NM[0])
M = int(NM[1])

PY = []
for i in range(1,M+1):
    sc = input()
    PY.append([int(sc.split()[0]),int(sc.split()[1]),i])

P_city = {}
for i in PY:
    if not i[0] in P_city:
        P_city[i[0]] = []
    P_city[i[0]].append([i[1],i[2]])
    
ans = {}
for i,j in P_city.items():
    j.sort()
    for index,k in enumerate(j):
        ans[k[1]] = str(i).zfill(6)+str(index+1).zfill(6)

for i in range(1,M+1):
    print(ans[i])

Measured memory_bytes: 67172
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                ios_base::sync_with_stdio(false);
                cin.tie(NULL);
                lli t,n,i,j,b,q,m;
                cin>>n;
                vector<lli> v(n);
                rep(i,n)cin>>v[i];
                sort(v.begin(),v.end());
                lli f=0;
                rep(i,n-1){
                    if(v[i]==v[i+1]){
                        f=1;
                        break;
                    }
                }
                if(f==0){
                    cout<<"YES"<<endl;
                }
                else{
                    cout<<"NO"<<endl;
                }

                return 0;
            }



Measured memory_bytes: 1792
s = str(input())

mm_list = ["01","02","03","04","05","06","07","08","09","10","11","12"]
yy_list = [str(i).rjust(2, "0") for i in range(0, 100)]

s_01 = s[0:2]
s_23 = s[2:]

if s_01 in yy_list and s_23 in mm_list and s_23 in yy_list and s_01 in mm_list:
    print("AMBIGUOUS")
elif s_01 in yy_list and s_23 in mm_list:
    print("YYMM")
elif s_23 in yy_list and s_01 in mm_list:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
n, m = map(int, input().split())
a = [[0] * m for i in range(n)]
b = [0] * m
for i in range(n):
	a[i] = list(map(int, input().split()))
for j in range(m):
	b[j] = int(input())
for i in range(n):
	s = 0
	for j in range(m):
		s += a[i][j] * b[j]
	print(s)



Measured memory_bytes: 5952
#include <bits/stdc++.h>
#include<iostream>
#include <math.h>//pow(x,y)=x^y
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(i,n) for (int i=0; i <(n);i++)
#define ll long long
#define rev(s) reverse(s.begin(),s.end())
#define sor(v) sort(v.begin(),v.end())

using namespace std;


int main() {
ll x,k,d,tmpp,tmpm,nokori;
cin>>x>>k>>d;

if(x<0){
    x = abs(x);
}

    tmpp = x%d;
    tmpm = abs(tmpp-d);

    ll kaisup = (x-tmpp)/d;
    nokori=k-kaisup;

    //cout<<"kakunin"<<endl;
    //cout<<"tmpp"<<tmpp<<endl;
    //cout<<"tmpm"<<tmpm<<endl;
    //cout<<"kaisup"<<kaisup<<endl;
    //cout<<"nokori"<<nokori<<endl;

    if(kaisup>=k){
        cout<<(x-k*d)<<endl;return 0;
    }


if(nokori%2==0){
    cout<<tmpp<<endl;
}else{
    cout<<tmpm<<endl;
}


}


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

const int INF = 0x3f3f3f3f;

vector <int> from[100010];
int L[100010], R[100010];
int id[100010];
bool ans;

void solve(int u = 0, int p = -1){
	L[u] = -INF - 1, R[u] = INF + 1;
	if (id[u] != -1) L[u] = R[u] = id[u];
	for (int i = 0; i < from[u].size(); i++){
		int v = from[u][i];
		if (v == p) continue;
		solve(v, u);
		if (L[v] < -INF / 2) continue;
		if (L[u] < -INF / 2) L[u] = L[v] - 1, R[u] = R[v] + 1;
		else {
			if (abs(L[v]) % 2 == abs(L[u]) % 2){
				ans = 0;
				return ;
			}
			L[u] = max(L[u], L[v] - 1);
			R[u] = min(R[u], R[v] + 1);
		}
	}
	if (L[u] > R[u]) ans = 0;
}

void make(int v = 0, int p = -1){
	if (v == 0 && id[v] == -1) id[v] = L[v];
	for (int i = 0; i < from[v].size(); i++){
		int to = from[v][i];
		if (to == p) continue;
		if (id[to] == -1){
			if (L[to] <= id[v] - 1 && id[v] - 1 <= R[to]) id[to] = id[v] - 1;
			else id[to] = id[v] + 1;
		}
		make(to, v);
	}
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		a--, b--;
		from[a].push_back(b);
		from[b].push_back(a);
	}
	memset(id, -1, sizeof(id));
	int m;
	scanf("%d", &m);
	for (int i = 0; i < m; i++){
		int v, p;
		scanf("%d%d", &v, &p);
		v--, id[v] = p;
	}
	ans = 1;
	solve();
	if (!ans){
		puts("No");
		return 0;
	}
	make();
	puts("Yes");
	for (int i = 0; i < n; i++){
		printf("%d\n", id[i]);
	}
	return 0;
}


Measured memory_bytes: 15360
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        final int n = scanner.nextInt();
        scanner.nextLine();
        final String[] text = new String[n];
        for (int i = 0; i < n; i++) {
            text[i] = scanner.nextLine() + " " + (i + 1);
        }

        final String output = Arrays.stream(text)
                .sorted((a, b) -> {
                    final String[] sp0 = a.split(" ");
                    final String[] sp1 = b.split(" ");

                    if (sp0[0].compareTo(sp1[0]) != 0) {
                        return sp0[0].compareTo(sp1[0]);
                    }

                    int num0 = Integer.parseInt(sp0[1]);
                    int num1 = Integer.parseInt(sp1[1]);

                    return num1 - num0;
                })
                .map(a -> a.split(" ")[2])
                .collect(Collectors.joining("\n"));


        System.out.println(output);

    }
}

Measured memory_bytes: 28372
# 初期入力
N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))

#
day_syukudai = sum(A)
day_asobu = N - day_syukudai
if day_asobu <0:
    print(-1)
else:
    print(day_asobu)

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#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 in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const ll MOD = 1e9 + 7;
vector<ll> inv_table(1e5+1), fact_table(2e5+1);

ll pow_mod(ll x, ll y)
{
    ll res=1;
    for (; y>0; y>>=1, x=(x*x)%MOD) {
        if (y&1) res = (res*x)%MOD;
    }
    return res;
}


void make_inv_table(vector<ll> &a)
{
    for (int i=0; i<=100000; i++) {
        a[i] = pow_mod(fact_table[i], MOD-2);
    }
}


void make_fact_table(vector<ll> &a)
{
    a[0] = 1;
    for (int i=1; i<=200000; i++) {
        a[i] = a[i-1] * i;
        a[i] %= MOD;
    }
}


ll comb(ll a, ll b)
{
    return (fact_table[a] * inv_table[a - b] % MOD) * inv_table[b] % MOD;
}


int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    make_fact_table(fact_table);
    make_inv_table(inv_table);

    ll ans = 0;

    int movableH = H - A;
    int movableW = W - B;

#if 0
    for (int i=1; i<=10; i++) { 
        cerr << fact_table[i] << ", " << inv_table[i] << endl;
    }
#endif

    for (int y=1; y<=movableH; y++) {
        ans += comb(y + B - 2, y - 1) * comb(movableW + (H - y + 1) - 2, movableW - 1);
        ans %= MOD;
    }
    
    cout << ans << endl;
}



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

const int mod = 1e9+7, maxn = 2e6 + 15;

int x,y,fact[maxn];

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

int main(){
	
	scanf("%d%d",&x,&y);
	
	fact[0] = 1;
	for(int i = 1; i < maxn; i++)
		fact[i] = 1LL * fact[i-1] * i % mod;
	
	int cnt = 0;
	if(x < y) swap(x,y);
	
	while(x > y){
		cnt++;
		x -= 2;
		y--;
	}
	
	if(x < 0 || y < 0 || x % 3 != 0){
		puts("0");
		return 0;
	}
	int k = x / 3;
	printf("%lld\n",1ll*fact[k+k+cnt]*power(fact[k+cnt], mod-2)%mod*power(fact[k], mod-2)%mod);
	
	return 0;
}

Measured memory_bytes: 8192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TwoArrays solver = new TwoArrays();
        solver.solve(1, in, out);
        out.close();
    }

    static class TwoArrays {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(0, n), b = in.nextIntArray(0, n);
            long aCapacity = 0, bRequire = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] < b[i]) aCapacity += (b[i] - a[i]) - ((b[i] - a[i]) % 2);
                if (a[i] > b[i]) bRequire += a[i] - b[i];
            }
            if (bRequire * 2 <= aCapacity) out.println("Yes");
            else out.println("No");
        }

    }

    static class InputReader {
        private StringTokenizer tokenizer;
        private BufferedReader reader;

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

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

        public int[] nextIntArray(int offset, int length) {
            int[] arr = new int[offset + length];
            for (int i = offset; i < offset + length; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

    }
}



Measured memory_bytes: 27348
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int L[101];

int main() {
  INCANT;
  cin >> N;
  rep(i, N) cin >> L[i];
  sort(L, L+N);
  int cnt=0;
  rep(i, N-2) {
    for (int j=i+1; j<N-1; j++) {
      for (int k=j+1; k<N; k++) {
        if (L[i]==L[j] || L[k]==L[j]) continue;
        if (L[k]<L[i]+L[j]) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3656
n,k,c = map(int,input().split())
s = input()

forward = dict()
backward = dict()

rep = list(range(n))
# forward
l = 0
kf = k
kb = k
while 1:
  if s[l] == 'x':
    l += 1
  else:
    forward[k-kf] = l+1
    kf -= 1
    l += c+1
  if (l > n-1) | (kf == 0):
    break
rep.reverse()
# backward
l = n-1
while 1:
  if s[l] == 'x':
    l -= 1
  else:
    backward[kb-1] = l+1
    kb -= 1
    l -= c+1
  if (l < 0) | (kb == 0):
    break
#judgement
ret = set(forward.items()) & set(backward.items())
lis = list()
for l in range(len(ret)):
  lis.append(ret.pop()[1])
lis = sorted(lis)
lis.reverse()
for l in range(len(lis)):
  print(lis.pop())

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

struct road
{
	int to, cost, k;//???????????????????????????
};
vector<road>rinsetu[100];
int mincost[100][101];//i??°??????j????????£?????????
struct A
{
	int x, y, z;//??´????????????????????????
};
bool operator <(A b, A c) {
	if (b.z != c.z)return b.z > c.z;
	return b.x * 1000 + b.y > c.x * 1000 + c.y;
}
signed main() {
	int a, b, c;
	while (scanf("%d%d%d", &a, &b, &c), a || b || c) {
		for (int d = 0; d < a; d++) {
			rinsetu[d].clear();
		}
		for (int d = 0; d < b; d++) {
			int e, f, g, h; scanf("%d%d%d%d", &e, &f, &g, &h);
			e--; f--;
			rinsetu[e].push_back({ f,g,h });
			rinsetu[f].push_back({ e,g,h });
		}
		memset(mincost, 0x3f, sizeof(mincost));
		mincost[0][c] = 0;
		priority_queue<A>Q;
		Q.push({0,c,0});
		while (Q.size()) {
			A d = Q.top(); Q.pop();
			if (d.z > mincost[d.x][d.y])continue;
			for (road i : rinsetu[d.x]) {
				//?????????????????????
				if (mincost[i.to][d.y] > d.z + i.k) {
					mincost[i.to][d.y] = d.z + i.k;
					Q.push({i.to,d.y,d.z + i.k });
				}
				//???????????????
				if (d.y >= i.cost) {
					if (mincost[i.to][d.y - i.cost] > d.z) {
						mincost[i.to][d.y - i.cost] = d.z;
						Q.push({ i.to, d.y - i.cost, d.z });
					}
				}
			}
		}
		int MIN = 1 << 29;
		for (int i = 0; i <= c; i++) {
			MIN = min(MIN, mincost[a-1][i]);
		}
		printf("%d\n", MIN);
	}
}

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

using namespace std;

const int N = (int) 1e5 + 7;
int n, m, balls[N];
bitset<N> act;

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

  cin >> n >> m;
  act[1] = 1;
  for (int i = 1; i <= n; i++) {
    balls[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (act[x]) {
      act[y] = 1;
      if (balls[x] == 1) {
        act[x] = 0;
      }
    }
    balls[x]--;
    balls[y]++;
  }
  cout << act.count() << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll MAX_L=10000;
 

int main(){
    ll n;
    cin >> n;
    deque<ll> q;
    ll a;
    cin >> a;
    q.pb(a);
    for(ll i=1;i<n;i++){
        cin >> a;
        auto itr=lower_bound(q.begin(),q.end(),a);
        if(itr==q.end()){
            if(q.back()<a) q.back()=a;
            else q.pb(a);
        }
        else{
            if(itr==q.begin()) q.push_front(a);
            else *(itr-1)=a;
        }
    }
    kaku(q.size());
}



Measured memory_bytes: 1024
/*	Don’t Quit
	
	When things go wrong as they sometimes will;
		When the road you’re trudging seems all uphill;
			When the funds are low, and the debts are high;
				And you want to smile, but you have to sigh;
					When care is pressing you down a bit
						Rest if you must, but don’t you quit.
*/
#pragma gcc optimize ("unroll-loop")
#pragma gcc optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int gcd(int n,int m)
{
	if(n==0)
		return m;
	else
		return gcd(m%n,n);
}
int32_t main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	int k=gcd(a,b);
	vector<int>vp;
	for(int i=1;i*i<=k;i++)
	{
		if(k%i==0)
		{
			vp.pb(k/i);
			if(k/i!=i)
				vp.pb(i);
		}
	}
	sort(all(vp));
	reverse(all(vp));
	cout<<vp[c-1]<<endl;




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 400007
#define modp 1000000007
using namespace std;
int n;
int a[Maxn],b[Maxn],c[Maxn];
int t[Maxn],s[Maxn];
int ans=0;
int power(int a,int b)
{
	int res=1,now=a,left=b;
	while (left>0)
	{
		if (left%2==1) res=(1LL*res*now)%modp;
		left/=2;
		now=(1LL*now*now)%modp;
	}
	return res;
}
void add(int pos,int val)
{
	for (int k=pos;k<=n;k+=k&(-k))
		s[k]=(s[k]+val)%modp;
}
int query(int pos)
{
	if (pos==0) return 0;
	int res=0;
	for (int k=pos;k;k-=k&(-k))
		res=(res+s[k])%modp;
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		++c[a[i]];
	}
	for (int i=n-1;i;i--)
		c[i]+=c[i+1]-1;
	for (int i=1;i<=n;i++)
		if (c[i]<=0)
		{
			printf("%d\n",0);
			return 0;
		}
	int sum=1;
	b[0]=1;
	for (int i=1;i<=n;i++)
	{
		sum=(1LL*sum*c[i])%modp;
		if (c[i]==1) b[i]=b[i-1]; else b[i]=(1LL*b[i-1]*(c[i]-1))%modp;
		b[i]=(1LL*b[i]*power(c[i],modp-2))%modp;
	}
	memset(s,0,sizeof(s));
	t[n]=n;
	for (int i=n-1;i;i--)
		if (c[i+1]>1) t[i]=t[i+1]; else t[i]=i;
	for (int i=n;i;i--)
	{
		int del=(query(t[a[i]])-query(a[i]-1)+modp)%modp;
		ans=(ans+1LL*del*power(b[a[i]],modp-2))%modp;
		add(a[i],b[a[i]]);
	}
	memset(s,0,sizeof(s));
	t[1]=1;
	for (int i=2;i<=n;i++)
		if (c[i]>1) t[i]=t[i-1]; else t[i]=i;
	for (int i=n;i;i--)
	{
		int del=(query(a[i]-1)-query(t[a[i]]-1)+modp)%modp;
		ans=(ans+modp-(1LL*del*b[a[i]])%modp)%modp;
		add(a[i],power(b[a[i]],modp-2));
	}
	ans=(1LL*ans*power(2,modp-2))%modp;
	memset(s,0,sizeof(s));
	for (int i=1;i<=n;i++)
	{
		ans=(ans+i+modp-1-query(a[i]))%modp;
		add(a[i],1);
	}
	printf("%lld\n",(1LL*ans*sum)%modp);
	return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

#define edge edge<int>
#define edges edges<int>
#define graph graph<int>
#define matrix matrix<int>

////////////////////////////////////////////////////////////////////

int n;vector<P> g[110000];
vector<int> ans(110000);
int mm = 0;
void dfs(int node, int pre, int preind){
  int ind = 1;
  rep(i,g[node].size()){
    P next = g[node][i];
    if(next.first == pre)continue;
    if(ind == preind)ind++;
    ans[next.second] = ind;chmax(mm, ind);
    ind++;
    dfs(next.first, node, ind-1);
  }
}
signed main(){
  cin>>n;
  rep(i,n-1){
    int a,b;cin>>a>>b;a--;b--;
    g[a].push_back(P(b,i));g[b].push_back(P(a,i));
  }
  dfs(0,-1,-1);
  cout << mm << endl;
  rep(i,n-1)cout << ans[i] << endl;
} 


Measured memory_bytes: 10112
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        char[] S = (sc.nextLine()).toCharArray();
        char[] T = (sc.nextLine()).toCharArray();
        int ans = 0;
        for (int i=0;i<3;i++){
            if (S[i] == T[i]) ans++;
        }
        System.out.printf("%d\n",ans);
        
    }
}


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

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

  int ans,tmp=0;
  for (int i=1; i<n; i++) {
    if (s.at(i) == 'E')
      tmp ++;
  }
  ans = tmp;

  for(int i=1; i<n; i++) {
    if (s.at(i-1) == 'W')
      tmp++;
    if (s.at(i) == 'E')
      tmp--;
    ans = min(tmp,ans);
  }

  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 1e5 + 10;

int n, a[N];

int main() {
#ifdef dream_maker
//  freopen("tst.in", "r", stdin);
#else
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
#endif
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  if (n % 3 != 0) {
    for (int i = 1; i < n; i++) {
      if (a[i + 1] != a[i]) {
        puts("No");
        return 0; 
      }
    }
    puts("Yes");
    return 0;
  } else {
    sort(a + 1, a + n + 1);
    for (int i = 1; i < n / 3; i++) {
      if (a[i] != a[i + 1]) {
        puts("No");
        return 0;
      }
    }
    for (int i = n / 3 + 1; i < n * 2 / 3; i++) {
      if (a[i] != a[i + 1]) {
        puts("No");
        return 0;
      }
    }
    for (int i = n * 2 / 3 + 1; i < n; i++) {
      if (a[i] != a[i + 1]) {
        puts("No");
        return 0;
      }
    }
    if (a[1] ^ a[n / 3 + 1] ^ a[n * 2 / 3 + 1]) puts("No");
    else puts("Yes");
    return 0;
  }
  return 0;
}


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

using namespace std;

int main() {
    int n, k;
    set<int> d;
    cin >> n >> k;
    while (k--) {
        int x;
        cin >> x;
        d.insert(x);
    }
    while (true) {
        int a = n, flag = 1;
        while (a) flag &= !d.count(a % 10), a /= 10;
        if (flag) {
            cout << n << endl;
            return 0;
        }
        ++n;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  ll suma=0,sumb=0;
  rep(i,n){ cin>>a[i]; suma+=a[i];}
  rep(i,n){ cin>>b[i]; sumb+=b[i];}
  if(suma<sumb){cout << -1 << endl; return 0;}
  bool flag=true;
  priority_queue<int> aa;
  ll bb=0;
  int ans=0;
  rep(i,n){ 
    if(a[i]<b[i]){
      flag=false;
      bb += b[i]-a[i];
      ans++;
    } else {
      aa.push(a[i]-b[i]);
    } 
  }
  if(flag){ cout << 0 << endl; return 0; }
  
  while(bb>0){
    int nxt = aa.top(); aa.pop();
    bb -= nxt;
    ans++;
  }
  
  
  cout << ans << endl;
  return 0;
}

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

int N, K;
int ans;
int parent[MAX];
vector<int> adj[MAX];

int prod(int a, int b)
{
	return 1LL * a * b % MOD;
}

void dfs(int depth, int v)
{
	int cur = K - 1;
	if (depth) cur--;
	for (int w : adj[v])
	{
		if (w == parent[v]) continue;
		ans = prod(ans, cur--);
		parent[w] = v;
		dfs(depth + 1, w);
	}
}

int main(void)
{
	cin >> N >> K;
	for (int i = 1; i < N; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	ans = K;
	dfs(0, 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, f;
int field[10][10];
int memo[3][2][1 << 16][8];
int win;

int GetP(int fs, int turn, int prev, int next) {
  int ret = 0;
  if (turn != 0) {
    if (fs == 0) {
      ret = field[next][prev];
    } else {
      ret = field[prev][next];
    }
  }
  return ret;
}

int calc(int yowai, int fs, int use, int prev) {
  int turn = __builtin_popcount(use);
  if (turn == 2 * n) { return f; }
  if (memo[yowai][fs][use][prev] != -1) { return memo[yowai][fs][use][prev]; }
  int used = 0;
  if (fs == 0) {
    used = use & ((1 << n) - 1);
  } else {
    used = (use >> n) & ((1 << n) - 1);
  }
  int ret = -10000000;
  if (yowai == fs) { ret = 10000000; }
  REP(i, n) {
    int nused = used | (1 << i);
    if (used == nused) { continue; }
    int nret = GetP(fs, turn, prev, i);
    int nuse = use | (nused << (fs * n));
    nret -= calc(yowai, fs ^ 1, nuse, i);
    if (yowai == fs) {
      ret = min(ret, nret);
    } else {
      ret = max(ret, nret);
    }
  }
  return memo[yowai][fs][use][prev] = ret;
}

int Search(int fs, int use, int prev, int p, int beta, int alpha) {
  int turn = __builtin_popcount(use);
  if (turn == 2 * n) { return 2 * n; }
  if (p + calc(fs ^ 1, fs, use, prev) < 0) { return turn + 1; }
  int used = 0;
  if (fs == 0) {
    used = use & ((1 << n) - 1);
  } else {
    used = (use >> n) & ((1 << n) - 1);
  }
  int ret = turn + 1;
  if (win == fs) { ret = 100; }
  REP(i, n) {
    if (beta <= alpha) { break; }
    int nused = used | (1 << i);
    if (used == nused) { continue; }
    int np = p + GetP(fs, turn, prev, i);
    int nuse = use | (nused << (fs * n));
    if (win == fs && np - calc(2, fs ^ 1, nuse, i) < 0) { continue; }
    int nret = Search(fs ^ 1, nuse, i, -np, beta, alpha);
    if (win == fs) {
      ret = min(ret, nret);
      beta = min(beta, ret);
    } else {
      ret = max(ret, nret);
      alpha = max(alpha, ret);
    }
  }
  return ret;
}

int main() {
  while (scanf("%d %d", &n, &f) > 0) {
    MEMSET(memo, -1);
    REP(y, n) {
      REP(x, n) {
        scanf("%d", &field[y][x]);
      }
    }
    int ans = calc(2, 0, 0, 0);
    if (ans > 0) {
      win = 0;
      puts("First");
      printf("%d\n", Search(0, 0, 0, 0, 100, -100));
    } else if (ans == 0) {
      puts("Draw");
      printf("%d\n", 2 * n);
    } else {
      win = 1;
      puts("Second");
      printf("%d\n", Search(0, 0, 0, 0, 100, -100));
    }
  }
}

Measured memory_bytes: 12000
A, B, C = map(int, input().split())
if A == B == C and A % 2 == 0:
    print(-1)
else:
    ans = 0
    while A % 2 == B % 2 == C % 2 == 0:
        A, B, C = (B//2+C/2), (A//2+C//2), (A//2+B//2)
        ans += 1
    print(ans)



Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<pair<string ,int> > v;
		rep(i,n){
			string t;
			cin>>t;
			int tt;
			cin>>tt;
			rep(j,t.size()){
				if(t[j]!='*'){
					v.PB(mkp(t.substr(j),tt));
					break;
				}
			}
		}
		// reverse(ALL(v));
		// rep(i,n){
			// cout<<v[i].F<<" "<<v[i].S<<endl;
		// }
		ll ans=0;
		rep(i,m){
			string t;
			cin>>t;
			rep(j,v.size()){
				// cout<<t.substr(t.size()-v[j].F.size())<<endl;
				if(t.substr(t.size()-v[j].F.size())==v[j].F){
					ans+=v[j].S;
					// cout<<v[i].S<<endl;
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll A, B; cin >> A >> B;

	ll cnt = 0;
	repe(i, A, B) {
		if (i / 10000 == i % 10 && i / 1000 % 10 == i / 10 % 10) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007
int n, m, q, ans;
int a[50], b[50], c[50], d[50], cn[50];

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

void dfs(int p, int x)
{
	if (p == n)
	{
		int var = 0;
		zip(i, 0, q)
		{
			if (cn[b[i]] - cn[a[i]] == c[i])
			{
				var += d[i];
			}
		}
		ans = max(ans, var);
		return;

	}

	else
	{
		for (int i = x; i <= m; i++)
		{
			cn[p] = i;
			dfs(p + 1, i);
		}
	}


}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	//int n, m, q;
	cin >> n >> m >> q;
	//int a[q], b[q], c[q], d[q];
	zip(i, 0, q)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	dfs(0, 1);
	//cout << ans << en;
	cout << ans << en;


	return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 4223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

struct edge { ll from, to, cost; };
vector<edge> G;
vector<ll> d(200000, -LINF);

int main() {
	int n, m; cin >> n >> m;
	int a, b, c;
	REP(i,m) {
		cin >> a >> b >> c;
		G.push_back({a,b,c});
	}
	d[1] = 0;
	for (int i=0;i<n;i++) {
		bool up = false;
		REP(j,m) {	
			edge e = G[j];
			if (d[e.from] != -LINF && d[e.to] < d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				up = true;
				if (i==n-1&&e.to==n) {
					cout << "inf" << endl;
					return 0;
				}
			}
		}
		if (!up)
			break;
	}
	cout << d[n] << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int len = S.size();
    rep(i,len){
        if (S[i] - 'A' + N >= 26){
            cout << char(S[i] + N - 26);
        }
        else{
            cout << char(S[i] + N);
        }
    }
    cout << endl;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
s = 0
for i in range(N):
    if i == 0:
        continue
    else:
        if(A[i]<A[i-1]):
            s += A[i-1]-A[i]
            A[i]=A[i-1]

print(s)

Measured memory_bytes: 32184