akhauriyash/Code-Regression huggingface dataset:
import sys

N, M, X = map(int, sys.stdin.readline().strip().split())

C = []
A = []
for _ in range(N):
    c, *a = map(int, sys.stdin.readline().strip().split())
    C.append(c)
    A.append(a)

ans = float('inf')

for i in range(2 ** N):
    bit = [(i >> j) & 1 for j in range(N)]  # 本を購入するかしないか

    understand = [0] * M
    for i, b in enumerate(bit):
        if b != 0:
            # print(f'i: {i}, lenA: {len(A)}, len under: {len(understand)}')
            understand = [x + y for x, y in zip(A[i], understand)]

    if min(understand) >= X:
        cost = [c * b for c, b in zip(C, bit)]
        ans = min(sum(cost), ans)

if ans == float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,a,b;
    cin>>x>>a>>b;
    x -= a;
    x -= b*(x/b);
    cout<<x<<endl;
}


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

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

typedef long long ll;
typedef long double ld;

int main(){
    int n,a,b; 
    cin >> n >> a >> b;
    string s; cin >> s;
    int san,pass(0),f(1);
    san = a+b;

    for(int i=0;i<n;i++){
        if(pass < san){
            if(s[i]=='a'){
                cout << "Yes" << endl;
                pass++;
                continue;
            }
            if(s[i]=='b' && f<=b){
                cout << "Yes" << endl;
                pass++;
                f++;
                continue;
            }
        }
    cout << "No" << endl;
    }
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e,f,g,h,i,j,k;
  cin>>a;
  b=a/100000000;
  c=a%100000000/10000000;
  d=a%10000000/1000000;
  e=a%1000000/100000;
  f=a%100000/10000;
  g=a%10000/1000;
  h=a%1000/100;
  i=a%100/10;
  j=a%10;
  k=b+c+d+e+f+g+h+i+j;
  if(a%k==0){
    cout<<"Yes"<<endl;
  }
    else{
      cout<<"No"<<endl;
    }
}
  

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

using namespace std;
vector<int> adj[200200];
vector<int> v(200200),c(200200);
void dfs(int u,int p,int val){
	c[u] = val + v[u];
	for(int v : adj[u]){
		if(v!=p){
			dfs(v,u,c[u]);
		}
	}
}
main(){
	int n,q;
	cin >> n >> q;
	for(int i=1;i<n;i++){
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for(int i=0;i<q;i++){
		int a,b;
		cin >> a >> b;
		v[a] += b;
	}
	dfs(1,-1,0);
	for(int i=1;i<=n;i++){
		cout << c[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 24320
s = input()
n = len(s)
f = ''
for i in range(2**(n-1)):
  b = format(i, 'b').zfill(n)
  for j in range(n):
    if b[j] == '1':
      f += '+' + s[j]
    else:
      f += s[j]
  f+= '+'
print(eval(f[:len(f)-1]))

Measured memory_bytes: 4140
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<atcoder/all>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

string s[55];
Int ans, cnt;

int main(){
    int n, m;
    cin >> n >> m;
    atcoder::mcf_graph<Int, Int> mcf(n*m + 2);
    Int S = n*m;
    Int T = S + 1;

    auto index = [&](int x, int y){return x * m + y;};
    for(int i = 0;i < n;i++)cin >> s[i];

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(s[i][j] == '#')continue;
            if(i && s[i-1][j] != '#')mcf.add_edge(index(i-1,j), index(i,j), n*m, 0);
            if(j && s[i][j-1] != '#')mcf.add_edge(index(i,j-1), index(i,j), n*m, 0);
            if(s[i][j] == 'o'){
                cnt++;
                ans -= i + j;
                mcf.add_edge(S, index(i,j), 1, 0);
            }
            mcf.add_edge(index(i, j), T, 1, n + m - i - j);
        }
    }

    Int cost = mcf.flow(S, T, cnt).second;
    ans += cnt * (n + m) - cost;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>
int main(){
    int  H,W,i,l;
    while(1){
        scanf("%d %d",&H,&W);
        if(H ==0 && W ==0)break;
        for(l=1;l<=H;l++){
        for(i=1;i<=W;i++){
            printf("#");
        }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2040
import sys
s=raw_input()
while True:
    flag=True
    n=len(s)
    if n==0:print 'YES';sys.exit()
    if n>4:
        if s[n-5:]=='dream' or s[n-5:]=='erase':
            s=s[:n-5]
            flag=False
    n=len(s)
    if n>5:
        if s[n-6:]=='eraser':
            s=s[:n-6]
            flag=False
    n=len(s)
    if n>6:
        if s[n-7:]=='dreamer':
            s=s[:n-7]
            flag=False
    if flag: print 'NO';sys.exit()
        


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> A;

    A = vector<vector<int>>(2, vector<int>(n));

    for(int i=0; i<2; i++){
        for(int j=0; j<n; j++){
            cin >> A[i][j];
        }
    }

    int max_counter=0;
    for(int i=0; i<n; i++){
        int counter=0;
        for(int j=0; j<n ; j++){
            if(j==i){
                counter += A[0][j] + A[1][j];
            }else if(j>i){
                counter += A[1][j];
            }else{
                counter += A[0][j];
            }
        }

        if(max_counter<counter){
            max_counter=counter;
        }
    }

    cout << max_counter;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    bool flag = 1;
    REP(i, N) {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 == 0 || a[i] % 5 == 0) {
                continue;
            } else {
                flag = 0;
                break;
            }
        }
    }
    if (flag) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
}

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

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = 9999999999;
    if (y >= x) ans = min(ans, y-x);
    if (-y >= x) ans = min(ans, 1-y-x);
    if (y >= -x) ans = min(ans, 1+y+x);
    if (-y >= -x) ans = min(ans, 2-y+x);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long m,n,res=0,x,a,b,res1=0;
    cin>>m>>n>>a>>b;

    if(m<=n)
    {
        res=m*a;
    }
    if(m>n)
    {
           res=n*a;

        x=m-n;
        res1=x*b;


    }


    res=res+res1;
    cout<<res<<endl;


    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def get_result(data):
    N, X, Y = data
    dist_cnt = [0 for i in range(N)]
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
            dist_cnt[min_dist] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int n,m,a[60],b[60],c[60],d[60];

int calc(int p,int q) {
  return abs(a[p]-c[q]) + abs(b[p]-d[q]);
}

int main() {
  cin >> n >> m;
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,m) cin >> c[i] >> d[i];
  rep(i,n) {
    int ptr = 0;
    REP(j,1,m) {
      if( calc(i,ptr) > calc(i,j) ) {
	ptr = j;
      }
    }
    cout << ptr + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
h = gets.chomp.split(' ').map{ |e| e.to_i }

dp = [0, (h[0] - h[1]).abs]

(n - 2).times{|ii|
  i = ii + 2
  cand1 = dp[i - 1] + (h[i - 1] - h[i]).abs
  cand2 = dp[i - 2] + (h[i - 2] - h[i]).abs
  # dp[0] = dp[1]
  if cand1 < cand2
    dp.push(cand1)
  else
    dp.push(cand2)
  end
  # p [h, dp]
}
puts dp.last


Measured memory_bytes: 11392
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k; cin>>n>>k;
    if(k==1) cout<<0<<endl;
    else cout<<n-k<<endl;
    return 0;
}

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

int a,N;
   cin>>a>>N;
  vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);}
vector<int> f(N);
  for(int i=0;i<N-1;i++){f.at(i)=vec.at(i+1)-vec.at(i);}
  f.at(N-1)=a-vec.at(N-1)+vec.at(0);
    sort(f.begin(),f.end());
  cout<<a-f.at(N-1)<<endl;
}

Measured memory_bytes: 1792
n=int(input())
if n==0 or n==1:
    print(1)
else:
    fib=[0]*(n+1)
    fib[0]=1
    fib[1]=1
    for i in range(2,n+1):
        fib[i]=fib[i-1]+fib[i-2]
    print(fib[n])



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
int main(){
	int l=read(),r=read();
	if(l<=0 && r>=0) printf("Zero\n");
	else if(l<0 && (r-l+1)%2) printf("Negative\n");
	else printf("Positive\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	if (a <= 2*b) {
		cout << 0 << endl;
	} else {
		cout << a - 2*b << endl;
	} 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(){
    double n,s,t,a,h,p,num;
    double tem=0;
    cin >> n ;
    cin >> t >> a;
    p = 10000000;
    tem = t;
    for(int i=0;i<n;i++){
        cin >> h;
        t = a-tem+p*0.006;
        s = a-tem+h*0.006;
        if(fabs(t) > fabs(s)){
            num = i;
            p = h;
        }
    }

    cout << num+1 << endl;
}


Measured memory_bytes: 256
import sys
N,M=map(int,input().split())

graph=[]
for _ in range(N+1):
  graph.append([])

uvlist = []
for i in range(M):
  u,v=map(int,input().split())
  graph[u].append(v)
  
S,T=map(int,input().split())

#print(graph)
table=[]
for i in range(N+1):
  table.append([False]*3)
#print(table)  
  
vlist=graph[S]
table[S][0]=True
t=0
while(True):
  t+=1
  #if t>300003:
  #  print(-1)
  #  sys.exit()
  
  #nlist = []
  nset = set()
  for v in vlist:
    if v == T and t%3 == 0:
      print(t//3)
      sys.exit()
    else:
      table[v][t%3]=True
      for vv in graph[v]:
        if not table[vv][(t+1)%3]:
          #nlist.append(vv)
          nset.add(vv)
          #table[vv][t%3]=True
          #print((vv,t%3))
      
  #print((t,nlist))
  #vlist = nlist
  vlist = list(nset)
  if len(vlist) == 0:
    print(-1)
    break
  


Measured memory_bytes: 68716
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007

int main() {

	int N, a = 0;
	cin >> N;
	VI L(N);
	REP(i, N)cin >> L[i];

	SORT(L);
	for (int i = 0; i < N - 1; i++) {
		a += L[i];
	}
	if (L[N - 1] < a)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long n,ans;
    cin>>n;
    if(n<7)ans=1;
    else{
        ans=n/11;
        int buf=n-ans*11;
        ans*=2;
        if(buf>6)ans+=2;
        else if(0<buf&&buf<=6)ans++;
        else if(-5<=buf&&buf<0)ans--;
        else if(-11<=buf&&buf<-5)ans-=2;
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,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,s) for (int i=a;s>0?i<n:i>n;i+=s)
#define rep(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int inf = 1e9+10, mod = 1e9+7; const long long llinf = 1e18;
// head

int main(){
  string s;
  cin >> s;
  rep(i,4)cout << s[i];
  cout << " ";
  rep(i,4,12) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<set>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=200005;
int n,a[N],bin[N],pos[N],st[2][20][N];
struct data
{
	int l,r,c;

	bool operator < (const data &t) const
	{
		return c<t.c;
	}
};
set <data> t;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

int query(int l,int r)
{
	int len=bin[r-l+1];
	return min(st[l&1][len][l],st[l&1][len][r-(1<<len)+1]);
}

int main()
{
	n=getint();
	rep(i,1,n) a[i]=getint(),pos[a[i]]=i;
	rep(i,1,n) st[i&1][0][i]=a[i],st[!(i&1)][0][i]=n+1;
	rep(i,2,n) bin[i]=bin[i>>1]+1;
	rep(tp,0,1) rep(i,1,bin[n]) rep(j,1,n-(1<<i)+1) st[tp][i][j]=min(st[tp][i-1][j],st[tp][i-1][j+(1<<i-1)]);
	t.insert((data){1,n,query(1,n)});
	while(!t.empty())
	{
		data p=*t.begin();
		int x=pos[query(p.l,p.r)];
		int y=pos[query(x+1,p.r)];
		printf("%d %d ",a[x],a[y]);
		t.erase(p);
		if(p.l<x-1) t.insert((data){p.l,x-1,query(p.l,x-1)});
		if(x+1<y-1) t.insert((data){x+1,y-1,query(x+1,y-1)});
		if(y+1<p.r) t.insert((data){y+1,p.r,query(y+1,p.r)});
	}
	puts("");
	return 0;
}

Measured memory_bytes: 37632
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N-1; i++ {
		a, b := sc.nextInt()-1, sc.nextInt()-1
		G[a] = append(G[a], b)
		G[b] = append(G[b], a)
	}
	// 0からN-1までのパス
	var R []int
	done := make([]bool, N)
	var dfs func(cur int, root []int)
	dfs = func(cur int, root []int) {
		if cur == N-1 {
			for i := 0; i < len(root); i++ {
				R = append(R, root[i])
			}
		}
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !done[next] {
				done[next] = true
				dfs(next, append(root, next))
			}
		}
	}
	done[0] = true
	dfs(0, []int{0})
	black := R[ceil(len(R), 2)-1]
	white := R[ceil(len(R), 2)]

	total := 0
	done2 := make([]bool, N)
	var dfs2 func(cur int)
	dfs2 = func(cur int) {
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if next != white && !done2[next] {
				done2[next] = true
				total++
				dfs2(next)
			}
		}
	}
	done2[black] = true
	total++
	dfs2(black)
	bc, wc := total, N-total
	if bc > wc {
		fmt.Fprintln(wtr, "Fennec")
	} else {
		fmt.Fprintln(wtr, "Snuke")
	}
}


Measured memory_bytes: 62848
// AOJ 1079 Cosmic Market
// 2018.2.3 bal4u

#include <stdio.h>
#include <string.h>

int a[50001], b[50001], ord[50001];
char mk[2][50001];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int in1()
{
	int c = getchar_unlocked() & 1;
	getchar_unlocked();
	return c;
}
int main()
{
	int R, C, Q, i, r, c;
	long long ans;

	while (R = in()) {
		C = in(), Q = in();
		for (i = 0; i < Q; i++)	a[i] = in1(), b[i] = in(), ord[i] = in1();

		memset(mk, 0, sizeof(mk));
		ans = 0; r = c = 0;
		i = Q; while (i--) {
			if (a[i]) {
				if (mk[0][b[i]]) continue;
				if (ord[i]) ans += R - r;
				mk[0][b[i]] = 1;
				c++;
			} else {
				if (mk[1][b[i]]) continue;
				if (ord[i]) ans += C - c;
				mk[1][b[i]] = 1;
				r++;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2416
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
   int n,m;
   cin>>n>>m;
   vector<string>a(n),b(m);
   rep(i,n)cin>>a[i];
   rep(i,m)cin>>b[i];
   m--;
   bool f = false;
   rep(i,n){
       if(i+m<n){
           rep(j,n){
               if(j+m<n){
                   bool fl = true;
                   rep(k,m+1){
                       rep(l,m+1){
                           if(a[i+k][j+l]!=b[k][l])fl=false;
                       }
                   }
                   if(fl)f= true;
               }
           }
       }
   }
   if(f)cout<<"Yes"<<endl;
   else
   {
       cout<<"No"<<endl;
   }
   

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    int N;

    cin >> N;

    vector<int> H(N);


    int max = 0;

    int count = 0;

    cin >> H[0];

    for(int i = 1; i < N; i++) {
        cin >> H[i];
        if(H[i] <= H[i - 1]) {
            count++;
            if(count > max) {
                max = count;
            }
        } else {
            count = 0;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
int  b[11],n,i,j,x,h,temp;
char a[101];
	scanf("%d",&n);
	while(n!=0){
		scanf("%s",a);
		for(i=0;i<n;i++){
	b[i]=0;
		}
	h=0;
	x=0;
	for(i=0;i<100;i++){
		if(a[i]=='S'){
			b[h]++;
		x=x+b[h];
		b[h]=0;
		}
		else if(a[i]=='L'){
			b[h]++;
			b[h]=b[h]+x;
			x=0;
		}
		else{
		b[h]++;
		}
		h++;
		if(h>=n){
		h=0;
		}
	}
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(b[i]>b[j]){
				temp=b[i];
				b[i]=b[j];
				b[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d ",b[i]);
	}
	printf("%d\n",x);
	scanf("%d",&n);
}
return 0;
}

Measured memory_bytes: 604
/*
 *  author: kiran bhanushali
 *  handle: kinibha
 *  time:
 *  email:kiranbhanushali143.kb143@gmail.com
 */


#include<bits/stdc++.h>
using namespace std;

#define int  long long 
  

int32_t main(){
    int n ;cin>>n;

    if(  floor(1.08*ceil(n/1.08)) == n) cout<<ceil(n/1.08)<<endl;
    else cout<< ":("<<endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e6 + 5;
const ll MOD = 998244353;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

int main()
{
    IOS
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(), a.end());
    int res = 0;
    for(int i=0;i<k;i++) res += a[i];
    cout << res << endl;
    return 0; 
}



Measured memory_bytes: 3656
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

int x[1020],y[1020],r[1020],N;
double d[1020]; bool chk[1020];

int main()
{
	scanf ("%d %d %d %d",x,y,x+1,y+1);
	scanf ("%d",&N); N+=2;
	for (int i=2;i<N;i++) scanf ("%d %d %d",&x[i],&y[i],&r[i]);
	for (int i=0;i<N;i++){
		d[i] = 1e18;
	}

	priority_queue<pair<double, int> > Q;
	Q.push({0,0}); d[0] = 0;
	while (!Q.empty()){
		int p = Q.top().second;
		double c = -Q.top().first; Q.pop();

		if (chk[p]) continue;
		chk[p] = 1;

		for (int q=0;q<N;q++) if (p != q){
			double dist = hypot(x[p]-x[q],y[p]-y[q]);
			dist -= r[p] + r[q];
			if (dist < 0) dist = 0;
			dist += c;
			if (d[q] > dist){
				Q.push({-dist,q}); d[q] = dist;
			}
		}
	}

	printf ("%.12lf\n",d[1]);

	return 0;
}

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

using namespace std;

#define LIMIT 1000000000
 
bool check(long long key){
    if(key > LIMIT) return true;
    return false;
}
 
int main(){
    long long n,T,ans,total = 0;
    string str;
    bool flg = false;
 
    cin >> n >> T >> str;
    for(int i = 0 ; i < str.size() ; i++){
        if('0' <= str[i] && str[i] <= '9'){
            if(str[i] == '0') total++;
            else{
                ans = 1;
                for(int j = 0 ; j < str[i]-'0' ; j++){
                    ans *= n;
                    if(check(ans)){
                        flg = true;
                        goto end;
                    }
                }
                total += ans;
            }
        }
    }
    total *= T;
    if(total > LIMIT) flg = true;
     
end:
    if(flg) cout << "TLE" << endl;
    else cout << total << endl;
     
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e16;

signed main(){
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B, Q;
  cin >> A >> B >> Q;
  
  vector<int> S(A);
  for( int i = 0; i < A; i++ ) cin >> S.at(i);
  vector<int> T(B);
  for( int i = 0; i < B; i++ ) cin >> T.at(i);
  
  for( int i = 0; i < Q; i++ ){
    int X;
    cin >> X;
    
    int RS = lower_bound(S.begin(), S.end(), X) - S.begin();
    int LS = RS-1;
    int RT = lower_bound(T.begin(), T.end(), X) - T.begin();
    int LT = RT-1;
    
    int ans = INF;
    //どっちも右
    if( RS < A && RT < B ) ans = max(S.at(RS), T.at(RT)) - X;
    //どっちも左
    if( LS >= 0 && LT >= 0 ) ans = min( ans, X-min(S.at(LS),T.at(LT)) );
    //左の神社と右の寺
    if( LS >= 0 && RT < B ){
      ans = min({ans, (X-S.at(LS))*2+(T.at(RT)-X), (X-S.at(LS))+(T.at(RT)-X)*2});
    }
    //右の神社と左の寺
    if( RS < A && LT >= 0 ){
      ans = min({ans, (S.at(RS)-X)*2+(X-T.at(LT)), (S.at(RS)-X)+(X-T.at(LT))*2});
    }
    cout << ans << endl;
    
  }
}


Measured memory_bytes: 2944
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

ans =0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i][j]*B[j]
    if sum+C>0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n,a[10],c[10],cnt=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        c[i]=a[i]%2+1;
    }
    for(int i=0;i<n;i++){
        cnt*=3-c[i];
    }
    cout<<pow(3,n)-cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
bool compare_by_b(pair<long , long > a, pair<long , long > b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(void)
{
    long long i, a, b, n, time=0;
    pair < long , long > w[200000];
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a >> b;
        w[i]=make_pair(a, b);
    }
    sort(w, w+n, compare_by_b);
    for(i=0;i<n;i++){
        time=time+w[i].first;
        if(time>w[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
 
    cout << "Yes" << endl;
    
        

    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l)for(int i=r;i>=l;i--)
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1e9+7
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf  INT_MAX
#define lnf LLONG_MAX
#define mii map<int,int>
#define mll map<ll,ll>
#define mil map<int,ll>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)```
using namespace std;
const int MX = 2e5 + 7;
ll modulo(ll num, ll MOD = mod) { return ((num%MOD) + MOD) % MOD; }
ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e&1) ans = (ans*b) % MOD; b = (b*b) % MOD; e /= 2; } return ans; }
ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a%b)); }
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int t,n,m;
	cin>>n>>m;
	if(n>0&&m>0&&m<10&&n<10)cout<<n*m<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 256
program main
  implicit none

  integer, allocatable :: x(:),y(:), b(:)
  integer :: n, i

  read(*,*) n

  allocate(x(n))
  allocate(y(n))
  allocate(b(n))


  read(*,*) x
  do i = 1, n
     y(i) = x(i)
  end do

  call heapsort(x)

  do i = 1, n
     if(y(i) <= x(n/2)) then
        b(i) = x(n/2 + 1)
     else
        b(i) = x(n/2)
     end if
     write(*,*) b(i)
  end do

  stop

  contains
  subroutine heapsort(array)
  implicit none
  integer, intent(inout) :: array(:)
  
  integer :: i,k,j,l
  double precision :: t
  
  if(n <= 0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n == 1)return

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j <= k)
        if(j < k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort
  

end program main

  


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll arr[n];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	ll s=0;
	for(ll i=1;i<n;i++)
	{
		s += min((arr[i]-arr[i-1])*a,b);
	}
	cout<<s<<"\n";
}

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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    priority_queue<ll> ab;
    ll bcnt = 0;
    rep(i,n) {
        ll a, b; cin >> a >> b;
        ab.push(a+b);
        bcnt += b;
    }
    ll abcnt = 0;
    while(true) {
        abcnt += ab.top();
        ab.pop();
        if(ab.empty()) break;
        ab.pop();
        if(ab.empty()) break;
    }

    cout << abcnt - bcnt << '\n';
;}

Measured memory_bytes: 1400
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, T):
    if S == T[:-1]:
        return 'Yes'
    return 'No'


def main():
    S = read_str()
    T = read_str()
    print(slv(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 76912
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,x;
    cin>> a>> b;
    x=a % 500 - b;
    if(x <= 0){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args) {
		new Main().calc();
	}

	int[] moveX = {0,0,-1,1};
	int[] moveY = {-1,1,0,0};
	char[][] map;
	boolean[][] check;
	int ans = 0;
	int x, y;

	void calc () {
		Scanner sc = new Scanner(System.in);
		while (true) {
			x = sc.nextInt();
			y = sc.nextInt();

			if (x == 0) break;

			ans = 0;
			map = new char[y][x];
			check = new boolean[y][x];

			for (int i = 0; i < y; i++)
				map[i] = sc.next().toCharArray();

			main:
			for (int i = 0; i < y; i++) {
				for (int j = 0; j < x; j++) {
					if (map[i][j] == '@') {
						ans = 1;
						check[i][j] = true;
						dfs(i, j);
						break main;
					}
				}
			}
			System.out.println(ans);
		}
	}
	void dfs (int y, int x) {
		for (int i = 0; i < moveX.length; i++) {
			int nextX = x + moveX[i];
			int nextY = y + moveY[i];

			if (0 <= nextX && nextX < map[0].length &&
				0 <= nextY && nextY < map.length &&
				map[nextY][nextX] == '.' &&
				!check[nextY][nextX]) {

				ans++;
				check[nextY][nextX] = true;
				dfs(nextY,nextX);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <map>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = numeric_limits<int>::infinity();
#define eqret(a, b, c) if (a == b) return c;

using ULL = unsigned long long;

map<ULL, ULL> memo;
ULL gA, gB, gC, gD;

ULL overCheck(ULL num){
    if (num < 0){
        return numeric_limits<ULL>::infinity();
    }
    else{
        return num;
    }
}

ULL coin(ULL num){
    /*if (num == 0){
        return 0;
    }
    if (num == 1){
        return gD;
    }*/
    eqret(num, 0, 0);
    eqret(num, 1, gD);
    if (memo.count(num)){
        return memo[num];
    }

    ULL lA = num / 2 * 2;
    ULL rA = (num + 1) / 2 * 2;
    ULL lB = num / 3 * 3;
    ULL rB = (num + 2) / 3 * 3;
    ULL lC = num / 5 * 5;
    ULL rC = (num + 4) / 5 * 5;
    ULL ans = numeric_limits<ULL>::infinity();
    if (ans / gD < num){
        ans = overCheck(num * gD);
    }/*
    ans = min(ans, overCheck(llabs(num - lA) * gD + gA + coin(lA / 2)));
    ans = min(ans, overCheck(llabs(num - rA) * gD + gA + coin(rA / 2)));
    ans = min(ans, overCheck(llabs(num - lB) * gD + gB + coin(lB / 3)));
    ans = min(ans, overCheck(llabs(num - rB) * gD + gB + coin(rB / 3)));
    ans = min(ans, overCheck(llabs(num - lC) * gD + gC + coin(lC / 5)));
    ans = min(ans, overCheck(llabs(num - rC) * gD + gC + coin(rC / 5)));*/
    ans = min(ans, llabs(num - lA) * gD + gA + coin(lA / 2));
    ans = min(ans, llabs(num - rA) * gD + gA + coin(rA / 2));
    ans = min(ans, llabs(num - lB) * gD + gB + coin(lB / 3));
    ans = min(ans, llabs(num - rB) * gD + gB + coin(rB / 3));
    ans = min(ans, llabs(num - lC) * gD + gC + coin(lC / 5));
    ans = min(ans, llabs(num - rC) * gD + gC + coin(rC / 5));

    return (memo[num] = ans);
}

int main(void)
{
    int T;
    cin >> T;
    
    vector<LL> N(T), A(T), B(T), C(T), D(T);
    rep(i, T){
        cin >> N[i] >> A[i] >> B[i] >> C[i] >> D[i];
    }
    rep (i, T){
        memo.clear();
        gA = A[i];
        gB = B[i];
        gC = C[i];
        gD = D[i];
        printf("%lld\n", coin(N[i]));
    }

    return 0;
}

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

int main()
{
  ll A, B; cin >> A >> B;
  ll ans = 0;
  for(int i = A; i < B+1; i++) {
    string s = to_string(i);
    string s_a="", s_b="";
    rep(j, s.size()) {
      s_a += s[j];
    }
    for (int j = s.size()-1; j >= 0; j--){
      s_b += s[j];
    }

    if(s_a == s_b) ans++;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int cnt=0;
    cin>>N;
    for(int i=1;i<=N;i++){
    if(1<=i && i<10) cnt++;
    if(100<=i && i<1000) cnt++;
    if(10000<=i && i<100000) cnt++;
    }
        cout<<cnt<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    std::string s;
    std::cin >> s;
    bool flag = true;
    if(s.length() % 2){
        std::cout << "No" << std::endl;
        return 0;
    }
    for(int i = 0; i < (s.length()/2); i++){
        flag &= (s[2*i] == 'h' && s[2*i+1] == 'i');
    }
    if(flag){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

int dp[200010][4];  // dp[i][j]
                    // i 文字目まで分割が決まって、最後が j+1 文字
                    // 分割最大数

int main() {
  string s;
  cin >> s;
  int n = s.size();

  // DPテーブル初期化
  for (int i = 0; i < 200010; i++) {
    for (int j = 0; j < 4; j++) {
      dp[i][j] = 0;
    }
  }

  // 初期値
  dp[0][0] = 1;  // 1 文字だけなら分割数は 1

  // DP遷移
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      if (i - j < 0) continue;
      for (int k = 0; k < 4; k++) {
        // dp[i+k+1][k] を決定していく
        if (i + k + 1 > n) continue;
        string bef = s.substr(i - j, j + 1);
        string aft = s.substr(i + 1, k + 1);
        if (bef == aft) {
          // 文字列が一致するときは分割せずにそのまま伸ばしたものを考える
          dp[i + k + 1][k] = max(dp[i + k + 1][k], dp[i][j]);
        } else {
          dp[i + k + 1][k] = max(dp[i + k + 1][k], dp[i][j] + 1);
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < 4; i++) {
    ans = max(ans, dp[n - 1][i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3844
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

sum_bin = [0 for _ in range(41)]  # sum_bin[i]: i-1ビット目に1がいくつあるか

for a in A:
    for j in range(len(format(a, 'b'))):
        if a >> j & 1:
            sum_bin[j] += 1
# print(sum_bin)


def f(x):
    c = 0
    for i in range(40, -1, -1):
        if x >> i & 1:
            c += (N-sum_bin[i])*2**i
        else:
            c += sum_bin[i]*2**i
    return c


# Kを考慮しないXの貪欲解
g_X = 0
for i in range(40, -1, -1):
    if sum_bin[i] <= N-sum_bin[i]:
        g_X += 2**i
# print('g_X', bin(g_X)[2:])


ans = f(0)

l = len(bin(K))-2
# print('l', l)
for i in range(l):  # 下の桁から見ていく
    if K >> i & 1:
        c = ''
        if K >> i+1 != 0:
            c = format(K >> i+1, 'b')
        c += '0'+bin(g_X)[43-i:]
        # print(c, i)
        ans = max(ans, f(int(c, 2)))
ans = max(ans, f(K))
print(ans)


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int dp[5][34567];
int n;

int main()
{
  rep(k, 4) dp[k][0] = 1;
  rrep(j, 1, 200) rrep(i, j * j, 33333) rep(k, 4) dp[k + 1][i] += dp[k][i - j * j];

  while(cin >> n, n) cout << dp[4][n] << endl;

  return 0;
}

Measured memory_bytes: 1700
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 100005;
const int MAXM = 50005;
const double EPS = 1e-8;
const int MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}



void solve()
{
	int n;
	cin >> n;
	vector<vector<ll>>v (5);
	rep (i,1,n)
	{
		ll x,y;
		cin >> x >> y;
		v[1].push_back(x + y);
		v[2].push_back(x - y);
		v[3].push_back(-x + y);
		v[4].push_back(-x - y);
	}
	rep (i,1,4)
		sort(v[i].begin(),v[i].end());		
	ll ans = 0;
	rep (i,1,4)
		ans = max(ans,v[i][n-1] - v[i][0]);
	cout << ans << endl;
}


int main()
{closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();

	solve();

    //cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 9704
import java.util.Scanner;

class Main{

	static	int count = 0;
	public static void main(String[] args) {



		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] l = new int[N];		
		int[] r = new int[N];		

		int ans = 0;
			for(int i = 0;i < N;i++){
				l[i] = scanner.nextInt();
				r[i] = scanner.nextInt();
				
			}
			
			for(int i= 0;i < N;i++){
				ans += r[i] -l[i]+1;
			}
		
			
			System.out.println(ans);
		


	}

}

class Pair implements Comparable{
	int from;
	int middle;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 25576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> x(N);
  vector<int> y(1000,0);
  for(int i=0;i<N;i++){
    cin>>x.at(i);
      for(int j=0;j<x.at(i);j++){
        cin>>y.at(30*i+j);
      }
  }
  int ans=0;
    for(int k=1;k<M+1;k++){
      int sum=0;
      for(int h=0;h<1000;h++){
        if(y.at(h)==k){
          sum++;
        }
      }
      if(sum==N){
        ans++;
      }
    }        
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char C;
  cin >> C;
  string s = "abcdefghijklmnopqrstuvwxyz";
  // 26 letters at total
  for (int i = 0; i < 25; i++){
    if (C == s.at(i)){
      cout << s.at(i+1) << endl;
      break;
    }
    
    
  }
  return 0;
}
  
  


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int main() {
  while (true) {
    int n, x;
    cin >> n >> x;
    int ans = 0;
    if ( n == 0 ) { break; }
    for (int a1 = 1; a1 <= n-2; a1++) {
      for (int a2 = a1+1; a2 <= n-1; a2++) {
        int a3 = x - a1 - a2;
        if ( a3 > a2 && a3 <= n ) {
          ans += 1;
        }
      }
    }
    printf("%d\n", ans);
  }

  return 0;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int N;
vector<int> target(3);
int ans = 1 << 30;
vector<int> l(8), check(8);

void calc(vector<int> v){

	vector<int> use(3, -1);
	vector<int> sum(3, 0);
	int cnt = 0;

	REP(i,N){
		if(v[i] != 3){
			sum[v[i]] += l[i];
			use[v[i]]++;
		}
	}

	REP(i,3){
		int t = max(0, use[i]);
		cnt += 10*t;
	}

	REP(i,3){
		if(sum[i]==0){
			REP(i,3)sum[i]=0;
			return;
		}
	}

	REP(i,3){
		cnt += abs(target[i] - sum[i]);
	}
	ans = min(ans, cnt);
	return ;

}

void dfs(int depth, vector<int> v){

	if(depth == N){
		calc(v);
		return ;

	}else{
		REP(i,4){
			v[depth] = i;
			dfs(depth+1, v);
		}
	}
	return ;
}

int main(void){

	cin >> N;
	REP(i,3) cin >> target[i];
	REP(i,N) cin >> l[i];
	dfs(0, check);

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256