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

using namespace std;

const int inf = 100000000;

int main(){
    int n,m,s,g,V,P,K[210][210],a,b,c,d;
    cin >> n >> m;
    for(int i = 0;i < 210;i++){
        for(int j = 0;j < 210;j++){
            K[i][j] = inf;
        }
    }
    for(int i = 0;i < m;i++){
        scanf("%d,%d,%d,%d",&a,&b,&c,&d);
        K[a][b] = c;
        K[b][a] = d;
    }
    scanf("%d,%d,%d,%d",&s,&g,&V,&P);
    for(int k = 1;k <= n;k++){
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= n;j++){
                if(K[i][j] > K[i][k] + K[k][j]){
                    K[i][j] =  K[i][k] + K[k][j];
                }
            }
        }
    }
    cout << V-P-K[s][g]-K[g][s] << endl;
}


Measured memory_bytes: 3316
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,len=0,n0001,n01,n10,ans=0,res,ach10,ach01;
pii a[100010],b[100010];
vector <pair <LL,pii> > v;
vector <pii> ch11,ch00;

void chmin(int i,int j)
{
	if(i>=ch11.size()||j>=ch00.size()||ch11[i].se==ch00[j].se) return;
	ans=min(ans,res+ch11[i].fi+ch00[j].fi);
}

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i].fi>>a[i].se;
		v.pb({a[i].fi,{i,0}});
		v.pb({a[i].se,{i,1}});
	}
	sort(v.begin(),v.end());
	rep(i,n)
	{
		ans+=v[i].fi;
		if(v[i].se.se==0) b[v[i].se.fi].fi=1;
		else b[v[i].se.fi].se=1;
	}
	rep(i,n)
	{
		if((b[i].fi==0&&b[i].se==0)||(b[i].fi==1&&b[i].se==1)) n0001++;else
		if(b[i].fi==0&&b[i].se==1) n01++;else
		n10++;
	}
	if(n0001>0||(n0001==0&&(n01==0||n10==0)))
	{
		cout<<ans<<endl;
		rt0;
	}
	res=ans;
	ans=1e18;
	rep(i,n)
	{
		if(b[i].fi==1&b[i].se==0)
		{
			ch11.pb({a[i].se,i});
			ch00.pb({-a[i].fi,i});
			ach01+=a[i].se-a[i].fi;
		}
		else
		{
			ch11.pb({a[i].fi,i});
			ch00.pb({-a[i].se,i});
			ach10+=a[i].fi-a[i].se;
		}
	}
	sort(ch11.begin(),ch11.end());
	sort(ch00.begin(),ch00.end());
	chmin(0,0);
	chmin(0,1);
	chmin(1,0);
	ans=min(ans,min(res+ach01,res+ach10));
	cout<<ans<<endl;
	rt0;
}

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

using namespace std;

void solve()
{
	string str;
	while(cin >> str, str != "#")
	{
		bool flag;
		if(str[0] == 'y' || str[0] == 'u' || str[0] == 'i' || str[0] == 'o' || 
		   str[0] == 'p' || str[0] == 'h' || str[0] == 'j' || str[0] == 'k' || 
		   str[0] == 'l' || str[0] == 'n' || str[0] == 'm')
		{
			flag = true;
		}
		else
		{
			flag = false;
		}
		int count = 0;
		for(int i = 0; i < str.size(); ++i)
		{
			if(!flag)
			{
				if(str[i] == 'y' || str[i] == 'u' || str[i] == 'i' || str[i] == 'o' || 
				   str[i] == 'p' || str[i] == 'h' || str[i] == 'j' || str[i] == 'k' || 
				   str[i] == 'l' || str[i] == 'n' || str[i] == 'm')
				{
					flag = !flag;
					++count;
				}
			}
			else
			{
				if(!(str[i] == 'y' || str[i] == 'u' || str[i] == 'i' || str[i] == 'o' || 
				   str[i] == 'p' || str[i] == 'h' || str[i] == 'j' || str[i] == 'k' || 
				   str[i] == 'l' || str[i] == 'n' || str[i] == 'm'))
				{
					flag = !flag;
					++count;
				}
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1184
import java.util.*;

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

        for (int i=0;i<n;i++){
            long input = sc.nextLong();
            if (input == 0) { result = 0; break;}

            if (result > 1000000000000000000L/input || result == -1) {
                result = -1;
            } else {
                result = result * input;
            }
        }

        System.out.println(result);
    }
}

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

s = [0] * n
t = [0] * n

s[0] = a[0]
t[0] = a[0]

for i in range(1, n):
    s[i] = s[i-1] + a[i]
    t[i] = t[i-1] ^ a[i]

s = [0] + s
t = [0] + t 

ans = 0
#print(s, t)

l = 1
r = l
while l < n+1:
    #print(l, r)
    if s[r] - s[l-1] == t[r] ^ t[l-1]:
        while True:
            #print(l, r, s[r] - s[l-1], t[r] ^ t[l-1])
            if s[r] - s[l-1] == t[r] ^ t[l-1]:
                r += 1
                if r > n:
                    ans += r - l
                    r = n
                    break
            else:
                ans += r - l 
                break
    else:
        while True:
            #print(l, r, s[r] - s[l-1], t[r] ^ t[l-1])
            if s[r] - s[l-1] == t[r] ^ t[l-1]:
                ans += r - l + 1
                break
            else:
                r -= 1
                if r == l:
                    ans += 1
                    r = l + 1
                    break

    l += 1

print(ans)

Measured memory_bytes: 37252
# -*- coding: utf-8 -*-

while(True):
	N,A,B,C,X = map(int, input().split())
	if (N==0&A==0&B==0&C==0&X==0):break
	y = list(int(i) for i in input().split())  
	frame = 0
	reel = 0
	while(True):
		if(frame ==10001):
			frame = -1
			break
		if y[reel] == X:
			reel += 1

		if reel == N:
			break
		X = (A * X + B)%C
		frame += 1

	print(frame)



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

int main(void){
  int n;
  while(cin >> n && n != 0){
    int cnt = 0;
    while(n != 1){
      if(n % 2 == 0) n /= 2;
      else n = 3 * n + 1;
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

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

	// Cal
	string left_input = s.substr(0,4);
	string right_input = s.substr(4,8);

	// Output
	cout << left_input << " " << right_input << endl;
	return 0;
}

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

int main(){
    int n, u, k, v;
    cin >> n;
    int M[n][n];
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u = u - 1;
        for(int j = 0; j < k; j++){
            cin >> v;
            v = v - 1;
            M[u][v] = 1;
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            if (a == b)
            {
                Console.WriteLine("a == b");
            }
        }
    }
}

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

int main(){
  int h, w;
  cin >> h >> w;
  int sum = 0;
  char a;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a;
      sum += a == '#' ? 1 : 0;
    }
  }
  cout << (sum == h + w - 1 ? "Possible" : "Impossible") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int h,w;
  cin>>h>>w;
  string s;
  string z;
  cin.ignore();
  for(int i=0;i<h;i++){
    getline(cin,s);
    z+=s+"\n";
    z+=s+"\n";
  }
 
  cout<<z<<endl;
  return 0;
}

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

using namespace std;

int main(){
	vector<int> w ,k;
	int n;
	for(int i = 0; i < 20; i++){
		cin >> n;
		if(i < 10){
			w.push_back(n);
		}else{
			k.push_back(n);
		}
	}
	sort(w.begin(), w.end());
	sort(k.begin(), k.end());
	cout << w[9] + w[8] + w[7] << " " << k[9] + k[8] + k[7]  << endl; 

}

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

using namespace std;

void Y(){
    cout << "Yes\n";exit(0);
}
void N(){
    cout << "No\n";exit(0);
}

void solve() {
    int n; cin >> n;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    auto check = [&](int l, int r){
        if ((r-l)&1) N();
        for (int i = l+1; i < r; i+=2) {
            if (a[i] != i) N();
        }
        for (int i = l; i <= r; i+=2) {
            if (a[i] == i) N();
        }
        int x = 0, y = 0;
        for (int i = l; i <= r; i+=2) {
            if (a[i] < i) {
                if (a[i] < x) N();
                x = a[i];
            } else {
                if (a[i] < y) N();
                y = a[i];
            }
        }
    };
    int l = 1, r;
    while (true) {
        while (l <= n && a[l]==l) {
            l++;
        }
        if (l > n) Y();
        r = l;
        int mi = a[l], mx = a[l];
        while (r <= n && (l!=mi || r!=mx)) {
            r++;
            mi = min(mi, a[r]);
            mx = max(mx, a[r]);
        }
        check(l, r);
        l = r+1;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

vector<ll> n(100, 0);

ll lucas(int i) {
  if(i == 0) return 2;
  if(i == 1) return 1;
  if(n[i] != 0) return n[i];
  ll temp = lucas(i - 1) + lucas(i - 2);
  n[i] = temp;
  return temp;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << lucas(N) << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import qualified Data.List as L

main :: IO ()
main = do
    [n, k] <- map read.words <$> getLine
    cs <- getLine
    print $ solve k cs

solve :: Int -> String -> Int
solve k cs = go 0 0 0 [] [] $ L.group cs
  where
    go !res !acc !num0 fs rs (l@('1':_):css)
        = go (max res acc') acc' num0 fs (l:rs) css
      where
        acc' = acc + length l
    go !res !acc !num0 fs rs (l@('0':_):css)
        | num0 + 1 <= k = go (max res acc') acc' (num0 + 1) fs (l:rs) css
      where
        acc' = acc + length l
    go !res !acc !num0 [] rs (l@('0':_):css) = go res acc num0 (reverse rs) [] (l:css)
    go !res !acc !num0 (f@('0':_):fs) rs (l@('0':_):css)
        = go (max res acc') acc' num0 fs (l:rs) css
      where
        acc' = acc - length f + length l
    go !res !acc !num0 (f@('1':_):fs) rs (l@('0':_):css)
        = go res acc' num0 fs rs (l:css)
      where
        acc' = acc - length f
    go res _ _ _ _ [] = res



Measured memory_bytes: 10748
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: 一次元リバーシ / 1D Reversi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int cnt = 0;
  char pc = ' ';
  for (int i = 0; i < s.size(); i++) {
    if (pc != s[i]) cnt++;
    pc = s[i];
  }

  printf("%d\n", cnt - 1);
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;
string f(ll n){
  if(n==0)return "";
  n--;
  return f(n/=26)+char(n%26+'a');
}
int main(){
 ll n;cin>>n;
 cout << f(n) << endl;
}

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

int main() {
  int h,w,n;
  cin >> w >> h >> n;
  int xM = w,xm = 0,yM = h,ym = 0;
  rep(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    if(a == 2 && x < xM) xM = x;
    if(a == 1 && x > xm) xm = x;
    if(a == 4 && y < yM) yM = y;
    if(a == 3 && y > ym) ym = y;
  }
  if(xM < xm || yM < ym) cout << 0 << endl;
  else cout << (xM-xm)*(yM-ym) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, d, a = map(int, input().split())
xh = sorted([tuple(map(int, input().split()))for _ in range(n)])
INF = 10**18
x_list = [x for x, h in xh]
x_list.append(INF)

end_idx_list = [0]*n
idx = 0
for i in range(n):
    while True:
        if x_list[i]+2*d < x_list[idx]:
            end_idx_list[i] = idx
            break
        idx += 1

damage = [0]*(n+1)
ans = 0
for i in range(n):
    x, h = xh[i]
    h -= damage[i]
    if 0 < h:
        cnt = -(-h//a)
        ans += cnt
        damage[i] += cnt*a
        end_idx = end_idx_list[i]
        damage[end_idx] -= cnt*a

    damage[i+1] += damage[i]
print(ans)


Measured memory_bytes: 47292
/****************************>>>>HEADFILES<<<<****************************/
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
using namespace std;
/****************************>>>>>DEFINE<<<<<*****************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define rep(i,a,b)      for(int i = a;i <= b;i++)
#define MP(a,b)         make_pair(a,b)
#define PB(a)           push_back(a)
#define fst             first
#define snd             second
/****************************>>>>>>DEBUG<<<<<<****************************/
#define out(x)          cout<<x<<"  ";
/****************************>>>>SEPARATOR<<<<****************************/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b,t;
    cin>>a>>b>>t;
    int ans=0;
    while(t>=0){
        t-=a;
        if(t>=0)
        ans+=b;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int N;
    cin >> N;
    int color[N];
    color[0] = -1;
    ll s[200005];
    ll tots = 1;
    for(int i = 1; i < N + 1; i++){
        int c;
        cin >> c;
        color[i] = c - 1;
    }
    for(int i = 0; i < 200005; i++){
        if(i == color[1]){
            s[i] = 1;
        }else{
            s[i] = 0;
        }

    }
    ll MOD = 1000000007;
    for(int i = 1; i < N + 1; i++){
        ll tmp = 0;
        ll currentCol = color[i];
        tmp = s[currentCol];
        //cout << tmp << endl;
        if(i == N){
            cout << tmp << endl;
            continue;
        }
        if(currentCol != color[i + 1]){
            s[color[i + 1]] = (s[color[i + 1]] + tmp) % MOD;
        }
    }




}


Measured memory_bytes: 2560
I=input
for _ in [0]*int(I()):
    t=I()
    ans=[t[0]]
    for x in range(1,len(t),3):
        if t[x+2] in ans:continue
        if t[x]=='-':ans+=[t[x+2]]
        else:ans=[t[x+2]]+ans
    print(*ans,sep='')

Measured memory_bytes: 7528
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

const int INF = 1001001001;

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

  string tmp = s;
  reverse(tmp.begin(), tmp.end());
  int n = s.size();
  rep(i, n){
    if (s[i] != tmp[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  tmp.clear();
  rep(i, (n-1)/2){
    tmp.push_back(s[i]);
  }
  reverse(tmp.begin(), tmp.end());
  rep(i, (n-1)/2){
    if (s[i] != tmp[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  tmp.clear();
  repr(i, (n+3)/2, n){
    tmp.push_back(s[i]);
  }
  reverse(tmp.begin(), tmp.end());
  repr(i, (n+3)/2, n){
    if (s[i] != tmp[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

N = int(input())
A = [list(map(lambda x: int(x) - 1, input().split(" "))) for i in range(N)]

canUse = set(range(N))

ans = 0
done = 0
while done < N:
    ans += 1
    canUseNew = set()
    # print("LC", len(canUse))
    for n in canUse:
        if not A[n]:
            continue

        first = A[n][-1]
        if first in canUseNew or n in canUseNew:
            continue

        if A[first][-1] == n:
            # print("Do", n + 1, first + 1)
            A[n].pop()
            if len(A[n]) == 0:
                done += 1
            A[first].pop()
            if len(A[first]) == 0:
                done += 1
            canUseNew.add(n)
            canUseNew.add(first)

    if len(canUseNew) == 0:
        print(-1)
        sys.exit(0)
    canUse = canUseNew

print(ans)


Measured memory_bytes: 35060
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	vector<ll> ans;
	vector<ll> b(n);
	REP(i,n) b[i]=a[i];
	sort(ALL(b));
	b.erase(unique(ALL(b)),b.end());
	map<ll,ll> at;
	ll c=0;
	REP(i,b.size()) {
		at[b[i]]=c;
		c++;
	}
	vector<ll> cnt(n+1);
	ll hoge=0;
	REP(i,n) {
		cnt[at[a[i]]]++;
		if(cnt[at[a[i]]]==1) hoge++;
		else if(cnt[at[a[i]]]==0) hoge--;
		cnt[at[a[n-1-i]]]--;
		if(cnt[at[a[n-1-i]]]==-1) hoge++;
		else if(cnt[at[a[n-1-i]]]==0) hoge--;
		if(hoge==0) ans.pb(i+1);
	}
	if((ll)ans.size()==0) cout<<endl;
	else DUMP(ans);
}



Measured memory_bytes: 8448
/* Name        : c
 * Creat       : Sat Jul 13 14:58:04 CST 2019
 * Accept      : Sat Jul 13 15:01:20 CST 2019
 * Author      : landcold7
 * Motto       : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n, m;
  cin >> n >> m;
  int lo = 0;
  int hi = (1 << 30);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    lo = max(lo, x);
    hi = min(hi, y);
  }
  trace(lo, hi);
  int ans = 0;
  if (lo <= hi) {
    ans = hi - lo + 1;
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


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

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
//#define int ll
const int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(true);
	
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
l=[i for i in range(1000) if len(str(i))==n]
for i in range(m):
    s,c=map(int,input().split())
    l=[i for i in l if str(i)[s-1]==str(c)]
print(min(l) if l!=[] else -1)

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

#define INF 100000

int main(void){
	int n;
	cin >> n;
	vector<string> a(n);
	string b;
	int alp[n][27];
	int ans[27];

	for(int i = 0; i < n; i++){
		cin >> a[i];
		for(int j = 0; j < 26; j++){
			alp[i][j] = 0;
		}
		for(int j = 0; j < a[i].length(); j++){
			alp[i][a[i][j] - 'a']++;
		}
	}
	for(int i = 0; i < 26; i++){
		ans[i] = INF;
	}

	for(int i = 0; i < 26; i++){
		for(int j = 0; j < n; j++){
			if(alp[j][i] < ans[i]){
				ans[i] = alp[j][i];
			}
		}
	}
	for(int i = 0; i < 26; i++){
		while(ans[i] > 0){
			char t = i + 'a';
			cout << t;
			ans[i]--;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define INF 2000000000
int a[MAXN],b[MAXN],c[MAXN];
int dpa[MAXN+1],dpb[MAXN+1],dpc[MAXN+1];
int n,k;
int main() {
	int i;
	int j;
	scanf("%d",&n,&k);
	for (i=0; i<n;i++) {
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	dpa[n]=dpb[n]=dpc[n]=0;
	for (i=n-1; i>=0; i--) {
		dpa[i]=a[i]+max(dpb[i+1],dpc[i+1]);
		dpb[i]=b[i]+max(dpa[i+1],dpc[i+1]);
		dpc[i]=c[i]+max(dpa[i+1],dpb[i+1]);
	}
	printf("%d\n",max(dpa[0], max(dpb[0], dpc[0])));
	return 0;
}

Measured memory_bytes: 6040
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut sum = 0i64;
    let mut v = vec![0; 110000];
    for _ in 0..n {
        let x:usize = read();
        sum += x as i64;
        v[x] += 1;
    }
    let q:usize = read();
    for _ in 0..q {
        let b:usize = read();
        let c:usize = read();
        sum += (c as i64 -b as i64) * v[b];
        v[c] += v[b];
        v[b] = 0;
        println!("{}", sum);
    }
}


Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,K;
    cin>>A>>B>>K;
    int count=0;
    int ans=min(A,B)+1;
    while(count<K){
        ans--;
        if(A%ans==0 && B%ans==0) count++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

	vector<vector<pair<int, int>>> graph(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			graph[u].emplace_back(v, c);
		}
	}

	vector<int> dist(n, INF);
	dist[0] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pq.emplace(0, 0);

	while (!pq.empty()) {
		pair<int, int> p = pq.top(); pq.pop();
		if (dist[p.first] < p.second) {
			continue;
		}

		for (auto e : graph[p.first]) {
			if (dist[e.first] > dist[p.first] + e.second) {
				dist[e.first] = dist[p.first] + e.second;
				pq.emplace(e.first, dist[e.first]);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}


int main(){
  int N, M;
  cin >> N >> M;
  vector<ipair> p(M);
  rep(i, M) cin >> p[i].first >> p[i].second;

  rep(x, 1000){
    int keta = 1;
    vector<int> d(1, x%10);
    int nx = x / 10;
    while(nx){
      keta++;
      d.push_back(nx%10);
      nx /= 10;
    }
    reverse(d.begin(), d.end());

    if(keta != N) continue;

    // check
    bool ok = true;
    rep(i, M) {
      if(d[p[i].first-1] != p[i].second){
        ok = false;
      }
    }

    if(ok){
      cout << x << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
n,*a=map(int,open(0).read().split())
l=np.zeros(max(a)+1)
a.sort()
a+=[10**7]
r=0
for i,j in zip(a,a[1:]):
    if l[i]==0:
        l[::i]=1
        if i!=j:
            r+=1
print(r)

Measured memory_bytes: 50528
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long H;
    cin >> H;
    long long k = 0;
    while(H > 0){
        H /= 2;
        k++;
    }
    k--;
    //cout << k << endl;
    long long S = 1;
    long long A = 1;
    while(k > 0){
        for(long long i = 0; i < k; i++){
            A *= 2;
        }
        S += A;
        A = 1;
        k--;
    }
    cout << S << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        final long MOD = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int a = 1;a<=n;++a)
        {
            count += n/a;
            if (n%a == 0) --count;
        }
        System.out.println(count);
        sc.close();
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

Measured memory_bytes: 27208
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	A+=B;
	C+=D;
	if(A>C) print("Left");
	else if(A<C) print("Right");
	else print("Balanced");
	return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;g
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll r = 0;
    ll g = 0;
    ll b = 0;

    for (int i = 0; i < n; ++i) {
        switch (s[i]) {
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
    }

    ll ng = 0;

    for (ll i = 0; i < n - 1; ++i) {
        for (ll j = i + 1; j < n; ++j) {
            ll k = j + (j - i);
            if (k >= n) continue;
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ng++;
        }
    }

    cout << r * g * b - ng << endl;
}


Measured memory_bytes: 3624
#UNIONFIND
class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
 
 
if __name__ == '__main__':
    n,k,l=map(int,input().split())
    pq=UnionFind(n+1)
    rs=UnionFind(n+1)
    for i in range(k):
        p,q=map(int,input().split())
        pq.union(p,q)
    for i in range(l):
        r,s=map(int,input().split())
        rs.union(r,s)
    sameroot=[]
    for i in range(1,n+1):
        sameroot.append([pq._root(i),rs._root(i),i])
    sameroot.sort()
    sameroot.append([0,0,n+1])
    cnt=[0]*(n+1)
    bx,by=0,0
    samelist=[]
    for x,y,i in sameroot:
        if bx==x and by==y:
            samelist.append(i)
        else:
            k=len(samelist)
            if k>0:
                for j in samelist:
                    cnt[j]=k
            samelist=[i]
            bx,by=x,y
    print(' '.join(map(str,cnt[1:])))

Measured memory_bytes: 48552
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple

using namespace std;

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

typedef tuple<int, int, int, int> T;


int main(){
	int n;
	while (cin >> n, n){
		vector<int> t(n), c(n);
		rep(i, n) cin >> t[i] >> c[i];

		// time, t, rem, pos
		priority_queue<T, vector<T>, greater<T>> q;
		rep(i, n) q.push(MT(0, t[i], c[i], 0));

		int lim[2] = {};
		while (!q.empty()){
			auto t = q.top();
			q.pop();
			int curtime, time, rem, pos;
			tie(curtime, time, rem, pos) = t;
			if (!rem) continue;

			int npos = pos ^ 1;
			int nxttime = max(curtime+time, lim[npos]);
			if (!npos) --rem;
			lim[npos] = max(lim[npos], nxttime);
			q.push(MT(nxttime, time, rem, npos));
		}
		cout << *max_element(lim, lim + 2) << endl;
	}


	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int digitsum(int n){
    int sum=0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N;
    cin >> N;
    if(N%digitsum(N)==0){
            cout << "Yes" << endl;
    }else{
            cout << "No" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;

    ll x = n*100/108;

    while((x*108)/100 < n)
        x++;

    while((x*108)/100 > n)
        x--;

    if((x*108)/100 != n)
    {
        cout << ":(";
    }
    else
        cout << x;
    return 0;
}




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

using namespace std;

vector<vector<pair<long long int,long long int>>> graph(100001);
int ans[1000001];

void dfs(long long int a, long long int x){
    for(int i=0;i<graph[a].size();i++){
        if(ans[graph[a][i].first]==0){
            if(graph[a][i].second%2==0){
                ans[graph[a][i].first] = x;
            }else{
                if(x==1){
                    ans[graph[a][i].first] = 2;
                }else{
                    ans[graph[a][i].first] = 1;
                }
            }
            dfs(graph[a][i].first, ans[graph[a][i].first]);
        }
    }
}

int main(){
    int N;
    cin >> N;
    for(int i=0;i<N-1;i++){
        long long int u,v,w;
        cin >> u >> v >> w;
        u--;
        v--;
        pair<long long int,long long int> node;
        node.first = v;
        node.second = w;
        graph[u].push_back(node);
        node.first = u;
        graph[v].push_back(node);
    }

    ans[0] = 0;

    dfs(0,1);

    for(int i=0;i<N;i++){
        cout << ans[i]-1 << endl;
    }
}

Measured memory_bytes: 9856
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <stdexcept>
#include <utility>
using namespace std;

int main()
{
    int m;
    vector<tuple<int, int, int, int>> answer;
    while (cin >> m && m != 0)
    {
        tuple<int, int, int, int> coin; // = {0, 0, 0, 0};
        get<0>(coin) = 0;
        get<1>(coin) = 0;
        get<2>(coin) = 0;
        get<3>(coin) = 0;

        int ten, fifty, one_hundred, five_hundred, change = 0, used_coin, max = -10000;
        cin >> ten >> fifty >> one_hundred >> five_hundred;
        for (int i = 0; i < ten + 1; i++)
        {
            for (int j = 0; j < fifty + 1; j++)
            {
                for (int k = 0; k < one_hundred + 1; k++)
                {
                    for (int l = 0; l < five_hundred + 1; l++)
                    {
                        change = i * 10 + j * 50 + k * 100 + l * 500 - m;
                        if (change >= 0)
                        {
                            used_coin = i + j + k + l;
                            used_coin -= change / 500;
                            change = change % 500;
                            used_coin -= change / 100;
                            change = change % 100;
                            used_coin -= change / 50;
                            change = change % 50;
                            used_coin -= change / 10;
                            if (used_coin > max) //default max=0 -> (10,0,1,0,2) WA
                            {
                                get<0>(coin) = i;
                                get<1>(coin) = j;
                                get<2>(coin) = k;
                                get<3>(coin) = l;
                                max = used_coin;
                            }
                            change = 0;
                            used_coin = 0;
                        }
                    }
                }
            }
        }
        answer.push_back(coin);
    }
    for (int i = 0; i < answer.size(); i++)
    {
        if (get<0>(answer.at(i)) != 0)
        {
            cout << 10 << " " << get<0>(answer.at(i)) << endl;
        }
        if (get<1>(answer.at(i)) != 0)
        {
            cout << 50 << " " << get<1>(answer.at(i)) << endl;
        }
        if (get<2>(answer.at(i)) != 0)
        {
            cout << 100 << " " << get<2>(answer.at(i)) << endl;
        }
        if (get<3>(answer.at(i)) != 0)
        {
            cout << 500 << " " << get<3>(answer.at(i)) << endl;
        }
        if (i != answer.size() - 1)
        {
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

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

    map<char, int> mp1, mp2;
    FOR(i,(int)'a',(int)'z'+1){
        mp1[i] = 0;
        mp2[i] = 0;
    }
    REP(i,s.size()){
        mp1[s[i]]++;
        
    }
    REP(i,t.size()){
        mp2[t[i]]++;
    }
    vector<int> num1(26,0),num2(26,0);
    for(auto x:mp1){
        num1[x.first - 'a'] = x.second;
    }
    for(auto x:mp2){
        num2[x.first - 'a'] = x.second;
    }

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

    REP(i,26){
        if(num1[i]!=num2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1020
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	static  ArrayList<Pair>adj[];
	static PrintWriter out=new PrintWriter(System.out);
        static Integer[] b;
	public static void main(String[] args) throws Exception {
	Scanner sc=new Scanner(System.in);
	int h=sc.nextInt();
	
	int n=sc.nextInt();
	int a[]=new int[n];
	long sum=0;
	for (int i = 0; i < a.length; i++) {
		a[i]=sc.nextInt();
		sum+=a[i];
	}
	if(sum>=h) {
		System.out.println("Yes");
	}
	else {
		System.out.println("No");
	}
	
out.flush();
	}

static long sum;	
	
	static void dfs(int u,int p,  int l, int r) {
		   

for(Pair v:adj[u]) {
	  if(r<l) {
		  return;
	  }
 if(p!=v.v&&v.cost<b[r]) {
	 int cur=r;
 while(l<=r&&v.cost<b[r])  	r--;
 
dfs(v.v,u,r+1,cur);
 }
}

 sum+= 1l*(r-l+1)*1l*(u + 1)*1l;
}

static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}	

	
	
	 static class Pair implements Comparable<Pair>{
		  int v;
		  int cost;
		  Pair(int a, int b){
			  v=a;
			  cost=b;
		  }
		public int compareTo(Pair p) {
			return (int) (p.cost-this.cost);
		 
				 
		}
	 }
}

Measured memory_bytes: 33268
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
  vi a(3);
  rep(i,3)cin>>a[i];
  sort(a.begin(), a.end());
  if(a[0] == a[1])cout<<a[2]<<endl;
  else cout<<a[0]<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int[] inp = Readint();
    if(inp[0]<inp[1]*2)
      WriteLine("0");
    else
      WriteLine((inp[0]-inp[1]*2).ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}


Measured memory_bytes: 13652
const int isDebugMode = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    string S; cin >> S;
    string cba = abc;
    reverse(all(cba));
    if (S == cba){
        pt(-1);
        return 0;
    }
    if(S.size() == 26){
        for(ll i = 25; 0 < i; i--){
            if(S[i] - 'a' > S[i - 1] - 'a'){
                ll lim = S[i - 1] - 'a';
                ll cnt = INF; 
                for(ll j = i; j < 26; j++){
                    if(lim < S[j] - 'a') chmin(cnt, S[j] - 'a');
                }
                S[i - 1] = abc[cnt];
                pt(S.substr(0, i));
                return 0;
            }
        }
    }else{
        for(auto e : abc){
            if(find(all(S), e) == S.end()){
                S += e;
                pt(S);
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputLongLongAry(long long *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoll(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}


int main(void){
    int N;
    long long x=0,X[100000],A,B;

    scanf("%d %lld %lld%*c",&N,&A,&B);
    InputLongLongAry(X,12*100000,N);
    for(int i=0;i+1<N;i++){   //町iから町i+1に動く
        if(A*(X[i+1]-X[i]) > B)
            x += B;
        else
            x += A*(X[i+1]-X[i]);
        
    }
    printf("%lld\n",x);
    return 0;
}

Measured memory_bytes: 1920
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

X,Y=get_i
if X.gcd(Y)==Y
    puts -1
else
    puts X*(Y+1)
end

Measured memory_bytes: 1788
a,b=map(int,raw_input().split())
y=raw_input()
for i in range(len(y)):
	if i==a and y[i]!='-':
		print "No"
		exit(0)
	if i!=a and y[i] not in '0123456789':
		print "No"
		exit(0)
print "Yes"

Measured memory_bytes: 2568
# ABC-141-B
S = list(input())
S.insert(0, None)
ans = "Yes"

for i in range(1, len(S)):
    if i % 2 == 1:
        if S[i] == "L":
            ans = "No"
            break
    else:
        if S[i] == "R":
            ans = "No"
            break
print(ans)

Measured memory_bytes: 2940
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    # 4の倍数がnum4個のとき、
    # 2の倍数がnum2個のとき、
    # num4*2 + 1 >= Nなら、Yes
    # ? 4 ? 4 ? 4 ?
    # そうでないなら、num4*2 + num2なら、Yes
    # 2 2 2 4 ? 4 ?
    num4 = 0
    num2 = 0
    for a in A:
        if a%4 == 0:
            num4 += 1
        elif a%2 == 0:
            num2 += 1
    
    if (num4*2+1) >= N:
        print("Yes")
    elif (num4*2)+num2 >= N:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    solve()


Measured memory_bytes: 14252
table = []
i = 0
while True:
  table.append(int(input()))
  if table[i] == 0:
    break
  i += 1

for num in table:
  if num == 0:
    break
  sum = 0
  i = 0
  while num != 0: 
    sum += num % 10
    num //= 10
    if num == 0:
      break
  print(sum)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  cout << N*N << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())

a = []

for _ in range(n):
    A = int(input())
    tmp = []
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        tmp.append([x, y])
    a.append(tmp)
    
ans = 0

for p in itertools.product([0,1], repeat=n):
    katei_list = list(p)
    mujun = False
    for i in range(n):
        if katei_list[i] == 1:
            for shogen in a[i]:
                if katei_list[shogen[0]] != shogen[1]:
                    mujun = True
                    break
            if mujun:
                break
        if mujun:
            break
    if not mujun and sum(p) > ans:
        ans = sum(p)

print(ans)

Measured memory_bytes: 3064