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

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

    int a[A],b[B];
    rep(i,A){
        cin>>a[i];
    }
    rep(i,B){
        cin>>b[i];
    }

    int x[M],y[M],c[M];
    rep(i,M){
        cin>>x[i]>>y[i]>>c[i];
    }

    int ans = 100000000;
    rep(i,M){
        int tmp = a[x[i]-1]+b[y[i]-1]-c[i];
        ans = min(ans,tmp);
    }
    int mina = 1000000;
    int minb = 1000000;
    rep(i,A){
        if(a[i]<mina)mina = a[i];
    }
    rep(i,B){
        if(b[i]<minb)minb = b[i];
    }
    int q = mina + minb;
    ans=min(ans,q);
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 2176
S = raw_input()
YYMM = 1<=int(S[2:])<=12
MMYY = 1<=int(S[:2])<=12

if YYMM and not MMYY:
  print "YYMM"
if not YYMM and MMYY:
  print "MMYY"
if YYMM and MMYY:
  print "AMBIGUOUS"
if not YYMM and not MMYY:
  print "NA"


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <time.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
const ll MAXN=2e3+5;
const ll MAXR=60000;
const ll INF=1e18;
const ll MOD=1e9+7;
ll n,k,a[MAXN],a1[MAXN],b1[MAXN];
ll mul(ll x,ll y)
{
    x%=MOD,y%=MOD;
    return x*y%MOD;
}
ll add(ll x,ll y)
{
    x%=MOD,y%=MOD;
    ll ret=x+y;
    if(ret>=MOD)
    {
        return ret-MOD;
    }
    return ret;
}
void solve()
{
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(a[j]<a[i])
            {
                a1[i]++;
            }
        }
        for(ll j=1;j<=n;j++)
        {
            if(a[j]<a[i])
            {
                b1[i]++;
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ll ans1=mul(k,a1[i]);
        ll ans2=mul(k*(k-1)/2,b1[i]);
        ans=add(ans,add(ans1,ans2));
    }
    printf("%lld\n",ans);
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
    while(~scanf("%lld %lld",&n,&k))
    {
//        string str2;
//        cin>>str2;
//      cout<<str2<<endl
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        solve();
    }
}
/*
*/


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int X,Y;
  cin>>X>>Y;
  for(int i=0;i<=X;i++){
    int j=X-i;
    if(i*4+j*2==Y){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N + 1);
	vector<ll> B(N);
	for (int i = 0; i <= N; i++) cin >> A[i];
	for (int j = 0; j < N; j++) cin >> B[j];
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		ll t = min(A[i], B[i]);
		sum += t;
		B[i] -= t;
		t = min(A[i + 1], B[i]);
		sum += t;
		A[i + 1] -= t;
	}
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int n;
  cin>>n;
  int a,b;
  cin>>a>>b;
  if((b-a)%2 == 0){
    cout<<"Alice"<<endl;
  }else{
    cout<<"Borys"<<endl;
  }
  return 0; 
}


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

using namespace std;

int ch[100005][2], val[100005], top = 1;

long long dfs(int u, long long d) {
  if (val[u]) return 0;
  long long ret = 0;
  for (int i = 0; i < 2; i++) {
    if (ch[u][i]) {
      ret ^= dfs(ch[u][i], d - 1);
    } else {
      int cnt = 1;
      long long t = d;
      while (t % 2 == 0) t /= 2, cnt++;
      ret ^= cnt;
    }
  }
  return ret;
}

int main(int argc, char *argv[]) {
  int n;
  long long L;
  cin >> n >> L;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int now = 0;
    for (auto c : s) {
      c -= '0';
      if (!ch[now][c]) ch[now][c] = top++;
      now = ch[now][c];
    }
    val[now] = 1;
  }
  cout << (!dfs(0, L) ? "Bob" : "Alice") << endl;
  return 0;
}


Measured memory_bytes: 7452
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

// UnionFind
class UF{
public:
    int n;
    vector<int> parent;
    vector<int> size;

    UF(int n){
        parent.resize(n);
        size.resize(n);
        for(int i = 0; i < n; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    bool unite(int a, int b){
        int parentA = find(a);
        int parentB = find(b);

        if(parentA == parentB){
            return false;
        }
        else{
            int sizeA = size[parentA];
            int sizeB = size[parentB];
            if(sizeA < sizeB){
                parent[parentA] = parentB;
                size[parentB] += sizeA;
            }
            else{
                parent[parentB] = parentA;
                size[parentA] += sizeB;
            }
            return true;
        }
    }

    int find(int node){
        int p = parent[node];
        if(p == node){
            return p;
        }
        else{
            int newP = find(p);
            parent[node] = newP;
            return newP;
        }
    }
};


int main(){

    int N, Q;
    cin >> N >> Q;
    
    UF uf(N);
    
    for(int i = 0; i < Q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            uf.unite(u, v);
        }
        else{   // t == 1
            if(uf.find(u) == uf.find(v)){
                cout << 1 << endl;
            }
            else{
                cout << 0 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4780
X = int(input())
primes = [1] * (10 ** 6) 
n = 1
primes[0] = 0
primes[1] = 0
while True:
    n += 1
    if primes[n] == 0:
        continue
    if n >= X:
        print(n)
        break
    i = 2
    while i * n < len(primes):
        primes[i * n] = 0
        i += 1


Measured memory_bytes: 16764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
  int a, b, c;
  cin >> a >> b;
  if (a < b) swap(a, b);
  while (a % b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  cout << b << endl;
}



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

int main() {
  int n, m, a, b;
  int cnt = 0;
  cin >> n >> m;
  vector<int> vec(100009);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  vector<map<string, string>> vmp(100009);

  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (vec.at(a-1) <= vec.at(b-1)) {
      vmp.at(a-1)["flg"] = "n";
    }
    if (vec.at(a-1) >= vec.at(b-1)) {
      vmp.at(b-1)["flg"] = "n";
    }
  }

  for (int i = 0; i < 100009; i++) {
    if (vmp.at(i)["flg"] == "n") {
      cnt++;
    }
  }
  cout << n - cnt << endl;
}

Measured memory_bytes: 19328
n = int(input())
s = [input() for _ in range(n)]
cnt_a = 0
cnt_b = 0
cnt_ba = 0
ans = 0
for i in range(n):
    ans += s[i].count('AB')
    if s[i][0] == 'B' and s[i][-1] == 'A':
        cnt_ba += 1
        continue
    if s[i][0] == 'B':
        cnt_b += 1
    if s[i][-1] == 'A':
        cnt_a += 1
if cnt_ba == 0:
    ans += min(cnt_a, cnt_b)
else:
    if cnt_a == 0 and cnt_b == 0:
        ans += max(cnt_ba - 1, 0)
    else:
        ans += cnt_ba + min(cnt_a, cnt_b)
print(ans)

Measured memory_bytes: 3700
#include <stdio.h>
  int main(){
   int a,b,c;
   int num1=0,num2=0;
   while(scanf("%d,%d,%d",&a,&b,&c) !=EOF){
          if(a==b) num2++;
          else if(a*a+b*b==c*c) num1++;
}
printf("%d\n%d\n",num1,num2);
return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var isUpper = Regex.IsMatch(Console.ReadLine(), "[A-Z]");

            Console.WriteLine(isUpper ? "A": "a");
        }
    }
}


Measured memory_bytes: 21600
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    K, T = MI()
    A= LI()
    A_max = max(A)
    others  = K - A_max
    if A_max < ceil(K,2):
        print(0)
    else:
        print(A_max - 1 - others)
if __name__ == '__main__':
    main()

Measured memory_bytes: 63468
#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 x, a, b;
	cin >> x >> a >> b;
	printf("%c\n", (abs(a-x) > abs(b-x)) ? 'B' : 'A');
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <cmath>  
#define INF 0x3f3f3f3f  
  
using namespace std;  
const int maxn=55;  
int N,a[maxn];  
  
int main()  
{  
    while(~scanf("%d",&N))  
    {  
        int t_min=INF,t_max=-INF;  
        int pos_min=1;  
        int pos_max=1;  
        for(int i=1;i<=N;i++)  
            scanf("%d",&a[i]);  
        for(int i=1;i<=N;i++)  
        {  
            if(a[i]<t_min)  
                t_min=a[i],pos_min=i;  
            if(a[i]>t_max)  
                t_max=a[i],pos_max=i;  
        }  
        printf("%d\n",N*2-2);  
        if(abs(t_min)<=abs(t_max))  
        {  
            for(int i=1;i<=N;i++)  
            {  
                if(i==pos_max) continue;  
                printf("%d %d\n",pos_max,i);  
            }  
            for(int i=2;i<=N;i++)  
                printf("%d %d\n",i-1,i);  
        }  
        else  
        {  
            for(int i=1;i<=N;i++)  
            {  
                if(i==pos_min) continue;  
                printf("%d %d\n",pos_min,i);  
  
            }  
            for(int i=N-1;i>=1;i--)  
                printf("%d %d\n",i+1,i);  
        }  
    }  
    return 0;  
}  

Measured memory_bytes: 256
#include <iostream>
int main()
{
    int a,b,c,d,e,f;
    std::cin >> a>>b>>c>>d>>e>>f;
    int x=a+b*5+c*10+d*50+e*100+f*500;
    if(x>=1000){
        std::cout<<"1"<<std::endl;
    }else{
        std::cout<<"0"<<std::endl;
    }   
   return 0;
}

Measured memory_bytes: 1160
//https://atcoder.jp/contests/abc139/tasks/abc139_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	string u;
	cin>>u;
	ll cnt=0;
	ll i;
	for(i=0;i<3;i++)
	{
		if(s[i]==u[i])
		{
			cnt=cnt+1;
		}
		else
		{
			cnt=cnt;
		}
	}
	cout<<cnt<<"\n";
	return 0;
	
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N, K;
  cin >> N >> K;

  long double ans=0;

  REP(i,N){
    int now=i+1;
    double prob=1.0/N;
    while(now<K){
      now*=2;
      prob/=2;
    }
    ans+=prob;
  }

  cout <<fixed << setprecision(9) <<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x" , tle)
print("RE x" , re )

Measured memory_bytes: 9212
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

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

	ll N;
	cin >> N;
	vector<ll> A(N);

	rep(i, N) {
		cin >> A[i];
	}

	//vector<ll> B(A);

	//ll  DP[100000][2];
	//DP[0][0] = 0;
	//DP[0][1] = 0;

	rep(i, N - 2) {
		if (A[i] < 0) {
			A[i] *= -1;
			A[i + 1] *= -1;
		}
	}

	//rrange(i, N, 1) {
	//	if (B[i] < 0) {
	//		B[i] *= -1;
	//		B[i - 1] *= -1;
	//	}
	//}

	if (A[N - 1] < 0 && A[N - 2] < 0) {
		A[N - 1] *= -1;
		A[N - 2] *= -1;
	}
	else if (A[N - 1] < 0 || A[N - 2] < 0) {
		ll dst = max(abs(A[N - 1]), abs(A[N - 2]));
		if (dst == -A[N - 1]) {
			A[N - 1] *= -1;
			A[N - 2] *= -1;
		}
		else if (dst == -A[N - 2]) {
			A[N - 1] *= -1;
			A[N - 2] *= -1;
		}
	}


	ll ret = 0;
	bool flg = false;
	rep(i, N) {
		if (A[i] < 0) {
			ret += -A[i];
			A[i] = -A[i];
			flg = true;
		}
		else {
			ret += A[i];
		}
	}

	if (flg) {
		ret -= (*min_element(A.begin(), A.end())) * 2;
	}


	cout << ret << endl;

	
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define Ns 10000
#define Nt 500

int linearSearch(int, int*, int);


int main(){

  int n, q, key, result, count=0;
  int i, j;
  int S[Ns], T[Nt];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &T[i]);
  }
   
  for(i=0; i<q; i++){
    key=T[i];
    //printf("key=%d\n", key);
    result=linearSearch(n, S, key);
    //printf("result=%d\n", result);
    if(result!= -1) count++;
  }
  printf("%d\n", count);
  return 0;
}
int linearSearch(int n, int S[], int key){

  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n) return -1;
  }
  return i;

}



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

long inf = 1000000007;


int main() {
	int n; cin >> n;
	int a = n%10;
	n /= 10;
	int b = n % 10;
	n /= 10;
	
	if (a == 7 or b == 7 or n == 7) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3588
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict.setdefault(A, 0)
  num_dict[A] += B
  A_list.append(A)

A_list = list(set(A_list))
A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)

 

Measured memory_bytes: 32024
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let c: HashSet<String> = s.into_iter().collect();
    println!("{}", c.len());
}


Measured memory_bytes: 21492
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n , k ;
    cin >> n >> k ;
    int count = 0;
    int ans = 1 ;
    if(k>n){
        cout << 1 << endl;
    }else{
    while(n>=ans){
        ans = ans * k;
        count++;
    }
    

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

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

int N,M;
using ll=long long;
ll dp[100010];
const int MOD=1000000007;

int main(){
  cin >> N >> M;
  set<int> S;
  for(int i=0;i<M;i++){
    int x;
    cin >> x;
    S.insert(x);
  }
  dp[0]=1;
  for(int i=0;i<N;i++){
    if (S.count(i)) continue;
    dp[i+2]=(dp[i+2]+dp[i])%MOD;
    dp[i+1]=(dp[i+1]+dp[i])%MOD;
  }
  
  cout << dp[N] << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	long long a, b;
	cin>>a>>b;
	long long g = __gcd(a, b);
	long long res = 1;
	long long m = g;
	for (long long i = 2; i * i <= m; i++)
		if (g % i == 0) {
			res++;
			while (g % i == 0)
				g /= i; 
		}
	res += (g > 1);
	cout<<res;	
}


Measured memory_bytes: 256
var
	K:Longint;
	L,R,M:int64;
function check(T:int64):Longint;
var
	dp:Array[1..15,0..1,0..1,0..9]of Longint;
	S:String;
	i,j,k,l,nj,lim,sum,z,llim,rlim:Longint;
begin
	S:='';
	while T>0 do begin
		S:=Chr(T mod 10+48)+S;
		T:=T div 10;
	end;
	for i:=1 to length(S)+1 do for j:=0 to 1 do for z:=0 to 1 do for k:=0 to 9 do dp[i,j,z,k]:=0;
	dp[1,0,1,0]:=1;
	for i:=1 to length(S) do begin
		for j:=0 to 1 do begin
			if j=0 then lim:=ord(S[i])-48 else lim:=9;
			inc(dp[i+1,1,1,0],dp[i,j,1,0]);
			for l:=1 to lim do begin
				nj:=j;
				if l<lim then nj:=1;
				inc(dp[i+1,nj,0,l],dp[i,j,1,0]);
			end;
			for k:=0 to 9 do begin
				llim:=k-1;if llim<0 then llim:=0;
				rlim:=k+1;if rlim>lim then rlim:=lim;
				for l:=llim to rlim do begin
					nj:=j;
					if l<lim then nj:=1;
					inc(dp[i+1,nj,0,l],dp[i,j,0,k]);
				end;
			end;
		end;
	end;
	sum:=0;
	for k:=0 to 9 do for i:=0 to 1 do begin
		inc(sum,dp[length(S)+1,i,0,k]);
	end;
	check:=sum;
end;
begin
	read(K);
	L:=0;
	R:=3234566667;
	while R-L>1 do begin
		M:=(L+R)div 2;
		if check(M)>=K then R:=M else L:=M;
	end;
	writeln(R);
end.


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

using namespace std;
#define int long long
#define x first
#define y second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(136786931);
int randlr(int l, int r) {
    return rand1() % (r - l + 1) + l;
}

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

    int k;
    cin >> k;

    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k - 1];

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template<uint64 MOD>
class modint {
public:
	uint32 a;
	modint(uint32 x = 0) :a(x < MOD ? x : x%MOD) {}
	const modint operator+(const modint &o) const{
		if (a + o.a < MOD) return modint(a + o.a);
		return modint(a + o.a - MOD);
	}
	modint &operator+=(const modint &o) {
		a += o.a;
		if (a >= MOD) a -= MOD;
		return *this;
	}
	const modint operator-(const modint &o) const{
		if (a < o.a) return modint(a + MOD - o.a);
		return modint(a - o.a);
	}
	modint &operator-=(const modint &o) {
		if (a < o.a) a += MOD;
		a -= o.a;
		return *this;
	}
	const modint operator*(const modint &o) const{
		return modint((uint64)a*(uint64)o.a%MOD);
	}
	modint &operator*=(const modint &o) {
		a = (uint64)a*(uint64)o.a%MOD;
		return *this;
	}
	const modint operator/(const modint &o) const {
		return *this*~o;
	}

	const modint operator-() const{
		if (a) return modint(MOD - a);
		return modint(0);
	}
	modint operator++() {
		++a;
		if (a == MOD) a = 0;
		return *this;
	}
	modint operator++(int) {
		if (a == MOD - 1) {
			a = 0;
			return modint(MOD - 1);
		}
		++a;
		return modint(a - 1);
	}
	modint operator--() {
		if (a) {
			--a;
		}
		else {
			a = MOD - 1;
		}
		return *this;
	}
	modint operator--(int) {
		if (a) {
			--a;
			return modint(a + 1);
		}
		a = MOD - 1;
		return modint(0);
	}
	modint operator~() const {
		int64 x = a, y = MOD, u = 1, v = 0, t;
		while (y) {
			t = x / y;
			x -= t*y;
			std::swap(x, y);
			u -= t*v;
			std::swap(u, v);
		}
		return modint(u);
	}
	bool operator!() const{
		if (a) return false;
		return true;
	}
	bool operator==(const modint o) const{
		return a == o.a;
	}
	bool operator!=(const modint o) const{
		return a != o.a;
	}
	bool operator<(const modint o) const{
		return a < o.a;
	}
	bool operator<=(const modint o) const{
		return a <= o.a;
	}
	bool operator>(const modint o) const{
		return a > o.a;
	}
	bool operator>=(const modint o) const{
		return a >= o.a;
	}
};

using mint = modint<1000000007>;
int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n;
	std::string s;
	std::cin >> n >> s;
	mint dp[5003][5003] = {};
	dp[0][0] = mint(1);
	for (uint32 i = 1;i <= n;++i) {
		dp[i][0] = dp[i - 1][1] + dp[i - 1][1] + dp[i - 1][0];
		for (uint32 j = 1;j <= i;++j) {
			dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j + 1];
		}
	}
	std::cout << dp[n][s.length()].a << "\n";
	return 0;
}

Measured memory_bytes: 195840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		StringBuffer firstSb = new StringBuffer();
		firstSb.append("a");
		dfs(n, firstSb, 2);
	}
	
	String[] alphavetArr = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

	public void dfs(int length, StringBuffer sb, int numOfKind) {
		if(length == sb.length()) {
			System.out.println(sb.toString());
			return;
		}
		
		for(int i = 0; i < numOfKind; i++) {
			StringBuffer nextSb = new StringBuffer();
			nextSb.append(sb);
			nextSb.append(alphavetArr[i]);
			if(i == numOfKind - 1) {
				dfs(length, nextSb, numOfKind+1);
			}else {
				dfs(length, nextSb, numOfKind);
			}
		}
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll Euclid(ll A, ll B){
    if(A<B) swap(A, B);
    ll C = B;
    while(C != 0){
        C = A%B;
        A = B;
        B = C;
    }
    return A;
}

ll lcm(ll A, ll B){
    ll C = Euclid(A, B);
    return A*(B/C); //()がないとオーバーフローする可能性があるので注意！
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    ll x = a[0]/2;
    REP(i, N){
    	x = lcm(a[i]/2, x);
    }

    bool ok = true;
    REP(i, N){
    	ll val = x/(a[i]/2);
    	if(val%2==0) ok =false;
    }

    //dump(x)

    ll res = 0;
    if(ok){
    	res = ((M/x)+1)/2;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int main(){
    int dp[50];
    rep(i,50)dp[i]=0;
    dp[0]=1;
    rep(i,35){
        for(int j=1;j<=3;j++){
            dp[i+j]+=dp[i];
        }
    }
    
    
    int n;
    while(cin>>n&&n){
        cout<<ceil(dp[n]/3650.0)<<endl;
    }
}

Measured memory_bytes: 3284
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=l if l<H and A[i]<A[l]else i
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65088
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

const ll mod = 2019;



int main() {
	string s;
	cin >> s;
	int n = s.size();
	reverse(s.begin(), s.end());

	ll a[n + 1];

	a[0] =0;
	ll degit = 1;

	for(int i = 0; i < n; i++) {
		a[i + 1] = (a[i] + (s[i] - '0') * degit) % 2019;
		degit = (degit * 10) % 2019;
	}

	vector<ll> b(2019, 0);
	for (int i = 0; i < n + 1; i++) {
		b[a[i]]++;
	}
	ll ans = 0;
	for (int i = 0; i < 2019; i++) {
		if (b[i] > 1) {
			ans += b[i] *( b[i] - 1) / 2;
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 4788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int k, s, cnt = 0;
    cin >> k >> s;

    for(int i = max(0,s-2*k); i <= k; i++){             //iはzの値
        for(int j = max(0,s-i-k); j <= min(k,s-i); j++){       //jは
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<functional>
#include<queue>
#include<cctype>
#include<algorithm>

#define MAXN 1024

using namespace std;

struct state{
  int i,j;
  int cost;
  state(int i, int j, int cost):i(i),j(j),cost(cost){}
};

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
const int infty =  1<<28;

int dist[10][10];

bool isinside(int i, int j, int H, int W){
  return 0<=i&&i<H&&0<=j&&j<W;
}

int compute_dist(int n, int H, int W, char M[MAXN][MAXN]){
  int si,sj;
  queue< state > q;
  bool vis[H][W];
  dist[n][n]=0;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      vis[i][j]=false;
      if(M[i][j]-'0' == n){
	si = i;
	sj = j;
      }
    }
  }
  q.push( state(si,sj,0) );
  while(!q.empty()){
    state nst=q.front();q.pop();
    for(int k = 0; k < 4; ++k){
      int ni = nst.i + di[k];
      int nj = nst.j + dj[k];
      if( isinside(ni,nj,H,W) && !vis[ni][nj] && M[ni][nj] !='X' ){
	if( isdigit(M[ni][nj]) ){
	  dist[n][M[ni][nj]-'0'] = nst.cost+1;
	}
	vis[ni][nj]=true;
	q.push( state(ni,nj,nst.cost+1) );
      }
    }
  }
}

int solve(int H, int W, int N, char M[MAXN][MAXN])
{
  int vis[N];
  for(int i = 0; i <= N; ++i){
    compute_dist(i,H,W,M);
    if(i>0)vis[i-1]=i;
  }
  int min_cost = infty;
  do{
    int now=0;
    int now_power = 1;
    int cost=0;
    for(int i = 0; i < N; ++i){
      if( now_power < vis[i] ){
	cost = infty;
	break;
      }else{
	now_power += 1;
	//cout << now << ' ' << vis[i] << ' ' << dist[now][vis[i]] << endl;
	cost += dist[now][vis[i]];
	now = vis[i];
      }
    }
    min_cost = min( min_cost, cost );
  }while(next_permutation(vis,vis+N));
  return min_cost;
}

int main()
{
  int H,W,N;
  while(cin >> H >> W >> N){
    static char M[MAXN][MAXN];
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	cin >> M[i][j];
	if(M[i][j]=='S')M[i][j]='0';
      }
    }
    cout << solve(H,W,N,M) << endl;
  }
  return 0;
}

Measured memory_bytes: 2848
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<int,int> P;
#define fi first
#define se second
int main(){
ios::sync_with_stdio(false);
   cin.tie(0);
int n,d;
cin>>n>>d;
vector<vector<int>> x(n,vector<int>(d));
for(int i=0;i<n;i++)for(int j=0;j<d;j++)cin>>x.at(i).at(j);
int count=0;
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
         int sum=0;
        for(int k=0;k<d;k++){
            sum+=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
        }
          int check=sqrt(sum);
          if(sum==check*check){
              count++;
          }
    }
}
cout<<count<<endl;
}


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

int main() {
  int n;cin>>n;
  vector<int> ans(n+1);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        int cnt=x*x+y*y+z*z+x*y+y*z+z*x;
        if(cnt<=n)ans[cnt]++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3656
import random
import sys
input = sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
cn=sorted(c)
h=cn[3]
P=[k+1 for k,v in enumerate(c) if v>=h]
s=[]
for _ in range(d):
    s.append(list(map(int,input().split())))
# t=[]
# for _ in range(d):
#     t.append(int(input()))
# m=int(input())
t=[]
for _ in range(d):
    z=random.randrange(len(P))
    t.append(P[z])

m=1000
q=[]
for _ in range(m):
    z2=random.randrange(len(P))
    z1=random.randrange(d)
    q.append([z1,P[z2]])
p=0
for k in range(m):
    ld=[-1]*26
    sc=0
    od=t[q[k][0]-1]
    t[q[k][0]-1]=q[k][1]

    for i in range(d):
        sc+=s[i][t[i]-1]
        ld[t[i]-1]=i

        C=0
        for j in range(26):
            C+=c[j]*(i-ld[j])
        sc-=C
    if p<sc:
        p=sc
    else:
        t[q[k][0]-1]=od

for f in range(len(t)):
    print(t[f])


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct edge{
  int from, to, cost;

  edge(int f, int t, int c) : from(f), to(t), cost(c) {}
};

bool operator < (const edge& a, const edge& b) {
  return a.cost < b.cost;
}
  
int N;
vector<P> x,y;
int p[100001];
int r[100001];
vector<edge> e;


void init(int N) {
  for(int i = 0; i < N; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int Find(int x) {
  if(x == p[x]) return x;
  return p[x] = Find(p[x]);
}

bool Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return false;
  
  if(r[a] > r[b]) p[b] = a;
  else {
    p[a] = b;
    if(r[a] == r[b]) r[b]++;
  }
  
  return true;
}

int main() {
  cin >> N;

  for(int i = 0; i < N; i++) {
    int xx, yy;
    cin >> xx >> yy;
    x.push_back(P(xx,i));
    y.push_back(P(yy,i));
  }    

    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    for(int i = 1; i < N; i++) {
      e.push_back(edge(x[i].second,x[i-1].second,x[i].first-x[i-1].first));
      e.push_back(edge(x[i-1].second,x[i].second,x[i].first-x[i-1].first));
      e.push_back(edge(y[i].second,y[i-1].second,y[i].first-y[i-1].first));
      e.push_back(edge(y[i-1].second,y[i].second,y[i].first-y[i-1].first));
    }
    
 sort(e.begin(),e.end());
 /* for(int i = 0; i < e.size(); i++) {
    cout <<e[i].from<<e[i].to<<e[i].cost<<endl;
  }
 */
  init(N);
  ll ans = 0;
  for(int i = 0; i < e.size(); i++) {
     
    if(Union(e[i].from,e[i].to)) {
      ans += e[i].cost;
      //cout <<"aaa"<<endl;
     
    }
  }


  cout << ans << endl;
    
}  


Measured memory_bytes: 10724
package main

import (
	"fmt"
	"math"
)

func main() {
	var ans []float64
	for {
		var n int
		fmt.Scan(&n)
		if n == 0 {
			break
		}
		var sum, mean float64
		s := make([]float64, n)
		for i := range s {
			fmt.Scan(&s[i])
			sum += s[i]
		}
		mean = sum / float64(n)
		var d float64
		for i := range s {
			d += (s[i] - mean) * (s[i] - mean)
		}
		d /= float64(n)
		ans = append(ans, math.Sqrt(d))
	}
	for i := range ans {
		fmt.Println(ans[i])
	}
}



Measured memory_bytes: 1268
chk s b =
  ( (b!!0 == s) && (b!!1 == s) && (b!!2 == s) ) ||
  ( (b!!3 == s) && (b!!4 == s) && (b!!5 == s) ) ||
  ( (b!!6 == s) && (b!!7 == s) && (b!!8 == s) ) ||

  ( (b!!0 == s) && (b!!3 == s) && (b!!6 == s) ) ||
  ( (b!!1 == s) && (b!!4 == s) && (b!!7 == s) ) ||
  ( (b!!2 == s) && (b!!5 == s) && (b!!8 == s) ) ||

  ( (b!!0 == s) && (b!!4 == s) && (b!!8 == s) ) ||
  ( (b!!2 == s) && (b!!4 == s) && (b!!6 == s) )

ans b
  | chk 'o' b = "o"
  | chk 'x' b = "x"
  | otherwise = "d"

main = do
  c <- getContents
  let i = lines c
      o = map ans i
  mapM_ putStrLn o
  

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

int main() {
    int A,B;
    cin >> A >> B;
    if((A-B)>=(A+B)) {
      if((A-B)>=(A*B)) cout << A-B << endl;
      else cout << A*B << endl;
    }
    else {
      if((A+B)>=(A*B)) cout << A+B << endl;
      else cout << A*B << endl;
    }
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<cmath>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
signed main(){
  init_io();
  ll r;
  cin >> r;
  cout << r*2*M_PI<<endl;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
int n,a[111111];
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	a[0] = a[n+1] = 0;
	int tot = 0;
	for(int i=1; i<=n+1; i++)
		tot += labs(a[i] - a[i-1]);
	for(int i=1; i<=n; i++){
		printf("%d\n",tot - labs(a[i] - a[i-1]) - labs(a[i+1] - a[i]) + labs(a[i+1] - a[i-1]));
	}
	return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int K,A,B;
	cin >> K>>A>>B;

	string s;
	//cin >> s;

	int n = K;
	while (true)
	{
		if (n >= A && n <= B)
		{
			cout << "OK" << endl;
			break;
		}
		else if (n > B)
		{
			cout << "NG" << endl;
			break;
		}
		n += K;
	}

	//cout << N << endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

vector<vector<int>> mat(100007);
vector<bool> visited(100007,false); 
vector<int> t;
vector<int> paths(100007);

void t_sort(int v)
{
    if(visited[v]) return;
    for(int i=0; i<mat[v].size(); i++)
    {
        t_sort(mat[v][i]);
    }
    t.push_back(v);
    visited[v]=true;
}

int main()
{
    int N,M;
    scanf("%d %d\n",&N,&M);
    for(int i=0,x,y; i<M; i++)
    {
        scanf("%d %d\n",&x,&y);
        mat[x].push_back(y);
    }

    for(int i=1; i<=N; i++)
    {
        t_sort(i);
    }
    reverse(t.begin(), t.end());
    
    for(int i=0; i<N; i++)
    {
        for(int k=0; k<mat[t[i]].size(); k++)
        {
            paths[ mat[t[i]][k] ]=max(paths[t[i]]+1, paths[ mat[t[i]][k] ]);
            //printf("%d %d p%d\n",t[i],k,paths[ mat[t[i]][k] ]);
        }
    }

    int res=0;
    for(int i=1; i<=N; i++){ res=max(paths[i],res); }
    printf("%d\n",res);

    return 0;
}

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

vector < set<int> > adj(28);
string s;
char c;
int q, a, b, d, ans;
int main()
{
 	int n;
    cin >> n >> s >> q;
    s = 'a' + s;
    for(int i = 1; i < s.size(); ++i)
        adj[s[i] - 'a'].insert(i);
    set<int>::iterator it;
    while(q--)
    {
        cin >> a;
        if(a == 1)
        {
            cin >> b >> c;
            adj[s[b] - 'a'].erase(b);
            s[b] = c;
            adj[c - 'a'].insert(b);
        }
        else
        {
            ans = 0;
            cin >> b >> d;
            for(int i = 0; i < 27; ++i)
            {
                it = adj[i].lower_bound(b);
              	
                ans += (*it <= d && *it >= b);
            }
            cout << ans << '\n';
        }
    }
}

Measured memory_bytes: 27252
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,K;
    ll res;

    cin >> N >> K;

    if(N % K == 0)res = 0;
    else res = 1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int p,q;
  if(a[0] > a[1]){
    p = 0;
    q = 1;
  }else{
    p = 1;
    q = 0;
  }
  for(int i=2;i<n;i++){
    if(a[p]<a[i]){
      q = p;
      p = i;
    }else if(a[q]<a[i]){
      q = i;
    }
  }
  for(int i=0;i<n;i++){
    if(i==p){
      printf("%d\n",a[q]);
    }else{
      printf("%d\n",a[p]);
    }
  }

  return 0;
}

Measured memory_bytes: 2304
#include <cstdio>
#include <algorithm>

typedef long long int64;

int main() {
	int64 n, i, b;
	int64 ans;
	
	scanf("%lld", &n);
	ans = 1 + n;
	for(i=2; i*i<=n; i++) 
		if(!(n%i))
			ans = std::min(ans, i + n / i);
	printf("%lld\n", ans-2);
	return 0;
}

Measured memory_bytes: 128
while True:
    h ,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(w):
            print('#', end = '')
        print('')
    
        for i in range(h - 2):
            print('#', end = '')
            for i in range(w - 2):
                print('.', end = '')
            print('#')
        
        for i in range(w):
            print('#', end = '')
        print('')
        print('')


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

int main()
{
	int n, left, right, mid, M1, M2;
	string s;
	cin >> n;
	cout << "0" << endl;
	cin >> s;
	if (s[0] == 'V')
		return 0;
	if (s[0] == 'M')
		M1 = 1;
	else
		M1 = 0;
	left = 0, right = n;
	while (left < right)
	{
		mid = (right + left) / 2;
		cout << mid << endl;
		cin >> s;
		if (s[0] == 'V')
			return 0;
		if (s[0] == 'M')
			M2 = 1;
		else
			M2 = 0;
		int t = (mid - left);
		if (t % 2 == 0)
		{
			if (M1 == M2)
				left = mid;
			else
				right = mid;
		}
		else
		{
			if (M1 == M2)
				right = mid;
			else
				left = mid, M1 = M2;
		}
	}
	cout << flush;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#include <math.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;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int x,a,b;
cin >> x >> a >> b;
if(a>=b) {
  cout << "delicious" <<endl;
} else if(a<b&&b<=a+x) {
  cout << "safe" << endl;
} else {
  cout << "dangerous" << endl;
}
return 0;
}


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

int main()
{
  string s;
  int count = 0;

  cin >> s;
  for (int i = 0; i < 3; i++)
  {
    if (s.at(i) == '1')
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
s = ""

def rec(i, word):
    if i == len(s):
        return eval("".join(word))
    ans = 0
    word.append('+')
    word.append(s[i])
    ans += rec(i+1, word)
    word.pop()
    word.pop()
    word.append(s[i])
    ans += rec(i+1, word)
    word.pop()
    return ans

def main():
    global s
    s = input()
    print(rec(1, [s[0]]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<unordered_map>
#include<bitset>
#include<cctype>
#include<sstream>
#define LL long long
#define ULL  unsigned  long long
#define maxn (LL)1e6
#define INF 0x3f3f3f3f
#define inf 0x7fffffff
#define PI  acos(-1.0)
#define pb push_back
#define re register LL
const double eps = 0.0000001;
using namespace std;
typedef pair<int,int> pii;
inline int sgn(double x) {
    return (x > eps) - (x < -eps);
}
static char buf[100000],*pa=buf,*pd=buf;
#define gc pa==pd&&(pd=(pa=buf)+fread(buf,1,100000,stdin),pa==pd)?EOF:*pa++
inline int read()
{
    register LL x(0),f(1);register char c(gc);
    while(c>'9'||c<'0')f=c=='-'?-1:1,c=gc;
    while(c>='0'&&c<='9')x=x*10+c-48,c=gc;
    return f*x;
}
int T,n,m;
LL A[10000];
int  main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
   // freopen("outl.txt","r",stdin);
    #endif // ONLINE_JUDE
    cin>>n;
    long double ans = 1;
    for(int i = 1;i<=n;++i) {
        cin>>A[i];
        ans *= A[i];
    }
    long double sum = 0;
    for(int i = 1;i<=n;++i)
    {
        sum += ans/A[i];
    }
    cout<<(long double)ans*1.0/sum<<endl;




}


Measured memory_bytes: 256
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if len(s)!=0:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
    if len(q)!=0:
            #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans += -p
print(ans)




Measured memory_bytes: 27880
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int seki = a * b;
            string retStr = "Odd";
            if (seki % 2 == 0)
            {
                retStr = "Even";
            }

            Console.WriteLine(retStr);
        }
    }

Measured memory_bytes: 11092
#include<stdio.h>

int main(void) {
   int a, b, c;

   scanf("%d %d %d",&a, &b, &c);

   if(a == b && b == c || a != b && b != c && a != c) {
      printf("No");
   } else {
      printf("Yes");
   }
   return 0;
}


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

int f[101][101];
int main() {
  int persim, w, h, x, y, max;
  while (cin >> persim && persim) {
    max = 0;
    cin >> w >> h;
    for (int i = 0; i < 101; i++)
      for (int j = 0; j < 101; j++) f[i][j] = 0;
    for (int i = 0; i < persim; i++) {
      cin >> x >> y;
      f[x][y] = 1;
    }
    for (int i = 1; i < 101; i++)
      for (int j = 1; j < 101; j++) {
        f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
      }
    cin >> x >> y, x--, y--;
    for (int i = 1; i + x <= w; i++) {
      for (int j = 1; j + y <= h; j++) {
        int n = f[i + x][j + y] - f[i + x][j - 1] - f[i - 1][j + y] +
                f[i - 1][j - 1];
        if (n > max) max = n;
      }
    }
    cout << max << endl;
  }
  return 0;
}



Measured memory_bytes: 3060