akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll inf = 1LL<<50;

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

  ll n, m;
  cin >> n >> m;
  vl dp(1<<n, inf);
  vl a(m), b(m);
  vector<vi> c(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) {
      int cc;
      cin >> cc;
      c[i].push_back(cc-1);
    }
  }

//  rep(i, 1<<n) {
//    cerr << dp[i] << endl;
//  }

  vector<bool> ch(1<<n);

  dp[0] = 0;
  priority_queue<pll, vector<pll>, greater<pll>> pq;
  pq.push({0, 0});
  while (pq.size()) {
    ll cnt, bit;
    tie(cnt, bit) = pq.top();
    pq.pop();

    rep(i, m) {
      ll bi = bit;
      ll cn = cnt;
      rep(j, b[i]) {
        if ((bi & 1<<c[i][j]) == 0) {
          bi |= 1<<c[i][j];
          cn++;
        }
      }
      cmin(dp[bi], dp[bit]+a[i]);
      if (bi != (1<<n)-1 && bi != bit && ch[bi] == 0) {
        ch[bi] = 1;
        pq.push({cn, bi});
      }
    }
  }

  if (dp[(1<<n)-1] == inf) cout << -1 << endl;
  else cout << dp[(1<<n)-1] << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  int cmp = n;
  do {
    cnt++;
    cmp /= k;
  }while(cmp > 0);
  
  cout << cnt << endl;
  return 0;
}

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


signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b });
	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    REP(i, h)
        cin >> v[i];
    
    REP(i,h)
    {
        cout << v[i] << "\n";
        cout << v[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void main()
{
  int n,i,flag=1;
  scanf("%d",&n);
  int array[n];
  for(i=0;i<n;i++){
  	scanf("%d",&array[i]);
  }
  for(i=0;i<n;i++){
  	if((array[i]%2)==0){
    	if((array[i]%3)!=0 && (array[i]%5)!=0){
          flag = -1;
          break;
        }
    }
  }
  if(flag==1)
    printf("APPROVED");
  else
    printf("DENIED");
}

Measured memory_bytes: 1704
m[100];X,Y,S,x,d;main(h){for(;~scanf("%d,%d,%d",&X,&Y,&S);)for(x=100;x--;)hypot(x%10-X,x/10-Y)*2<=S+1?h-=!m[x],d=fmax(++m[x],d):0;x=!printf("%d\n%d\n",99+h,d);}

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

int main()
{
	

	char s[19];
	
	for (int i = 0; i < 19; i++)
		cin >> s[i];
	s[5] = ' ';
	s[13] = ' ';
	for (int j = 0; j < 19; j++)
		cout << s[j];
}

Measured memory_bytes: 3536
/* vishal shrivastava
     185023
     nit hamirpur
   */
  #include <bits/stdc++.h>
  using namespace std;
  #define minpq priority_queue <int, vector<int>, greater<int> >;
  #define maxpq  priority_queue <int>;
  #define F first
  #define S second
  #define mp make_pair
  #define pb push_back
  #define f(i,x,n) for(int i=x;i<n;i++)
  #define all(c) c.begin(),c.end()
  #define ll long long
  #define pll pair<ll,ll>
  #define pii pair<int,int>
  const int mod = 1e9+7, N = 1e5 + 10;
  int solve()
  {
     ll n;
     cin>>n;
     string s[n];
     for(int i=0;i<n;i++)
     {
         string s1;
         cin>>s1;
         sort(all(s1));
         s[i]=s1;
     }
     sort(s,s+n);
     ll co=1,ans=0;
     for(int i=0;i<n-1;i++)
     {
         if(s[i]==s[i+1])
            co++;
         else
         {
             ans+=(co*(co-1))/2;
             co=1;
         }
     }
     ans+=(co*(co-1))/2;
     cout<<ans;
  }

  int32_t main(){
    /*ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    int test=1;
    //cin>>test;
    while(test--)
    {
      solve();
    }
  }


Measured memory_bytes: 5760
N, T = raw_input().split()
sct = []
for i in xrange(int(N)):
    ci, ti = raw_input().split()
    if int(ti) <= int(T):
        s = set()
        s.add(ci)
        s.add(ti)
        sct.append(int(ci))
print('TLE' if sct ==[] else min(sct))

Measured memory_bytes: 2568
//D
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        long N, A, B;
        N = cin.nextLong();
        A = cin.nextLong();
        B = cin.nextLong();

        long ans = Math.Max(0, (A + B * (N - 1)) - (A * (N - 1) + B) + 1);
        Console.WriteLine(ans);
    }
    
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();

        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
int main()
{
    int x;
    scanf("%d",&x);
    if(x>=400 && x<600)
    printf("8\n");
    else if(x>=600 && x<800)
    printf("7\n");
    else if(x>=800 && x<1000)
    printf("6\n");
    else if(x>=800 && x<1200)
    printf("5\n");
    else if(x>=1200 && x<1400)
    printf("4\n");
    else if(x>=1400 && x<1600)
    printf("3\n");
    else if(x>=1600 && x<1800)
    printf("2\n");
    else if(x>=1800 && x<2000)
    printf("1\n");
    
    return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>
int main(){
	int N,K;//N日分のシミュレーション
	scanf("%d %d",&N,&K);
	long long int dp[N][3];
	long long int delete[3];
	int i,j,k;
	memset(dp,0,sizeof(dp));//初期化
	memset(delete,0,sizeof(delete));
	int a,b;
	for(i=0;i<K;i++){
		scanf("%d %d",&a,&b);
		dp[a-1][b-1]=1;
	}
	if(dp[0][0]==0&&dp[0][1]==0&&dp[0][2]==0){//予約がなければ全てあり得る
		dp[0][0]++;
		dp[0][1]++;
		dp[0][2]++;
	}
	int flag;
	long long int temp=0;
	for(i=1;i<N;i++){
		flag=0;
		temp=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
		for(j=0;j<3;j++){
			if(dp[i][j]==1){
				dp[i][j]=temp-delete[j];
				for(k=0;k<3;k++){
					if(k==j){
						delete[j]=dp[i-1][j]-delete[j];//2日連チャンで食べている通り
					}
					else{
						delete[k]=0;
					}
				}
				flag=1;
				break;
			}
		}
		if(flag==0){
			for(j=0;j<3;j++){
				dp[i][j]=temp-delete[j];
				delete[j]=dp[i-1][j]-delete[j];
			}
		}
		if(delete[0]>10000&&delete[1]>10000&&delete[2]>10000){
			delete[0]%=10000;
			delete[1]%=10000;
			delete[2]%=10000;
			dp[i][0]=(dp[i][0]%10000)+10000;
			dp[i][1]=(dp[i][1]%10000)+10000;
			dp[i][2]=(dp[i][2]%10000)+10000;
			
		}
	}
	printf("%lld\n",(dp[N-1][0]+dp[N-1][1]+dp[N-1][2])%10000);
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define inf 100000000
#define _GLIBCXX_DEBUG
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int main(){
    stack<int> S;
    int a,b,x;
    string s;

    while (cin>>s){
        if (s[0] =='+'){
            a=S.top();S.pop();
            b=S.top();S.pop();
            S.push(a+b);
        }else if (s[0] =='-'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b-a);
        }else if (s[0]=='*'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a * b);
        }else{
            S.push(stoi(s));
        }
        // cout << S.top() << endl;
    }
    cout<<S.top()<<endl;
}



Measured memory_bytes: 3196
S = input()
even_0 = 0
even_1 = 0
odd_0 = 0
odd_1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            even_0 = even_0 + 1
        else:
            even_1 = even_1 + 1
    else:
        if S[i] == "0":
            odd_0 = odd_0 + 1
        else:
            odd_1 = odd_1 + 1
print(min(even_0 + odd_1, even_1 + odd_0))
        

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	IOS;

	lln a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(a*c,max(a*d,max(b*c,b*d)));
	return 0;    
}

Measured memory_bytes: 3648
def main():
    n,m = map(int, input().split())
    S,C = [],[]
    for i in range(m):
        s,c = map(int, input().split())
        S.append(s)
        C.append(c)
    ans = ['0']*n
    for i in range(m):
        if n != 1 and S[i]==1 and C[i]==0:
            print(-1)
            return
        for j in range(i+1, m):
            if S[i] == S[j]:
                if C[i] != C[j]:
                    print(-1)
                    return
        ans[S[i]-1] = str(C[i])
    if len(ans)!=1 and ans[0] == '0':
        ans[0] = '1'
    ans = int(''.join(ans))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
using System;

namespace AtCoder.ABC093
{
    class a
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            if (line.Length != 3) Console.WriteLine("No");
            else
            {
                if (line.IndexOf("a") >= 0 && line.IndexOf("b") >= 0 && line.IndexOf("c") >= 0) Console.WriteLine("Yes");
                else Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
signed main(){
  ll n,sum=0;
  string s;
  cin>>n;
  map<string,ll> mp;
  rep(i,n){
    cin>>s;
    mp[s]++;
    if(mp[s]==1){
      sum++;
    }
  }
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 19228
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bitset>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;
const int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string T;
    cin >> T;
    int ans = 0;
    for(int i = 0; i < T.size(); i++){
        if(T[i] == 'D')ans++;
        if(T[i] == '?'){
            T[i] = 'D';
            ans++;
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {
	public static final int maxN = 123456;
	public static void main(String args[]) {
		boolean[] isnotPrime = new boolean[maxN*2+1];
		for(int i=2;i*i<=maxN*2;i++) {
			if (isnotPrime[i]) {
				continue;
			}
			int n = i*2;
			while(n<maxN*2+1) {
				isnotPrime[n] = true;
				n+=i;
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = 0;
			n = sc.nextInt();
			if (n==0) {
				break;
			}
			int ans = 0;
			for(int i=n+1;i<=2*n;i++) {
				if (!isnotPrime[i]) {
					ans++;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 20676
N,M =map(int,input().split())
K=[]; A =[]
for i in range(N):
    temp = input().split()
    K.append(temp[0])
    A.append(temp[1:])
c = 0
#check
for food in list(range(1,M+1)):
    for row in range(N):
        if str(food) not in A[row]:
            break
    else:
        c += 1
        continue
    
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    int n;
    cin>>n;
    if(n%2==0)
        cout<<n/2;
    else
        cout<<(n+1)/2;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: x,mx,ans

    read*, x
    mx = mod(x,11_8)
    ans = 2_8*(x/11_8)

    if (mx > 0) then
        ans=ans+1
        if (mx/7 > 0) ans=ans+1
    end if 
    print'(i0)', ans
end program name

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,m;
   cin>>n>>m;
   int g=__gcd(n,m);
   cout<<(n*m)/g<<endl;
}


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

typedef struct {
	int id;
	int score;
} Pert;

int cmp(const void* x,const void* y) {
	Pert* a;
	Pert* b;
	a=(Pert*)x;
	b=(Pert*)y;
	if(a->score < b->score)return 1;
	if(a->score > b->score)return -1;
	if(a->id > b->id)return 1;
	if(a->id < b->id)return -1;
	return 0;
}

int main(void) {
	while(1){
		int n, i, j;
		scanf("%d", &n);
		if(n==0) break;

		Pert cand[40];
		int score[10][3];
		for(i=0; i<n; i++) {
			scanf("%d",&cand[i].id);
			for(j=0; j<9; j++) {
				scanf("%d", &score[j][0]);
				score[j][1] = 0;
				if(score[j][0]!=10) scanf("%d",&score[j][1]);
			}
			scanf("%d", &score[9][0]);
			scanf("%d", &score[9][1]);
			score[9][2] = 0;
			if(score[9][0]==10 || score[9][0]+score[9][1]==10) scanf("%d",&score[9][2]);

			cand[i].score = 0;
			for(j=0;j<9;j++) {
				cand[i].score += score[j][0] + score[j][1];
				if(score[j][0]==10){
					cand[i].score += score[j+1][0];
					if(score[j+1][0]==10 && j<8) cand[i].score+=score[j+2][0];
					else cand[i].score += score[j+1][1];
				}else if(score[j][0]+score[j][1] == 10) {
					cand[i].score+=score[j+1][0];
				}
			}
			cand[i].score+=score[9][0]+score[9][1]+score[9][2];
		}
		qsort(cand,n,sizeof(Pert),cmp);
		for(i=0;i<n;i++){
			printf("%d %d\n",cand[i].id,cand[i].score);
		}
	}
	return 0;
}


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

int main() {
  ll h,w;
  cin >> h >> w;
  map<char,ll> count;
  for(ll i=0;i<h;i++) {
    string temp;
    cin >> temp;
    for(ll j=0;j<w;j++) {
      count[temp[j]]++;
    }
  }
  ll g1=h%2*w%2;
  ll g2=w%2*h/2+h%2*w/2;
  ll g4=h/2*(w/2);
  while(g1--) {
    for(auto p:count) {
      if(p.second%2) {
        count[p.first]--;
        break;
      }
    }
  }
  while(g2--) {
    for(auto p:count) {
      if(p.second%4==2) {
        count[p.first]-=2;
        break;
      }
    }
  }
  for(auto p:count) {
    if(p.second%4) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import math
N = int(input().strip())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while(True):

    if is_prime(N):
        print(N)
        break

    else:
        N += 1

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

int main()
{
  double s[10], res;
  
  while(cin >> s[0]){
    res = s[0];
    for (int i = 1; i < 10; i++){
      if (i % 2 == 0){
        s[i] = s[i - 1] / 3;
      }
      else {
        s[i] = s[i - 1] * 2;
      }
      res += s[i];
    }
    cout << setprecision(10) << res << endl;
  }
  return (0);
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;

ll ans,mx,mn=1e10,sum;
int main(){
	ll n,m;
	cin>>n>>m;
	vector <pair<ll,ll>> v;
	for(int i=0; i<n; i++){
		ll a,b;
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(),v.end());
	for(int i=0; i<n; i++){
		if(m==0) break;
		if(v[i].second <= m) {
			m -= v[i].second;
			ans += v[i].first * v[i].second;
		}
		else if(v[i].second > m){
			ans += m * v[i].first;
			m = 0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _val(x) cerr << #x << " is " << x << "\n";
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define pb push_back
#define mp make_pair
#define rep(x, a, b, c) for(ll x = a; x <= b; x += c)
#define rrep(x, a, b, c) for(ll x = a; x >= b; x -= c)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long> > vpll;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+1;
const double eps = 1e-6;

void solve() {
	int n; cin >> n;
	int eat[n], b[n], c[n-1];
	rep(i, 0, n-1, 1) cin >> eat[i];
	rep(i, 0, n-1, 1) cin >> b[i];
	rep(i, 0, n-2, 1) cin >> c[i];
	int sum = 0;
	rep(i, 0, n-1, 1) {
		sum += b[eat[i]-1];
		if(i+1 <= n-1 && eat[i+1]-1 == eat[i])
			sum += c[eat[i]-1];
	}
	cout << sum << "\n";
}	

int main(void){
	// #ifndef ONLINE_JUDGE
	//  	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1; //cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> grid;
vector<vector<ll>> ans;
ll h,w;
ll a=0;
void f(ll x,ll y,ll d){
    if(ans[x][y]<=d)return;
    ans[x][y]=d;
    if(x>0){
        if(grid[x-1][y]=='.')f(x-1,y,d+1);
    }
      if(y>0){
        if(grid[x][y-1]=='.')f(x,y-1,d+1);
    }
      if(x<h-1){
        if(grid[x+1][y]=='.')f(x+1,y,d+1);
    }
      if(y<w-1){
        if(grid[x][y+1]=='.')f(x,y+1,d+1);
    }
}

int main(){
    cin>>h>>w;
    grid.resize(h);
	for (int z=0;z<h;z++)cin >> grid[z];
    for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(grid[i][j]=='.'){
            ans.resize(0);
            ans.resize(h,vector<long long>(w,LLONG_MAX));
            f(i,j,0);
            for(int x=0;x<h;x++){
            for(int y=0;y<w;y++)if(ans[x][y]!=LLONG_MAX)a=max(ans[x][y],a);
        }}
    }}
    cout<<a;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
 
#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
 
const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;
 
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_NV = 110;
const int MAX_T = 210;
 
int N;
vector<int> T,V;
map<int, int> limits;
double dp[MAX_NV * MAX_T * 2][MAX_NV * 2];
int sum;
double memo(int pos, int v){
    if (v < 0){
      return -INF;
    }
 
    if (v > limits[pos]){
      return -INF;
    }
    if (pos >= sum){
      if (v == 0){
        return 0;
      }
      return -INF;
    }
 
    double &res = dp[pos][v];
    if (res > -2 * INF){
      return res;
    }
    res = -INF;
    res = max(res, memo(pos + 1, v) + v);
    if (v < limits[pos]){
      res = max(res, memo(pos + 1, v + 1) + v + 0.5);
    }
    res = max(res, memo(pos + 1, v - 1) + v - 0.5);
    return res;
}
 
int main() {
  cin >> N;
  T.resize(N);
  V.resize(N);
  for (int i = 0; i < N; i++){
    cin >> T[i];
    T[i] *= 2;
    sum += T[i];
  }
  for (int i = 0; i < N; i++){
    cin >> V[i];
    V[i] *= 2;
  }
  for (int i = 1; i < N; i++){
    T[i] += T[i - 1];
  }
  int pre = 0;
  for (int i = 0; i < N; i++){
    for (int j = pre; j <= T[i]; j++){
      limits[j] = V[i];
    }
    pre = T[i];
  }
  // double dp[MAX_NV * MAX_T][MAX_NV * 2];
  for (int i = 0; i < MAX_NV * MAX_T * 2; i++){
    for (int j = 0; j < MAX_NV * 2; j++){
      dp[i][j] = -2 * INF;
    }
  }
  double result = (double)memo(0, 0) / 4;
  if (result <= 0){
    result = 0;
  }
  printf("%.20lf\n", result);
  return 0;
}

Measured memory_bytes: 85248
N = gets.to_i
class Node
    attr_accessor :index, :children, :parent, :sibling

    def initialize()
        @children = []
        @parent = nil
        @sibling = nil
    end

    def depth
        parent == nil ? 0 : parent.depth + 1
    end

    def degree
        children.length
    end

    def height
        if children.empty?
            0
        else
            children.map {|e| e.height }.max + 1
        end
    end
end
nodes = Array.new(N) { Node.new }
N.times do
    line=gets.chomp.split(" ").map(&:to_i)
    node = nodes[line[0]]
    node.index = line[0]
    
    node.children = line[1..2].select{|e| e!=-1 }.map {|e| nodes[e] }
    node.children.each do |child|
        child.parent = node
    end

    if node.children.length == 2
        nodes[line[1]].sibling = nodes[line[2]]
        nodes[line[2]].sibling = nodes[line[1]]
    end
end

nodes.each_with_index do |node|
    is_root = node.parent == nil
    is_leaf = node.children.empty?
    has_sibling = node.sibling != nil
    puts "node #{node.index}: parent = #{is_root ? -1 : node.parent.index}, sibling = #{has_sibling ? node.sibling.index : -1}, degree = #{node.degree}, depth = #{node.depth}, height = #{node.height}, #{is_root ? "root" : is_leaf ? "leaf" : "internal node"}"
end


Measured memory_bytes: 6880
#include "bits/stdc++.h"
using namespace std;

const int MXN = 100005;
vector<int> adj[MXN];
int blo;

int dista[MXN], distt[MXN], depth[MXN];

void dfsa(int node, int last, int dist) {
	dista[node] = dist;
	for (int i=0; i<adj[node].size(); i++) {
		if (adj[node][i] == last) continue;
		dfsa(adj[node][i], node, dist+1);
	}
}

void dfst(int node, int last, int dist) {
	distt[node] = dist;
	for (int i=0; i<adj[node].size(); i++) {
		if (adj[node][i] == last) continue;
		dfst(adj[node][i], node, dist+1);
	}
}

void dfs_dep(int node, int last, int dep) {
	depth[node] = dep;
	for (int i=0; i<adj[node].size(); i++) {
		if (adj[node][i] == last) continue;
		dfs_dep(adj[node][i], node, dep+1);
	}
}

int mx(int node) {
	int ma = 0;
	for (int i=0; i<adj[node].size(); i++) {
		int ot = adj[node][i];
		// cout << " > " << ot << endl;
		if (depth[ot] > depth[node]) ma = max(ma, mx(ot) + 1);
	}
	// cout << node << ' ' << ma << endl;
	return ma;
}


int main() {
	
	int n, t, a;
	cin >> n >> t >> a;
	
	for (int i=0; i<n-1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	int need = 0;
	
	dfsa(a, -1, 0);
	dfst(t, -1, 0);
	
	int rt = dista[t];
	int rn;
	
	int ht = rt - (rt / 2) - 1;
	int ha = rt - ht;
	
	need += ht;
	if (ha - 2 == ht) {
		need++;
		// cout << "2dist" << endl;
	}
	
	for (int i=1; i<=n; i++) {
		if (distt[i] == ht && dista[i] == ha) {
			rn = i;
		}
	}
	blo = a;
	dfs_dep(a, -1, 0);
	
	// cout << rn << endl;
	
	cout << need + mx(rn) << endl;
	
}


Measured memory_bytes: 12032
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main() {
	string s; cin >> s;
	unsigned long long count = 0;
	unsigned long long bcount = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			bcount++;
		}
		else {
			count += bcount;
		}
	}
	cout << count << endl;
}

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

using namespace std;

int main() {
  int n, K;
  cin >> n >> K;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int k = min_element(a.begin(), a.end()) - a.begin();
  int ans = 1e9;
  for (int i = 0; i <= K - 1; i++) {
    int j = K - 1 - i;
    int L = k;
    int R = n - k - 1;
    int cl = max(0, (L - i + K - 2) / (K - 1));
    int cr = max(0, (R - j + K - 2) / (K - 1));
    ans = min(ans, 1 + cl + cr);
  }
  cout << ans << endl;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define _ 				ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main(){	
	_;
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4]==s[5])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;	


}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
int n,a[200100],ans;
bool bo=true;
std::map<int,int> mp;
bool check(int x){
	mp.clear();
	for(int i=2;i<=n;i++)
		if(a[i-1]>=a[i]){
			while(!mp.empty()){
				int maxn=mp.rbegin()->first;
				if(maxn>a[i])mp.erase(maxn); 
				else break;
			}
			int j=a[i];
			while(mp[j]+1==x)
				mp.erase(j),j--;
			if(j==0)return false;
			mp[j]++;
		}
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]<=a[i-1])bo=false;		
	}
	if(bo)return puts("1"),0;
	int L=2,R=n;
	while(L<=R){
		int mid=(L+R)/2;
		if(check(mid))ans=mid,R=mid-1;
		else L=mid+1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, ans = 0;
  scanf("%lld", &n);
  for(i = 1; i <= n; ++i) if(i % 3 && i % 5) ans += i;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

int main() {
  int n, q, total = 0;
  cin >> n;
  vi s(n);
  rep(i, n) cin >> s[i];

  cin >> q;
  rep(i, q) {
    int t;
    cin >> t;
    
    for (auto j: s) {
      if (j == t) {
        total++;
        break;
      }
    }
  } 

  cout << total << endl;
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const int MAX_N = 5005;
typedef pair<ll, ll> P;
P HP[MAX_N];

const ll INF = 1LL << 58;
ll dp[MAX_N][MAX_N];

void naive(int N) {
  vector<int> ord(N);
  iota(ALL(ord), 0);

  vector<int> best_ord;
  int ans = 0;
  do {
    ll h = 0;
    int job = 0;
    vector<int> jobs;
    REP(i, N) if (HP[ord[i]].first >= h) {
      job++;
      h += HP[ord[i]].second;
      jobs.push_back(i);
    }
    // cout << job << " ";pv(ALL(ord));
    if (ans < job) {
      best_ord = jobs;
    }
    chmax(ans, job);

  } while (next_permutation(ALL(ord)));
  cout << ans << endl;
  REP(i, ans) {
    cout << HP[best_ord[i]];
  }
  cout << endl;
}

int main2() {
  int N; cin >> N;
  REP(i, N) {
    cin >> HP[i].first >> HP[i].second;
  }
  
  // if (N <= 10){
    // naive(N);
    // return 0;
  // }

  sort(HP, HP+N, [](const P& a, const P& b) -> bool {
    if (a.second + a.first != b.second + b.first)
      return a.second + a.first < b.second + b.first;
    return a.first < b.first;
  });

  REP(i, N+1) REP(j, N+1) dp[i][j] = INF;
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N; j++) chmin(dp[i+1][j], dp[i][j]);
    for (int j = 0; j < N; j++) {
      if (dp[i][j] <= HP[i].first) {
        chmin(dp[i+1][j+1], dp[i][j] + HP[i].second);
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= N; j++) {
    if (dp[N][j] < INF) ans = j;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int n, m;
int d[30];
int dp[50010];

int main() {

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> d[i];
    }
    sort(d, d + m);

    for (int i = 0; i <= n; i++) {
        dp[i] = 1000000;
    }
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i < d[j]) break;

            dp[i] = min(dp[i], dp[i-d[j]]+1);
        }
    }
    cout << dp[n] << endl;
    
    return 0;
}


Measured memory_bytes: 3356
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> t(S.size() + 1);
    for (size_t i = 0; i < S.size(); i++) {
        t[i + 1] = t[i];
        if (i < S.size() - 1 && S[i] == 'A' && S[i + 1] == 'C') t[i + 1]++;
    }
    for (int i = 0, l, r; i < Q; i++) {
        cin >> l >> r;
        cout << t[r - 1] - t[l - 1] << endl;
    }
}

Measured memory_bytes: 1408
import java.util.Scanner;

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

        String S = sc.next();
        String T = sc.next();

        System.out.println(solve(S, T) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(String S, String T) {
        return T.startsWith(S);
    }
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;

int D;
vector<int>c(26);

int main(){
    cin >> D;
    rep(i,26)cin>>c[i];
    vector<vector<int> >s(D,vector<int>(26));
    rep(i,D)rep(j,26)cin>>s[i][j];
    vector<int>last(D,0);
    ll manzoku = 0;
    vector<ll>ans;
    rep(i,D){
        ll t = 0;
        ll M = 0;
        /*ここにtを選ぶアルゴリズムをかく*/
        rep(j,26){
            ll now = 0;
            now += s[i][j];
            rep(k,26){
                if(k==j)continue;
                now -= c[k]*(i+1-last[k]);
            }
            if(chmax(M,now)){
                t = j;
            }
        }
        manzoku += s[i][t];
        last[t]=i+1;
        rep(j,26){
            manzoku -= c[j]*(i+1-last[j]);
        }
        ans.push_back(t);
    }
    rep(i,ans.size()){
        cout << ans[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */

#include <iostream>
#include <fstream>

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

class DKi {
    int n;
    int q;
    vector<vector<int>> ab;
    vector<int> cnt;
    vector<bool> f;
public:
	void solve(std::istream& in, std::ostream& out) {
        in >> n;
        in >> q;
        ab=vector<vector<int>>(n);
        cnt=vector<int>(n,0);
        f=vector<bool>(n,true);
        rep(i,n-1){
            int a,b;
            in >> a >> b;
            a--;b--;
            ab[a].push_back(b);
            ab[b].push_back(a);
        }
        rep(i,q){
            int t,x;
            in >> t >> x;
            t--;
            cnt[t]+=x;
        }
        queue<int> qq;
        qq.push(0);
        f[0]=false;
        while(!qq.empty()){
            int node=qq.front();
            qq.pop();
            for(int i=0;i<ab[node].size();i++){
                if(f[ab[node][i]]){
                    f[ab[node][i]]=false;
                    cnt[ab[node][i]]+=cnt[node];
                    qq.push(ab[node][i]);
                }
            }
        }
        rep(i,n){
            out << cnt[i] << " ";
        }out << endl;
	}
};


int main() {
	DKi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 15604
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		while(true) {
			int n=in.nextInt();
			if(n==0)break;
			
			List<Integer> ls=new LinkedList<>();
			for(int i=0;i<n;i++)ls.add(Integer.parseInt(in.next()));
			
			int i=0;
			while(true) {
				//System.out.println(ls);
				if(isTriangle(ls)) {
					System.out.println(i);
					break;
				}
				if(i>10000) {
					System.out.println(-1);
					break;
				}
				
				int s=ls.size();
				ListIterator<Integer> itr=ls.listIterator();
				while(itr.hasNext()) {
					int v=itr.next()-1;
					if(v==0)itr.remove();
					else itr.set(v);
				}
				ls.add(s);
				
				i++;
			}
			//System.out.println(ls);
		}
	}
	
	static boolean isTriangle(List<Integer> ls) {
		int i=0;
		for(;i<ls.size();i++) {
			if(ls.get(i)!=i+1)break;
		}
		
		if(i==ls.size())return true;
		else return false;
	}

}



Measured memory_bytes: 248224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> N;
    if(N<30)cout << "No";
    else cout << "Yes";
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int ans = 0;
		if(X == 3)
			ans += 100000;
		else if(X == 2)
			ans += 200000;
		else if(X == 1)
			ans += 300000;
		if(Y == 3)
			ans += 100000;
		else if(Y == 2)
			ans += 200000;
		else if(Y == 1)
			ans += 300000;
		if(X == 1 && Y == 1)
			ans += 400000;
		System.out.println(ans);

	}

}


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


int main(){

	int m, d; cin >> m >> d;

	int ans = 0;

	for (int im = 1; im <= m; im++) {
		for (int id = 1; id <= d; id++) {
			int d1 = id % 10, d10 = id / 10;
			if (d1 >= 2 && d10 >= 2 && im == d1 * d10) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = input().split()
h = [int(m) for m in a]
#dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
dp = [None] * (n + 1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(h[1] - h[0])
for i in range(3, n + 1):
    dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i - 2]), dp[i - 2] + abs(h[i - 1] - h[i - 3]))

print(dp[n])

Measured memory_bytes: 17860
#include<stdio.h>
int main(void)
{
    long long int i,n,box=0,min=1000001,max=-1000001,sum=0;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&box);

        sum+=box;
        if(box<=min)
        {
            min=box;
        }
        if(box>=max)
        {
            max=box;
        }

    }
    printf("%lld %lld %lld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 600
using System;

class Plogram
{
    static void Main()
    {
        var num = Console.ReadLine().Split();
        int D = int.Parse(num[0]);
        int N = int.Parse(num[1]);

        if(N==100)
        {
            Console.WriteLine(101 * (int)Math.Pow(100, D));
        }
        else
        {
            Console.WriteLine(N * (int)Math.Pow(100, D));
        }
    }
}

Measured memory_bytes: 11092
// AGC021
// A - Digit Sum 2

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_K = 16;

ll N;
int d[MAX_K + 1];

int solve() {
    int seq_9 = -1;
    int K;
    for (ll i = 0, t = 1; i <= MAX_K; i++, t *= 10) {
        d[i] = N / t % 10;
        if (d[i] == 9 && seq_9 == i - 1) {
            seq_9 = i;
        }
        if (d[i] != 0) {
            K = i + 1;
        }
    }
    if (seq_9 >= K - 2) {
        return d[K - 1] + (K - 1) * 9;
    }
    return d[K - 1] - 1 + (K - 1) * 9;
}

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll K;
    cin>>K;

    ll a=7;
    ll b=70;
    ll cnt = 0;
   set<ll> s;

    while(1){
        cnt++;
        s.insert(a);
        a = a%K;

        //cout<<"a----- "<<a<<endl;
        if(a % K == 0){
            //cout<<a<<endl;
            cout<<cnt<<endl;
            return 0;
        }

        
        //cout<<"b----- "<<b<<endl;
        a = a+b;
        if(s.find(a) != s.end()){
            cout<<-1<<endl;
            return 0;
        }        
        b = (10*b)%K;
    }

    return 0;
}

Measured memory_bytes: 50496
#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,c; cin >>a>>b>>c;
  cout << min(b/a,c) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  string l_str, r_str;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    l_str = s.substr(0, i);
    r_str = s.substr(i, 100);
    sort(l_str.begin(), l_str.end());
    sort(r_str.begin(), r_str.end());
    l_str.erase( unique(l_str.begin(), l_str.end()), l_str.end());
    r_str.erase( unique(r_str.begin(), r_str.end()), r_str.end());
    int cnt = 0;
    for (int k = 0; k < l_str.size(); k++) {
      for (int l = 0; l < r_str.size(); l++) {
        if (l_str[k] == r_str[l]) cnt++;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,k,n,l,r,s1,s2,s3,x;
    scanf("%d%d%d",&n,&l,&r);
    r++;
    s1=0;
    s2=0;
    s3=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(x<=l)
            s1++;
        else
        if(x>=r)
            s3++;
        else
            s2++;
    }
    printf("%d\n",min(s1,min(s2,s3)));
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
#define popcnt __builtin_popcount
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int edge[20],p[233],dp[1<<15|1];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),u,v;
	for(int i=1;i<=m;++i)u=gi(),v=gi(),edge[u]|=1<<v-1;
	p[0]=1;for(int i=1;i<233;++i)p[i]=p[i-1]*2%mod;
	for(int i=1;i<1<<n;++i){
		if(((i>>1)&1)^(i&1))continue;
		dp[i]=1;
		for(int N=i,P;N;N=(N-1)&i){
			P=i^N;int mul=1;
			for(int j=1;j<=n;++j)if((N>>j-1)&1)mul=1ll*mul*p[popcnt(edge[j]&P)]%mod;
			for(int j=1;j<=n;++j)if((P>>j-1)&1)mul=1ll*mul*(p[popcnt(edge[j]&N)]-1)%mod;
			dp[i]=(dp[i]+1ll*dp[P]*mul)%mod;
		}
	}
	int ans=1;for(int i=1;i<=m;++i)ans=ans*2%mod;
	ans=(ans-dp[(1<<n)-1]+mod)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
N,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
for looking in range(1,len(a)):
    calc=a[looking]+a[looking-1]
    if calc<=x:
        continue
    sa=calc-x
    taberu=min(a[looking],sa)
    a[looking]-=taberu
    ans+=taberu
    sa-=taberu
    a[looking-1]-=sa
    ans+=sa
print ans

#print a

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
int par[100001];
int find(int cur){
    if (par[cur] == cur){
        return cur;
    }
    par[cur] = find(par[cur]);
    return par[cur];
}
int main(){
  prep();
  int n;
  cin >> n;
  iota(par, par+n, 0);
  pair<int, int> xs[n];
  pair<int, int> ys[n];
  pair<int, int> arr[n];
  for (int i=0; i<n; i++){
      int x, y;
      cin >> x >> y;
      arr[i] = {x, y};
      xs[i] = {x, i};
      ys[i] = {y, i};
  }
  sort(xs, xs+n);
  sort(ys, ys+n);
  int diffx[n-1];
  int diffy[n-1];
  vector<pair<int, pair<int, int> > > together;
  for (int i=0; i<n-1; i++){
      together.emplace_back(abs(xs[i].first-xs[i+1].first), make_pair(xs[i].second, xs[i+1].second));
      together.emplace_back(abs(ys[i].first-ys[i+1].first), make_pair(ys[i].second, ys[i+1].second));
      
  }
  sort(together.begin(), together.end());
  long long sum = 0;
  for (int i=0; i<together.size(); i++){
      int a = together[i].second.first;
      int b = together[i].second.second;
      int para = find(par[a]);
      int parb = find(par[b]);
      if (para == parb){
          continue;
      }
      sum += together[i].first;
      if (para < parb){
          par[parb] = para;
      }else{
          par[para] = parb;
      }
  }
  cout << sum;
  return 0; 
}

Measured memory_bytes: 7668
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for i in range(n)]

for i in b:
    for j in range(3):
        if i == a1[j]:
            a1[j] = "x"
        if i == a2[j]:
            a2[j] = "x"
        if i == a3[j]:
            a3[j] = "x"
            
if a1.count("x") == 3 or a2.count("x") == 3 or a3.count("x") == 3:
    print("Yes")
elif a1[0] == "x" and a2[0] == "x" and a3[0] == "x":
    print("Yes")
elif a1[1] == "x" and a2[1] == "x" and a3[1] == "x":
    print("Yes")
elif a1[2] == "x" and a2[2] == "x" and a3[2] == "x":
    print("Yes")
elif a1[0] == "x" and a2[1] == "x" and a3[2] == "x":
    print("Yes")
elif a1[2] == "x" and a2[1] == "x" and a3[0] == "x":
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a[9] = {0};
    for (ll i = 0; i < 9; i++)
    {
        cin >> a[i];
    }
    
    ll n;
    cin>>n;

    vector<ll> b(n);
    for (ll k = 0; k < n; k++)
    {
        cin>>b[k];
        for (ll i = 0; i < 9; i++)
        {
            if(a[i]==b[k]){
                a[i]=0;
            }
        }
            
    }

    ll v[][3] = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
    for (ll i = 0; i < 8; i++)
    {
        if(a[v[i][0]]==0&&a[v[i][1]]==0&&a[v[i][2]]==0){
            cout<<"Yes"<<endl;
            exit(0);
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256