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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
    ll s,w;
    cin>>s>>w;
    if(w>=s)    cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll no;
    // cin>>no;
    no = 1;
    while(no--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day [] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
vector <string> v;
void dfs (string str, string t = "", int cnt = 0) {
    if (cnt == 2) {
        v.push_back (t);
        return;
    } else {
        for (int i = 0; i <str.size (); i ++) {
            dfs (str, t + str [i], cnt + 1);
        }
    }
}
int main () {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    while(cin>>n){
        if(n==25)cout<<"Christmas"<<endl;
        else if(n==24)cout<<"Christmas Eve"<<endl;
        else if(n==23)cout<<"Christmas Eve Eve"<<endl;
        else cout<<"Christmas Eve Eve Eve"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
 
  int i,n,score[1001],sum;
  double ave,sig,v;
 
   
  while(1){
 
    scanf("%d", &n );
    if ( n == 0 ) break;
     
    for ( i  = 0 ; i < n ; i++ ){
      scanf("%d", &score[i] );
    }
 
    sum = 0;
     
    for ( i = 0 ; i < n ; i++ ){
      sum+=score[i];
    }
     
    ave = 1.0 * sum / n;
 
    sig = 0;
     
    for ( i = 0 ; i < n ; i++ ){
      sig +=( score[i] - ave ) * ( score[i] - ave );
    }
 
    v = sqrt( sig / n );
 
    printf("%.8lf\n", v );
 
  }
   
  return 0;
     
}

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

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

    long long a[3*n];
    for(int i = 0; i < 3*n; i++)  cin >> a[i];
    sort(a, a+3*n);

    long long ans = 0;
    for(int i = n; i < 3*n; i+=2){
        ans += a[i];
    }

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

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll P = 1000000007;
ll n, x, y, z;
ll mask = (1<<18) - 1;
vvl dp = VV(41, (1<<18), 0, ll);
vector<int> mem(1<<18, -1);

int judge(ll state){
  if(mem[state]!=-1) return mem[state]==1;
  vll dat(3, 0);
  ll cnt = 0;
  for(int i=0;i<19;i++){
    dat[cnt]++;
    if((state>>i)&1){
      if(cnt==0&&dat[0]==x) cnt++;
      if(cnt==1&&dat[1]==y) cnt++;
      if(cnt==2&&dat[2]==z){
        return mem[state] = 1;
      }
    }
  }
  return mem[state] = 0;
}
int main(int argc, char const *argv[]) {
  std::cin >> n >> x >> y >> z;
  ll ans = 0;
  dp[0][0] = 1;
  vll t(50, 1);
  for(int i=1;i<50;i++) t[i]=(t[i-1]*10)%P;
  for(int i=0;i<n;i++){
    for(int j=0;j<(1<<18);j++){
      for(int num=1;num<=10;num++){
        if(dp[i][j]==0) continue;
        ll nx = ((j<<num)|(1<<(num-1)))&mask;
        if(judge(nx)){
          ans = (ans + (dp[i][j]*t[n-1-i])%P)%P;
        }else{
          dp[i+1][nx] = (dp[i+1][nx] + dp[i][j])%P;
        }
      }
    }
  }
  // O(20 * 2^18 + 40 * 10 * 2^18)
  // だいたい O(10^8) 定数倍重め
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 87032
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    double t, x;
    cin >> t >> x;
    exout(t/x);
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

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

    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;

        st.insert({ x, y });
    }

    int i1 = h - 1;
    int j = 0;
    vector<int> b(h);
    for (int i = 0; i < h; i++) {
        if (i + 1 == h || st.count({ i + 1, j })) {
            b[i] = j;
            i1 = i;
            break;
        }
        if (j + 1 != w && !st.count({ i + 1, j + 1 })) {
            j++;
        }
        b[i] = j;
    }

    for (const auto& p : st) {
        int x = p.first;
        int y = p.second;
        if (x <= i1 && y < b[x]) {
            i1 = x - 1;
        }
    }

    cout << i1 + 1 << endl;

    return 0;
}

Measured memory_bytes: 10368
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import javax.management.monitor.CounterMonitor;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="Yes";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W[] = new int[N];
        for(int i=0;i<N;i++)
        {
            W[i]=sc.nextInt();
        }

        for(int T=0;T<N;T++)
        {
            int s1=0;
            int s2=0;
            for(int i=0;i<N;i++)
            {
                if(i<=T)
                {
                    s1+=W[i];
                }else if(i>T)
                {
                    s2+=W[i];
                }
            }
            //System.err.println("s1="+s1);
            //System.err.println("s2="+s2);
            if(Math.abs(s1-s2)<min)
            {
                min=Math.abs(s1-s2);
            }
        }
        answer=min;
        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        //System.err.println(space);
        //System.err.println(sSwitch);
        System.out.println(answer);
    }
}

Measured memory_bytes: 23252
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1335

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main()
{
	int N,K,S;
	while(cin >> N >> K >> S && N)
	{
		int ans=0;
		rep( bit, 1<<N )
		{
			if(__builtin_popcount(bit)!=K){ continue; }	
			int res=0;
			REP( n, 1, N+1 ){
				if( bit&1<<(n-1) ){ res+=n; }
			}
			if(res == S){ ans++; }
		}
		cout << ans << endl;
	}

	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		// TODO ?????????????????????????????????????????????
		Scanner scn = new Scanner(System.in);
		ArrayList<Integer> deck = new ArrayList<Integer>();
		ArrayList<Integer> deckout = new ArrayList<Integer>();
		while(true){
			int n = scn.nextInt();
			int r = scn.nextInt();
			if(n==0&&r==0) break;
			for(int k=0;k<n;k++){
				deck.add(n-k);
			}
			for(int k=0;k<r;k++){
				int p = scn.nextInt();
				int c = scn.nextInt();
				for(int i=0;i<c;i++){
					deck.add(0,deck.remove(p-2+c));
				}
			}
			deckout.add(deck.get(0));
			deck.clear();

		}
		for(Integer i:deckout){
			System.out.println(i);
		}

		scn.close();
	}
}

Measured memory_bytes: 36364
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
   string s;
   cin >> s;
   for(int i = 0; i < s.size(); ++i){
       cout << "x";
   }
   cout << endl;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    a,b = [int(x) for x in stdin.readline().strip().split()]
    if b>=0 and a<=0:
        print('Zero')
    elif b>0 and a>0:
        print("Positive")
    else:
        a = abs(a)
        b = abs(b)
     
        if ((b-a)+1)%2==0:
            print("Positive")
        else:
            print("Negative")
main()


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


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    ll N,sum=0;;
    cin>>N;
    unordered_map<string,ll> mp;
    rep(i,N){
        string t;
        cin>>t;
        sort(t.begin(),t.end());
        if(mp.empty()){
            mp[t]=0;
            continue;
        }
        if( mp.find(t) != mp.end() ) {
            if(mp[t]==0)mp[t]=1;
            else mp[t]++;
        } 
        else {
            mp[t]=0;
        }
        sum+=mp[t];
    }
    cout<<sum<<endl;
}


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

int main(){
  int dx[6]={1,-1,0,0,0,0},dy[6]={0,0,1,-1,0,0},dz[6]={0,0,0,0,1,-1};
  long long a, b, c;
  cin>>a>>b>>c;
  int n;
  cin>>n;
  int x,y,z;
  int usedx[1000],usedy[1000],usedz[1000];

  long long area=a*b*2+a*c*2+b*c*2;
  int cx,cy,cz;

  for(int i=0;i<n;i++){
    cin>>x>>y>>z;
      usedx[i]=x,usedy[i]=y,usedz[i]=z;
    for(int j=0;j<6;j++){
      int f=0;
      cx=x+dx[j],cy=y+dy[j],cz=z+dz[j];
      if(cx<a &&cy<b && cz<c && cx>=0 && cy>=0 && cz>=0 ){
	for(int k=0;k<i;k++)if(usedx[k]==cx && usedy[k]==cy && usedz[k]==cz)area--,f=1;
	if(!f)area++;
      }else area--;
    }
  }

  cout<<area<<endl;

  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;

    for (int i = k; i <= n + 1; i++) {
        ans += i * (n - i + 1) + 1;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

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

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

// {person, is_true}, is_true = 1 if honest, otherwise 0
vector<vector<pair<int, int>>> A;

bool check(const int bits, const int N) {
    // {person, is_honest}
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        int bit = bits & (1 << i);
        if (bit) {
            m[i] |= 1;
            for (auto &p : A[i]) {
                m[p.first] |= (p.second == 1 ? 1 : 2);
            }
        } else {
            m[i] |= 2;
        }
    }

    // printf("bits: 0x%x\n", bits);
    for (auto &p : m) {
        // printf("%d: %d\n", p.first, p.second);
        if (p.second == 3) {
            return false;
        }
    }
    return true;
}

int bits_count(int bits) {
    int res = 0;
    while (bits > 0) {
        if (bits & 0x1) {
            res++;
        }
        bits >>= 1;
    }
    return res;
}

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

    A.resize(N);
    for (int i = 0; i < N; i++) {
        int n;
        cin >> n;
        for (int j = 0; j < n; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            A[i].push_back({x, y});
        }
    }

    int ans = 0;
    for (int bits = 0; bits < ((int) (1 << N)); bits++) {
        if (check(bits, N)) {
            chmax(ans, bits_count(bits));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(void)
{
	double x, y;
	int n;
	int i;
	double arc, rad, tan;
	
	while (1){
		scanf("%d", &n);
		
		if (n == -1){
			break;
		}
		x = y = rad = 0;
		for (i = 0; i < n; i++){
			x += cos(rad);
			y += sin(rad);
			
			if (i != 0){
				rad -= (M_PI / 2 - asin(1 / sqrt(i + 1)));
			}
			rad += M_PI / 2;
		}
		
		printf("%.2f\n%.2f\n", x, y);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size(),i=0;
    ll ans=0;
    while(i<n){
        ll left=0,right=0;
        while(i<n&&s[i]=='<'){
            left++;
            i++;
        }
        while(i<n&&s[i]=='>'){
            right++;
            i++;
        }
        if(left<right) left--;
        else right--;
        ans+=left*(left+1)/2+right*(right+1)/2;
    }
    cout<<ans;
}

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

using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;

bool accept(const vi& A, ll i, ll m, ll v, ll p){
    if (A[i] + m < A[p-1]) return false;
    ll n = A.size();
    ll score = m * (v - p - n + i + 1);
    if (score <= 0) return true;
    for (ll k = p-1; k < i; k++) score += A[k];
    if (score % (i+1-p) == 0) score /= (i+1-p);
    else score = score / (i+1-p) + 1;
    return A[i] + m >= max(score, A[p-1]);
}

int main(){
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vi A(n);
    for (ll& i : A) cin >> i;
    sort(A.begin(), A.end(), greater<ll>());
    ll l = p, r = n-1, ans = p-1;
    while (l <= r) {
        ll mid = (l+r)/2;
        if (accept(A, mid, m, v, p)) {
            l = mid+1;
            ans = mid;
        }
        else r = mid-1;
    }
    cout << ans+1 << endl;
}


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

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

    vector<int> d(N);
    rep(i, N) cin >> d.at(i);

    sort(d.begin(), d.end());
    int left = d.at(N/2 - 1);
    int right = d.at(N/2);

    cout << right - left << endl;
}


Measured memory_bytes: 640
import numpy as np

x1, y1, x2, y2 = map(int, input().split())

X1 = np.array([x1, y1])
X2 = np.array([x2, y2])

A = np.array([[0, -1], [1, 0]])
X3 = X2 + np.dot(A, X2 - X1)
X4 = X3 + np.dot(A, X3 - X2)

print(X3[0], X3[1], X4[0], X4[1])

Measured memory_bytes: 21528
X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
print(sum(sorted(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Measured memory_bytes: 23200
def gcd(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    while a!=b and b!= 0:
        c = a%b
        a = b
        b = c
    return a

a,b = list(map(int,input().split()))
g = gcd(a,b)
ans = 1
d = []
p = []
for i in range(1,int(g**0.5)+1): #因数リスト
    if g%i==0:
        if i!=1:
            d.append(i)
        if g//i!=1:
            d.append(g//i)
d = list(dict.fromkeys(d))
        
f = [True]*len(d)
for i in range(len(d)):
    for j in range(i):
        if d[i]>d[j] and d[i]%d[j]==0:
            f[i] = False
        if d[i]<d[j] and d[j]%d[i]==0:
            f[j] = False
print(f.count(True)+1)
            

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

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

    int maxDiff = 0;

    int firstHousePosition, lastHousePosition;

    int prevHousePosition;
    cin >> prevHousePosition;

    firstHousePosition = prevHousePosition;

    for (int i = 1; i < n; ++i)
    {
        int input;
        cin >> input;

        maxDiff = max(maxDiff, input - prevHousePosition);

        if (i == n - 1)
        {
            lastHousePosition = input;
        }

        prevHousePosition = input;
    }

    maxDiff = max(maxDiff, firstHousePosition + (k - lastHousePosition));

    cout << (k - maxDiff) << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}
int main(){
  int n; cin >> n;
  for(ll i = 1; i <= 3500; ++i){
    for(ll j = 1; j <= 3500; ++j){
      ll x = n * i * j;
      ll y = 4*i*j-n*i-n*j;
      if(y > 0 && x % y == 0){
	cout << i << ' ' << j << ' ' << x/y << endl;
	return 0;
      }
    }
  }
}


Measured memory_bytes: 3584
using System;

namespace AOJ.intro
{
    namespace AOJ_1_2_A
    {
        public static class SmallLargeOrEqual
        {
            public static void Main(string[] args)
            {
                string[] twoNum = Console.ReadLine().Split();

                int firstNum;
                int secondNum;

                firstNum  = int.Parse(twoNum[0]);
                secondNum = int.Parse(twoNum[1]);

                if (firstNum < secondNum)
                {
                    Console.WriteLine("a < b");
                }
                else if (firstNum > secondNum)
                {
                    Console.WriteLine("a > b");
                }
                else if (firstNum == secondNum)
                {
                    Console.WriteLine("a == b");
                }
            }
        }
    }
}


Measured memory_bytes: 8872
x = int(input())
a0, a1 = -118, 119
b0, b1 = -119, 118
flag = False
for a in range(a0, a1+1):
    for b in range(b0, b1+1):
        if a**5 - b**5 == x:
            a_ , b_ = a, b
            flag = True
            break
    if flag is True:
        break
print(a_, b_)

Measured memory_bytes: 9176
#include<stdio.h>
#include<string.h>
void hws(int a,int b)
{
    int i,l=0,s=0,t=0,dzs=0;
    for(i=a; i<=b; i++)
    {
        t=i;
        dzs=0;
        while(t!=0)
        {
            l=t%10;
            t=t/10;
            dzs=dzs*10+l;
            if(i==dzs)
                s++;

        }
    }
    printf("%d",s);
}
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    hws(a,b);
    return 0;
}


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int res = a + b;
  if (res & 1) {
    puts("IMPOSSIBLE");
  } else {
    cout << (res >> 1) << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,k = map(int,input().split())
L = list( map(int,input().split()))
l = len(L)
L = Counter(L)
L = sorted(list(L.most_common(k)))

ans = 0
for i in range(len(L)):
    ans += L[i][1]
print(l - ans)

Measured memory_bytes: 32540
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<int> s_list(N, 0);
	int result = 0;

	for (int i = 0; i < N; i++)
	{
		cin >> s_list[i];
		result += s_list[i];
	}

	if (result % 10 != 0)
	{
		cout << result;
		return 0;
	}

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

	for (int e : s_list)
	{
		if (e % 10 != 0)
		{
			cout << result - e;
			return 0;
		}
	}

	cout << 0;

	return 0;
}

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

int main() {
  string N;
  cin >> N;
  
  int sum = 0;
  int n = 0;
  
  for (int i = 0; i < N.size(); i++) {
    n = N.at(i)-48;
    sum += n;
  }
  
  if (sum % 9 == 0){
    cout <<"Yes"<<endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

ll gcd(ll x, ll y){
  if(y == 0) return x;
  return gcd(y, x % y);
}

vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for( ll i = 2; i * i <= n; ++i){
    if(n % i) continue;
    res.emplace_back(i, 0);
    while(n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if(n != 1) res.emplace_back(n, 1);
  return res;
}

int main(){
  ll a, b;
  cin >> a >> b;

  ll g = gcd(a, b);

  auto f = factorize(g);

  ll ans = f.size() + 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
def f():
 c=0
 for W in iter(input,'0'):
  c+=1
  W=int(W)
  d=[0]*-~W
  for _ in[0]*int(input()):
   v,w=map(int,input().split(','))
   for i in range(W,w-1,-1):
    if d[i]<d[i-w]+v:d[i]=d[i-w]+v
  print(f'Case {c}:\n{d[W]}\n{d.index(d[W])}')
f()


Measured memory_bytes: 5624
//ABC 081

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("");
  const s1 = parseInt(input[0],10);
  const s2 = parseInt(input[1],10);
  const s3 = parseInt(input[2],10);
  var sum = s1+s2+s3;
  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 205;
const int mod = 1e9 + 7;

void solve(){
	int n; string s;
	cin >> n >> s;
	if(n & 1){
		puts("No");
	}
	else{
		puts(s.substr(0, n/2) == s.substr(n/2, n/2) ? "Yes" : "No");
	}
}
int main(){
//	freopen("input.txt", "rb", stdin);
//	freopen("output.txt", "wb", stdout);
//	int tc; scanf("%d",&tc);
int tc = 1;
	while(tc--) solve();
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n;
  cin>>n;
  int l[2*n];
  for(int i = 0;i<2*n;i++){
    cin>>l[i];
  }
  sort(l,l+2*n);
  
  long ans = 0;
  for(int i = 0;i<2*n;i+=2){
    // cout<<l[i]<<endl;
    ans += min(l[i],l[i+1]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

ll GCD(ll a, ll b) {
	while (max(a, b) % min(a, b)) {
		if (a < b)b %= a;
		else a %= b;
	}
	return min(a, b);
}
int n, x, a;
int ans;
int main() {
	cin >> n >> x >> ans;
	ans = abs(x - ans);
	rep(i, n - 1) {
		cin >> a;
		ans = GCD(ans, abs(a - x));
	}
	cout << ans << endl;
	return 0;


}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt()-1;
    StringBuilder sb = new StringBuilder(sc.next());
    sb.setCharAt(k,(char)(sb.charAt(k)+32));
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
int main(void){
    int i;
    char s[4096],p[4096],s2[4096];
    scanf("%s",s);
    scanf("%s",p);
    sprintf(s2,"%s%s",s,s);
    
    if((strstr(s2,p)) == NULL){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2144
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int N;
  cin >> N;
  for(int h = 1; h <= 3500; h++)
  for(int n = 1; n <= 3500; n++) {
    // 1/(4/N-1/h-1/n)
    // = Nhn / (4hn - Nn - hN)
    ll X = (ll) N * h * n;
    ll Y = (4 * h * n - (ll) N * n - (ll) h * N);
    if(Y != 0 && X % Y == 0) {
      ll w = X / Y;
      if(w > 0) {
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }
  assert(0);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")
MOD = 1000000007  # type: int


def solve(N: int, M: int, S: "List[int]", T: "List[int]"):

    DP = [[1]*(N+1) for _ in range(M+1)]
    for i in range(1, N+1):
        for j in range(1, M+1):
            DP[j][i] = DP[j-1][i] + DP[j][i-1] - \
                DP[j-1][i-1]
            DP[j][i] %= MOD

            if S[i-1] == T[j-1]:
                DP[j][i] += DP[j-1][i-1]
                DP[j][i] %= MOD
    # print(*DP, sep="\n")
    print(DP[M][N])


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    T = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, S, T)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73180
using System;
using System.IO;
using System.Linq;

namespace ABC119A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var ymd = Console.ReadLine().Split('/').Select(int.Parse).ToArray();
            var year = ymd[0];
            var month = ymd[1];
            var day = ymd[2];

            if (10000 * year + 100 * month + day <= 20190430)
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename T>string join(V<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;V<ll> al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}
mt19937 rnd; void set_rnd(){random_device r;rnd=mt19937(r());}
V<ll> fact, rfact; void set_fact(int n, ll m){fact.pb(1);rfact.pb(1);FOR(i,1,n+1)fact.pb(fact[i-1]*i%m),rfact.pb(modpow(fact[i],m,m-2));}
const int iinf = 1e9+6;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 1e5;
void init(){
  set_rnd();
//  set_fact(N);
}
struct Prime{
  vector<ll> pl;
  void init(int a){ // a以下の素数列挙
    pl.resize(0);
    vector<bool> z(a+1, true);
    FOR(i, 2, a+1){
      if(z[i])pl.push_back(i);
      for(int b=i*2; b <= a; b+=i) z[b]=false;
    }
  }
  void prime_division(ll a, vector<pair<ll, int> >&v){ // vに素因数分解の結果が入る
    v.resize(0);
    for(ll b: pl){
      if(b*b > a) break;
      if(a%b) continue;
      int c = 0;
      while(a%b==0) a/=b, c++;
      v.push_back(make_pair(b, c));
    }
    if(a>1) v.push_back(make_pair(a, 1));
  }
} pr;

ll n, p;
V<pair<ll, int> > v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cin >> n >> p;
  pr.init(1000000);
  pr.prime_division(p, v);
  ll ans = 1;
  each(itr, v) FOR(i, 0, itr->se/n) ans *= itr->fi;
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  deque<int> dq;
  for(int i=0; i<n; i++){
    int v; cin>>v;
    dq.push_back(v);
  }
  int op=min(n,k);
  vector<ll> ans;
  for(int l=0; l<=op; l++){
    for(int r=0; r<=op-l; r++){
      vector<int> v;
      deque<int> dq2=dq;
      for(int i=0; i<l; i++){
        int tmp=dq2.front();
        dq2.pop_front();
        v.push_back(tmp);
      }
      for(int i=0; i<r; i++){
        int tmp=dq2.back();
        dq2.pop_back();
        v.push_back(tmp);
      }
      int rv=k-r-l;
      int s=v.size();
      rv=min(rv,s);
      sort(v.begin(), v.end());
      for(int i=0; i<rv;i++){
        if(v[i]>=0) continue;
        v[i]=0;
      }
      ll total=accumulate(v.begin(),v.end(),0LL);
      ans.push_back(total);
    }
  }
  cout<<*max_element(ans.begin(),ans.end())<<endl;
}


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


class Main{
    public static void main(String[] args){
	Scanner scn = new Scanner(System.in);

	while(true){
	    int n=scn.nextInt(),m=scn.nextInt();
	    int[] p = new int[n+1],sum = new int[(n+1)*(n+2)/2];

	    if(n==0&&m==0) break;

	    for(int i=0; i<n; i++)
		p[i] = scn.nextInt();

	    for(int i=0,cnt=0; i<n+1; i++) for(int j=i; j<n+1; j++)
	       sum[cnt++] = p[i]+p[j];

	    Arrays.sort(sum);

	    int max = 0;
	    loop: for(int i:sum){
		int from=0,to=sum.length-1;
		while(true){
		    int center = (from+to)/2;

		    if(from==to||from+1==to){
			int ttl=0;
			if(i+sum[center]<=m)
			    ttl = i+sum[center];
			else if(center>0)
			    ttl = i+sum[center-1];
			max = (max>ttl)?max:ttl;
			break;
		    }

		    if(i+sum[center]>m)   to = center;
		    else if(i+sum[center]<m) from = center;
		    else{
			max = m;
			break loop;
		    }
		}
	    }
	    

	    System.out.println(max);
	}
    }
}

Measured memory_bytes: 15000
import sys
a,b,c,d=[i for i in input()]
op=["+","-"]
for i in op:
  for j in op:
    for k in op:
      if eval(a+i+b+j+c+k+d)==7:
        print(a+i+b+j+c+k+d+"=7")
        sys.exit()

Measured memory_bytes: 3060
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
#[fastout]
fn main() {
    input!{
        n: usize,
        k: i64,
        _p: [usize;n],
        c: [i64;n],
    }

    let mut p: Vec<usize> = Vec::new();
    for &i in &_p {
        p.push(i-1);
    }

    let mut ans = 10_i64.pow(18) * (-1);

    for i in 0..n {
        let mut v = i;
        let mut cycle_sum = 0;
        let mut cycle_cnt = 0;

        loop {
            cycle_cnt += 1;
            cycle_sum += c[v];
            v = p[v];
            if v==i {
                break;
            }
        }

        let mut path = 0;
        let mut cnt = 0;

        loop {
            cnt += 1;
            path += c[v];
            if cnt > k {
                break;
            }
            let num: i64 = (k-cnt) / cycle_cnt;
            let score: i64 = path + std::cmp::max(0, cycle_sum) * num;
            ans = std::cmp::max(ans, score);

            v = p[v];
            if v==i {
                break;
            }
        }
    }

    println!("{}", ans);

    // let mut ans_max = c[0];
    // let mut ans_index = 0;
    // for i in 0..n {
    //     if ans_max < c[i] {
    //         ans_max = c[i];
    //         ans_index = i;
    //     }
    // }

    // let mut ans: Vec<i64> = Vec::new();
    // ans.push(ans_max);
    // k -= 1;
    // while k!=0 {
    //     ans_index = p[ans_index] - 1;
    //     ans_max += c[ans_index];
    //     ans.push(ans_max);
    //     k -= 1;
    // }

    // ans.sort();
    // ans.reverse();

    // println!("{}", ans[0]);

}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

ll n;
ll d[] = { 3, 5, 7 };
set<ll> s;

void dfs(ll cnt, ll v, bool a = 0, bool b = 0, bool c = 0)
{
  if (v > n) return;
  if (v > 0 && a && b && c) s.em(v);

  rep(i, 3) {
    dfs(cnt+1, v * 10 + d[i], a | (i == 0), b | (i == 1), c | (i == 2));
  }
}

signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  cin >> n;
  dfs(0, 0);

  ll ans = distance(s.begin(),s.upper_bound(n));
  cout << ans << endl;
}

Measured memory_bytes: 4848
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    int N;
    cin >> N;
    if(N == 1)cout << "Hello World" << endl;
    else{
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}

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

using namespace std;

int main(){
    string S;
    cin >> S;

    int a_cnt = 0, b_cnt = 0, c_cnt = 0;
    for(int i = 0; i < S.length(); ++i){
        if(S[i] == 'a'){
            a_cnt++;
        }
        if(S[i] == 'b'){
            b_cnt++;
        }
        if(S[i] == 'c'){
            c_cnt++;
        }
    }
    
    
    if(abs(a_cnt - b_cnt) <= 1 && abs(b_cnt - c_cnt) <= 1 && abs(c_cnt - a_cnt) <= 1){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	unordered_set<int> st;
	rep(i, n) {
		int a;
		cin >> a;
		if (st.find(a) == st.end()) {
			st.insert(a);
		} else {
			st.erase(a);
		}
	}

	cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 4388
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(N):
        if A[i] == 0:
            print(0)
            return
    
    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            return
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 84668
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;


int go(int *a,int *b,int *c,int n){

}




int main(){
    int n;
    cin>>n;
    int **cost=new int*[3];
    for(int i=0;i<3;i++){
      cost[i]=new int[n];
    }


    REP(i,n){
      cin>>cost[0][i]>>cost[1][i]>>cost[2][i];
    }
    int **dp=new int*[3];
    for(int i=0;i<3;i++){
      dp[i]=new int[n];
    }
    for(int i=0;i<3;i++){
      dp[i][0]=cost[i][0];
    }

    for(int j=1;j<n;j++){
      for(int i=0;i<3;i++){
        dp[i][j]=max(dp[(i+2)%3][j-1],dp[(i+1)%3][j-1]) + cost[i][j];
      }
    }
 
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;


    return 0;
}


Measured memory_bytes: 2560
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<array>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;

//繋げる方向を一方向にする
typedef struct union_find{
    
    vector<ll> pa;//親
    vector<ll> ra;//木の深さ
    vector<ll> siz;
    //n要素で初期化
    void init(ll n){
        pa.resize(n);
        ra.resize(n);
        siz.resize(n);
        for(ll i = 0;i < n;i++){
            pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
            ra[i] = 0LL;/*各ノード自体の高さは0*/
            siz[i] = 1LL;
        }
    }
    //木の根を求める
    ll find(ll x){
        if(pa[x] == x){
            return x;/*根ならそのノードの番号を返す*/
        }else{
            return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
        }
    }

    //xとyの属する集合を併合する
    void unite(ll x,ll y){
        x = find(x);//xの根の番号を探す
        y = find(y);//yの根の番号を探す
        if(x == y){//一致すればつながっている
            return;
        }
        pa[y] = x;
        siz[x] += siz[y];
    }

    //xとyが同じ集合に属するか判定
    bool same(ll x,ll y){
        return find(x) == find(y);//同じ集合なら1、違うなら0が返る
    }
}UF;
vector<vector<int> > graph;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

    int n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r+(100*(10-n))<<endl;
    }

	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)1e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //test
  {
    int n,k;
    cin>>n>>k;
    vector<int> v(n),vis(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
    }
    int i=0;
    int cyc=0;
    while(!vis[i])
    {
      vis[i]=1;
      i=v[i]-1;
      cyc++;
    }
    int j=0;
    int lin=0;
    while(j!=i){
      lin++;
      j=v[j]-1;
    }
    if(k>lin)
    {
      k=(k-lin)%(cyc-lin)+lin;
    }
    int ans=0;
    while(k--)
    {
      ans=v[ans]-1;
    }
    cout<<ans+1<<endl;

  }
  return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '+')
        cout << a + b << endl;
    else
        cout << a - b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x;cin >> x;
    ll ans=(x/500)*1000;x%=500;
    ans+=(x/5)*5;
    cout << ans;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string weather;
  cin >> weather;
  if(weather=="RRR"){
    cout << 3 << endl;
  }else if(weather=="SSS"){
    cout << 0 << endl;
  }else if(weather=="RRS"||weather=="SRR"){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3600