akhauriyash/Code-Regression huggingface dataset:
/*input
1 1
snuke
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) REP(j,m){
		string tmp;cin>>tmp;
		if(tmp=="snuke"){
			cout<<char('A'+j)<<i+1<<'\n';
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

int top = 0,s[200];

void push(int x){
  s[top++] = x;
}

int pop(){
  top--;
  return s[top];
}

int main() {
  char x[0];
  int a,b;
  while(cin >> x){
    if(x[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(x[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(x[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else {
      push(atoi(x));
    }
  }

  cout << pop() << endl;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define sf scanf
#define pf printf
#define pb push_back
#define F first
#define S second

int main()
{
    BOOST

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        long double a,b;
        cin>>a>>b;
        cout<<(long long)(a*b)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3700
#include <iostream>
#include <cmath>

int main()
{
    long long a, b, c;
    std::cin >> a >> b >> c;
    bool yes;

    if (c < a+b)
        yes = false;
    else yes = 4*a*b < (c-a-b)*(c-a-b);
    

    std::cout << (yes ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc095/tasks/abc095_b
# Python 3rd Try


def solver(donuskind, maxpowder, eachpowder):
    result = donuskind  # mindonuts
    sumpowder = 0
    minpowder = 10**5
    # print(eachpowder)
    for j in eachpowder:
        sumpowder = sumpowder + j
        if j <= minpowder:
            minpowder = j
    # print(minpowder, sumpowder)
    result = result + (maxpowder - sumpowder) // minpowder
    return result


if __name__ == "__main__":
    m = []
    N, X = map(int, input().split(' '))
    for j in range(0, N):
        m.append(int(input()))
    print("{}".format(solver(N, X, m)))


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> city(N, 0);
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    
    city.at(a - 1)++;
    city.at(b - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << city.at(i) << endl;
  }
  
}

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

using namespace std;

class Cube 
{
	public:
		int f[6];
		Cube(){}
		void roll_z() {roll(1, 2, 4, 3);}
		void roll_y() {roll(0, 2, 5, 3);}
		void roll_x() {roll(0, 1, 5, 4);}
		void roll(int i, int j, int k, int l)
		{
			int t = f[i];
			f[i] = f[j];
			f[j] = f[k];
			f[k] = f[l];
			f[l] = t;
		}
		void move(char ch)
		{
			if(ch == 'E')
				for(int i = 0; i < 3; i++)
					roll_y();
            else if(ch == 'W')
            	roll_y();
            else if(ch == 'N')
            	roll_x();
            else if(ch == 'S')
            	for(int i = 0; i < 3; i++)
            		roll_x();
		}
};

int main()
{
	Cube c;
	string s;
	
	for(int i = 0; i < 6; i++)
		cin >> c.f[i];
	
	cin >> s;
	
	for(int i = 0; i < s.size(); i++)
		c.move(s[i]);
	
	cout << c.f[0] << "\n";
	
	return 0;
}


Measured memory_bytes: 3196
import sys
input = sys.stdin.readline

a = ['0'] + list(input())
n = len(a)-1
for i in range(n):
    a[i] = int(a[i])

res = 0
for i in range(n-1,-1,-1):
    if a[i] <= 4:
        res += a[i]
    elif a[i] == 5:
        if a[i-1] >= 5:
            res += 5
            a[i-1] += 1
        else:
            res += 5

    else:
        res += 10-a[i]
        a[i-1] += 1
print(res)

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

using namespace std;

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

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

    vector<string> v;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n ;i++) {
        string s;
        cin >> s;
        v.push_back(s);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == '.') {
                v[i][j] = '0';
                for (int dir = 0; dir < 8; dir++) {
                    int nextx = i + dx[dir];
                    int nexty = j + dy[dir];
                    if (nextx >= 0 && nextx < n && nexty >= 0 && nexty < m) {
                        if (v[nextx][nexty] == '#') {
                            v[i][j]++;
                        }
                    }
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << v[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<map>
using namespace std;
int main() {
	int A;
	int B;
	cin >> A >> B;
	if (A >= 13)
		cout << B << endl;
	if (A>=6&&A<=12)
		cout << B / 2 << endl;
	if (A <= 5)
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		long N = scan.nextInt();
		ArrayList<String> namebox = new ArrayList<String>();	
		long[] judge = new long[5];
		for(int i= 0;i < N;i++){
			String x = scan.next();
			namebox.add(x);
			if(x.charAt(0) == 'M'){
				judge[0]++;
			}else if(x.charAt(0) == 'A'){
				judge[1]++;
			}else if(x.charAt(0) == 'R'){
				judge[2]++;
			}else if(x.charAt(0) == 'C'){
				judge[3]++;
			}else if(x.charAt(0) == 'H'){
				judge[4]++;
			}
		}
		
		long ans = (judge[0]*judge[1]*judge[2]) +  (judge[0]*judge[1]*judge[3]) +  (judge[0]*judge[1]*judge[4]) +  (judge[0]*judge[2]*judge[3]) 
				+  (judge[0]*judge[2]*judge[4]) +  (judge[0]*judge[3]*judge[4]) +  (judge[1]*judge[2]*judge[3]) +  (judge[1]*judge[2]*judge[4])
				+  (judge[1]*judge[3]*judge[4]) +  (judge[2]*judge[3]*judge[4]) ;
		
		System.out.println(ans);

	}






}


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


int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if(b <= a) cout << "delicious\n";
	else if(b-a <= x) cout << "safe\n";
	else cout << "dangerous\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    map<ll, ll> m;

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

    set<int> s;
    for (int i = 1; i < 1000010; i++)
    {
        s.insert(i);
    }

    for (auto x : m)
    {
        for (int j = x.first * 2; j < 1000010; j += x.first)
        {
            s.erase(j);
        }
    }

    ll ans = 0;

    for (auto x : s)
    {
        if (m[x] == 1)
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 112968
#include<iostream>

using namespace std;
//X+Y+Z = S, K

int main(){
  int K,S,Z,count=0; cin >> K >> S;

  for(int i=0; i<=K; i++){
      for(int j=0; j<=K; j++){
        Z = S -(i+j);
        if(Z >= 0 && Z <= K){
          count += 1;
        }
      }
  }

cout << count<< endl;

return 0;

}


Measured memory_bytes: 256
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
N = len(S)
ans = int(0)

k = N

for i in range(N-1):
    if S[i]!=S[i+1]:
        k = min(max(i+1,N-1-i),k)
ans = k
print(ans)



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


int main()
{
	int n;
	cin>>n;
	int ans=1;
	for(int i=1;i<=3;i++)
	{
		ans=ans*n;
	}
	cout<<ans<<'\n';
   return 0;
}

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

#ifdef HOME
#define db(x) cerr << #x << " = " << x << endl
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dbv(a) cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

using namespace std;
typedef long long ll;
typedef double dbl;


const int INF = 1.01e9;
const int MOD = (int)1e9 + 7;


int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    const int N = 200200;
    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);

        vector<int> nxt(n);
        vector<int> last(N, n);
        for (int i = n - 1; i >= 0; i--) {
            nxt[i] = last[a[i]];
            last[a[i]] = i;
        }

        vector<int> dp(n + 1);
        dp[n] = 1;
        for (int i = n - 1; i >= 0; i--) {
            dp[i] = dp[i + 1];
            if (nxt[i] != n && nxt[i] != i + 1) {
                dp[i] = (dp[i] + dp[nxt[i]]) % MOD;
            }
        }
        cout << dp[0] << endl;
    };

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 3328
A,B = map(int,input().split())

cnt = B-A+1

if cnt%4 == 0:
    if A%2 == 0:
        print(0)
    else:
        print((A-1)^B)
elif cnt%4 == 1:
    if A%2 == 0:
        print(B)
    else:
        print(A)
elif cnt%4 == 2:
    if A%2 == 0:
        print(1)
    else:
        print(A^B)
else:
    if A%2 == 1:
        print(A-1)
    else:
        print(B+1)

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

int main() {
  int a, b, c, d, tnum, anum;
  cin >> a >> b >> c >> d;
  if((c - (c/b) * b) > 0){
    tnum = c/b +1;
  } else{
    tnum = c/b;
  }
  if((a - (a/d) * d) > 0){
    anum = a/d +1;
  } else{
    anum = a/d;
  }
  string  ans = "Yes";
  if(tnum > anum){
    ans = "No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 100005

using namespace std;

int main()
{
    char str[sz];
    ll frq[150];

    scanf("%s",str);

    memset(frq,0,sizeof(frq));

    for(ll i=0; i<strlen(str); i++)
    {
        frq[str[i]]++;
    }

    ll flag=0;

    for(ll i=97; i<=122; i++)
    {
        if(!frq[i])
        {
            printf("%c\n",i);
            flag=1;
            break;
        }
    }

    if(!flag)
        printf("None\n");

    return (0);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int x = 1; x <= n; ++x) {
        double tmp = 1.0 / n;
        int now = x;
        while (now < k) {
            now *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	long long data[31];

	data[1] = 1;
	data[2] = 2;
	data[3] = 4;

	for(int i=4; i < 31; i++){
		data[i] = data[i-1] + data[i-2] + data[i-3];
	}

	int n,num;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		num = 0;

		num += data[n]/3650;
		if(data[n]%3650 > 0)num++;

		printf("%d\n",num);
	}

    return 0;
}

Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define int long long 

using namespace std;

int query(int a, int b){
  if( a == b ){ return 2*(a-1);}
  
  if( a > b ){ swap(a,b);}
  
  int left = a-1,right = b+1;
  
  while( right - left > 1 ){ 
    
    int x = (left+right)/2;
    //xを固定した時の(a+1+y)*(x-y)の最大値を求める
    // yは 0 <= y <= x-a-1　の範囲を動く
    
    int judge;
    
    if( (x-a)%2 == 1 ){
      // この時、 y == (x-a-1)/2にて、最大値 ( (x+a+1)/2 )^2を取る
      judge = (x+a+1)/2;
      judge *= judge;
    }
    else{ 
      // y == (x-a)/2にて、最大値( (x+a+2)*(x+a) ) /4を取る
      judge = (x+a+2)/2;
      judge *= (x+a)/2;
    }
    
    if( judge >= a*b ){ //rightがでかすぎた
      right = x;
    }
    else{
      left = x;
    }
    
  }

  return 2*(a-1)+right-a;
  
}
      

    

  
  

signed main(void){
  int Q; cin >> Q;
  while(Q--){ 
    int a,b; cin >> a >> b;
    cout << query(a,b) << endl;
  }
  
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

#include <ext/rope> //header with rope
using namespace std;
using namespace __gnu_cxx; //namespace with rope and some additional stuff
using namespace __gnu_pbds;

#define rep(i, a, b) for(int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int, int> ii;

const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;


int eh[200020], sum[200020];
void primo(){
	rep(i, 0, 200020){
		eh[i] = 1;
		sum[i] = 0;
	}
	eh[0] = eh[1] = 0; int f = sqrt(200020), F = 200020;
	for(int i=2; i<f; i++){
		if(eh[i])
			for(int j=i*i; j<F; j+=i)
				eh[j] = 0;
	}
	for(int i=1; i<F; i++){
		sum[i] = sum[i-1];
		sum[i] += (eh[i]&eh[(i+1)/2]);
	}
}

int main(){
	
	primo();
	int Q, l, r; cin >> Q;
	while(Q--){
		scanf("%d %d", &l, &r);
		printf("%d\n", sum[r]-sum[l-1]);
	}
	
	return 0;
	
}

Measured memory_bytes: 2176
while True:
    X = input()
    if X == '0': break
    r = ''
    minus = False
    if X[0] == '-':
        minus = True
        X = X[1:]

    kuri = 0
    #for a in [int(a) for a in X[::-1]]:
    idx = len(X)-1
    while idx >= 0:
        a = int(X[idx])

        if minus:
            # r.insert(0, kuri + 10 - a)
            r = str((10 - a - kuri) % 10) + r
            kuri = 0 if kuri + a == 0 else 1
        else:
            # r.insert(0, kuri + a)
            r = str((kuri + a) % 10) + r
            kuri = (kuri + a) // 10 
        # r.insert(0, (lambda x: x+kuri)(10 - a if minus else a))

        minus = not minus
        if idx == 0 and kuri > 0:
            X = '0' + X
        else:
            idx -= 1

    # r.insert(0,kuri)
    r = str(kuri) + r
    print(int(r))

Measured memory_bytes: 6724
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r:i32 = read();
    println!("{}", 3 * r * r);
}


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

set<char> S[101];
char A[110], B[110], C[110];

int main() {
   int N;
   int res = 0;
   scanf("%d", &N);
   scanf("%s %s %s", A, B, C);
   for (int i = 0; i < N; i++) {
      S[i].insert(A[i]);
      S[i].insert(B[i]);
      S[i].insert(C[i]);
      res += (int)S[i].size() - 1;
   }//for
   printf("%d\n", res);
   return 0;
}//main


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
          	//cout<<"";
        }
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
      	//cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}


Measured memory_bytes: 1792
n, w = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(n + 1).map{Array.new(w + 1, 0)}
(1..n).each do |i|
	vv, ww = gets.chomp.split(" ").map(&:to_i)
	ww.times do |j|
		dp[i][j] = dp[i - 1][j]
	end
	(ww..w).each do |j|
		dp[i][j] = [dp[i - 1][j], dp[i - 1][j - ww] + vv].max
	end
end
puts dp[n][w]








Measured memory_bytes: 14764
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	var S, T string
	fmt.Scan(&S, &T)
	ans := ""
	for i := 0; i < N; i++ {
		ans += string(S[i])
		ans += string(T[i])
	}
	fmt.Println(string(ans))
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
	int n[100][100],r,c,i,j,t[100],v[100],b=0;
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&n[i][j]);
			t[i]+=n[i][j];
			v[j]+=n[i][j];
			b+=n[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			printf("%d ",n[i][j]);
		}
		printf("%d\n",t[i]);
	}
	for(i=0;i<=c;i++){
		if(i!=c){
			printf("%d ",v[i]);
		}else{
			printf("%d\n",b);
		}
	}
	return 0;
}

Measured memory_bytes: 2712
N, K = gets.split.map(&:to_i)

counter = Hash.new(0)

N.times do
  a, b = gets.split.map(&:to_i)

  counter[a] += b
end

counter = counter.sort_by { |v, cnt| v }.to_h

k = 0
ans = nil

counter.each do |v, cnt|
  break if k >= K

  ans = v
  k += cnt
end

puts ans


Measured memory_bytes: 13104
// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    let x = (a + d - 1) / d;
    let y = (c + b - 1) / b;

    if x < y {
        println!("No");
    } else {
        println!("Yes");
    }
}

Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using llGraph = vector<vl>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename T>
struct is_vector : false_type{};

template<typename T>
struct is_vector<vector<T>> : true_type{};

template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) {
    return ostr;
  }
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    if (is_vector<T>()) ostr << "\n" << *itr;
    else ostr << ' ' << *itr;
  }
  return ostr;
}

template<typename T>
bool CompareBySecond(pair<T, T> a, pair<T, T> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

template<typename T>
T GCD(T a, T b) {
  T c = a % b;
  while (c != 0) { a = b; b = c; c = a % b; }
  return b;
}


/* -------- <templates end> -------- */


void solve() {
  int N, M; cin >> N >> M;
  Graph Tree(N);
  vector<set<int>> Parent(N);
  rep(i,N-1+M) {
    int a, b; cin >> a >> b; --a; --b;
    Tree[a].push_back(b);
    Parent[b].insert(a);
  }
  queue<int> q;
  int v = 0;
  while (!Parent[v].empty()) {
    v = *begin(Parent[v]);
  }
  q.push(v);
  Parent[v].insert(-1);
  while (!q.empty()) {
    int p = q.front(); q.pop();
    for (auto v : Tree[p]) {
      if (Parent[v].size() > 1) {
        Parent[v].erase(p);
      } else {
        q.push(v);
      }
    }
  }
  rep(i,N) cout << *begin(Parent[i]) + 1 << endl;
}


/* -------- <programs end> -------- */


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 15744
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

const int N = 200010;
ll cnt[N];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll ans = 0;
  rep(i, N){
    ans += cnt[i]*(cnt[i]-1)/2;
  }
  rep(i, n){
    print(ans - cnt[a[i]]*(cnt[a[i]]-1)/2 + (cnt[a[i]]-1)*(cnt[a[i]]-2)/2);
  }
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    cout << (t.substr(0, s.size()) == s ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,k,dif;char s[100005];
int main()
{
    scanf("%d%d%s",&n,&k,s+1);
    rap(i,1,n) if(s[i]!=s[i+1]) dif++;
    printf("%d",n-dif-1+min(k*2,dif));
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  bool danceable = true;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0 && S.at(i) == 'L') {
      danceable = false;
      break;
    }
    else if (i % 2 == 1 && S.at(i) == 'R') {
      danceable = false;
      break;
    }
  }
  if (danceable) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long MOD=1000000007;
long long N,M,a;
cin>>N>>M;
long long A[M];
for(int i=0;i<M;++i){
  cin>>a;
  A[i]=a;
}
long long counter=0;
long long dp[N+10];
dp[0]=1;
//1については別でしょり
if(A[0]==1){
  counter+=1;
  dp[1]=0;
}
else{
  dp[1]=1;
}

for(int j=2;j<=N;++j){
  if(A[counter]==j){
    dp[j]=0;
    counter+=1;
  }
  else{
    dp[j]=(dp[j-1]+dp[j-2])%MOD;
  }
}
cout<<dp[N]<<"\n";
return 0;
}

Measured memory_bytes: 1792
H, W = map(int, input().split())
S = [input() for _ in range(H)]

cost = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if i == j == 0: 
            continue
        if i == 0:
            cost[i][j] = cost[i][j-1] + 1*(S[i][j] != S[i][j-1])
        elif j == 0:
            cost[i][j] = cost[i-1][j] + 1*(S[i][j] != S[i-1][j])
        else:
            cost[i][j] = min(cost[i][j-1] + 1*(S[i][j] != S[i][j-1]), cost[i-1][j] + 1*(S[i][j] != S[i-1][j]))

if S[0][0] == S[-1][-1] == '.':
    ans = cost[-1][-1]//2
elif S[0][0] != S[-1][-1]:
    ans = cost[-1][-1]//2 + 1
else:
    ans = cost[-1][-1]//2 + 1

print(ans)

Measured memory_bytes: 9240
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  val n = scala.io.StdIn.readLine()

  def solve() = {
    n.takeRight(1) match {
      case "3" => "bon"
      case s if s == "0" || s == "1" || s == "6" || s == "8" => "pon"
      case _ => "hon"
    }
  }

  println(solve())

}



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

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout<<(#x)<<" >> "<<(x)<<endl

using namespace std;

ll fastpow(ll angka,ll pangkat,ll MOD){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka)%MOD;
		angka=(angka*angka)%MOD;
		pangkat=pangkat>>1;
	}
	return res;
}

ll fastpow(ll angka,ll pangkat){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka);
		angka=(angka*angka);
		pangkat=pangkat>>1;
	}
	return res;
}

ll gcd(ll angka1,ll angka2){
	while(angka2){
		swap(angka1,angka2);
		angka2=angka2%angka1;
	}
	return angka1;
}

ll lcm(ll angka1,ll angka2){
	return (angka1/gcd(angka1,angka2))*angka2;
}


void solve(){
	int x;
	cin>>x;
	
	cout<<(x+1)%2<<endl;	

}

int main(){
	
	fastio();

//	freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

	int t=1;
//	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>

#define ELEMENTS 100

using namespace std;

double distance(double x[ELEMENTS], double y[ELEMENTS], unsigned int n, double p){

    if(p == INFINITY){

        double abs_list[ELEMENTS] = {0}, max = 0;
        unsigned int i;

        max = abs(x[0] - y[0]);

        for(i=1;i<n;i++){
            if(max < abs(x[i] - y[i])){
                max = abs(x[i] - y[i]);
            }
        }

        return max;

    }else{

        unsigned int i;
        double sum = 0;

        for(i=0;i<n;i++){
            sum += pow( abs(x[i] - y[i]), p);
        }

        return pow(sum, 1/p);
    
    }
}

int main(){

    unsigned int n, p;
    double vec_x[ELEMENTS] = {0}, vec_y[ELEMENTS] = {0};
    unsigned int i, j;
    double d;

    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%lf", &vec_x[i]);
    }
    for(i=0;i<n;i++){
        scanf("%lf", &vec_y[i]);
    }

    printf("%.6lf\n", distance(vec_x, vec_y, n, 1));
    printf("%.6lf\n", distance(vec_x, vec_y, n, 2));
    printf("%.6lf\n", distance(vec_x, vec_y, n, 3));
    printf("%.6lf\n", distance(vec_x, vec_y, n, INFINITY));

    return 0;

}


Measured memory_bytes: 2896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n,d;
    cin >> n >> d;
    int xd[10][10] = {0};
    int ans = 0;
    rep(i,n){
        rep(j,d) cin >> xd[i][j];
    }
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n;j++){
            int pos_dist = 0;
            for (int k=0; k<d; k++){
                pos_dist += pow(xd[i][k]-xd[j][k],2);
            }
            int dist = sqrt(pos_dist);
            if (pow(dist,2) == pos_dist)  ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
	int a, b, k;
	cin >> a >> b >> k;
	int v[110];
	for(int i = 1; i < 110; ++i){
		if(a%i==0 && b%i==0) v[i] = 1;
		else v[i] = 0;
	}
	int cnt = 0;
	for(int i = 100; i > 0; --i){
		if(v[i]==1) cnt++;
		if(cnt == k){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.ABC101
{
    class a
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Trim();
            var cnt = 0;
            for(var i = 0; i < S.Length; ++i)
            {
                if (S[i].Equals('+')) ++cnt;
                else --cnt;
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005][3];
int dp[100005][2][2][2];
int solve(int i,bool k1,bool k2,bool k3)
{
	// if(i<0)
	// 	return 0;
	// if(i==0)
	// 	return max(a[0][0],max(a[0][1],a[0][2]));
	if(i==n)
		return 0;
	if(i>n){
		return INT_MIN;
	}
   if(dp[i][k1][k2][k3]!=-1)
   {
   	 return dp[i][k1][k2][k3];
   	 //cout<<"safder";
   }
		

	return dp[i][k1][k2][k3]=max(k3?solve(i+1,1,1,0)+a[i][2]:INT_MIN,max(k2?solve(i+1,1,0,1)+a[i][1]:INT_MIN,k1?solve(i+1,0,1,1)+a[i][0]:INT_MIN));
	// if(i==n-1){
	// 	return max(solve(i-1,!k1,k2,k3)+a[n-1][0],max(solve(i-1,k1,!k2,k3)+a[n-1][1],solve(i-1,k1,k2,!k3)+a[n-1][2]));
	// }
	// else{
       
 //        return !k1?max(solve(i-1,!k1,))

	// }


}

int main()
{
  

   cin>>n;
  memset(dp,-1,sizeof(dp));
 //int a[n][3];
   for(int i=0;i<n;i++)
   {
      for(int j=0;j<3;j++)
      {
      	cin>>a[i][j];
      }
   }
   cout<<solve(0,true,true,true)<<endl;

 //   // bool k1=true;
 //   // bool k2=true;
 //   // bool k3=true;
 //   // cout<<solve(n-1,k1,k2,k3)<<endl;
 //   int dp[n][3]={0};
 //   for(int i=0;i<n;i++)
 //   {
 //   	for(int j=0;j<3;j++)
 //   	{
 //   		if(i==0)
 //   		{
 //   			dp[i][j]=a[0][j];
 //   		}
 //   	}
 //   }
 
 //   	for(int i=1;i<n;i++)
 //   {
 //   	for(int j=0;j<3;j++)
 //   	{
 //   		 if(j==0)
 //   			dp[i][j] =a[i][j]+max(dp[i-1][j+1],dp[i-1][j+2]);
 //   		else if(j==1)
 //   			dp[i][j]=a[i][j]+max(dp[i-1][j+1],dp[i-1][j-1]);
 //   		else
 //   			dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j-2]);
 //   	}
 //   }
  
   
 //   int ans=-1;
 //   for(int i=0;i<3;i++)
 //   {
 //   	ans=max(ans,dp[n-1][i]);
 //   }
 //   cout<< ans<<endl;

}

   



   


Measured memory_bytes: 15488
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2666;
char s[N][N];int n;
void heng(int x, int y){
	s[x][y]=s[x][y+1]='a'+(x&1);
}
void shu(int x, int y){
	s[x][y]=s[x+1][y]='c'+(y&1);
}
int main() {
	read(n);rep(i,1,n)rep(j,1,n)s[i][j]='.';
	if(n<3){puts("-1");return 0;}
	if(n==3){
		puts("aa.");
		puts("..b");
		puts("..b");
		return 0;
	}
	if(n%2==0){
		for(int i=1;i<=n;i+=2){
			s[i][i]=s[i][i+1]='a';
			s[i+1][i]=s[i+1][i+1]='b';
			int x=i+2;if(x>n)x-=n;
			s[i][x]=s[i+1][x]='c';
			s[i][x+1]=s[i+1][x+1]='d';
		}
		rep(i,1,n){rep(j,1,n)printf("%c",s[i][j]);puts("");}
		return 0;
	}
	if(n&1){
		heng(1,1);heng(n,1);heng(n,3);heng(n-1,2);shu(n-2,1);shu(n-1,n);shu(1,n);
		per(i,n-1,3)shu(n-i,i);
		rep(i,3,n-2)heng(i,n+2-i);
		s[n][1]=s[n][2]='z';
		rep(i,1,n){rep(j,1,n)printf("%c",s[i][j]);puts("");}
		return 0;
	}
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}
int max(vector<int> a){
   cout << *max_element(a.begin(), a.end());
}

const int INF = 1e9 + 7;
const int N = 1e5 + 2000;

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   vector<int> dp(3, 0);
   int n;
   cin >> n;
   for(int day = 0; day < n; day ++){
      vector<int> c(3);
      vector<int> new_dp(3, 0);
      for(int i = 0; i < 3; i ++){
         cin >> c[i];
      }
      for(int i = 0; i < 3; i ++){
         for(int j = 0; j < 3; j ++){
            if(i != j){
               new_dp[j] = max(new_dp[j], dp[i] + c[j]);
            }
         }
      }
      dp = new_dp;
   }
   cout << max({dp[0], dp[1], dp[2]});
}



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

int main()
{
  int x, n;
  cin >> x >> n;
  vector<int> p;
  while (n--)
  {
    int input;
    cin >> input;
    p.push_back(input);
  }
  sort(p.begin(), p.end());

  int minimum = 9999;
  for (int i = -100; i <= 200; ++i)
  {
    // cout << i << endl;
    if (find(p.begin(), p.end(), i) == p.end())
    {
      // cout << i << "is not exited" << endl;
      if (abs(minimum - x) > abs(i - x))
      {
        minimum = i;
        // cout << i << "updated" << endl;
      }
    }
  }
  cout << minimum << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;

LL vis[65][2][2][2], dp[65][2][2][2];
vector<int> d1, d2;

void trans(vector<int> &d, LL x) {
	for (int i = 0; i < 60; i++) {
		d.push_back(x % 2);
		x /= 2;
	}
}

LL dfs(int pos, int lim1, int lim2, int sig) {
	if (pos < 0) return 1;
	if (vis[pos][lim1][lim2][sig]) return dp[pos][lim1][lim2][sig];
	vis[pos][lim1][lim2][sig] = 1;
	
	LL res = 0;
	for (int y = 0; y <= 1; y++) {
		for (int x = 0; x <= y; x++) {
			if (lim1 && y > d1[pos]) continue;
			if (lim2 && x < d2[pos]) continue;
			if (!sig && y == 1 && x != 1) continue;
			res += dfs(pos - 1, lim1 && y == d1[pos], lim2 && x == d2[pos], sig || y == 1);
		}
	}
	res %= MOD;
	
	return dp[pos][lim1][lim2][sig] = res;
}

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

	LL l, r;
	cin >> l >> r;
	trans(d1, r);
	trans(d2, l);
	cout << dfs(59, 1, 1, 0) << '\n';

	return 0;
}

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

signed main(){
	int h, w;
	scanf("%lld%lld", &h, &w);
	if(h%3 == 0 || w%3 == 0){
		printf("0\n");
		return 0;
	}
	int res1 = min(h, w), res2 = 1e18;
	for(int i = 1;i < w;i++){
		int mn = h/2, mx = h/2+(h%2);
		int s = (w-i)*h;
		int res = max(llabs(s-mn*i), llabs(s-mx*i));
		res2 = min(res2, res);
	}
	for(int i = 1;i < h;i++){
		int mn = w/2, mx = w/2+(w%2);
		int s = (h-i)*w;
		int res = max(llabs(s-mn*i), llabs(s-mx*i));
		res2 = min(res2, res);
	}
	printf("%lld\n", min(res1, res2));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    int n;
    cin >> n;
    int a[n];
    int i;
    rep(i,n){
        cin >> a[i];
    }
    int target=0;
    int ans=0;
    while(true){
        if(a[target]==0) {
            //無理だった
            break;
        }
        int nt = target;
        target = a[nt]-1;
        //pri2("移動した:",target);
        a[nt] = 0;
        ans++;
        if(target==1) {
            pri(ans);
            return 0;
        }
    }
    pri("-1");

    return 0;
}



Measured memory_bytes: 640
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		pw.println(nextInt()*nextInt());
	}
	public static void solutionB(String[] args) throws Exception{

	}
	public static void solutionC(String[] args) throws Exception{

	}
	public static void solutionD(String[] args) throws Exception{

	}



	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

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

	int h, w;
	cin >> h >> w;

	vector<vector<int> > a(h, vector<int>(w));
	vector<int> col(w, 0), row(h, 0);
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> a[i][j];

			if(!a[i][j]) {
				++col[j];
				++row[i];
			}
		}
	}

	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if((col[j] + row[i] + (1 - a[i][j])) & 1)
				cout << "1";
			else
				cout << "0";

			cout << (j + 1 == w ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 4964
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p)*(b))%m;
		b=((b)*(b))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll absol(ll x)
{
	return x>0?x:-x;
}
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll x,k,d;
	cin>>x>>k>>d;
	if (x<0)
	{
		x = -x;
	}
	ll t1 = x/d, t2 = x/d + 1;
	ll ans = 0;
	if (t1%2==k%2)
		{
			if(t1<=k)
				{
					ans=x-t1*d;
				}
			else{
				ans = x - k*d;
			}
		}
		else{
			if(t2<=k)
			{
				ans = x - t2*d;
			}
			else{
				ans = x - k*d;
			}
		}
		cout<<absol(ans)<<endl;
	return 0;
}


Measured memory_bytes: 27068
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int i,cnt=0;
	char lea=s[0],ru,chu;
	for (i=1;i<=s.size()-1;i++)
	{
		if (s[i]=='E')
		{
			cnt++;
		}
	}
	int minv=cnt;
	ru=s[1];
	chu=s[0];
	for (i=1;i<=s.size()-1;i++)
	{
		if (s[i]=='E')
		{
			if (s[i-1]=='E')
			{
				cnt--;
			}
		}
		if (s[i]=='W')
		{
			if (s[i-1]=='W')
			{
				cnt++;
			}
		}
		if (cnt<minv)
		{
			minv=cnt;
		}
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    int c=0;
    for(int i=0;i<n;i++)
        {cin>>a[i];
        if(a[i]>=k)
            c++;}
     cout<<c;


}



Measured memory_bytes: 640
#include <cstdio>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

int read() {
	int r = 0;
	while (true) {
		char c = getchar_unlocked();
		if (c == ' ' || c == '\n') {
			return r;
		} else {
			r = r * 10 + c - 48;
		}
	}
}

// x shoud be greater than or equal to zero
void write(i64 x) {
	char d[20];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putchar(d[i]);
	}
}

int A[100001];
signed main() {
	int n = read();
	REP(i, n + 1) {
		A[i] = read();
	}
	i64 s = 0;
	REP(i, n) {
		int b = read();
		int m = A[i] < b ? A[i] : b;
		s += m;
		b -= m;
		m = A[i + 1] < b ? A[i + 1] : b;
		s += m;
		A[i + 1] -= m;
	}
	write(s);
}


Measured memory_bytes: 512