akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int mod=10000;
char a[505],b[505];
int m;
int dp[501][500][10][2][2];//????????????m??§?????£??????????????°??????????????????????¢?????????????????°?????????????n??¨?????´?????????????????´?????????

int check(char *n){//n??\???????????°??¶??°??°
	int i;
	for(i=0;i<501;i++) for(int j=0;j<500;j++) for(int k=0;k<10;k++) for(int r=0;r<2;r++) for(int l=0;l<2;l++) dp[i][j][k][r][l]=0;
	for(i=1;n[i+1]!=0;i++) for(int k=1;k<10;k++) for(int r=0;r<2;r++) dp[i][k%m][k][r][0]=1;
	for(int k=1;k<10;k++) dp[i][k%m][k][0][0]=1;
	for(i=1;i<n[0]-48;i++) dp[0][i%m][i][1][0]=dp[0][i%m][i][0][0]=1;
	dp[0][(n[0]-48)%m][n[0]-48][0][1]=dp[0][(n[0]-48)%m][n[0]-48][1][1]=1;
	for(i=0;n[i+1]!=0;i++) for(int j=0;j<m;j++) for(int k=0;k<10;k++){
		for(int z=0;z<10;z++){
			if(k==z) continue;
			dp[i+1][(j*10+z)%m][z][z>k][0]+=dp[i][j][k][z<k][0];
			if(n[i+1]-48==z) dp[i+1][(j*10+z)%m][z][z>k][1]+=dp[i][j][k][z<k][1];
			if(n[i+1]-48>z)  dp[i+1][(j*10+z)%m][z][z>k][0]+=dp[i][j][k][z<k][1];
			dp[i+1][(j*10+z)%m][z][z>k][0]%=10000;
		}
	}
	int res=0;
	if(i==0){
		for(int j=1;j<=n[0]-48;j++) if(j%m==0) res++;
		return res;
	}
	for(int k=0;k<10;k++) for(int r=0;r<2;r++) for(int l=0;l<2;l++){ res+=dp[i][0][k][r][l]; res%=10000;}
	return res%10000;
}

int zig(char *n){//n????????°??¶??°?????????
	if(n[1]==0) return 1;
	if(n[0]==n[1]) return 1;
	bool c=n[0]<n[1];
	for(int i=1;n[i+1]!=0;i++) if((n[i]<n[i+1])==c||n[i]==n[i+1]) return 0; else c=n[i]<n[i+1];
	return 1;
}

int main(){
	scanf("%s%s%d",a,b,&m);
	printf("%d\n",(check(b)-check(a)+zig(a)+10000)%10000);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

char S[MAXN+10], T[MAXN+10];

int main()
{
	int i, j;

	scanf("%s%s", S+1, T+1);
	int ans=0;
	for(i=1; S[i]; i++) ans+=S[i]!=T[i];
	printf("%d\n", ans);
}

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

typedef long long ll;
const int mod = 1e9 + 7;

ll N, M;

int main() {
    cin >> N >> M;

    ll ans = 1;
    for (ll A = 1; A * A <= M; A++) {
        if (M % A != 0) continue;

        ll B = M / A;
        if (A * N <= M) ans = max(ans, A);
        if (B * N <= M) ans = max(ans, B);
    }
    cout << ans << endl;
}

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

// このコードでは活用していないが、
// (a+b)^2= (a-b)^2+ 4ab より
// sqrt(N)に近い約数のペアa,bがa+bを最小化する
int main(){
  int64_t N;
  cin >> N;

  int64_t ans= INT64_MAX;
  int64_t div= 1;
  while(div*div <= N){
    if(N% div==0){
      ans= min(ans, (div- 1)+(N/div- 1)); 
    }

    div++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
G = [list(map(int, input().split())) for _ in range(M)]
edges = [[] for _ in range(N)]
for a, b in G:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

def dfs(start, edges, path):
    path.append(start)
    if len(path) == N:
        path.pop()
        return 1
    ans = 0
    for u in edges[start]:
        if u in path:
            continue
        ans += dfs(u, edges, path)
    path.pop()
    return ans

print(dfs(0, edges, []))

Measured memory_bytes: 3064
/*------------------RandomStuff------------------*/
//      Author: CNH_Tourist
//      Date: 30/08/2020
//      Time: 15:26:22
/*-----------------------------------------------*/
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")
using namespace std;
/*---------------------Define--------------------*/
#define filename "TestCode"
#define pi acos(-1)
#define endl '\n'
#define X first
#define Y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define ull unsigned long long
#define hash OoOoO
#define gcd __gcd
#define y1 FlyingTuna 
/*-----------------------------------------------*/
const long long mod  = 1e9+7;
const long long mod2 = 1e9+9;
const long long INF  = 1e15;
const long long oo   = 2e18+7;
const long long base = 31;
const double eps = 1e-8;
int test=1;
/*-----------------------------------------------*/
void FlyingTuna()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
/*
    ifstream *fi = new ifstream (filename".inp");
    ofstream *fo = new ofstream (filename".out");
    if(*fi)
    {
        cin.rdbuf( fi->rdbuf() );
        cout.rdbuf( fo->rdbuf() );
    }
*/
}
/*-------------------Global----------------------*/
int n;
ll d[100010];
ll f[100010], a[17][17];
/*------------------Functions--------------------*/

/*-----------------------------------------------*/
void In()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            cin >> a[i][j];
}

void Solve()
{
    In();

    for(int mask = 1; mask < 1 << n; mask ++)
    {
        for(int i = 0; i < n; i ++)
            for(int j = i + 1; j < n; j++)
                if((1 & (mask >> i)) == 1 && (1 & (mask >> j)) == 1)
                    d[mask] += a[i+1][j+1];
    }

    for(int mask = 1; mask < 1 << n; mask ++)
    {
        f[mask] = max(f[mask], d[mask]);
        for(int i = mask; i > 0; i =((i-1)&mask))
            f[mask] = max(f[mask], f[i] + d[i^mask]);
    }
    
    int t = (1 << n) - 1;
    cout << f[t];

}

int32_t main()
{
    FlyingTuna();
    
    //cin>>test;while(test--)
    Solve();

}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
 
#define hell                         1000000007
#define hell2                        998244353
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           int
#define vll                          vector<ll>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define all(v)                       v.begin(),v.end()
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'
 
const ll MAX=500005;
const ll SQN=330;
const ll LG=22;
const double PI=atan(1)*4;
using namespace std;

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

    ll k,a,b;
    cin >> k >> a >> b;
    rep(i,a,b+1) {
    	if(i%k==0) {
    		ret("OK");
    	}
    }
    ret("NG");
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

void sali() {
	int A, B, K;
	cin >> A >> B >> K;
	K--;
	for (size_t i = A; i <= B; i++)
	{
		if (i <= A + K || B - K <= i) {
			cout << i << endl;
		}
	}
}
int main() {
	sali();
	return 0;
}

Measured memory_bytes: 256
Q = int(input())
point=[]
query=[]
for i in range(Q):
    l,r=[int(i) for i in input().split()]
    point.append(l)
    point.append(r)
    query.append([l,r])
# print(point)
point_uniq = list(set(point))
# print(point_uniq)
point_sorted = sorted(point_uniq)
# print(point_sorted)

def binary_search(list,target):

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = (left + right)//2
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	return result


#ふるい
SIZE=100001
is_prime=[True for i in range(SIZE)]
is_prime[0]=False
is_prime[1]=False
for i in range(2,SIZE):
    # print(i,is_prime)
    if is_prime[i]==False:
        continue
    else:
        tmp=i+i
        while(tmp<SIZE):
            is_prime[tmp]=False
            tmp+=i

MIN=point_sorted[0]
MAX=point_sorted[-1]
N_count=0
index=1
range_N=[]
for i in range(MIN,MAX+1):
    if i%2==0:
        continue
    if is_prime[i]==True and is_prime[int((i+1)/2)]==True:
        N_count+=1
    if i==point_sorted[index]:
        index+=1
        range_N.append([MIN,i,N_count])
# print(range_N)

for q in query:
    ans=0
    l_index=binary_search(point_sorted,q[0])
    r_index=binary_search(point_sorted,q[1])

    # l_index=point_sorted.index(q[0])
    # r_index=point_sorted.index(q[1])
    # print(q,l_index,r_index)
    if l_index==r_index:
        ans=1 if is_prime[q[0]] and is_prime[int((q[0]+1)/2)] else 0
    elif l_index==0:
        ans=range_N[r_index-1][2]
    else:
        ans=range_N[r_index-1][2]-range_N[l_index-1][2]
        if is_prime[q[0]] and is_prime[int((q[0]+1)/2)]:
            ans+=1
    print(ans)


Measured memory_bytes: 32324
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll x,y,a,b,c,i;
    ll p;
    vector<pair<ll,ll>> app;
    cin>>x>>y>>a>>b>>c;
    for (i=0;i<a;i++)
    {
        cin>>p;
        app.pb(mp(p,1LL));
    }
    for (i=0;i<b;i++)
    {
        cin>>p;
        app.pb(mp(p,2LL));
    }
    for (i=0;i<c;i++)
    {
        cin>>p;
        app.pb(mp(p,3LL));
    }
    sort(app.begin(),app.end());
    ll r=0,g=0,ex=0,ans=0;
    for (i=app.size()-1;i>=0;i--)
    {
        if (r+g+ex>=x+y)
            break;
        if (app[i].ss==1)
        {
            if (r<x)
            {
                ans+=app[i].ff;
                r++;
            }
        }
        else if (app[i].ss==2)
        {
            if (g<y)
            {
                ans+=app[i].ff;
                g++;
            }
        }
        else
        {
            ans+=app[i].ff;
            ex++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10476
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define int long long
// inline int abbs(int x) { if (x>0) return x; return -x; }
signed main()
{
	int x,k,d;
	scanf("%lld%lld%lld",&x,&k,&d);
    if(x<0)x=-x;
	int ans=x%d;
	if ((x/d)>=k) return printf("%lld\n",x-k*d),0;
	if ((k-(int)(x/d))%2==0) printf("%lld\n",ans);
	else printf("%lld\n",min(ans+d,-(ans-d)));
	return 0; 
}

Measured memory_bytes: 3804
import java.util.*;
class Main{
	public static void main(String[]z){
		Scanner c=new Scanner(System.in);
		int i,n,s;
		for(;(n=c.nextInt())>0;System.out.println(s/(n-2))){
			List<Integer> l=new ArrayList<Integer>();
			for(s=i=0;i<n;i++)l.add(c.nextInt());
			Collections.sort(l);
			l.remove(n-1);l.remove(0);
			for(int x:l)s+=x;
		}
	}
}

Measured memory_bytes: 12000
h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][j] > c[i][k] + c[k][j]:
                c[i][j] = c[i][k] + c[k][j]
ans = 0
for i in range(h):
    a = list(map(int, input().split()))
    for j in a:
        if j != -1:
            ans += c[j][1]
print(ans)

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())

    X = min(A, B, C, D, E)
    q, r, = divmod(N, X)
    num = q + int(r > 0)

    ans = 5 + (num - 1)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val an = IntArray(n, { readLine()!!.toInt() })
  val selected = BooleanArray(n, { false })
  
  var s = 0;
  var count = 0;
  while(true){
    if (selected[s]){
      count = -1;
      break;
    }
    selected[s] = true;
  	s = an[s] - 1;
    count += 1;
    if (s == 1){
      break;
    }
  } 
  println(count);
}

Measured memory_bytes: 37592
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	char c;
	string s;
	int cnt=0,n;
	cin >> s;
	n = s.length();

	REP(i,n){
		cnt += (s[i]=='0')? -1:1;
	}
	println(s.length()-abs(cnt));

	return 0;
}


Measured memory_bytes: 512
// Atcoder grand 025.cpp : Defines the entry point for the console application.
//

#include <bits/stdc++.h>


using namespace std;

int sum(int n)
{
	int sum{ 0 };
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}
int main()
{
	int N;
	cin >> N;
	int ans{ 99999999 };

	for (int i = 1; i < (N / 2)+1; i++)
	{
		ans = min(ans, sum(i) + sum(N - i));

	}
	cout << ans;




    return 0;
}



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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, l; cin >> n >> l;
	vector<string> v;
	string temp;
	for (int i = 0; i < n; ++i) {
		cin >> temp;
		v.push_back(temp);
	}
	sort(v.begin(), v.end());
	
	for (string i : v)
		std::cout << i;
}

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

int main() {
  int n;
  int64_t s = 0, arai = 0, ans;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    arai += a.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    s += a.at(i);
    arai -= a.at(i);
    if (i == 0) {
      ans = abs(s - arai);
    }
    else {
      ans = min(ans, abs(s - arai));
    }
  }
  cout << ans << endl;
}

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



using namespace std;

int main()
{
    int n; // the number of temperatures to analyse
  	int k;
  	vector<int> h;
  	int cost[1000000];
  	
    cin >> n; cin.ignore();
    cin >> k; cin.ignore();
    for (int i = 0; i < n; i++) {
        int t; // a temperature expressed as an integer ranging from -273 to 5526
        cin >> t; cin.ignore();
        h.push_back(t);
    }

  cost[0]=0;
  cost[1] = abs(h[1]-h[0]);
	
  for (int i = 2; i < n; i++) {
    int mincost= 1000000000;
    for (int j = 0; j < k; j++) {
      if(j == i) break;
      mincost= min(mincost, cost[i-(j+1)]+ abs(h[i]-h[i-(j+1)]));
    }  
    cost[i] =mincost;
  } 	
    cout<<cost[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 3192
#include<stdio.h>

int main(){
	double a=0;
	while(scanf("%lf",&a)!=EOF){
		if(a<=48.00){
			printf("light fly\n");
		}
		else if(a<=51.00){
			printf("fly\n");
		}
		else if(a<=54.00){
			printf("bantam\n");
		}
		else if(a<=57.00){
			printf("feather\n");
		}
		else if(a<=60.00){
			printf("light\n");
		}
		else if(a<=64.00){
			printf("light welter\n");
		}
		else if(a<=69.00){
			printf("welter\n");
		}
		else if(a<=75.00){
			printf("light middle\n");
		}
		else if(a<=81.00){
			printf("middle\n");
		}
		else if(a<=91.00){
			printf("light heavy\n");
		}
		else {
			printf("heavy\n");
		}
	}
return 0;
}

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

void solve(int N, int x)
{
    int ans = 0;
    for(int i=1; i<=N; i++)
    {
        for(int j=i+1; j<=N; j++)
        {
            int k = x - i - j;
            if(k > j && k <= N) ans++;
        }
    }
    cout << ans << '\n';
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, x;
    while(cin >> N >> x)
    {
        if(N==0 && x==0) break;
        solve(N, x);
    }
    

    return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
	int A, B, C;
	scanf("%d %d %d",&A ,&B ,&C);
		if(A==5&&B==5&&C==7){
			printf("YES\n");
		}
		else if(A==5&&B==7&&C==5){
			printf("YES\n");
		}
		else if(A==7&&B==5&&C==5){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
		return 0;
	
}



Measured memory_bytes: 128
#define yuki(x, y) for(int i = x; i < (y); ++i)
#define yukj(x, y) for(int j = x; j < (y); ++j)
#define yukii(x, y) for(int i = x; i <= (y); ++i)
#define yukji(x, y) for(int j = x; j <= (y); ++j)
#define yuk(x, y, z) for(int x = y; x < (z); ++x)
#define yui(x, y, z) for(int x = y; x >= (z); --x)
#define sclr(x) memset(x, 0, sizeof(x))
#define sclr1(x) memset(x, -1, sizeof(x))
#define scl(x, y) memset(x, y, sizeof(x))
#define ft first
#define sc second
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long lol;
int n, k, a[100100];
lol sum1, sum2, ans;
void sread()
{
    scanf("%d%d", &n, &k);
    yukii(1, n) scanf("%d", a+i);
}
int main(int argc, char **argv)
{
	sread();
	int l = 1, r = k;
	yukii(k+1, n) if(a[i] > 0) sum1 += a[i];
	yukii(1, k) sum2 += a[i];
	while(r <= n)
    {
        ans = max(ans, sum1+max(sum2, 0ll));
        if(a[l] > 0) sum1 += a[l];
        sum2 -= a[l++];
        if(a[++r] > 0) sum1 -= a[r];
        sum2 += a[r];
    }
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640
n=int(input())
l=[[] for i in range(n)]
for i in range(n-1):
    x,y = map(int,input().split())
    x-=1
    y-=1
    l[x].append(y)
    l[y].append(x)
from collections import deque
q=deque([0])
lf=[10**100 for i in range(n)]
lf[0]=0
while q:
    p=q.popleft()
    for i in l[p]:
        if lf[p]+1<lf[i]:
            lf[i]=lf[p]+1
            q.append(i)
q=deque([n-1])
ls=[10**100 for i in range(n)]
ls[n-1]=0
while q:
    p=q.popleft()
    for i in l[p]:
        if ls[p]+1<ls[i]:
            ls[i]=ls[p]+1
            q.append(i)
s,f=0,0
for i in range(n):
    if lf[i]<=ls[i]:
        f+=1
    else:
        s+=1
if f<=s:
    print("Snuke")
else:
    print("Fennec")

        



Measured memory_bytes: 29552
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)a.size() 
#define all(a) a.begin(),a.end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 

#define int long long 

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 1e5 + 5 ;

vii g[N] ;
bool vis[N];
int ans[N] ;

void bfs() {
	queue<int> q;
	vis[1] = 1 ;
	q.push(1) ;

	while(!q.empty()) {
		int p = q.front() ; q.pop() ;
		for(auto i : g[p]) {
			if(!vis[i]) {
				vis[i] = 1;
				ans[i] = p ;
				q.push(i); 
			}
		}
	}
}

void solve() {
	int n,m; cin >> n >> m ;
	rep(i,0,m) {
		int u,v; cin >> u >> v; 
		g[u].eb(v) ;
		g[v].eb(u);
	}
	bfs();

	rep(i,1,n+1) if(!vis[i]) {cout <<"No"; return ;}

	cout << "Yes\n";

	rep(i,2,n+1) cout << ans[i] << nl ;
}	

int32_t main() {

    fast; 
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve() ;
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 13120
#include <cstdio>
int arr[505], sz_l[505], sz_r[505], ans[300005];
int main()
{
	// freopen("AGC008-D.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i);
		arr[i]--;
	}
	for (int i = 0; i < n * n; i++)
	{
		ans[i] = -1;
		for (int j = 0; j < n && -1 == ans[i]; j++)
		{
			if (arr[j] == i)
				ans[i] = j;
		}
		int pos = -1;
		for (int j = 0; j < n && -1 == ans[i]; j++)
		{
			if (i < arr[j] && sz_l[j] < j && (pos == -1 || arr[j] < arr[pos]))
				pos = j;
		}
		if (~pos)
		{
			ans[i] = pos;
			sz_l[pos]++;
		}
		for (int j = 0; j < n && -1 == ans[i]; j++)
		{
			if (arr[j] < i && sz_r[j] < n - j - 1)
			{
				ans[i] = j;
				sz_r[j]++;
			}
		}
		if (ans[i] == -1)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	for (int i = 0; i < n * n; i++)
		printf("%d%c", ans[i] + 1, " \n"[i + 1 == n * n]);
	return 0;
}


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

using namespace std;

const int N=10;

int n;
int k;
int d[N];
bool vis[10];

int main()
{
	cin>>n>>k;
	for(int i=1;i<=k;++i)
	{
		cin>>d[i];
		vis[d[i]]=true;
	}
	for(int i=n;i<=99999;++i)
	{
		int k=i;
		bool ok=false;
		while(k>0)
		{
			if(vis[k%10])
			{
				ok=true;
				break;
			}
			k/=10;
		}
		if(!ok)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	/*
	for(int i=0;i<n.size();++i)
	{
		int c=n[i];
		bool ok=false;
		if(i==0)bool ok2=false;
		for(int j=0;j<10;++j)
		{
			if(vis[j])continue;
			if(i==0&&j<)
		}
	}
	*/
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long A,B,C,X,Y,p,ans;
int main()
{
	scanf("%lld%lld%lld%lld%lld",&A,&B,&C,&X,&Y);X*=2;Y*=2;
	if(2*C<A+B){
		ans+=min(X,Y)*C;
		if(X<=Y){
			Y-=X;
			if(2*C<B)ans+=Y*C;
			else ans+=(Y/2)*B;
		}
		else{
			X-=Y;
			if(2*C<A)ans+=X*C;
			else ans+=A*(X/2);
	}
}
	else{
	ans=A*X+B*Y;ans/=2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp

black_count = s.count('#')
white_count = s.count('.')
if black_count == 0 || white_count == 0
  puts 0
  exit
end

first_index = s.index('.#')
if first_index == nil
  black_count = s.count('#')
  white_count = s.count('.')
  count = black_count > white_count ? white_count : black_count
  puts count
  exit
end
first_count = s[0...first_index].count('#') + s[(first_index+1)...n].count('.')

index = first_index + 1
previous_count = first_count
min_count = first_count
while true do
  black_index = s.index('.#', index)
  break if black_index == nil
  substr = s[index..black_index]
  count = previous_count + substr.count('#') - substr.count('.')

  if count < min_count
    min_count = count
  end

  index = black_index + 1
  previous_count = count
end
puts min_count


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll n,a[101],f[101][100010],k,sum[101][100010];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	f[0][0]=1;
	for(int i=0;i<=k;i++)
		sum[0][i]=sum[0][i-1]+f[0][i];
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			f[i][j]=(sum[i-1][j]+mod-sum[i-1][j-min((ll)j,a[i])-1])%mod;
			sum[i][j]=(f[i][j]+sum[i][j-1])%mod; 
		}
	}
	cout<<f[n][k]<<endl;
	return 0;
}


Measured memory_bytes: 158080
N, Y = map(int, input().split())

Y //= 1000

for i in range(Y//10 + 1):
  Y1 = Y - 10*i
  for j in range(Y1//5 + 1):
    Y2 = Y1 - 5*j
    if Y2 == N - (i+j):
      print(i, j, Y2)
      exit()

print(-1, -1, -1)

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

using namespace std;

int main(){
 string s;
  int n, q;
  cin >> n >> q;
 cin >> s;
  int acum1[s.size() + 1], acum2[s.size() + 1];
  memset(acum1, 0, sizeof acum1);
  memset(acum2, 0, sizeof acum2);
  for(int i = 0; i < s.size() - 1; i++){
  	 acum1[i + 1] = acum1[i] + (s[i] == 'A' && s[i + 1] == 'C');
  }
  acum1[s.size()] += acum1[s.size() - 1];
  for(int i = 1; i < s.size(); i++){
  	 acum2[i + 1] = acum2[i] + (s[i] == 'C' && s[i - 1] == 'A');
  }
  while(q--){
   	int a, b;
    cin >> a >> b;
    if(s[a - 1] == 'C')a++;
    if(s[b - 1] == 'A')b--;
    if(a >= b)cout << "0" << endl;
    else cout << min(acum1[b] - acum1[a - 1], acum2[b] - acum2[a - 1]) << endl;
  }
 return 0; 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main(){
  int n;cin>>n;
  ll a[n],b[n];rep(i,n)cin>>a[i]>>b[i];
  ll ctr=0;
  rep(rei,n){
    int i=n-1-rei;
    ctr+=(b[i]-(a[i]+ctr)%b[i])%b[i];
  }
  cout<<ctr<<endl;
}


Measured memory_bytes: 1792
n = int(input())
x = sorted(list(map(int,input().split())))
ans = float("inf")
def solve(p,m):
  a = len(m)
  b = 0
  for i in range(a):
    b += (m[i]-p)**2
  return b
for j in range(1,101):
  ans = min(ans,solve(j,x))
print(ans)

Measured memory_bytes: 38768
#include <iostream>
#include <cmath>
#include <complex>

using namespace std;

int main(){
	int n;
	cin >> n;
	while(n){
		complex<long double> p[300];
		int s = 1;
		for(int i = 0; i < n; i++){
			long double a,b;
			cin >> a >> b;
			p[i] = complex<long double>(a,b);
		}
		for(int i  = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				if(abs(p[i]-p[j]) < 2){
					complex<long double> _p = polar(pow(1-norm(p[i]-p[j])/4,0.5),arg(p[i]-p[j])+M_PI_2);
					complex<long double> o[2];
					for(int k = 0; k < 2; k++){
						o[k] = complex<long double>(real(p[i]+p[j])/2,imag(p[i]+p[j])/2);
					}
					o[0] += _p;
					o[1] -= _p;
					for(int k = 0; k < 2; k++){
						int t = 0;
						for(int l = 0; l < n; l++){
							if(abs(p[l]-o[k]) <= 1.0001) ++t;
						}
						s = max(s,t);
					}
				}
			}
		}
		cout << s << endl;
		cin >> n;
	}
}

Measured memory_bytes: 996
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;



int main(void) {
	ll n,m=0,sum=1,k= 998244353;

	cin >> n;
	vint d(n);
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		m = max(m, a);
		d[a]++;
		if (i == 0 && a != 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	if (d[0] != 1) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < d[i+1]; j++) {
			sum = (sum*d[i]) % k;
		}
	}
	cout << sum << endl;
}




Measured memory_bytes: 1024
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    _ <- getLine
    vs <- map fromIntegral <$> getIntList
    print $ solve vs

solve [v] = v
solve vs = solve (((v1 + v2) / 2) : vs')
   where (v1 : v2 : vs') = sort vs

Measured memory_bytes: 636
#include "stdio.h"

int kaijo(int a){
  int c=1;
  for(int i=1;i<=a;i++) c*=i;
  return c;
}

int main(){
  int n,x[9],y[9];double d=0;
  scanf("%d ",&n);
  for(int i=0;i<n;i++){
     scanf("%d %d",&x[i],&y[i]);
  }
 for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
    if(i!=j)d+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
   }
 }
  printf("%lf",(double)d/n);
  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
  val (N, K) = readInts()
  val P = readInts()
  val P2 = P.map { it + 1 }

  val sums = Array(N) { 0 }
  sums[0] = P2[0]
  for (i in 1 until N) {
    sums[i] = sums[i - 1] + P2[i]
  }
  var max = sums[K - 1]
  for (i in K until N) {
    max = Math.max(max, sums[i] - sums[i - K])
  }
  println(max / 2.0)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 81284
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}

signed main (){
    int n,m;
    cin>>n>>m;
    vector<int> v(m,0);
    rep(i,0,n){
        int k;cin>>k;
        rep(j,0,k){
            int a;cin>>a;a--;
            v[a]++;
        }
    }

    int ans=0;
    rep(i,0,m){
        ans+=(v[i]==n);
    }
    cout<<ans<<endl;
}
/*
00001
00110
00011

00122
*/


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		int h = Integer.parseInt(tmpArray[0]);
		int w = Integer.parseInt(tmpArray[1]);

		char[][] board = new char[h][w];

		DisjointSet ufVertical = new DisjointSet(h*w);
		DisjointSet ufHorizontal = new DisjointSet(h*w);


		for(int i = 0; i < h; i++){
			board[i] = br.readLine().toCharArray();
		}

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(board[i][j] == '#'){
					continue;
				}

				if(i >= 1 && board[i][j] == board[i - 1][j]){
					ufVertical.union(i*w + j, (i - 1)*w + j);
				}

				if(j >= 1 && board[i][j] == board[i][j - 1]){
					ufHorizontal.union(i*w + j, i*w + j - 1);
				}
			}
		}

		//各グループの数を数えておく（後で比較的高速に参照可）
		int[] groupCountV = new int[h*w];
		int[] groupCountH = new int[h*w];
		for(int i = 0; i < h*w; i++){
			groupCountV[ufVertical.findSet(i)]++;
			groupCountH[ufHorizontal.findSet(i)]++;

		}

		int result = 0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(board[i][j] == '#'){
					continue;
				}

				int tmp = groupCountV[ufVertical.findSet(i*w + j)] + groupCountH[ufHorizontal.findSet(i*w + j)] - 1;

				result = Math.max(tmp, result);
			}

		}

		System.out.println(result);
	}

}

class DisjointSet {
	private int n;
	private int[] p;
	private int[] rank;

	public DisjointSet(int n){
		this.n = n;

		p = new int[n + 1];
		rank = new int[n + 1];

		for(int i = 1; i <= n; i++){
			makeSet(i);
		}
	}

	private void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}

	public void union(int x, int y){
		link (findSet(x), findSet(y));
	}

	//今回の問題では特別にpublic
	public int findSet(int x){
		if(x != p[x]){
			p[x] = findSet( p[x]);
		}
		return p[x];
	}

	public boolean isSameSet(int x, int y){
		return findSet(x) == findSet(y);
	}

	private void link(int x, int y){
		if(rank[x] > rank[y]){
			p[y] = x;
		}
		else {
			p[x] = y;
			if(rank[x] == rank[y]){
				rank[y]++;
			}
		}
	}
}

Measured memory_bytes: 152448
A=[int(input()) for x in range(5)]
j=0
for i in range(4):
  if (A[j]-1)%10>(A[i+1]-1)%10:
    j=i+1
B=[(A[i]//10)*10+10 if A[i]%10!=0 else A[i] for i in range(5)]
B[j]=A[j]
print(sum(B))

Measured memory_bytes: 3060
H,W=map(int,input().split())
A=[]
for i in range(H):
  a=input()
  A.append(a)
aw_h=[]
aw_v=[]
for i in range(H):
  if '#' not in A[i]:
    aw_h.append(i)
for i in range(len(aw_h)):
  A.pop(aw_h[i]-i)
for i in range(W):
  count=0
  for j in range(len(A)):
    if A[j][i]=='.':
      count+=1
  if count==len(A):
    aw_v.append(i)
for i in range(len(A)):
  for j in range(len(aw_v)):
    A[i]=A[i][:aw_v[j]-j]+A[i][aw_v[j]-j+1:]
for i in range(len(A)):
  print(str(A[i]))

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

using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> p(N);
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    for (int i = 0; i < N; i++) a[i] = p[i];

    sort(a.begin(), a.end());

    bool f = true;
    for (int i = 0; i < N; i++) {
        if (a[i] == p[i]) continue;
        else f = false;
    }
    if (f) {
        cout << "YES" << endl;
        return 0;
    }


    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            swap(p[i], p[j]);

            bool flag = false;
            for (int k = 0; k < N-1; k++) {
                if (p[k] <= p[k+1]) continue;
                else {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                cout << "YES" << endl;
                return 0;
            }

            swap(p[i], p[j]);
        }
    }
    cout << "NO" << endl;
}






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

int main()
{
  char chara;
  cin >> chara;
  
  if (chara=='a' || chara=='i'||chara=='u'||chara=='e'||chara=='o')
  	cout << "vowel" << endl;
  else
    cout << "consonant" <<endl;
  
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vs=vector<string>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
int main(){
    cin.sync_with_stdio(0);

    ll d, t, s;
    cin >> d >> t >> s;
    cout << ((t * s >= d) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3608
from math import *
from bisect import bisect_left

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
    while l <= r: 
        mid = l + (r - l) // 2; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a,b = cin()
    arr = cina()
    arr.sort()
    ans = 0
    for i in range(b):
        ans += arr[i]
    print(ans)





if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  string s;
  cin>>s;
  int q;
  cin>>q;
  int f=0;
  string s1,s2;
  while(q--){
    int t;
    cin>>t;
    if(t==1){
        f=!f;
    }
    else{
        int c;char ch;
        cin>>c>>ch;
        if(f==0){
            if(c==1){
                s1.push_back(ch);
            }
            else{
                s2.push_back(ch);
            }
        }
        else if(f==1){
            if(c==1){
                s2.push_back(ch);
            }
            else{
                s1.push_back(ch);
            }
        }
    }
  }
  if(f){
    reverse(s2.begin(),s2.end());
    reverse(s.begin(),s.end());
    s2+=s+s1;
    cout<<s2<<endl;
    }
  else{
    reverse(s1.begin(),s1.end());

    s1+=s+s2;
    cout<<s1<<endl;
  }

}


Measured memory_bytes: 1348
end_price = int(input())
price = end_price/1.08
price = int(price)

start_price = [price, price+1, price-1]
prices = [int(price*1.08), int((price+1)*1.08), int((price-1)*1.08)]

for ind, x in enumerate(prices):
    if x == end_price:
        print(start_price[ind])
        exit(0)
print(":(")

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

typedef long long LL;

LL memo[100005];
LL h[100005];
int k = 2;
int n;

LL dp(int idx){
   if(idx == n) return 0LL;
   LL &ret = memo[idx];
   if(ret!=-1) return ret;
   ret = 1e17;
   for(int i=1;i<=k;i++){
      if(idx+i>n) break;
      ret = min(ret,dp(idx+i) + abs(h[idx] - h[idx+i]));
   }
   return ret;
}

int main(){
   memset(memo,-1,sizeof(memo));
   scanf("%d",&n);
   scanf("%d",&k); //for frog 2
   for(int i=1;i<=n;i++) scanf("%lld",&h[i]);
   LL ans = dp(1);
   printf("%lld\n",ans);
	return 0;
}


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

#define ll            long long
#define pb            push_back
#define si            set <int>
#define F             first
#define S             second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define fr(i,a,b)     for(int  i=a;i<=b;i++)
#define loop(i,n)     for(int i=0;i<n;i++)
#define all(v)        v.begin(),v.end()
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define mp            make_pair
#define input(arr,n)  loop(i,n) cin>>arr[i]
#define output(arr,n) loop(i,n) cout<<arr[i]<<" "
#define mod           998244353
#define sof           sizeof
using namespace std;
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}

bool isPrime(int num){
    
    if(num==2) return true;
    if(num<2 || num%2==0) return false;
    for(int i = 3; i*i <=num; i+=2) {
       if(num % i == 0) {
          
          return false;
       }
    }
    return true;
   
}

bool comp(const pair<int,int> &a,const pair<int,int> &b){
  return a.F>b.F;
}



void solve(){
  
  int n;
  cin>>n;
  vector<vector<int>> arr(3,vector<int>(n,0));
  vector<vector<int>> dp(3,vector<int>(n,0));

  loop(i,n){
    cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
  }
  dp[0][0]=arr[0][0];
  dp[1][0]=arr[1][0];
  dp[2][0]=arr[2][0];
  fr(i,1,n-1){
    dp[0][i]=arr[0][i]+max(dp[1][i-1],dp[2][i-1]);
    dp[1][i]=arr[1][i]+max(dp[0][i-1],dp[2][i-1]);
    dp[2][i]=arr[2][i]+max(dp[0][i-1],dp[1][i-1]);
  }
  cout<<max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1]);


}




signed main()   
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout); 
  #endif  

  int t;
  t=1;
  //cin>>t;
  loop(i,t){

      solve();
      if(i<t-1) cout<<"\n";
  }

  
  
  //directed graph
    



}
  


  



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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

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

int main(){
	int n;
	cin>>n;
	vi a(n),b(n);

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

	sort(all(b));

	int h=n/2;
	for (int i = 0; i < n; i++){
		if(a[i]<b[h]){
			cout<<b[h]<<endl;
		}else{
			cout<<b[h-1]<<endl;
		}
	}
	

	return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int a = 0;
        int b = S.length()-1;
        int counter = 0;
        while (a<=b) {
            if (S.charAt(a)!=S.charAt(b))
                counter++;
            a++;
            b--;
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 23764
N,K = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))
n = [int(c) for c in str(N)]
len_n = len(n)
digits = []
for i in range(10):
    if not(i in A):
        digits.append(i)


def need_big_keta():
    if n[0] <  digits[-1]:
        return False
    i=0
    while i < len_n and n[i] == digits[-1] :
        i+=1
    if i==len_n:
        return False
    if n[i] < digits[-1]:
        return False
    return True

if not need_big_keta():
    for i in range(N,int("9"*len_n)+1):
        j = i
        flag = True
        while j:
            if not j%10 in digits:
                flag = False
                break
            j/=10
        if flag:
            print i
            break
elif 0 in digits:
    print str(digits[1])+"0"*len_n
else:
    print str(digits[0])*(len_n+1)


Measured memory_bytes: 2944
list = []
for i in range(5):
    list.append(int(input()))
ans = 0
odd_l = []
for i in range(5):
    odd_l.append(list[i] % 10)
#print(odd_l)

count = 0
for i in range(5):
    if odd_l[i] == 0:
        ans += list[i]
        list[i] = 0
        odd_l[i] = 999999
        count += 1
#print(ans)

#print(list[odd_l.index(min(odd_l))])
ans += list[odd_l.index(min(odd_l))]
odd_l[odd_l.index(min(odd_l))] = 99999
#print(odd_l)

for i in range(5):
    if odd_l[i] <= 123:
        ans += (int(list[i] / 10) + 1) * 10
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int main(){
    int N; cin >> N;

    bool f = false;
    for (int i = 0; i < N; i++){
        char S; cin >> S;
        if (S == 'Y'){
            f = true;
            break;
        }
    }

    if (f == true){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[1111];

void MAIN() {
    scanf("%s", S);
    N = strlen(S);
    bool yes = true;
    if (N % 2) yes = false;
    REP (i, N) {
	if (i % 2 == 0) {
	    if (S[i] != 'h') yes = false;
	} else {
	    if (S[i] != 'i') yes = false;
	}
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 764
N, Y = map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if k>=0 and 10000*i+5000*j+1000*k == Y:
            print(i,j,k)
            exit()
print(-1,-1,-1)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int ans[100010];
int main()
{
	string S;
	cin >> S;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R' && S[i + 1] == 'L') {
			ans[i]++;
			ans[i + 1]++;
			for (int j = i - 1; j >= 0; j--) {
				if (S[j] == 'L') break;
				if ((i - j) % 2 == 1) ans[i + 1]++;
				else ans[i]++;
			}
			for (int j = i + 2; j < N; j++) {
				if (S[j] == 'R') break;
				if ((j - i - 1) % 2 == 1) ans[i]++;
				else ans[i + 1]++;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 4068
#include<iostream>
int main()
{
    int a,b,c,k,ans=0;
    std::cin>>a;
    std::cin>>b;
    std::cin>>c;
    std::cin>>k;
    if(a-k>=0){
        ans+=k;
    }else{
        ans+=a;
        if(b-(k-a)<0){
            ans+=b-(k-a);
        }
    }
    std::cout<<ans<<std::endl;
}

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

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

int main() {
    int x, y, z;

    cin >> x >> y >> z;

    int ans = 1;
    while (true) {
        if (x < (z + (y + z) * ans)) {
            ans--;
            break;
        }
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
X = [0] * N
Y = [0] * N
result = [0] * N
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    Dist = X[i]**2 + Y[i]**2
    if Dist <= D**2:
        result[i] = 1
    else:
        result[i] = 0
print(sum(result))


Measured memory_bytes: 26220