akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= b) {
        rep(i,a) printf("%d", b);
        printf("\n");
    }
    else {
        rep(i,b) printf("%d", a);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    // 整数の入力
    int N,D,Q,Query,i,j;
    cin >> N >> D;

    int* moves = new int[N+1];
    int* distances = new int[N+1];
    int* canNotReach = new int[N+1];
    // スペース区切りの整数の入力
    moves[0] = 0;
    distances[0] = D;
    for (i=1;i<=N;i++){
        cin >> moves[i];
        if (abs(moves[i] - distances[i-1]) < distances[i-1]){
            distances[i] = abs(moves[i] - distances[i-1]);
        }else{
            distances[i] = distances[i-1];
        }
    }

    canNotReach[N+1] = 1;
    for (i=N;i>=1;i--){
        if (canNotReach[i+1] <= moves[i]/2){
            canNotReach[i] = canNotReach[i+1];
        }else{
            canNotReach[i] = canNotReach[i+1] + moves[i];
        }
    }

    cin >> Q;
    for (i=0;i<Q;i++){
        cin >> Query;
        if (canNotReach[Query+1] <= distances[Query -1]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

int main()
{
	//Sunny, Cloudy, or Rainy.
	string n; cin>>n;
	if ( n == "Sunny" )
		cout<<"Cloudy";
	else if ( n == "Cloudy" )
		cout<<"Rainy";
	else
		cout<<"Sunny";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e17;
using vi = vector <int>;
using vvi = vector <vi>;

signed main(){
	int n, m;
	cin >> n >> m;
	pair <int, int> g[n][n];
	rep(i, n)rep(j, n)
		g[i][j] = i == j ? make_pair(0LL, 0LL) : make_pair(INF, INF);

	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a][b] = g[b][a] = make_pair(c, c);
	}

	rep(k, n)rep(i, n)rep(j, n)
		g[i][j].first = min(g[i][j].first, g[i][k].first + g[k][j].first);

	int ans = 0;
	rep(i, n)range(j, i + 1, n){
		bool belong = false;
		if(g[i][j].second == INF)continue;
		rep(k, n){
			if(i == k)continue;
			if(g[i][k].first == g[i][j].second + g[j][k].first)
				belong = true;
		}
		ans += !belong;
	}

	cout << ans << endl;

}


Measured memory_bytes: 384
import sys
import copy
import bisect

sys.setrecursionlimit(202020)

INF = 10**12
MAX_N = 202020

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for i in range(N-1):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    to[u].append(v)
    to[v].append(u)

dp = [INF for _ in range(MAX_N)]
ans = [0 for _ in range(N)]

def dfs(v, p=-1):
    i = bisect.bisect_left(dp, a[v])
    old = dp[i]
    dp[i] = a[v]
    ans[v] = i
    if p != -1:
        ans[v] = max(ans[v], ans[p])
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    dp[i] = old

dp[0] = -INF
dfs(0)
print(*ans)


Measured memory_bytes: 265868
n = input()

if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
  print("hon")
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9120
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int card[4][13] = {0};
    char kind[4] = {'S', 'H', 'C', 'D'};

    cin >> n;

    for (int i=0; i<n; i++)
    {
        char c;
        int num;
        cin >> c >> num;

        if (c == 'S')
            card[0][num-1] = 1;
        else if (c == 'H')
            card[1][num-1] = 1;
        else if (c == 'C')
            card[2][num-1] = 1;
        else if (c == 'D')
            card[3][num-1] = 1;
    }

    for (int i=0; i<4; i++)
    {
        char c = kind[i];
        for (int j=0; j<13; j++)
        {
            if (card[i][j] == 0)
            {
                int num = j + 1;
                cout << c << " " << num << endl;
            }
        }
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 998244353

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

ll binary_square(ll x, ll n);

int main() {
  ll n, maxim = 0, res = 1, m = MOD;
  cin >> n;
  vector<ll> d(n, 0);
  rep(i, n) {
    ll x;
    cin >> x;
    if ((i == 0 && x != 0) || (i != 0 && x == 0)) {
      cout << 0 << endl;
      return 0;
    }
    maxim = max(maxim, x);
    d[x]++;
  }
    rep2(i, 1, maxim + 1) { 
        res = (res * binary_square(d[i-1], d[i])) % m;
    }
    cout << res << endl;
  return 0;
}

ll binary_square(ll x, ll n) {
  ll m = MOD;
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * x % m;
    }
    x = x * x % m;
    n >>= 1;
  }
  return ans % m;
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

main() {
  string sap = "apple";
  string spc = "peach";
  string s; getline(cin,s);
  unsigned int pos=0;
  while((pos=s.find(sap,pos)) != string::npos) {
    s.replace(pos,1,"1");
  }
  pos=0;
  while((pos=s.find(spc,pos)) != string::npos) {
    s.replace(pos,sap.length(),sap);
  }
  pos=0;
  while((pos=s.find("1",pos)) != string::npos) {
    s.replace(pos,spc.length(),spc);
  }
  cout << s << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)

int n,len;
string str;
vector<int> t,u,ans;
int mini,cnt;

int calc_sum(vector<int> &vec){
  int res=0;
  for(int i=0;i<(int)vec.size();i++)res+=vec[i];
  return res;
}

int change(int p){
  return str[p]-'0';
}

void rec(int p,int num){
  num=num*10+change(p);
  
  if(p+1==len){
    t.push_back(num);
    int sum=calc_sum(t);
    /*    
    for(int i=0;i<(int)t.size();i++){
      cout<<t[i]<<' ';
    }cout<<endl;
    cout<<sum<<endl;
    */
    if(sum<=n){
      if(n-sum<mini){
	mini=n-sum;cnt=1;ans=t;
      }else if(n-sum==mini)cnt++;
    }
    t.pop_back();
    return;
  }

  rec(p+1,num);
  
  t.push_back(num);
  rec(p+1,0);
  t.pop_back();
  
}

int main(){
  while(1){
    cin>>n>>str;
    if(n==0&&str=="0")break;
    len=str.size();
    mini=INF;
    rec(0,0);
    if(mini==INF){
      cout<<"error"<<endl;
    }else if(cnt==1){
      cout<<n-mini;
      for(int i=0;i<(int)ans.size();i++)
	cout<<' '<<ans[i];
      cout<<endl;
    }else{
      cout<<"rejected"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<set<int>> v(26);
	for (int i = 0; i < s.size(); i++) {
		v[s[i]-'a'].insert(i+1);
	}
	int q;
	cin>>q;
	for (int i = 0; i < q; i++) {
		int f;
		cin>>f;
		if (f == 1) {
			int j;
			char c;
			cin>>j>>c;
			if (s[j-1] != c) {
				v[s[j-1]-'a'].erase(j);
				v[c-'a'].insert(j);
				s[j-1] = c;
			}
		} else {
			int a, b;
			cin>>a>>b;
			int res = 0;
			for (int k = 0; k < 26; k++) {
				auto ia = v[k].lower_bound(a);
				auto ib = v[k].upper_bound(b);
				if (ia != ib) res++;
			}
			cout<<res<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 24348
abk = input().split(" ")
a = int(abk[0])
b = int(abk[1])
k = int(abk[2])

def main(a, b, k, k_first):
    if k % 2 == k_first % 2:
        if a % 2 == 1:
            a -= 1
        new_a = int(a / 2)
        new_b = b + int(a / 2)
    else:
        if b % 2 == 1:
            b -= 1
        new_b = int(b / 2)
        new_a = a + int(b / 2)
    if k - 1 == 0:
        print(str(new_a) + " " + str(new_b))
    else:
        main(new_a, new_b, k - 1, k_first)

main(a, b, k, k)

Measured memory_bytes: 3064
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int k,s;cin>>k>>s;
    int ans=0;
    for(int x=0;x<=k;x++)
        for(int y=0;y<=k;y++)
                if(x+y<=s&&s-x-y<=k)
                    ans++;
    cout<<ans<<Endl;
    //------------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 896
#include<stdio.h>
#define min(lhs,rhs) ((rhs)<(lhs)?(rhs):(lhs))


int main(void){
    long long a,b,c,k;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
    if(a+b >= k)printf("%lld",min(a,k));
    else printf("%lld",a - (k-a-b));
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

const int N = 100010;
ll n, a[N], sm, mn, neg;

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	sm = neg = 0;
	mn = (ll)1e18;
	for (int i = 0; i < n; i++) {
		if (a[i] < 0) { a[i] *= -1; neg++; }
		sm += a[i];
		mn = min(mn, a[i]);
	}
	if (neg & 1) sm -= 2 * mn;
	printf("%lld\n", sm);
}

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

int main(){
    int N;
    cin >> N;
    vector<long double> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    long double denomi =0;
    for(int i=0;i<N;i++){
        denomi += (1/A[i]);
    }
    cout << setprecision(10) << 1/denomi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace  std;
#define mp make_pair
#define pb push_back
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(int i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
	
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}
int b[6000][6000];
long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}
//long long freq[(long long)1e7*3]={};
int a[(int)1e5];
ll dp[(int)1e5];
ll mincost(int x, int n)
{
	if(x==n-1)
		return 0;
	if(dp[x]>-1)
		return dp[x];
	else
	{
		ll s1, s2=-1;
		if(x+1 <= n-1)
			s1=abs(a[x+1]-a[x])+mincost(x+1,n);
		if(x+2<=n-1)
			s2=abs(a[x+2]-a[x])+ mincost(x+2,n);

		if(s2 == -1)
		{
			dp[x]=s1;
			return dp[x];
		}
		else
			{	
				dp[x]=min(s1,s2);
				return min(s1,s2);
			}	

	}
}
int main()
{
	//memset(ncandidate,0,sizeof(ncandidate));	
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			//cout<<dp[i]<<'\n';
		}	
	cout<<mincost(0,n);

	 

	 	//	cerr<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<int>> A(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    queue<pair<int, pair<int, int>>> q;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
            {
                A[i][j] = 1;
                q.push(make_pair(i, make_pair(j, 0)));
            }
        }
    }
    int ans = 0;
    while (!q.empty())
    {
        pair<int, pair<int, int>> u = q.front();
        q.pop();
        int i = u.first;
        int j = u.second.first;
        ans = u.second.second;
        if (i < 0 || j < 0 || h <= i || w <= j)
            continue;
        if (0 < i)
            if (A[i - 1][j] == 0)
            {
                q.push(make_pair(i - 1, make_pair(j, ans + 1)));
                A[i - 1][j] = 1;
            }
        if (i < h - 1)
            if (A[i + 1][j] == 0)
            {
                q.push(make_pair(i + 1, make_pair(j, ans + 1)));
                A[i + 1][j] = 1;
            }
        if (j < w - 1)
            if (A[i][j + 1] == 0)
            {
                q.push(make_pair(i, make_pair(j + 1, ans + 1)));
                A[i][j + 1] = 1;
            }
        if (0 < j)
            if (A[i][j - 1] == 0)
            {
                q.push(make_pair(i, make_pair(j - 1, ans + 1)));
                A[i][j - 1] = 1;
            }
    }
    cout << ans << endl;
}

Measured memory_bytes: 17296
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int min,max;

  for (int i = 0;i < 5;i++)
  {
    int tmp;
    cin >> tmp;
    if(i == 0){
      min = tmp,max = tmp;
    } else {
      if (tmp < min)
        min = tmp;
      if (tmp > max)
        max = tmp;
    }
  }
  int k;
  cin >>k; 
  if (max - min <=k) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
  cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int id = 0;
            var diceCommand = new DiceCommand();

            var diceList = Console.ReadLine().Split(' ').Select(n => new Dice(++id, int.Parse(n))).ToList();
            foreach (var item in Console.ReadLine().ToArray())
            {
                diceCommand.Exec(item);
            }
            
            Console.WriteLine(diceList.SingleOrDefault(n => n.Id == diceCommand.Top).Number);

            Console.ReadKey();
        }
    }

    class DiceCommand
    {
        public int Top = 1;
        public int S = 2;
        public int E = 3;

        const int diceUpDownSum = 7;

        public DiceCommand()
        {
        }

        public DiceCommand(int top, int s, int e)
        {
            Top = top;
            S = s;
            E = e;
        }

        public void Exec(char command)
        {
            switch (command)
            {
                case 'S':
                    RollDice(ref Top, ref S);
                    break;
                case 'E':
                    RollDice(ref Top, ref E);
                    break;
                case 'W':
                    RollDice(ref E, ref Top);
                    break;
                case 'N':
                    RollDice(ref S, ref Top);
                    break;
            }

        }

        void RollDice(ref int main, ref int sub)
        {
            int work = main;
            main = diceUpDownSum - sub;
            sub = work;
        }
    }

    class Dice
    {
        public int Id { get; set; }
        public int Number { get; set; }

        public Dice(int id, int number)
        {
            Id = id;
            Number = number;
        }
    }
}

Measured memory_bytes: 20340
#include <stdio.h>
 
int main(){
int a,i,c=0,j,temp,data[100];
scanf("%d",&a);
for(i=0;i<a;i++)
{
    scanf("%d",&data[i]);
}
for(i=0;i<a-1;i++)
{
    for(j=a-1;j>i;j--){
        if(data[j-1]>data[j]){
            temp=data[j-1];
            data[j-1]=data[j];
            data[j]=temp;
            c++;
        }
    }
}
for(i=0;i<a;i++)
{
    printf("%d",data[i]);
    if(i!=a-1) printf(" ");
}
printf("\n");
printf("%d\n",c);
return 0;
}

Measured memory_bytes: 604
/**
*    created: 05.05.2020 09:43:29
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int a[3][3];
    int m;
    rep(i, 3){
         rep(j, 3){
              cin >> a[i][j];
         }
    }
    cin >> m;
    int b[m];
    rep(i,m){
         cin >> b[i];
         rep(j,3){
             rep(k,3){
                 if(a[j][k]==b[i]){
                     a[j][k] = -1;
                     }
                 }
             
        }
    }
    //cout << a[1][1]<<a[2][2]<<a[0][0] << endl;

    if(a[0][0]*a[0][1]*a[0][2]==-1||a[1][0] * a[1][1] * a[1][2] == -1||a[2][0] * a[2][1] * a[2][2] == -1||a[0][1] * a[1][1] * a[2][1] == -1||a[0][0] * a[1][0] * a[2][0] == -1||a[0][2] * a[1][2] * a[2][2] == -1||a[0][0] * a[1][1] * a[2][2] == -1||a[0][2] * a[1][1] * a[2][0] == -1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int N;
   std::cin >> N;
   int h[N];
   for(int i=0; i<N; ++i)
      std::cin >> h[i];

   int count = 0;
   bool flag = true;
   while(flag){
      flag = false;
      bool water = false;
      for(int i=0; i<N; ++i){
	 if(h[i]>0){
	    --h[i];
	    flag = true;
	    water = true;
	    if(i==N-1) ++count;
	 }else if(water){
	    ++count;
	    water = false;
	 }
      }
   }

   std::cout << count << std::endl;
   return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}

void solve() {
  vvi bingo(3,vi(3)),ans(3,vi(3,0));
  rep(i,3)rep(j,3){
    cin>>bingo[i][j];
  }
  int n;
  cin>>n;
  vi b(n);
  rep(k,n){
    cin>>b[k];
    rep(i,3)rep(j,3){
      if(bingo[i][j]==b[k]) ans[i][j]++;
    }
  }
  bool how=false;
  rep(i,3){
    if(ans[i][0]==1&&ans[i][1]==1&&ans[i][2]==1){
      how=true; goto SKIP;
    }
  }
  rep(i,3){
    if(ans[0][i]==1&&ans[1][i]==1&&ans[2][i]==1){
      how=true; goto SKIP;
    }
  }
  if(ans[0][0]==1&&ans[1][1]==1&&ans[2][2]==1){
    how=true; goto SKIP;
  }
  if(ans[0][2]==1&&ans[1][1]==1&&ans[2][0]==1){
    how=true; goto SKIP;
  }
SKIP:
  YesNo(how);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
n = int(input())
li = []
for i in range(n):
    li.append(input())

if len(set(li)) != len(li):
    print("No")
else:
    for i in range(n):
        if i == n-1:
            print("Yes")
            break
        else: 
            if li[i][-1] != li[i+1][0]:
                print("No")
                break
                

Measured memory_bytes: 3060
#include <iostream>
#include<iomanip>
#include <deque>
using namespace std;
int main(){
    long long n,k;
    long long ans;
    cin >> n >> k;
    int i=0;
    int kaisu=1;
    int keta=k;
    while(i<1){
        if(n<keta){
            cout << kaisu << endl;
            i=1;
        }else{
            kaisu++;
            keta = keta * k;
        }
    }
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            char[][] t = new char[h][w];
            for (int i = 0; i < h; i++) {
                t[i] = in.nextString().toCharArray();
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (t[i][j] == '.') {
                        int cnt = 0;
                        for (int k = -1; k <= 1; k++) {
                            for (int l = -1; l <= 1; l++) {
                                if (k == 0 && l == 0) continue;
                                if (RangeUtils.isInside(i + k, j + l, h, w)
                                        && t[i + k][j + l] == '#') {
                                    cnt++;
                                }
                            }
                        }
                        t[i][j] = (char) (cnt + '0');
                    }
                }
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    out.print(t[i][j]);
                }
                out.println();
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }

    static class RangeUtils {
        public static boolean isInside(int y, int x, int h, int w) {
            return y >= 0 && x >= 0 && y < h && x < w;
        }

    }
}



Measured memory_bytes: 25044
#include <stdio.h>

int main(void){
    int num=0;
    scanf("%d",&num);
    
    int h=num/3600;
    int m=(num/60)%60;
    int s=num%60;
    
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
    
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    vector<LL> leftR(N, 0);
    vector<LL> leftG(N, 0);
    vector<LL> leftB(N, 0);
    REP(i, N - 1) {
        leftR[i + 1] = leftR[i] + (S[i] == 'R');
        leftG[i + 1] = leftG[i] + (S[i] == 'G');
        leftB[i + 1] = leftB[i] + (S[i] == 'B');
    }
    vector<LL> rightR(N, 0);
    vector<LL> rightG(N, 0);
    vector<LL> rightB(N, 0);
    for(int i = N - 1;0 < i;i--) {
        rightR[i - 1] = rightR[i] + (S[i] == 'R');
        rightG[i - 1] = rightG[i] + (S[i] == 'G');
        rightB[i - 1] = rightB[i] + (S[i] == 'B');
    }

    LL res = 0;
    REP(i, N) {
        if(S[i] == 'R') {
            LL grb = leftG[i]*rightB[i];
            LL brg = leftB[i]*rightG[i];
            for(int j = 1;0 <= i - j && i + j < N;j++) {
                if(S[i - j] == 'G' && S[i + j] == 'B') {
                    grb--;
                }
                if(S[i - j] == 'B' && S[i + j] == 'G') {
                    brg--;
                }
            }
            res += grb + brg;
        }
        if(S[i] == 'G') {
            LL bgr = leftB[i]*rightR[i];
            LL rgb = leftR[i]*rightB[i];
            for(int j = 1;0 <= i - j && i + j < N;j++) {
                if(S[i - j] == 'B' && S[i + j] == 'R') {
                    bgr--;
                }
                if(S[i - j] == 'R' && S[i + j] == 'B') {
                    rgb--;
                }
            }
            res += bgr + rgb;
        }
        if(S[i] == 'B') {
            LL rbg = leftR[i]*rightG[i];
            LL gbr = leftG[i]*rightR[i];
            for(int j = 1;0 <= i - j && i + j < N;j++) {
                if(S[i - j] == 'R' && S[i + j] == 'G') {
                    rbg--;
                }
                if(S[i - j] == 'G' && S[i + j] == 'R') {
                    gbr--;
                }
            }
            res += rbg + gbr;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=1e6+500;
const ll mod=1e9+7;
const ll inf=1e9+500;

ll a[maxn];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    n*=2;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ans=0;
    for(ll i=0;i*2<n;i++){
        ans+=a[2*i];
    }
    cout<<ans;
}


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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	sort(all(s));
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<float.h>
#include<string>

#define llong long long; 
using namespace std;

int main(){
  int n; cin >> n;
  int s[101];
  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> s[i];
    count += s[i];
  }
  sort(s, s + n);

  int secret = count;
  for(int i = 0; i < n; i++){
    if(s[i] % 10 != 0){
      secret = s[i];
      break;
    }
  }

  if(count % 10 != 0) cout << count << endl;
  else {
    cout << count - secret << endl;
  }
}

Measured memory_bytes: 256
x,y = [int(i) for i in input().split()]

groupA = [1,3,5,7,8,10,12]
groupB = [4,6,9,11]
groupC = [2]

if x in groupA and y in groupA:
    print("Yes")
elif x in groupB and y in groupB:
    print("Yes")
elif x in groupC and y in groupC:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  REP(i,s.size()){
    if(s[i] != t[i]) ++ans;
  }

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

Measured memory_bytes: 3916
N, K = map(int, input().split())
hs = [int(input()) for i in range(N)]
hs.sort()

m = hs[K-1] - hs[0]
for i in range(1,N-K+1):
    m = min(m, hs[i + K - 1] - hs[i])
print(m)

Measured memory_bytes: 13332
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! { s: chars }
    let mut t = s.clone();
    t.reverse();
    let t: String = t.into_iter().collect();
    let u: String = s.into_iter().collect();
    if t == u {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long n, ans;
int main()
{
  cin >> n;
  for (int i=1; 1ll*i*i<=n; i++){
    if (n % i == 0) {
      ans = i + n / i;
    }
  }
  cout << ans - 2;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define SZ(v)      ((int)(v).size())
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

/*二項係数(mod付き)*/
struct Combination{
	const int num=1e6;			//num:=(要素数). 適宜変更する!
	const int mod=1e9+7;
	vector<llong> fact,inv,finv;//fact[i]:=(iの階乗),inv[i]:=(iの逆元),finv[i]:=(iの逆元の階乗).
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){//組み合わせ.
		if(n<k or (n<0 or k<0)) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	template<typename Type>
	Type big_nCk(Type n,int k){//nが大きい場合に使用.
		if(n<k or (n<0 or k<0)) return 0;
		llong res=1LL;
		REP(i,k) res=res*((n-i)%mod)%mod;
		res=res*finv[k]%mod;
		return Type(res);
	}
	int nPk(int n,int k){//順列.
		if(n<k) return 0;
		return fact[n]*finv[n-k]%mod;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

int main(){//Refering other editorials. 連立方程式を解く.
	int x,y;
	cin>>x>>y;
	
	if((x+y)%3!=0){
		cout<<0<<endl;
		return 0;
	}
	
	int n=(2*y-x)/3;
	int m=(2*x-y)/3;
	debug(n+m);
	
	Combination ob;
	int ans=ob.nCk(n+m,n);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26740
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n-1); i >= 0; i--)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    map<string, ll> mp;
    ll ans = 0;

    rep(i , N) {
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    for (auto const& x : mp) {
        ans += (x.second*(x.second - 1)) / 2;
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
	string A,B,C;
	cin >> A >> B >> C;
	if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0])cout << "YES" <<endl;
    else cout << "NO" << endl;
}


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

using namespace std;

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

main(){
	int n;
	cin >> n;
	int v[n], c[n];
	for(int i=0;i<n;++i) cin >> v[i];
	for(int i=0;i<n;++i) cin >> c[i];
	int ans = 0;
	for(int i=0;i<(1<<n);++i){
		int x = 0, y = 0;
		for(int j=0;j<n;++j){
			if(i & (1<<j)){
				x += v[j];
				y += c[j];
			}
		}
		ans = max(ans, x-y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string a,b;
bool vis[3009][3009];
int memo[3009][3009];
vector<pair<ll,ll> >v;
int sol(ll x,ll y){
  if(x>=a.size() || y>=b.size())return 0;
  if(vis[x][y])return memo[x][y];
  vis[x][y]=1;
  int ma=0;
  ma=max(ma,sol(x+1,y));
  ma=max(ma,sol(x,y+1));
  if(a[x]==b[y])ma=max(ma,sol(x+1,y+1)+1);
  return memo[x][y]=ma;
}
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
		cin>>a>>b;
		int best=sol(0,0);
		int x=0,y=0;
		while(1){
      if(x>=a.size() || y>=b.size())return 0;
      if(sol(x+1,y)==best){
        x++;
        continue;
      }
      if(sol(x,y+1)==best){
        y++;
        continue;
      }
      cout<<a[x];
      x++;
      y++;
      best--;
		}
    return 0;
}

Measured memory_bytes: 44800
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		
		long[] h = new long[n];
		
		for(int i = 0; i < n; i++)
		{
			h[i] = sc.nextLong();
		}
		
		Arrays.sort(h);
		
		long l = 1;
		long r = 2000000000;
		long min = 2000000000;
		
		while(l<=r)
		{
			long con = (l+r)/2;
			
			long coll = b*con; //collateral damage
			long need = 0;
			for(int i = n-1; i >= 0; i--)
			{
				long sindam = a-b;
				long hel = h[i] - coll;
				
				if(hel>0)
				{
					need += hel/sindam;
					if(hel%sindam != 0)need++;
				}
			}
			
			if(need <= con)
			{
				min = Math.min(min, con);
				r = con-1;
			}
			else
			{
				l = con+1;
			}
			
		}
		
		System.out.println(min);
	}

}


Measured memory_bytes: 50692
char*p;l;M(r){for(r=T();*p%5==2;)*p&1?r/=T():(r*=T());return r;}A(r){for(r=M();abs(*p-=44)<2;)r-=*p*M();return++p,r;}T(){return*++p-40?strtol(p,&p,10):A(p);}main(f,E){for(;~scanf("%s",E);f=0)f||printf("%d\n",A(p=E-1));}

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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
const double PI = 3.1415926535897932;

ll cnt[1010];
int main()
{
    int n,k; cin >> n >> k;
    vector<ll> v;
    rep(i,n) cin >> cnt[i+1];
    rep(i,n) cnt[i+1] += cnt[i];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n+1; j++){
            v.push_back(cnt[j]-cnt[i]);
        }
    }
    ll ans = 0;
    for(int i = 40; i >= 0; i--){
        ll cur = ans + (1LL << i);
        int ok = 0;
        for(auto tmp : v) if((cur & tmp) == cur) ok++;
        if(ok >= k) ans = cur;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7452
N,A,B,C,D=map(int,input().split())
S=list(input())
a=0
E=N-D
if C>D:
    for i in range(N-3):
        if S[i]=="#":
            for j in range(1,4):
                if S[i]==S[i+j]:
                    a=1
    if E==0:
        for i in range(B-2,D-2):
            if S[i]==".":
                if S[i]==S[i+1] and S[i+1]==S[i+2]:
                    a=0
                    break
    if E>=1:
        for i in range(B-2,D-1):
            if S[i]==".":
                if S[i]==S[i+1] and S[i+1]==S[i+2]:
                    a=0
                    break
for i in range(A,D):
    if S[i]=="#":
        if S[i+1]=="#":
            a=1
if a==0:
    print("Yes")
if a==1:
    print("No")

Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		int k = sc.nextInt();
		
		//asume k = 3
		int d = s.length();
		boolean[] restiszero = new boolean[d];
		boolean[] hasNonZeroToTheLeft = new boolean[d];
		int fir = s.charAt(0)-'0';
		int rest = d-1;
		
		for(int i = s.length()-1; i >= 0; i--)
		{
			if(s.charAt(i) == '0')
			{
				restiszero[i] = true;
			}
			else break;
		}
		boolean foundz = false;
		for(int i = 1; i < s.length(); i++)
		{
			hasNonZeroToTheLeft[i] = foundz;
			if(s.charAt(i) != '0')
				foundz = true;
		}
		
		long an = 0;
		if(k==3)
		{
			if(d<3)
			{
				System.out.println(0);
				return;
			}
			
			//same digit cases
			
			//first digit lesser
			if(d>=3)
				an += (((d-1)*(d-2))/2) * (fir-1) * 9 * 9;
			if(an<0)System.out.println("ERROR");
//			System.out.println("test " + an);
			
			//first digit is same
			for(int pos1 = 1; pos1 < s.length(); pos1++)
			{
				boolean pos2foundz = false;
				for(int pos2 = pos1+1; pos2 < s.length(); pos2++)
				{
					if(hasNonZeroToTheLeft[pos1])
						an += 9*9;
					else
					{
						int d1 = s.charAt(pos1)-'0';
						int d2 = s.charAt(pos2)-'0';
						int num = (d1-1)*9 + d2;
						if(d2==0)num=0;
						if(pos2foundz)num = d1 * 9;
						if(d1==0)num=0;
						if(num<0)System.out.println("ERROR");
//						if(num>0)System.out.println(pos1 + " " + pos2 + ": " + num);
						an+=num;
					}
					if(s.charAt(pos2) != '0')pos2foundz = true;
				}
			}
//			System.out.println("test " + an);
			//less digit cases
			long les = 0;
			for(int dig = k; dig < d; dig++)
			{
				//k=3
				les = (((dig-1)*(dig-2))/2) * 9 * 9 * 9;
				if(les<0)System.out.println("ERROR");
				an += les;
//				System.out.println(les);
			}
		}
		else if(k==2)
		{
			if(d<2)
			{
				System.out.println(0);
				return;
			}
			
			//same digit cases
			
			//first digit lesser
			if(d>=2)
				an += (d-1) * (fir-1) * 9;
			
			//first digit is same
			for(int pos1 = 1; pos1 < s.length(); pos1++)
			{
				int d1 = s.charAt(pos1)-'0';
				if(hasNonZeroToTheLeft[pos1])
				{
					an += 9;
				}
				else an += d1;
			}

			
			//less digit cases
			long les = 0;
			for(int dig = k; dig < d; dig++)
			{
				//k=2
				les = (dig-1) * 9 * 9;
				an += les;
			}
		}
		else if(k==1)
		{
			an = 9 * (d-1);
			an += fir;
		}
		System.out.println(an);
	}

}


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

using namespace std;

int num;

int Search(int now, vector<int> &h, vector<int> &dis) {
	if (dis[now] != -1)
		return dis[now];
	int ans = min(abs(h[now] - h[now + 1]) + Search(now + 1, h, dis)
					, abs(h[now] - h[now + 2]) + Search(now + 2, h, dis));
	dis[now] = ans;
	return ans;
}

int main(void) {
	int i = 0;
	cin >> num;
	vector<int> h(num), dis(num, -1);
	for (; i < num; i++)
		scanf("%d", &h[i]);
	dis[num - 1] = 0;
	dis[num - 2] = abs(h[num - 2] - h[num - 1]);
	cout << Search(0, h, dis) << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
const double pi=3.1415926535897932384626434;
int n;
inline int abs(int x)
{
	return x>0?x:-x;
}
struct Point
{
	int x,y;
	bool operator < (const Point &b) const
	{
		return x<b.x;
	}
} s,t,p[maxn];
int yy[maxn],ly=0;
int g[maxn];

int up()
{
	int ans=0;
	g[0]=-1;
	for (int i=1; i<=ly; i++)
	{
		int L=0,R=ans;
		while (L<R)
		{
			int mid=(L+R+1)>>1;
			if (g[mid]<yy[i]) L=mid;
			else R=mid-1;
		}
		g[L+1]=yy[i];
		if (L==ans) ans++;
	}
	return ans;
}
int down()
{
	for (int i=1; i<=ly/2; i++)
	{
		int t=yy[i];
		yy[i]=yy[ly-i+1];
		yy[ly-i+1]=t;
	}
	return up();
}

int main()
{
	scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);
	if (s.x>t.x) swap(s,t);
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+1+n);
	p[0].x=-1;
	p[n+1].x=1e9;
	int L=0,R=n+1;
	while (L<R)
	{
		int mid=(L+R)>>1;
		if (p[mid].x<s.x) L=mid+1;
		else R=mid;
	}
	int left=L;
	L=0,R=n+1;
	while (L<R)
	{
		int mid=(L+R+1)>>1;
		if (p[mid].x>t.x) R=mid-1;
		else L=mid;
	}
	int right=L;
	for (int i=left; i<=right; i++)
		if (p[i].y>=min(s.y,t.y) && p[i].y<=max(s.y,t.y)) 
			yy[++ly]=p[i].y;
	if (s.y>t.y) L=down();
	else L=up();
	double ans=(abs(t.y-s.y)+(t.x-s.x))*1ll*100-L*(20-5*pi);
	if (abs(t.y-s.y)+1==L || t.x-s.x+1==L) ans=ans+5*pi;
	printf("%.15lf\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n,k,a=1;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		if(a>k){
			a+=k;
		}
		else{
			a+=a;
		}
	}
	cout <<a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll,ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll n;
vector<ll> v;
string s;

void solve()
{
	cin>>n;
	while(n>0)
	{
		int r=n%26;
		// cout<<n<<" "<<r<<endl;	
		s+=((r-1+26)%26+'a');
		if(r==0) n-=26;
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}

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

Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll a = 0;
    rep(i,N) a+=A[i];
    ll b = 0;
    ll ans = a;
    rep(i,N){
        b += A[i];
        ans = min(ans, abs(a-b-b));
        //cout << a-b << endl;
    }
    cout << ans << endl;
    
    
    return 0;
}



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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 100100;

int n;
int a[M];
int d[M];
vector<int> g[M];
bool u[M];

void read() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    --a[i];
    g[a[i]].push_back(i);
  }
}

int dfs(int v) {
  if (u[v])
    return d[v];
  u[v] = true;
  vector<int> rest;
  for (int to : g[v]) {
    rest.push_back(dfs(to));
  }
  sort(rest.begin(), rest.end(), greater<int>());

  for (int i = 0; i < (int) rest.size(); ++i)
    d[v] = max(d[v], i + 1 + rest[i]);

  return d[v];
}

int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  cout << dfs(0) << endl;
}



Measured memory_bytes: 16000
#include <stdio.h>

int main(void) {
	int N;
	int syougen[16][16] = {{0}};
	int i, j;
	int answer = 0;
	int search;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int A;
		if (scanf("%d", &A) != 1) return 1;
		for (j = 0; j < A; j++) {
			int x, y;
			if (scanf("%d%d", &x, &y) != 2) return 1;
			syougen[i][x - 1] = (y == 1 ? 1 : -1);
		}
	}
	for (search = 0; search < (1 << N); search++) {
		int score = 0;
		int ok = 1;
		for (i = 0; ok && i < N; i++) {
			if ((search >> i) & 1) {
				score++;
				for (j = 0; ok && j < N; j++) {
					if (syougen[i][j] != 0) {
						if (((search >> j) & 1) != (syougen[i][j] == 1)) ok = 0;
					}
				}
			}
		}
		if (ok && score > answer) answer = score;
	}
	printf("%d\n", answer);
	return 0;
}


Measured memory_bytes: 128
let () =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun n -> n) in
        let arr = Array.init n (fun i -> Scanf.sscanf (read_line ()) "%s %d" (fun s p -> s, p, i + 1)) in
        Array.sort (fun (s1, p1, _) (s2, p2, _) -> compare (s1, -p1) (s2, -p2)) arr;
        Array.iter (fun (_, _, i) -> Printf.printf "%d\n" i) arr
    in
    main ()

Measured memory_bytes: 640