akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        for (int i=0; i<5; i++) {
            orderTimes[i] = sc.nextInt();
        }

        int lastOrder = 0;
        int sum = 0;

        for (int ot: orderTimes) {
            if (ot % 10 == 0) {
                sum += ot;
            } else {
                if (lastOrder == 0) {
                    lastOrder = ot;
                    continue;
                }

                if (lastOrder % 10 <= ot % 10) {
                    sum += ot;
                    sum += 10 - (ot % 10);
                } else {
                    sum += lastOrder;
                    sum += 10 - (lastOrder % 10);
                    lastOrder = ot;
                }
            }
        }
        System.out.println(sum + lastOrder);
    }
}



Measured memory_bytes: 21844
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		int xor = 0;
		for (int value : A) {
			xor ^= value;
		}
		StringJoiner joiner = new StringJoiner(" ");
		for (int i : A) {
			joiner.add(String .valueOf(xor ^ i));
		}
		System.out.println(joiner.toString());
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

int main(){
    int n;
    cin>>n;
    int ms[n];
    int k;cin>>k;
    rep(i,n){
        cin>>ms[i];
    }
    int ans=0;
    rep(i,n){
        ans+=min(ms[i]*2,2*abs(ms[i]-k));
    }
               
                cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int main() {
	int X;
	cin >> X;
	int d, r;
	d = X / 100;
	r = X % 100;
	if(d*5<r){
		cout << 0;
	}else{
		cout << 1;
	}
}

Measured memory_bytes: 256
//
import java.math.*;
import java.util.*;
import java.io.*;

  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000;

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

    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/

        new Main().d();
        out.flush();
    }

    void d() throws Exception
    {
        int[] ary = toIntArray();
        int n = ary[0], m = ary[1];
        int ans = 0;
        
        for(int i = 1; i <= Math.sqrt(m) + 1; i++)
        {
            if(m % i == 0)
            {
                int a = i, b = m / i;
                // System.out.printf("%d %d\n", a, b);
                if(n <= a) ans = Math.max(ans, b);
                if(n <= b) ans = Math.max(ans, a);
            }
        }


      	out.println(ans);
    }

    
}


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

using namespace std;

int main(){

    int n;
    cin>>n;

    int dp[n];

    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    memset(dp,0,sizeof(dp));
    dp[0] = 0;
    for(int i=1;i<n;i++){
        if(i>=2) dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
        else dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
    }

    cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 4344
n, kosuu = map(int, input().split(" "))
a=list(map(int, input().split(" ")))
first = sum(a[:kosuu])
temp = []
temp.append(first)
for i in range(n - kosuu):
  first = first + a[i + kosuu] - a[i]
  temp.append(first)
print((max(temp) + kosuu) / 2)

Measured memory_bytes: 25060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
static const int Max = 200000;

int main()
{
	int R[Max], n;

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

	int maxv = -2000000000;
	int minp = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minp);
		minp = min(minp, R[i]);
	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3880
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll S, W;
    cin>>S>>W;
    if(W>=S) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3636
x=int(input())
if x>=400 and x<=599:
    print(8)
    exit()
if x>=600 and x<=799:
    print(7)
    exit()
if x>=800 and x<=999:
    print(6)
    exit()
if x>=1000 and x<=1199:
    print(5)
    exit()
if x>=1200 and x<=1399:
    print(4)
    exit()
if x>=1400 and x<=1599:
    print(3)
    exit()
if x>=1600 and x<=1799:
    print(2)
    exit()
if x>=1800 and x<=1999:
    print(1)
    exit()


Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
static const int MAX_N = 100;

char s[MAX_N + 1];

void solve(){
	int n = strlen(s);
	printf("%c%d%c\n", s[0], n - 2, s[n - 1]);
}

int main(){
	scanf("%s", s);
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt(),m=sc.nextInt();
		Integer[][]a=new Integer[n][2];
		for(int i=0;i<n;i++)
			a[i]=new Integer[] {sc.nextInt(),sc.nextInt()};
		Arrays.sort(a,(x,y)->x[0]-y[0]);
		long ans=0;
		for(Integer []x:a)
		{
			int min=Math.min(x[1], m);
			ans+=min*1L*x[0];
			m-=min;
		}
		out.println(ans);
		
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 51436
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
X=list(map(int, input().split()))

for i in range(5):
    if X[i]==0:
        print(i+1)
        sys.exit()


Measured memory_bytes: 72780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



class AOJ
{

    public static void Main()
    {

        string str;

        while ((str = Console.ReadLine()) != null)
        {

            string[] s = str.Split(',');

            double xa = double.Parse(s[0]);
            double ya = double.Parse(s[1]);

            double xb = double.Parse(s[2]);
            double yb = double.Parse(s[3]);

            double xc = double.Parse(s[4]);
            double yc = double.Parse(s[5]);

            double xd = double.Parse(s[6]);
            double yd = double.Parse(s[7]);

            double acd = 0.5 * Math.Abs((xc - xa) * (yd - ya) - (yc - ya) * (xd - xa));
            double abc = 0.5 * Math.Abs((xb - xa) * (yc - ya) - (yb - ya) * (xc - xa));
            double bcd = 0.5 * Math.Abs((xc - xb) * (yd - yb) - (yc - yb) * (xd - xb));
            double abd = 0.5 * Math.Abs((xb - xa) * (yd - ya) - (yb - ya) * (xd - xa));

            if (acd + abc == bcd + abd)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}
            

Measured memory_bytes: 5664
using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            List<List<int>> pointList = new List<List<int>>();
            List<int> point = new List<int>();
            string[] initial =Console.ReadLine().Split();
            string[] line;
            double root = 0;
            int answer = 0;

            int N = int.Parse(initial[0]);
            int D = int.Parse(initial[1]);

            for(int i=0; i < N; i++)
            {
                line= Console.ReadLine().Split();
                for(int j=0; j<D; j++)
                {
                    point.Add(int.Parse(line[j]));
                }
                pointList.Add(point);
                point = new List<int>();
            }
            
            int rootNakami = 0;

            for(int i=0; i < N; i++)
            {
                for(int j=0; j<N; j++)
                {
                    if (i == j || j>i)
                    {
                        continue;
                    }
                    for(int k=0; k<D; k++)
                    {
                        rootNakami += (pointList[i][k] - pointList[j][k]) * (pointList[i][k] - pointList[j][k]);
                    }
                    root=Math.Sqrt(rootNakami);
                    if(root == (int)root)
                    {
                        answer++;
                    }
                    rootNakami = 0;
                    root = 0;
                }
            }
            Console.Write(answer);
        }
    }


Measured memory_bytes: 13268
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final BigInteger MOD = BigInteger.valueOf((long) 1e9 + 7);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        out.println(Math.min(a*n, b));

    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll n, k, a[200005], v[200005];

int main() {
	ll i, j;
	cin >> n >> k;
	for(i=1; i<=n; i++) scanf("%lld", &a[i]);
	for(i=1, j=1; !v[i] && k; i=a[i], j++, k--) v[i] = j;
	k %= (j - v[i]);
	for(; k; i=a[i], k--);
	cout << i;
	return 0;
}

Measured memory_bytes: 6892
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
		    vars
		    (mapcar (constantly '(read))
			    vars)))
       ,@body)))

(defun check (x y)
  (let* ((g1 '(1 3 5 7 8 10 12))
	 (g2 '(4 6 9 11))
	 (h1 (member x g1 :test #'equal))
	 (h2 (member y g1 :test #'equal))
	 (h3 (member x g2 :test #'equal))
	 (h4 (member y g2 :test #'equal)))
    (or (and h1 h2) (and h3 h4))))

(defsolver prob-a (x y)
  (format t "~:[No~;Yes~]"
	  (check x y)))

(prob-a)

Measured memory_bytes: 6504
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

*/

int n, k;
int a[120000];


int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	cout << (n - 1 + (k - 2)) / (k - 1) << "\n";
	return 0;
}




Measured memory_bytes: 640
/*
    Author: aksayushx
*/

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 998244353
using namespace std;
typedef long long ll;
typedef long double ld;

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
ll power(ll x, ll y)  
{  
    ll res = 1; 
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x)%mod;  
        y = y>>1; 
        x = (x*x)%mod;  
    }  
    return res;  
} 
void aksayushx()
{
    ll n;
    cin>>n;
    vector<ll> h(n);
    for(ll i=0;i<n;i++)
    cin>>h[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(ll i=2;i<n;i++)
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    cout<<dp[n-1]<<'\n';

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


int main(){

  ll a,b,c;
  cin >> a >> b >> c;
  ll to = max({a,b,c});
  ll sa = 3*to-(a+b+c);
  if(sa%2==1)to++;
  ll ans = to*3 - (a+b+c);
  ans/=2;
  cout << ans << endl;

}




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

using namespace std;

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

	vector<long long> f(n + 1);
	for(int x = 1; x <= n; ++x) {
		for(int y = 1; y <= n && x * x + y * y + x * y <= n; ++y) {
			for(int z = 1; z <= n && x * x + y * y + z * z + x * y + y * z + z * x <= n; ++z) {
				f[x * x + y * y + z * z + x * y + y * z + z * x] += 1;		
			}
		}
	}

	for(int i = 1; i <= n; ++i) {
		cout << f[i] << '\n';
	}

	return 0;
}


Measured memory_bytes: 3624
s = list(input())
n = len(s) - 1 
p = 0
for i in range(2**n):
    m = int(s[0])
    x = i
    for j in range(n):
        if x % 2 != 0:
            p += m
            m = int(s[j+1])
        else:
            m = m * 10 + int(s[j+1])
        x = x // 2
    p += m
print(p)     

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
//#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll h[2],m[2];
    ll t[2];
    rep(i,0,1){
        cin>>h[i]>>m[i];
        t[i]=60*h[i]+m[i];
    }
    ll T=t[1]-t[0];
    ll k;cin>>k;
    cout<<T-k<<endl;
    
    return 0;
}





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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d)<< "\n";	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>

#define rep(i,n)for(ll i=0;i<(n);i++)
using namespace std;
using ll =long long;
//const int mod = 1000000007;
//class mint {
//	long long x;
//public:
//	mint(long long x = 0) : x((x% mod + mod) % mod) {}
//	mint operator-() const {
//		return mint(-x);
//	}
//	mint& operator+=(const mint & a) {
//		if ((x += a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator-=(const mint & a) {
//		if ((x += mod - a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator*=(const  mint & a) {
//		(x *= a.x) %= mod;
//		return *this;
//	}
//	mint operator+(const mint & a) const {
//		mint res(*this);
//		return res += a;
//	}
//	mint operator-(const mint & a) const {
//		mint res(*this);
//		return res -= a;
//	}
//	mint operator*(const mint & a) const {
//		mint res(*this);
//		return res *= a;
//	}
//	mint pow(ll t) const {
//		if (!t) return 1;
//		mint a = pow(t >> 1);
//		a *= a;
//		if (t & 1) a *= *this;
//		return a;
//	}
//	// for prime mod
//	mint inv() const {
//		return pow(mod - 2);
//	}
//	mint& operator/=(const mint & a) {
//		return (*this) *= a.inv();
//	}
//	mint operator/(const mint & a) const {
//		mint res(*this);
//		return res /= a;
//	}
//
//	friend ostream& operator<<(ostream & os, const mint & m) {
//		os << m.x;
//		return os;
//	}
//};

int main() {
	int N;
	cin >> N;
	int ans=0;
	vector<int>p(N);
	rep(i, N) { cin >> p[i]; }

	rep(i, N-1) {

		if (p[i] == i+1) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}
	if (p[N - 1] == N) {

		ans++;
	}
	cout << ans;

}




Measured memory_bytes: 640
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        vector<ll> c(n);
        rep(i, n) cin >> c[i];
        ll dp[n + 1]; // dp[i] iで区切った時の場合の数
        dp[0] = 1;
        mp[c[0]] = 1;
        for (int i = 1; i < n; ++i) {
            if (c[i] != c[i - 1]) {
                dp[i] = dp[i - 1] + mp[c[i]];
            } else {
                dp[i] = dp[i - 1];
            }
            dp[i] %= mod;
            mp[c[i]] = dp[i];
        }
        cout << dp[n - 1] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll X;
  cin >> X;
  ll n = 0;
  ll num = 100;
  while(num < X){
    num *= 1.01;
    n++;
  }
  cout << n << endl;
}


Measured memory_bytes: 3620
def selectionSort(A, N):
    count = 0
    for i in xrange(0,N):
        minj = i
        for j in xrange(i,N):
            if A[j] < A[minj]:
                minj = j
                
        if minj != i:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            count += 1
    return A, count

def main():
    N = int(raw_input())
    A = map(int,raw_input().split())
    newA, count = selectionSort(A, N)
    print ' '.join(map(str,newA))
    print count
    return 0

if __name__ == "__main__":
    main()

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  string S;
  cin >> S;
  int N = SZ(S), ans = 0;
  
  REP(i,N/2) {
    if(S.at(i) != S.at(N-1-i)) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
function move(x,arr){
var d1=arr[0];
var d2=arr[1];
var d3=arr[2];
var d4=arr[3];
var d5=arr[4];
var d6=arr[5];
var after=[];
if(x=="N")after=[d2,d6,d3,d4,d1,d5];
if(x=="S")after=[d5,d1,d3,d4,d6,d2];
if(x=="E")after=[d4,d2,d1,d6,d5,d3];
if(x=="W")after=[d3,d2,d6,d1,d5,d4];
if(x=="R")after=[d1,d3,d5,d2,d4,d6];
if(x=="L")after=[d1,d4,d2,d5,d3,d6];
return after;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var dice;
var sum;
for(var i=0;i<Arr.length;i++){
   var v=Arr[i].charAt(0);
   if(v.match(/[NSEWRL]/)){
      dice=move(v,dice);
      sum+=dice[0];
   }else{
      if(i!=0)console.log(sum);
      dice=[1,2,3,4,5,6];
      sum=1;
   }
   if(Arr[i]=="0")break;
}

Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  bool isPrime(ll a);
  ll X; cin >> X;
  ll ans=X;
  while(!isPrime(ans)){
    ans++;
  }
  cout << ans;
}
bool isPrime(ll a){
  ll temp=a;
  for(ll i=2; i*i<=a; i++){
    while(temp%i==0){
      temp/=i;
    }
  }
  return temp==a;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i += 1)
        cin >> a[i];
    
    vector<vector<int64_t>> dp(2, vector<int64_t> (n + 1, 0));
    
    dp[1] = vector<int64_t> (a.begin(), a.end());

    for (int len = 2; len <= n; len += 1)
        for (int start = 0; start + len - 1 < n; start += 1)
            dp[len & 1][start] = max(-dp[1 - (len & 1)][start] + a[start + len - 1], -dp[1 - (len & 1)][start + 1] + a[start]);

    cout << dp[n % 2][0] << "\n";
}

Measured memory_bytes: 384
import sys
def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
AB = []
C = []
for _ in range(M):
    AB.append(tuple(int(i) for i in S().split()))
    C.append(sum(1<<(int(i)-1) for i in S().split()))

dp = [10**8+1]*(1<<N)
dp[0] = 0

for i in range(1<<N):
    for (a,b),c in zip(AB,C):
        m = i|c
        dp[m] = min(dp[m],dp[i]+a)

if dp[-1] == 10**8+1:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 42988
#include <bits/stdc++.h>
using namespace std;
#define ll long long
using namespace std;
#define N 1500
int a[N];
int main()
{
    ll n;
    scanf("%lld", &n);
    if (n <= 6) {
        cout << 1 << endl;
    } else {
        ll ans = 0;
        ll x = n / 11;
        ll y = n % 11;
        ans += 2 * x;
        if (y <= 6 && y >= 1) {
            ans++;
        } else if (y > 6) {
            ans += 2;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n m ->
    let pref = Array.make n 0 in
    let py = Array.init m (fun i -> Scanf.scanf " %d %d" (fun p y -> p, y, i)) in
    let id = Array.make m "" in
    Array.sort compare py;
    Array.iter (fun (p, y, i) ->
        pref.(p - 1) <- pref.(p - 1) + 1;
        id.(i) <- Printf.sprintf "%06d%06d" p pref.(p - 1)
    ) py;
    Array.iter print_endline id
)

Measured memory_bytes: 12416
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Maybe (fromJust)

solve :: String -> String -> String
solve "H" b = b
solve "D" "H" = "D"
solve "D" "D" = "H"

main :: IO ()
main = do
    (a:b:_) <- map BS.unpack . BS.words <$> BS.getLine
    putStrLn $ solve a b

Measured memory_bytes: 380
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())
import heapq

n, m = mi()
g = [[] for i in range(n + 1)]
deg = [0] * (n + 1)
for i in range(n + m - 1):
    u, v = mi()
    g[u].append(v)
    deg[v] += 1

pq = []
for u in range(1, n + 1):
    if deg[u] == 0:
        pq.append((0, u))
par = [0] * (n + 1)
dist = [0] * (n + 1)
while pq:
    d, u = heapq.heappop(pq)
    if d > deg[u]: continue
    for v in g[u]:
        if dist[v] < dist[u] + 1:
            dist[v] = dist[u] + 1
            par[v] = u
        deg[v] -= 1
        heapq.heappush(pq, (deg[v], v))

print(*par[1:], sep='\n')


Measured memory_bytes: 25992
#include <iostream>
#include <atcoder/all>
using namespace std;int main(){int N,Q;cin>>N>>Q;atcoder::fenwick_tree<long> b(N);for(int i=0;i<N;i++){long a;cin>>a;b.add(i,a);}while(Q--){int w,e,r;cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<endl;else b.add(e,r);}}

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

int main() {
    int k,n,ans=0;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ans = max(k-a[n-1]+a[0],ans);
    rep(i,n-1){
        ans = max(ans,a[i+1]-a[i]);
    }
    cout << k-ans << endl;
}

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

int main( ) {
  int A, B, X;
  cin >> A >> B >> X;
  
  if(A <= X && X <= A + B){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  } 
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);

        Integer a = Integer.parseInt(scanner.next());
        Integer b = Integer.parseInt(scanner.next());
        Integer c = Integer.parseInt(scanner.next());

        if (a.equals(b) != a.equals(c) || b.equals(a) != b.equals(c)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Activity{
    ll start;
    ll end;
    Activity(ll s, ll t):start(s), end(t){}
    bool operator<(const Activity &another) const{
        return end < another.end;
    }
};

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

    // input
    ll N;
    cin >> N;

    vector<Activity> A;
    FOR(i, 0, N){
        ll s, t;
        cin >> s >> t;
        A.push_back(Activity(s, t));
    }
    sort(ALL(A));

    ll count = 0;
    ll t = 0;
    FOR(i, 0, N){
        if(A[i].start > t){
            t = A[i].end;
            count++;
        }
    }
    p(count);
    
    return 0;
}


Measured memory_bytes: 4928
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int a[3];
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  sort(a,a+3);
  printf("%d %d %d\n",a[0],a[1],a[2]);
  return 0;
}

Measured memory_bytes: 2752
package main

import "fmt"

func main() {
	var n, unused int
	fmt.Scan(&n, &unused)
	m := make(map[int]int)

	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)

		for j := 0; j < k; j++ {
			var a int
			fmt.Scan(&a)
			if _, ok := m[a]; ok {
				m[a]++
			} else {
				m[a] = 1
			}
		}
	}

	res := 0
	for _, v := range m {
		if v == n {
			res++
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==5&&b==7&&c==5)puts("YES");
	else if(a==7&&b==5&&c==5)puts("YES");
	else if(a==5&&b==5&&c==7)puts("YES");
	else puts("NO");
	return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n+1;i++){
    if( (4*i)+(2*(n-i))==m ){
      cout << "Yes" << endl;
      break;
    }
    else if (i==n){
      cout << "No" << endl;
  }
  }
}


Measured memory_bytes: 3676
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 100100
using namespace std;

char str[MAX], V[MAX];
int main()
{
	int N, K, R, S, P, sum = 0;
	scanf("%d%d%d%d%d%s", &N, &K, &R, &S, &P, str);
	for (int i = 0; i < N; i++) {
		if (i - K >= 0 && V[i - K] && str[i - K] == str[i]) continue;
		if (str[i] == 'r') sum += P;
		if (str[i] == 's') sum += R;
		if (str[i] == 'p') sum += S;
		V[i] = 1;
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int N = s.length();
		int K = sc.nextInt();
		int count = 0;
		int x = 0;
		if( N>=5 ){
			count = 5*N-10;
			x = 5;
		}else{
			count = N*(N+1)/2;
			x = N;
		}
		String[] sub = new String[count];
		s = s + "A";
		int a = 0;
		for( int i=x; i>0; i-- ){        
			for( int j=0; j<=N-i; j++ ){
				sub[a] = s.substring(j,j+i);
				a++;              
			}
		}     
		Arrays.sort(sub);
		int b = 0;  
		if( N>1 ){	//
		for( int i=0; i<a-1; i++ ){  
			if( !(sub[i].equals(sub[i+1])) ){
				b++;
			}      
			if( b==K ){
				System.out.println(sub[i]);             
				break;
			}
		}  
		}  		// 
		if( N>1 && b<K ){
			System.out.println(sub[a-1]);          
        }          
		if( N==1 ){
			System.out.println(sub[0]);
		} 
	}
}


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

int n;
string curr;
vector<string> ans;
void recurse(int i, char c) {
    if (i == n) {
        ans.push_back(curr);
        return;
    }
    for (char b = 'a'; b <= c+1; b++) {
        curr += b;
        recurse(i+1,b==c+1?c+1:c);
        curr.pop_back();
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    recurse(0,'a'-1); 
    sort(ans.begin(),ans.end());
    for (auto s: ans) {
        cout << s << '\n';
    }
}


Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int city,road,i,counter;
  counter=0;
  cin>>city>>road;
  vector<int>vec(city);
  for(i=0;i<road*2;i++){
    int f;
    cin >> f;
    vec.at(f-1)++;
  }
  for(int x:vec)
    cout << x <<endl;
}

Measured memory_bytes: 3600
import sys
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
g1=[1,1]
g2=[1,1]
inverse=[0,1]
 
for i in range(2,n*2):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

ct=[0,0,0]
ans=1
for i in range(n):
  f=0
  ct2=0
  for j in range(3):
    if a[i]==ct[j]:
      if ct2==0:
        ct[j]+=1
      ct2+=1
  ans*=ct2
print(ans%mod)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

int adj[505][505] = {0};

void dfs(int l, int r, int k){
	if(r-l<2) return;
	int m = (l+r)/2;
	for(int i=l;i<m;i++){
		for(int j=m;j<r;j++){
			adj[i][j] = k;
		}
	}
	dfs(l, m, k+1);
	dfs(m, r, k+1);
	return;
}

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

    ll N;
    cin >> N;

    dfs(0, N, 1);

    REP(i, N-1){
    	REP(j, N){
    		if(j>i) cout << adj[i][j] << " ";
    	}
    	cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1536
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    for i in range(N - M + 1):
        for j in range(N - M + 1):
            found = True
            for x in range(M):
                for y in range(M):
                    if A[i + x][j + y] != B[x][y]:
                        found = False
                        break
                if not found:
                    break
            if found:
                print(YES)
                return
    print(NO)
    return


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
    A = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    B = [ next(tokens) for _ in range(M) ]  # type: "List[str]"
    solve(N, M, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int64_t MOD = 1000000007;
vector<int64_t> Stair(100001, 0);

int main()
{
  int64_t N, M, a;
  cin >> N >> M;
  for (int i = 0; i < M; i++)
  {
    cin >> a;
    Stair.at(a) = -1;
  }
  Stair.at(0) = 1;
  if (Stair.at(1) != -1)
    Stair.at(1) = 1;
  for (int i = 2; i <= N; i++)
  {
    if (Stair.at(i) == -1)
      continue;
    if (Stair.at(i - 2) != -1)
      Stair.at(i) = (Stair.at(i) + Stair.at(i - 2)) % MOD;
    if (Stair.at(i - 1) != -1)
      Stair.at(i) = (Stair.at(i) + Stair.at(i - 1)) % MOD;
  }
  cout << Stair.at(N) << endl;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi a(n);
	rep(i, n) cin >> a[i];

	vi b(a);
	sort(ASC(b));

	int cnt = 0;
	rep(i, n) if (a[i] == b[i]) cnt++;
	if (cnt == n) {
		cout << 0 << endl;
		return 0;
	}

	int q;
	cin >> q;

	rep(i, q) {
		int x, y;
		cin >> x >> y;
		x--, y--;

		if (a[x] == b[x]) cnt--;
		if (a[y] == b[y]) cnt--;

		swap(a[x], a[y]);

		if (a[x] == b[x]) cnt++;
		if (a[y] == b[y]) cnt++;

		if (cnt == n) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


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

int leng(int n) {
  int keta = 1;
  for (int i = 0; i < 99999999999999; i++) {
    if (n / 10 == 0) break;
    else {
      keta++;
      n /= 10;
    }
  }
  return keta;
}

signed main() {
  int N, K;
  cin >> N >> K;
  vector<char> dis(K);
  for (int i = 0; i < K; i++) {
    cin >> dis[i];
  }

  bool ok = true;
  for (int i = N; i < 999999999; i++) {
    ok = true;
    for (int j = 0; j < leng(i); j++) {
      for (int k = 0; k < K; k++) {
        if ( to_string(i)[j] == dis[k] ) ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      break;
    }
  }


}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/05/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<array<int, 3>> dp(n+1);
  dp[0] = {0,0,0};
  for (int i = 1; i <= n; i++) {
    int a,b,c; cin>>a>>b>>c;
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;

  return 0;
}


Measured memory_bytes: 1408
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):  # リストに重複した要素があるか判定（要素にリストがある場合）
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


s = list(map(str, input()))
# print(s)
for i in range(-1, 2):
    #print(i, s[i])
    if s[i] == 'C':
        print('WA')
        exit()

for c in s[1:]:
    if c == 'A':
        print('WA')
        exit()


def cnt(s):
    a = 0
    for i in range(2, len(s)-1):
        # print(i, s[i])
        if s[i] == 'C':
            a += 1
    if a == 1:
        return True
    else:
        return False


def remove(s):
    s.remove('A')
    s.remove('C')
    return s


def func(s):
    if s[0] == 'A':
        pass
    else:
        return False
    if cnt(s):
        pass
    else:
        return False
    return True


if func(s):
    s = remove(s)
    aa = 0
    for i in range(len(s)):
        if s[i].islower():
            aa += 1
    if aa == len(s):
        print('AC')
        exit()
print('WA')


Measured memory_bytes: 3832
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N; std::cin >> N;
  int cnt = 0;
  int ab_cnt = 0, aend_cnt = 0, bstart_cnt = 0;
  for (int i = 0; i < N; ++i) {
    std::string s; std::cin >> s;
    for (int i = 0; i < (int)s.size() - 1; ++i) {
      if (s[i] == 'A' && s[i+1] == 'B') ++cnt;
    }
    if (s[0] == 'B' && s[s.size() - 1] == 'A') {
      ++ab_cnt;
    } else {
      if (s[0] == 'B') ++bstart_cnt;
      if (s[s.size() - 1] == 'A') ++aend_cnt;
    }
  }

  if (ab_cnt > 0) {
    if (aend_cnt > 0) {
      cnt += ab_cnt;
    } else if (bstart_cnt > 0) {
      cnt += ab_cnt;
    } else {
      cnt += ab_cnt - 1;
    }
  }

  cnt += std::min(aend_cnt, bstart_cnt);
  std::cout << cnt << std::endl;
}


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

using namespace std;

int main(){
	char b;
    cin >> b;
	
	if(b == 'A') cout << "T" ;
	if(b == 'T') cout << "A" ;
	if(b == 'G') cout << "C" ;
	if(b == 'C') cout << "G" ;
	
	return 0;
}



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

#define pb push_back
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pf push_front

using namespace std;

typedef long long llong;

const int MXN = (int)1e6 + 7;
const llong INF = (llong)1e18 + 7;
const int MOD = (int)1e9 + 7;

int n;
set <int> st;

int main()
{
  cin >> n;
  for(int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    st.insert(x);
  }
  if(st.size() == n){
    cout << "YES";
  }else cout << "NO";
  return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <vector>
#include<iostream>

using namespace std;

struct Node {
	Node() {
		parent = -1;
		depth = num_of_children = 0;
	}
	int parent;
	int depth;
	vector<int> children;
	int num_of_children;
};

void calcDepth(Node nodes[], int root_id) {
	for (int i = 0; i < nodes[root_id].num_of_children; i++) {
		nodes[nodes[root_id].children[i]].depth = nodes[root_id].depth + 1;
		calcDepth(nodes, nodes[root_id].children[i]);
	}
}

int main() {
	int n, id, k, child_id, root_id;
	cin >> n;
	Node nodes[n];

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &id, &k);
		for (int j = 0; j < k; j++) {
			scanf("%d", &child_id);
			nodes[id].children.push_back(child_id);
			nodes[id].num_of_children++;
			nodes[child_id].parent = id;
		}
	}

	for (root_id = 0; root_id < n; root_id++) {
		if (nodes[root_id].parent == -1) break;
	}

	calcDepth(nodes, root_id);

	for (int i = 0; i < n; i++) {
		if (nodes[i].parent == -1) {
			printf("node %d: parent = -1, depth = 0, root, ", i);
		}
		else if (nodes[i].num_of_children == 0) {
			printf("node %d: parent = %d, depth = %d, leaf, ", i, nodes[i].parent, nodes[i].depth);
		}
		else {
			printf("node %d: parent = %d, depth = %d, internal node, ", i, nodes[i].parent, nodes[i].depth);
		}
		printf("[");
		for (int j = 0; j < nodes[i].num_of_children - 1; j++) {
			printf("%d, ", nodes[i].children[j]);
		}
		if (nodes[i].num_of_children > 0) {
			printf("%d", nodes[i].children[nodes[i].num_of_children - 1]);
		}
		printf("]\n");
	}
}



Measured memory_bytes: 7944
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int x,n;
	cin>>x>>n;
	set<int>p;
	rep(i,n){
		int k;
		cin>>k;
		p.insert(k);
	}
	int mindis=1e9;
	int ans=0;
	FOR(i,-2,102){
		if(!p.count(i)){
			int dis=abs(x-i);
			if(dis<mindis){
				mindis=dis;
				ans=i;
			}
		}
	}
	cout<<ans<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3680