akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()
lst = []
for loop in range(n):
    x, y = map(int, raw_input().split())
    lst.append((x, y))
lst += lst[:2]

ans = 1
for i in range(1, n + 1):
    x0, y0 = lst[i]
    x1, y1 = lst[i - 1]
    x2, y2 = lst[i + 1]
    if (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0) > 0:
        ans = 0

print ans


Measured memory_bytes: 5036
p[]={-1,0,1,-2,2,-2,2,-2,2,-1,0,1};
P[]={-2,-2,-2,-1,-1,0,0,1,1,2,2,2};
s[]={-1,0,1,-1,0,1,-1,0,1};
S[]={-1,-1,-1,0,0,0,1,1,1};
m[10],M[10];int D(x,y,d,n){int i=0,j;
for(;i<12;i++)for(j=0;j<9;j++)if(x+p[i]==m[d]+s[j]&&y+P[i]==M[d]+S[j]&&0<=x+p[i]&&x+p[i]<10&&0<=y+P[i]&&y+P[i]<10)if(d==n-1||D(x+p[i],y+P[i],d+1,n))return 1;
return 0;}
main(X,Y,n,i,x,y){for(;scanf("%d%d%d",&X,&Y,&n)>2;puts(D(X,Y,0,n)?"OK":"NA"))for(i=0;i<n;i++)scanf("%d%d",m+i,M+i);exit(0);}

Measured memory_bytes: 584
#include <iostream>

int main()
{
  int nitems;
  std::cin >> nitems;
  int max_price = 0;
  int total_cost = 0;
  for (int i = 0; i < nitems; i++) {
    int price;
    std::cin >> price;
    max_price = std::max(max_price, price);
    total_cost += price;
  }
  total_cost -= max_price / 2;
  std::cout << total_cost << std::endl;
  return 0;
}


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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 200000;
int n;
i64 a[MAX_N];
i64 psum[MAX_N+1];

int main()
{
  cin >> n;
  psum[0] = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    psum[i+1] = psum[i] + a[i];
  }

  i64 m = LLONG_MAX;
  // i: 右端(含む)
  for (int i = 1; i < n-2; i++) {
    i64 t = psum[i+1];
    int j = upper_bound(psum, psum+i+2, t/2) - psum;
    pair<i64,i64> p1 = minmax(psum[j], t - psum[j]);
    if (j > 0) {
      pair<i64,i64> p2 = minmax(psum[j-1], t - psum[j-1]);
      if (p1.second - p1.first > p2.second - p2.first)
        p1 = p2;
    }
    //printf("p1={%ld, %ld}\n", p1.first, p1.second);

    i64 u = psum[i+1] + (psum[n] - psum[i+1]) / 2;
    int k = upper_bound(psum+i+2, psum+n+1, u) - psum;
    pair<i64,i64> p2 = minmax(psum[k] - psum[i+1], psum[n] - psum[k]);
    if (k > i+2) {
      pair<i64,i64> p3 = minmax(psum[k-1] - psum[i+1], psum[n] - psum[k-1]);
      if (p2.second - p2.first > p3.second - p3.first)
        p2 = p3;
    }
    //printf("p2={%ld, %ld}\n", p2.first, p2.second);
    //printf("i=%d j=%d k=%d\n", i, j, k);

    m = min(m, max(p1.second, p2.second) - min(p1.first, p2.first));
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 3328
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	flag := 0
	if N/100 != 7 {
		N = N % 100
		if N/10 != 7 {
			N = N % 10
			if N != 7 {
				fmt.Println("No")
				flag = 1
			}
		}
	}

	if flag == 0 {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 1832
#include<bits/stdc++.h>
#define N 200010
using namespace std;
int arr[N];
int brr[N];
int p=0,q=0;
int n,m;
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a==1)arr[p++]=b;
        if(b==n)brr[q++]=a;
    }
    if(p==0||q==0){
        cout<<"IMPOSSIBLE";
        return 0;
    }
    sort(arr,arr+p);
    sort(brr,brr+q);
    int i,j=1;
    for(i=0;i<p;i++){
        j--;
        for(j;j<q;j++){
            if(arr[i]==brr[j])break;
            if(arr[i]<brr[j])break;
        }
        if(arr[i]==brr[j])break;
    }
    if(arr[i]==brr[j]&&i!=p)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
    return 0;
}

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

typedef long long ll;

const long double PI = (acos(-1));

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

    int r; cin >> r;
    double ans = 2*PI*r;
    printf("%.12lf\n",ans);
    return 0;
}

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

int main(void)
{
    int n, m;
    cin >> n >> m;

    vector<int> b(m);
    vector<vector <int>> A(n, vector<int>(m));

    for (auto &i : A)
        for (auto &j : i)
            cin >> j;

    for (auto &j : b)
        cin >> j;

    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j < m; j++)
            sum += A[i][j] * b[j];
        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll N, M;
    cin >> N;
    vector<ll> a(N);
    for(ll i = 0;i < N;i++) cin >> a[i];
    
    cin >> M;
    for(ll i = 0;i < M;i++){
        ll b;
        cin >> b;
        if(!binary_search(a.begin(), a.end(), b)){
            cout << 0 <<endl;
            return 0;
        }
    }
    cout << 1 <<endl;
}


Measured memory_bytes: 4400
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
string str;
int main(){
	int i;
	ios::sync_with_stdio(false);
	cin>>str;
	i=str.length()-1;
	for (;i>=0;){
		if (str[i-4]=='d' && str[i-3]=='r' && str[i-2]=='e' && str[i-1]=='a' && str[i]=='m'){
			i-=5;
		}else if (str[i-4]=='e' && str[i-3]=='r' && str[i-2]=='a' && str[i-1]=='s' && str[i]=='e'){
			i-=5;
		}else if (str[i-6]=='d' && str[i-5]=='r' && str[i-4]=='e' && str[i-3]=='a' && str[i-2]=='m' && str[i-1]=='e' && str[i]=='r'){
			i-=7;
		}else if (str[i-5]=='e' && str[i-4]=='r' && str[i-3]=='a' && str[i-2]=='s' && str[i-1]=='e' && str[i]=='r'){
			i-=6;
		}else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans = 0;
        for (int i = 1; i < N; i++) {
            ans += i;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
package main

import "fmt"

func main() {
	var x, n, tmp, diff int
	fmt.Scan(&x, &n)
	p := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		p[tmp] = true
	}
	for {
		if !p[x-diff] {
			fmt.Println(x - diff)
			return
		}
		if !p[x+diff] {
			fmt.Println(x + diff)
			return
		}
		diff++
	}
}


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

int main() {
  int n;
  cin>>n;
  int t[n];
  double max_v[n+1];
  for (int i=0; i<n; i++) cin>>t[i];
  for (int i=0; i<n; i++) cin>>max_v[i];
  max_v[n] = 0;

  double v[n+1];
  v[0] = 0;
  v[n] = 0;
  double cur_v = 0;
  for (int i=0; i<n-1; i++) {
    double max_vi = min(v[i] + t[i], max_v[i]);
    v[i+1] = max_vi;
    int acc_t = -t[i];
    for (int j=i+1; j<=n; j++) {
      acc_t += t[j-1];
      if (max_vi - acc_t <= max_v[j]) {
        continue;
      }
      v[i+1] = min(v[i+1], max_v[j] + acc_t);
    }
  }
  double ans = 0.0;
  for (int i=0; i<n; i++) {
    double v_start = v[i];
    double v_end = v[i+1];
    double v_high = (v_start + v_end + t[i]) / 2.0;
    v_high = min(v_high, max_v[i]);
    double t1 = v_high - v_start;
    double t2 = v_high - v_end;
    ans += (v_start + v_high) *t1 / 2.0 + (v_end + v_high) * t2 / 2.0 + v_high * (t[i] - t1 - t2);
  }
  printf("%.5lf", ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#define EPS 0.0000001

using namespace std;

int main() {
  int a, b, c, d, e, f;

  double x, y;

  while(cin >> a >> b >> c >> d >> e >> f) {
    x = 1.0 * ( c*e - b*f ) / ( a*e - b*d ) + EPS;
    y = 1.0 * ( c*d - a*f ) / ( b*d - a*e ) + EPS;
    printf("%.3lf %.3lf\n", x, y);
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

using intpair = pair<int, int>;
vector<intpair> hint;
int main(){
    string res = "000";
    int n, m; cin >> n >> m;
    hint = vector<intpair>(m);
    bool is_violated = false;
    bool has_tophint = false;
    rep(i,m){
        int s,c; cin >> s >> c;
        s--;
        if(s==0 && c==0 && n!=1) is_violated = true;
        if(s==0) has_tophint = true;
        rep(j,i){
            if(hint[j].first == s && hint[j].second != c){
                is_violated = true;
            }
        }
        hint[i] = intpair(s,c);
    }
    if(!has_tophint){
        if(n!=1){
            hint.push_back(intpair(0,1));
        }else{
            hint.push_back(intpair(0,0));
        }
        m++;
    }
    if(is_violated){
        cout << -1 << endl;
        return 0;
    }
    rep(i,m) res[hint[i].first] = hint[i].second+'0';
    cout << stoi(res)/(int)pow(10,3-n) << endl;
  	return 0;
}

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

int merge(int *,int,int,int,int);
int mergeSort(int *,int,int,int);

int count;
int L[500000/2+2],R[500000/2+2];

int main()
{
  int A[500000],n,i;
  count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(A[i] >= 1000000001){
	return 0;
      }
  }

  mergeSort(A,0,n,n);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}

int merge(int A[],int left,int mid,int right,int n)
{
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  /*L=(int*)malloc((n1+1)*sizeof(int));
    R=(int*)malloc((n2+1)*sizeof(int));*/
  for (i=0;i<n1;i++)L[i] = A[left + i];
  for (i=0;i<n2;i++)R[i] = A[mid + i];
  L[n1] = 1000000001;
  R[n2] = 1000000001;
  i = 0;
  j = 0;
    for (k=left;k<right;k++){
      count++;
      if (L[i] <= R[j]){
	A[k] = L[i];
	i = i + 1;
      }
      else{ 
	A[k] = R[j];
	j = j + 1;
      }
    }
    return;
}

int mergeSort(int A[],int left,int right,int n){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid,n);
    mergeSort(A,mid,right,n);
    merge(A,left,mid,right,n);
      }
return;
}



Measured memory_bytes: 5600
package main

import "fmt"

func main() {
	var n, k, x, y int
	fmt.Scan(&n, &k, &x, &y)

	var sum int

	for i := 0; i < n; i++ {
		if i < k {
			sum = sum + x
		} else {
			sum = sum + y
		}
	}

	fmt.Println(sum)

}


Measured memory_bytes: 512
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  string s,t;
  cin>>s>>t;

  auto f = [](string const& base,string const& sub){
    int n = size(base);
    int m = size(sub);
    ll ans = INF;
    rep(i,n-m+1){
      ll tmp = 0;
      rep(j,m)if(base[i+j]!=sub[j])tmp++;
      chmin(ans,tmp);
    }
    return ans;
  };

  ll ans = f(s,t);
  cout<<(ans)<<endl;

}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 11000

int V;
vector<int> G[MAX_V]; // グラフの隣接リスト表現
vector<int> rG[MAX_V];// 辺の向きを逆にしたグラフ
vector<int> vs;       // 帰りがけ順の並び
bool used[MAX_V];     // すでに調べたか
int cmp[MAX_V];       // 属する強連結成分のトポロジカル順序

// from から to への辺を張る関数
void add_edge(int from, int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
	vs.push_back(v);
}

void rdfs(int v, int k){
	used[v] = true;
	cmp[v] = k;
	for(int i = 0; i < rG[v].size(); i++){
		if(!used[rG[v][i]]){
			rdfs(rG[v][i], k);
		}
	}
}

// 強連結成分分解を行う関数、返り値は強連結成分の個数
int scc(){
	memset(used, 0, sizeof(used));
	vs.clear();
	for(int v = 0; v < V; v++){
		if(!used[v]){
			dfs(v);
		}
	}
	memset(used, 0, sizeof(used));
	int k = 0;
	for(int i = vs.size() - 1; i >= 0; i--){
		if(!used[vs[i]]){
			rdfs(vs[i], k++);
		}
	}
	return k;
}

int main(){
	
	int E, Q;
	
	cin >> V >> E;
	
	// s から t への有向辺を張る
	for(int i = 0; i < E; i++){
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	
	scc();
	
	/*
	// トポロジカル順序を出力
	for(int i = 0; i < V; i++){
		cout << cmp[i] << " ";
	}
	*/
	
	// 同じ強連結成分に属するか判定
	cin >> Q;
	for(int i = 0; i < Q; i++){
		int u, v;
		cin >> u >> v;
		cout << (cmp[u] == cmp[v]) << endl;
	}
	
	return 0;
}


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

int main() 
{
    int n,k;
    cin>>n>>k;

    vector<int> a(n);

    for(int i=0; i<n; i++)
        cin>>a[i];

    vector<bool> dp(k+1);

    for(int stones=0; stones <= k; stones++)
    {
        for(int x : a)
        {
            if(stones >= x && dp[stones-x] == false)
                dp[stones] = true;
        }
    }

    if(dp[k])
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;

    return 0;
} 


Measured memory_bytes: 3572
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  solve <$> replicateM n f >>= putStrLn
  where
    f = g <$> words <$> getLine
    g ["(", x] = read x
    g [")", x] = negate $ read x

solve :: [Int] -> String
solve = f 0
  where
    f b []
      | b == 0 = "YES"
      | otherwise = "NO"
    f b (x:xs)
      | b + x < 0 = "NO"
      | otherwise = f (b + x) xs



Measured memory_bytes: 4744
#include <iostream>
#include <math.h>
#include <string.h>

using namespace std;

int main(int argc, char const* argv[])
{
	char S[100];
	cin >> S;
	if(strlen(S) == 3)
	{
		if((S[0] == S[1] && S[1] == S[2]))
		{
			cout << "No" << endl;
		}
		else
		{
			cout << "Yes" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N+1){rep(j,M+1){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
#define MAX_N 100000
int par[MAX_N];
int _rank[MAX_N];
void init(int n){
	rep(i,n){
		par[i]=i;
		_rank[i]=0;
	}
}
int find(int x){
	if(par[x]==x){
		return x;
	} else{
		return par[x] = find(par[x]); 
	}
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(_rank[x]<_rank[y]){
		par[x] =y;
	} else {
		par[y]= x;
		if(_rank[x] ==_rank[y]) _rank[x]++;
	}
}
bool same (int x,int y){
	return find(x)==find(y);
}
//--------------------------------------//
struct E{
	int cost,from,to;
};
bool comp(const E& s1,const E& s2){
	return s1.cost<s2.cost;
}
struct V{
	int x,y,n;
};
bool compx(const V& s1,const V& s2){
	return s1.x<s2.x;
}
bool compy(const V& s1,const V& s2){
	return s1.y<s2.y;
}
int n;
V vs[MAX_N];
vector<E> es;
int main(){
	cin>>n;
	rep(i,n){
		cin>>vs[i].x>>vs[i].y;
		vs[i].n=i;
	}
	sort(vs,vs+n,compx);
	rep(i,n-1){
		es.pb(E{vs[i+1].x-vs[i].x,vs[i].n,vs[i+1].n});
	}
	sort(vs,vs+n,compy);
	rep(i,n-1){
		es.pb(E{vs[i+1].y-vs[i].y,vs[i].n,vs[i+1].n});
	}
	sort(es.begin(),es.end(),comp);
	init(n);
	int ans=0;
	rep(i,es.size()){
		E e=es[i];
		if(!same(e.to,e.from)){
			unite(e.to,e.from);
			ans+=e.cost;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
int a[105];
int mp[1005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=1;i<=5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
            cout<<i<<'\n';
    }





}


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

using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

#define pb push_back;
#define mp make_pair;
#define fi first;
#define se second;
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define forin(i, n) for (auto& i : (n))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

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

const int INF = 1 << 29;
const int MOD = 1e9 + 7;
 
int main() {
  ll n, m;
  scanf("%I64d%I64d", &n, &m);
  priority_queue<ll> que;  
  forn(i,n) {
    ll a;
    cin >> a;
    que.push(a);
  }
  forn(j,m) {
    ll top = que.top() / 2;  // trace(top);
    que.pop();
    que.push(top);
  }
  ll ans = 0;
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1400
N = int(input())
ABC = []
for _ in range(N):
    ABC.append(list(map(int, input().split())))

table = [[0]*3 for i in range(N)]


for i in range(0, N):# i日目
    if i == 0:
        table[i] = ABC[i]
    else:
        for j in range(3): #a,b,c
            table[i][j] = max(
                [table[i-1][j1] + ABC[i][j] for j1 in range(3) if not j1 == j ]
                 )
# print(table)
        
print(max(table[-1]))

Measured memory_bytes: 74200
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> pii;

string s[]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

void init();
void work();
int ca=1;
int main(){
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
//    init();
//    int T;cin>>T;
//    while(T--)
    work();
    return 0;
}
void work(){
    string str;
    cin>>str;
    for(int i=0;i<7;i++)if(str==s[i]){
        cout<<7-i;
        return;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
}



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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z;
	cin>>z;
	int ans=0;
	int a;
	for(int q=1;q<=z;q++)
	{
		cin>>a;
		if(a%2==1)ans++;
	}
	if(ans%2==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define int long long
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  // SOLVE C
  // int n;
  // cin >> n;
  // vector<int> v(n);
  // for (int i = 0; i < n; i++)
  //   cin >> v[i];
  // int arrSum = 0;
  // for (int i = 0; i < n; i++)
  //   arrSum = (arrSum + v[i]);
  // int sq = (arrSum * arrSum);
  // int tmp = 0;
  // for (int i = 0; i < n; i++)
  //   tmp = tmp + v[i] * v[i];
  // cout << ((sq - tmp) / 2) % MOD;
  // SOLVE B
  string s, t;
  cin >> s >> t;
  int ss = (int)s.size();
  int ts = (int)t.size();
  int ans = INT_MAX;
  for (int i = 0; i < ss - ts + 1; ++i) {
    int c = ts;
    for (int j = 0; j < ts; ++j) {
      if (s[i + j] == t[j])
        --c;
    }
    ans = min(ans, c);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <cmath>
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;


int main(){
	  int N;
		cin>>N;
	  ll H[N];
		for (int i = 0; i < N; ++i) {
		  cin>>H[i];
		}
		H[0]--;
    bool ans=true;
		int tmp=H[0];
		for (int i = 1; i < N-1; ++i) {
			if(H[i+1]-H[i]>=0){
				if((H[i]-1)>tmp){
					tmp=H[i]-1;
				}
			}
			else if(H[i]-H[i+1]==1 && H[i+1]>=tmp){
				H[i]--;
				tmp=H[i];
			}
			else{
				ans=false;
				break;
			}
		}
		if(ans)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long int a,b,n; cin>>a>>b>>n;
    if(n<b){
        cout<<floor(a*n/b);
    }
    else
    {
        cout<<floor(a*(b-1)/b);
    }
    return 0;
}

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

int isprime(int );

main(){

  int p,n,i,a,b=0;


  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&p);
    a=isprime(p);
    if(a==1) b++;
  }
  printf("%d\n",b);
  return 0;
}

int isprime(int a){
  int i=3;
  if(a==2) return 1;
  if(a<2 || a%2==0) return 0;
  while(i<=sqrt(a)){
    if(a%i==0) {
      return 0;
      break;
    }
    i=i+2;
  }
    return 1;
}

Measured memory_bytes: 596
#include"bits/stdc++.h"
#include<atcoder/mincostflow.hpp>
using namespace atcoder;
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pll = pair<ll, ll>;
using tp3 = tuple<ll, ll, ll>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 40;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============
using pii = pair<int, int>;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<ll>> A(N, vector<ll>(N));
    rep(i, N)rep(j, N)cin >> A[i][j];

    int source = 2 * N;
    mcf_graph<int, ll> graph(source + 2);

    ll res = N * K * INFL;
    graph.add_edge(source, source + 1, N*K, INFL);

    rep(i, N) {
        graph.add_edge(source, i, K, 0);
        graph.add_edge(N + i, source + 1, K, 0);
    }
    rep(i, N)rep(j, N) {
        int left = i;
        int right = N + j;
        graph.add_edge(left, right, 1, INFL - A[i][j]);
    }

    res -= graph.flow(source, source + 1, N*K).second;
    cout << res << endl;

    vector<string> panel(N, string(N, '.'));
    for (auto edge : graph.edges()) {
        if (edge.from < source && edge.to < source) {
            // cout << edge.to%N << "," << edge.from%N << " | " << edge.cap << "," << edge.flow << "..." << edge.cost << endl;
            if (edge.cap == edge.flow) {
                panel[edge.from%N][edge.to%N] = 'X';
            }
        }
    }
    for (auto row : panel)cout << row << endl;
    return 0;
}


Measured memory_bytes: 3932
n, x, m = map(int, input().split())
S = [0]
F = [None] * m
for j in range(m + 1):
    S.append(S[-1] + x)
    if F[x] is not None:
        i = F[x]
        q, r = (n - i) // (j - i), (n - i) % (j - i)
        print((S[j] - S[i]) * q + S[i + r])
        exit()
    F[x] = j
    x = pow(x, 2, m)


Measured memory_bytes: 13600
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct node{ int parent, left, right;};
node t[100];
int n, NIL = -1;

void Preorder(int u) {
	if( u == NIL) return;
	printf(" %d", u);
	Preorder(t[u].left);
	Preorder(t[u].right);
}

void Inorder(int u) {
	if( u == NIL) return;
	Inorder(t[u].left);
	printf(" %d", u);
	Inorder(t[u].right);
}

void Postorder(int u) {
	if( u == NIL) return;
	Postorder(t[u].left);
	Postorder(t[u].right);
	printf(" %d", u);
}

int main(){
	int v, c, l, r;
	int n; cin >> n;
	for( int i = 0; i < n; i++) t[i].parent = NIL;
	for( int i = 0; i < n; i++) {
		cin >> v;
		for( int j = 0; j < 2; j++) {
			cin >> c;
			if( j == 0) t[v].left = c;
			else t[v].right = c;
			if( c != NIL) t[c].parent = v;
		}
	}
	for( int i = 0; i < n; i++) {
		if( t[i].parent == NIL) r = i;
	}

	cout << "Preorder" <<endl;
	Preorder(r);
	cout << endl;
	cout << "Inorder" <<endl;
	Inorder(r);
	cout << endl;
	cout << "Postorder" <<endl;
	Postorder(r);
	cout << endl;

	return 0;
}

Measured memory_bytes: 1188
a,b,c=map(int,input().split())
ans=0
d=c-a
if(d>=0):
  ans+=a
elif(d<0):
  ans+=c
if(d>0):
  h=d-b
  if(h>=0):
    ans+=b
  elif(h<0):
    ans+=d
c=c-ans
ans+=b
if(c>=1):
  ans+=1
print(ans)


Measured memory_bytes: 38384
cards = list(map(int,input().split()))
K = int(input())
for i in range(K):
    if cards[1]<=cards[0]:
        cards[1]*=2
        
    elif cards[2]<=cards[1]:
        cards[2]*=2
        
    else:
        break

if cards[0]<cards[1]<cards[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9000
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int h, w, leaves;
vector<char> path;
char mapData[10][10];
bool visited[10][10];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};
const string str = "URDL";


bool dfs(int y, int x, int d){
  if(leaves == 0){
    path.push_back(d);
    return true;
  }
  for(int i=0;i<4;i++){
    if(abs(i-d) == 2) continue;
    int ny = y;
    int nx = x;
    while(1){
      ny += dy[i];
      nx += dx[i];
      if(ny<0 || ny>= h) break;
      if(nx<0 || nx>= w) break;
      if(mapData[ny][nx] == 'o' && !visited[ny][nx]){
        visited[y][x] = true;
        --leaves;
        if(dfs(ny, nx, i)){
          path.push_back(i);
          return true;
        }
        visited[y][x] = false;
        ++leaves;
        break;
      }
    }
  }
  return false;
}

main(){
  while(cin >> h >> w && h|w){
    path.clear();
    fill(visited[0], visited[10], false);
    int sy, sx, sd;
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        cin >> mapData[i][j];
        if(mapData[i][j] == 'o') ++leaves;
        if(mapData[i][j] != 'o' && mapData[i][j] != '.'){
          sy = i;
          sx = j;
          if(mapData[i][j] == 'U') sd = 0;
          if(mapData[i][j] == 'R') sd = 1;
          if(mapData[i][j] == 'D') sd = 2;
          if(mapData[i][j] == 'L') sd = 3;
        }
      }
    }
    dfs(sy, sx, sd);
    reverse(path.begin(), path.end());
    for(int i=0;i<(int)path.size()-1;++i){
      cout << str[path[i]];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int h=fs.nextInt(), w=fs.nextInt();
		boolean[][] board=new boolean[w][h];
		for (int y=0; y<h; y++) {
			char[] line=fs.next().toCharArray();
			for (int x=0; x<w; x++) board[x][y]=line[x]=='#';
		}
		int[] dx= {1, 0}, dy= {0, 1};
		ArrayDeque<Integer> xs=new ArrayDeque<>(), ys=new ArrayDeque<>();
		int[][] dist=new int[w][h];
		for (int x=0; x<w; x++) Arrays.fill(dist[x], Integer.MAX_VALUE/2);
		dist[0][0]=board[0][0]?1:0;
		xs.add(0); ys.add(0);
		while (!xs.isEmpty()) {
			int x=xs.removeFirst(), y=ys.removeFirst();
			for (int d=0; d<2; d++) {
				int nx=x+dx[d], ny=y+dy[d];
				if (nx>=w||ny>=h) continue;
				int cost=(!board[x][y]&&board[nx][ny]?1:0);
				if (dist[nx][ny]<=dist[x][y]+cost) continue;
				dist[nx][ny]=dist[x][y]+cost;
				if (cost==0) {
					xs.addFirst(nx);
					ys.addFirst(ny);
				}
				else {
					xs.addLast(nx);
					ys.addLast(ny);
				}
			}
		}
		System.out.println(dist[w-1][h-1]);
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int(i)=int (a);i<=int (b);i++)
#define ff(i,a,b) for(int (i)=int (a);i<int(b);i++)
#define F(i,a,b) for(int (i)=int(a);i>=int (b);i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vt vector
#define ll long long
#define ld long double
#define all(x) x.begin(),x.end()
#define lower(p,x) lower_bound(all(p),x)
#define upper(p,x) upper_bound(all(p),x)
#define ms(a,x) memset(a,x,sizeof a)
typedef pair<int,int> ii;
const double pi=acos(-1.0);
const double eps=1e-5;
const int N=1e6+6,mod=1e9+7,INF=1<<30;
char s[1002][1002];
int d[1002][1002];
int n,m,k;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
bool pd(int x,int y){
	if(x>0&&x<=n&&y>0&&y<=m&&s[x][y]!='#') return 1;
	return 0;
}
void solve()
{
	int ans=0;
	cin>>n>>m;
	queue<ii> qu;
	ms(d,-1);
	f(i,1,n){
		f(j,1,m){
			cin>>s[i][j];
			if(s[i][j]=='#'){
				qu.push(ii(i,j));
				d[i][j]=0;
			}
		}
	}
	while(!qu.empty()){
		int x=qu.front().fi,y=qu.front().se;
		qu.pop();
		ff(i,0,4){
			int nx=x+dx[i],ny=y+dy[i];
			if(!pd(nx,ny)) continue;
			if(d[nx][ny]==-1){
				d[nx][ny]=d[x][y]+1;
				ans=max(ans,d[nx][ny]);
				qu.push(ii(nx,ny));
			}
		}
	}
	cout<<ans<<'\n';

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












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


 main()
{
        int x,y;
        cin>>x>>y;
        int mx = x*4;
        int mn = x*2;
        if(y % 2 == 0 && mn<=y && y <= mx)cout<<"Yes\n";
        else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3620
using System;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }
    static object Solve() {
        var N = cinInt();
        var T = cinArrInt(N);
        var M = cinInt();
        var sb = new StringBuilder();
        var sum = 0;
        for (int i = 0; i < N; i++) {
            sum += T[i];
        }
        for (int i = 0; i < M; i++) {
            var p = cinInt() - 1;
            var x = cinInt();
            sb.Append(sum - T[p] + x).AppendLine();
        }
        return sb.ToString();
    }
}

class Scanner
{
    static string[] s = new string[0];
    static int index;
    public static string cin() {
        if (index < s.Length) return s[index++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return cin();
        index = 0;
        return s[index++];
    }
    public static int cinInt() => int.Parse(cin());
    public static int[] cinArrInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = cinInt() + add;
        return array;
    }
}

Measured memory_bytes: 27228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
ll counter(ll N){
  if(N == 1){
    return 1;
  }
  return 1 + 2 * counter(N / 2);
}
int main() {
  ll H;
  cin >> H;
  cout << counter(H) << endl;
  return 0;
}

Measured memory_bytes: 3596
main = do
  getLine
  tas <- map (map read . words) . lines <$> getContents
  print (report tas)
 
report :: [[Integer]] -> Integer
report ([t,a]:tas) = uncurry (+) (foldl asum (t,a) tas)
 
asum (at,aa) [t,a] = let n = max (div1 at t) (div1 aa a) in (n*t, n*a)

div1 x y = let (q,r) = divMod x y in q + signum r


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

main(){
  int n,a,x,d=0,s=1;
  cin>>n>>a;
  for(int i=0; i<n;i++){
    cin>>x;
    d = d+x;
    if(d<=a) s =s+1;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3544
#include<iostream> 
#include<algorithm>
#include<cstring>
using namespace std;
struct node{
	int a;
	int b;
}s[100005];
int cmp(node x,node y)
{
	return x.a<y.a; 
}
int main()
{
	int n,m;
	int sum=1;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s[i].a>>s[i].b;
	}
	sort(s,s+m,cmp);
	int minb=s[0].b;
	for(int i=1;i<m;i++)
	{
		if(s[i].b<minb)
		minb=s[i].b;
		if(s[i].a>=minb)
		{
				minb=s[i].b	;
				sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split(" ")]

s = 0
num1 = 0
for i, x in enumerate(a):
    if i == 0:
        if x > 0:
            s = x
        else:
            s = 1
            num1 += abs(1-x)
    else:
        if s > 0:
            if s + x < 0:
                s += x
            else:
                num1 += abs(-s-x-1)
                s = -1
        else:
            if s + x > 0:
                s += x
            else:
                num1 += abs(-s-x+1)
                s = 1
s = 0
num2 = 0
for i, x in enumerate(a):
    if i == 0:
        if x < 0:
            s = x
        else:
            s = -1
            num2 += abs(-1-x)
    else:
        if s > 0:
            if s + x < 0:
                s += x
            else:
                num2 += abs(-s-x-1)
                s = -1
        else:
            if s + x > 0:
                s += x
            else:
                num2 += abs(-s-x+1)
                s = 1
print(min([num1, num2]))

Measured memory_bytes: 14332
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
	int n;
	long s;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		cout<<"Case "<<i<<":"<<endl;
		for(int j=0;j<10;j++){
			s = s*s;
			s /= 100;
			if(s>=10000) s = s%10000;
			cout<<s<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 55;
ll dp[N * N * N];
int n, lim[N], m, l, fa[N], per[N];
ll val[N], sz[N];
void add_dp(int v,ll w) {
  rrp (i, n * n * n, v)
    ckmn(dp[i], dp[i - v] + w);
}
void solve() {
  memset(dp, 0x3f, sizeof dp);
  dp[0] = 0;
  rep (i, 1, n) {
    int v = lim[i];
    for (int j = 1; j <= v; j <<= 1)
      add_dp(j * sz[i], j * val[i]), v -= j;
    add_dp(v * sz[i], v * val[i]);
  }
}
int main() {
  read(n), read(m), read(l);
  read(val[1]);
  rep (i, 2, n)
    read(val[i]), read(fa[i]);
  rep (i, 1, n) sz[i] = 1;
  rrp (i, n, 2) {
    val[fa[i]] += val[i];
    sz[fa[i]] += sz[i];
  }
  rep (i, 2, n) lim[i] = min(n, l);
  lim[1] = n;
  solve();
  rep (i, 1, n) per[i] = i;
  sort(per + 1, per + n + 1, [=](const int& a,const int& b) -> bool {
      return val[a] * sz[b] < val[b] * sz[a];
    });
  ll ans = 0, cur = 0;
  rep (i, 1, n) {
    rep (j, 0, n * n * n) if (m >= dp[j]) {
      int res = m - dp[j];
      int tmp = res / val[per[i]];
      if (per[i] != 1) ckmn(tmp, l - lim[per[i]]);
      ckmx(ans, cur + j + (ll)tmp * sz[per[i]]);
    }
    if (per[i] == 1 || m / val[per[i]] < (l - lim[per[i]])) break;
    m -= (l - lim[per[i]]) * val[per[i]];
    cur += (l - lim[per[i]]) * sz[per[i]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner input = new Scanner(System.in);
    
    int n = input.nextInt();
    long k = input.nextLong();
    
    int[] A = new int[n];
    for (int i = 0; i < n; i++) {
      A[i] = input.nextInt();
    }
    
    long step = 0;
    int cur = 1;
    Set<Integer> vis = new HashSet<>();
    while (true) {
      if (vis.contains(cur)) {
        break;
      }
      vis.add(cur);
      step++;
      cur = A[cur - 1];
      if (step == k) {
        System.out.println(cur);
        return;
      }
    }
    
    if (cur != 1) {
      int start = A[0];
      int initialLen = 1;
      while (start != cur) {
        initialLen++;
        start = A[start - 1];
      }

      k -= initialLen;
    }
    
    List<Integer> list = new ArrayList<>();
    list.add(cur);
    int start = A[cur - 1];
    while (start != cur) {
      list.add(start);
      start = A[start - 1];
    }
    
    k %= list.size();
    
    System.out.println(list.get((int)k));
  }
}


Measured memory_bytes: 65900
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n, k;
llint a[200005], b[400005];
llint npos[200005];
P succ[60][200005];
set<llint> S;
stack<llint> stk;

int main(void)
{
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < 2*n; i++) b[i] = a[i%n];
	
	for(int i = 2*n-1; i >= 0; i--){
		if(i < n){
			llint x = npos[b[i]]+1;
			succ[0][i] = P(x/n, x%n);
		}
		npos[b[i]] = i;
	}
	
	for(int i = 1; i < 60; i++){
		for(int j = 0; j < n; j++){
			P p = succ[i-1][j], q = succ[i-1][succ[i-1][j].second];
			llint x = p.first+q.first, y = q.second;
			if(x >= k+1) x = k+1;
			succ[i][j] = P(x, y);
		}
	}
	
	llint x = 0, y = 0;
	for(int i = 59; i >= 0; i--){
		llint nx = x + succ[i][y].first, ny = succ[i][y].second;
		if(nx <= k-1) x = nx, y = ny;
	}
	
	for(; x < k; x++){
		for(; y < n; y++){
			if(!S.count(a[y])){
				S.insert(a[y]);
				stk.push(a[y]);
			}
			else{
				while(stk.top() != a[y]){
					S.erase(stk.top());
					stk.pop();
				}
				S.erase(a[y]);
				stk.pop();
			}
		}
		y = 0;
	}
	
	vector<llint> ans;
	while(stk.size()){
		ans.push_back(stk.top());
		stk.pop();
	}
	reverse(ans.begin(), ans.end());
	
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
	
	return 0;
}


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

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


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 312345;
int L[MAX_N];
int R[MAX_N];

int main2() {
  int N = nextInt();
  string s; cin >> s;

  L[0] = 0;
  for (int i = 0; i < N; i++) {
    L[i+1] = L[i] + (s[i] == 'W');
  }
  R[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    R[i] = R[i+1] + (s[i] == 'E');
  }

  int ans = N;
  for (int i = 0; i < N; i++) {
    int cur = R[i+1] + L[i];
    chmin(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int c = 1;
  int i;
  for(i=0;i<n;i++){
    if(c<=k) c*=2;
    else c+=k;
  }
  cout << c << "\n";
  return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        int N;
        HashMap<Integer, Integer> mp;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            mp = new HashMap<>();
            for (int i = 0; i < N; i++) {
                int a = in.nextInt();
                mp.putIfAbsent(a, 0);
                mp.put(a, mp.get(a) + 1);
            }

            int dup = 0;
            for (Map.Entry<Integer, Integer> e : mp.entrySet()) {
                if (e.getValue() > 1) {
                    dup += e.getValue() - 1;
                }
            }

            int ans = 0;
            if (dup % 2 == 0) {
                ans = N - dup;
            } else {
                ans = N - dup - 1;
            }
            out.println(ans);
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 47084
from collections import deque


n = int(input())
L = deque()

for i in range(n):
    com = input()
    if com[0] == 'i':
        C = com.split()
        L.appendleft(int(C[1]))
    else:
        if com[6] == 'F':
            L.popleft()
        elif com[6] == 'L':
            L.pop()
        else:
            C = com.split()
            x = int(C[1])
            try:
                L.remove(x)
            except:
                pass

print(*L)


Measured memory_bytes: 45948
from numpy import *
M=998244353
N,S,*A=map(int,open(0).read().split())
a=0
f=zeros(S+1,int)
for b in A:
  f[0]+=1
  f[b:] += f[:-b].copy()
  f%=M
  a+=f[S]
print(a%M)



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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int a, b, x;
  cin >> a >> b >> x;
  if (x >= a && x <= a + b) cout << "YES" << '\n';
  else cout << "NO" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3588
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
v = list(map(int, input().split()))

heapq.heapify(v)
ans = heapq.heappop(v)
for i in range(1,N):
    ans += heapq.heappop(v)
    ans /= 2

print(ans)

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    string s;
    cin >> s;
    REP(i, 3)
    {
        if (s[i] - '0' == 1)
        {
            cout << 9;
        }
        else if (s[i] - '0' == 9)
        {
            cout << 1;
        }
    }
    cout << endl;

    return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <cassert>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	cout << min(A, B) << " " << max(0, A+B-N) << endl;

	return 0;
}


Measured memory_bytes: 256