akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
using namespace std;
typedef long long ll;
const ll N=2020;
char s[N],t[N];
ll k,ans=0,n,ss,Ans=0;
int tag[N],Tag[N];
int main()
{
	scanf("%s",s+1);
	scanf("%lld",&k);
	n=strlen(s+1);
	FOR(i,2,n) if (s[i]!=s[i-1]) ss=1;
	if (!ss) {printf("%lld\n",1LL*n*k/2);exit(0);}
	
	FOR(i,2,n) if (s[i]==s[i-1])
	{
		if (tag[i-1]) continue;
		tag[i]=1;
		ans++;
	}
	ans*=k;
	if ((!tag[n])&&(s[n]==s[1])) ans+=k-1;
	
	FOR(i,1,n) t[i]=s[n-i+1];
	FOR(i,2,n) if (t[i]==t[i-1])
	{
		if (Tag[i-1]) continue;
		Tag[i]=1;
		Ans++;
	}
	Ans*=k;
	if ((!Tag[n])&&(t[n]==t[1])) Ans+=k-1;
	
	ans=min(Ans,ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num,i,j,data[11][11]={0};
	
	while(scanf("%d",&num),num){
	
		for(i=0;i<num;i++){
			switch(num){
				case 1:
					scanf("%d",&data[i][0]);
					break;
				case 2:
					scanf("%d %d",&data[i][0],&data[i][1]);
					break;
				case 3:
					scanf("%d %d %d",&data[i][0],&data[i][1],&data[i][2]);
					break;
				case 4:
					scanf("%d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3]);
					break;
				case 5:
					scanf("%d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4]);
					break;
				case 6:
					scanf("%d %d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4],&data[i][5]);
					break;
				case 7:
					scanf("%d %d %d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4],&data[i][5],&data[i][6]);
					break;
				case 8:
					scanf("%d %d %d %d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4],&data[i][5],&data[i][6],&data[i][7]);
					break;
				case 9:
					scanf("%d %d %d %d %d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4],&data[i][5],&data[i][6],&data[i][7],&data[i][8]);
					break;
				case 10:
					scanf("%d %d %d %d %d %d %d %d %d %d",&data[i][0],&data[i][1],&data[i][2],&data[i][3],&data[i][4],&data[i][5],&data[i][6],&data[i][7],&data[i][8],&data[i][9]);
					break;
			}
		}
	
		for(i=0;i<num;i++){
			for(j=0;j<num;j++){
				data[i][num]=data[i][num]+data[i][j];
				data[num][i]=data[num][i]+data[j][i];
			}
		}
		for(i=0;i<num;i++){
			data[num][num]=data[num][num]+data[num][i];
		}		
		
		for(i=0;i<=num;i++){
			for(j=0;j<num;j++){
				printf("%5d",data[i][j]);
			}
			printf("%5d\n",data[i][num]);
		}
		
		for(i=0;i<11;i++){
			for(j=0;j<11;j++){
				data[i][j]=0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 608
n = int(input())
t = list(map(int,input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    t1,t2 = map(int,input().split())
    p.append(t1)
    x.append(t2)
sum_t = sum(t)
for i in range(m):
    sa = t[p[i] - 1] - x[i]
    print(sum_t-sa)

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

int main()
{
  int x,i,j;
  cin>>x;
  for(i=x;;i++)
    {
        for(j=2;j<i;j++)
          {if(i%j==0) break;}
    if(i==j) {cout<<i;break;}
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var ABK = ReadLine().Split().Select(int.Parse).ToArray();
        var A = ABK[0];
        var B = ABK[1];
        var K = ABK[2];
        if (B - A + 1 > 2 * K)
        {
            for (int i = 0; i < K; i++)
            {
                WriteLine(A + i);
            }
            for (int i = K - 1; i >= 0; i--)
            {
                WriteLine(B - i);
            }
        }
        else
        {
            foreach (var i in Enumerable.Range(A, B - A + 1))
            {
                WriteLine(i);
            }
        }
    }
}



Measured memory_bytes: 13396
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  seen=String[]
  pre=chomp(readline())
  push!(seen,pre)
  flag=true
  for i=1:n-1
    s=chomp(readline())
    if pre[end]!=s[1] || (s in seen)
      flag=false
    end
    pre=s
    push!(seen,s)
  end
  println(flag ? "Yes" : "No")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 108944
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        char[] data = s.toCharArray();
        int[] count = new int[3];
        for (int i = 0; i < data.length; i++) {
            count[data[i]-'a'] += 1;
        }
        int number_of_characters = number_of_characters(count);
        if (number_of_characters == 1) {
            if (data.length == 1) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
            return;
        }
        if (number_of_characters == 2) {
            if (data.length == 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
            return;
        }
        if (data.length <= 4) {
            System.out.println("YES");
            return;
        }
        Arrays.sort(count);
        if (count[2]-count[0]<= 1) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }
    private int number_of_characters(int [] count) {
        int number_of_characters = 0;
        for (int i = 0; i < 3; i++) {
            if (0 < count[i]) {
                number_of_characters += 1;
            }
        }
        return number_of_characters;
    }
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = K; i < N; i++) {
		cout << (A[i] > A[i - K] ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 4048
#include <functional>
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include <numeric>
#include<string>
using ll = long long;
using namespace std;
# define maxn 100
# define maxm 50

int main() {
  int n;
  vector <int>w;
  cin>>n;
  for (int i(0);i<n;i++){
    int wi;
    cin>>wi;
    w.push_back(wi);
  }
  int mini(10000000);
  for (int t(0);t<n;t++){
    int sum1(0),sum2(0);
    for (int i(0);i<n;i++){
      if (i<=t){
        sum1+=w[i];
      }else{
        sum2+=w[i];
      }
    }
    mini = min(mini,abs(sum1-sum2));
  }
  cout<<mini;
  return 0;
}

Measured memory_bytes: 888
@A=glob<>;printf sort{$a-$b}map{@v=//;$x=-30;$v[$t=$'>>2*$_&3]+=$t&&$l[$x+=10,$_]for 0..@l;$x+=abs$A[$_]-($v[$_]||1e9)for 1..3;$x}1..1<<2*(@l=<>)

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

int main() {
  int n, w;
  cin >> n >> w;
  int w1, v1;
  cin >> w1 >> v1;
  vector<vector<int>> v(4);
  v[0].push_back(v1);
  for (int i = 1; i < n; i++) {
    int wi, vi;
    cin >> wi >> vi;
    v[wi-w1].push_back(vi);
  }

  for (int i = 0; i < 4; i++) {
    sort(v[i].begin(), v[i].end(), greater<int>());
    for (int j = 1; j < v[i].size(); j++) {
      v[i][j] += v[i][j-1];
    }
    v[i].insert(v[i].begin(), 0);
  }

  long long a[4] = {w1, w1+1, w1+2, w1+3};
  int ans = 0;
  for (int i = 0; i < v[0].size(); i++) {
    for (int j = 0; j < v[1].size(); j++) {
      for (int k = 0; k < v[2].size(); k++) {
        for (int l = 0; l < v[3].size(); l++) {
          if (a[0]*i+a[1]*j+a[2]*k+a[3]*l <= w) {
            ans = max(ans, v[0][i]+v[1][j]+v[2][k]+v[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
trait Integer {
    fn is_sqrt_int(&self) -> bool;
}

impl Integer for i64 {
    fn is_sqrt_int(&self) -> bool {
        let f = *self as f64;
        let sqrt = f.sqrt() as i64;
        *self / sqrt == sqrt && *self % sqrt == 0
    }
}

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn comb2(n: usize) -> Vec<(usize, usize)> {
    let mut v = Vec::new();
    for i in 0..(n - 1) {
        for j in (i + 1)..n {
            v.push((i, j));
        }
    }
    v
}

fn distance2(p0: &Vec<i64>, p1: &Vec<i64>) -> i64 {
    p0.iter().zip(p1.iter()).map(|(x0, x1)| (x0 - x1) * (x0 - x1)).sum()
}

fn main() {
    let nums: Vec<i64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (n, _) = (nums[0] as usize, nums[1]);
    let ps: Vec<Vec<i64>> = (0..n).map(|_| read_line().split_whitespace().map(|x| x.parse().unwrap()).collect()).collect();
    
    let count = comb2(n)
        .into_iter()
        .filter(|&(i, j)| distance2(&ps[i], &ps[j]).is_sqrt_int())
        .count();

    println!("{}", count);
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int i = B*10;
  while(i<B*10+10) {
      if(A==(int)(i*0.08)) {
          cout << i << endl;
          return 0;
      }
      i++;
  }

  cout << -1 << endl;
}

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

using namespace std;

void binPrint(unsigned long long x, int bits){
  for (int i=bits-1; i>=0; i--){
    cout << (x&(1ull<<i)?1:0);
  }
  cout << endl;
}
int main(void){
  unsigned long long flg=0, mask[10];
  int n,q, qtype, i, s;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int k;
    cin >> k;
    mask[i] = 0ull;
    for (int j=0; j<k; j++){
      int t;
      cin >> t;
      mask[i] |= 1ull << t;
    }
  }
  cin >> q;
  for (int _i=0; _i<q; _i++){
    cin >> qtype >> i;
    switch(qtype){
    case 0: // TST
      cout << (flg&(1ull<<i)?1:0) << endl;
      break;
    case 1: // SET
      flg |= mask[i];
      break;
    case 2: // CLR
      flg &= ~mask[i];
      break;
    case 3: // FLP
      flg ^= mask[i];
      break;
    case 4: // ALL
      cout << ((flg&mask[i])==mask[i]?1:0) << endl;
      break;
    case 5: // ANY
      cout << ((flg&mask[i])?1:0) << endl;
      break;
    case 6: // NON
      cout << ((flg&mask[i])==0?1:0) << endl;
      break;
    case 7: // CNT
      s=0;
      for (unsigned long long tmp=flg&mask[i]; tmp; tmp>>=1){
        s += tmp&1;
      }
      cout << s << endl;
      break;
    case 8: // VAL
      cout << (flg&mask[i]) << endl;
    }
  //binPrint(flg, 64);
  }
  return 0;
}




Measured memory_bytes: 3092
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);

    int x = a + (a-1);
    int y = a + b;
    int z = b + (b-1);

    int max;

    if( x >= y)
    {
        max = x;
    }
    else
    {
        max = y;
    }
    
    if(max <= z)
    {
        max = z;
    }

    printf("%d",max );

    return 0;

}

Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	static int[][] map = new int[21][21];
	static double[] d = new double[21];
	static int n;
	static HashSet<Integer> hash = new HashSet<Integer>();
	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		while(true){
			n = sc.nextInt();
			for(int s=0;s<21;s++){
				for(int t=0;t<21;t++){
					map[s][t] = Integer.MAX_VALUE;
				}
			}
			int hx = sc.nextInt();
			int hy = sc.nextInt();
			int dx = sc.nextInt();
			int dy = sc.nextInt();
			if(n==0&&hx==0&&hy==0&&dx==0&&dy==0){
				break;
			}
			int[] x = new int[n];
			int[] y = new int[n];
			for(int k=0;k<n;k++){
				x[k] = sc.nextInt();
				y[k] = sc.nextInt();
			}
			for(int k=0;k<n;k++){
				map[0][k+1] = (hx-x[k])*(hx-x[k])+(hy-y[k])*(hy-y[k]);
			}
			for(int s=0;s<n;s++){
				for(int t=0;t<n;t++){
					map[s+1][t+1] = (x[s]-x[t])*(x[s]-x[t])+(y[s]-y[t])*(y[s]-y[t]);
				}
			}
			d[0] = Integer.MAX_VALUE;
			for(int k=1;k<n+1;k++){
				d[k] = Math.sqrt((dx-x[k-1])*(dx-x[k-1])+(dy-y[k-1])*(dy-y[k-1]));
			}
			if(dfs(0,0)<Integer.MAX_VALUE){
				pr.println("YES");
			}else{
				pr.println("NO");
			}

		}
		pr.flush();
		sc.close();
	}

	private static double dfs(double i,int node) {
		if(i>=d[node]) return Integer.MAX_VALUE;
		if(hash.size()==n) return i;
		for(int k=1;k<n+1;k++){
			if(map[node][k]<Integer.MAX_VALUE&&hash.contains(k)!=true){
				hash.add(k);
				if (i + Math.sqrt(map[node][k]) >= d[k]) {
					hash.remove(k);
					return Integer.MAX_VALUE;
				}
				hash.remove(k);
			}
		}
		for(int k=1;k<n+1;k++){
			if(map[node][k]<Integer.MAX_VALUE&&hash.contains(k)!=true){
				hash.add(k);
				if(dfs(i+Math.sqrt(map[node][k]),k)<Integer.MAX_VALUE){
					hash.remove(k);
					return i;
				}
				hash.remove(k);
			}
		}
		return Integer.MAX_VALUE;
	}
}

Measured memory_bytes: 288500
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


ll gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}

ll lcm( ll m, ll n ){
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
    return ((m / gcd(m, n)) * n);// lcm = m * n / gcd(m,n)
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    set<int> prime;
    ll L = 1;
    REP(i,N){
        cin >> a[i];
        a[i] /= 2;
        L = lcm(L, a[i]);
        int cnt = 0;
        while(a[i] % 2 == 0){
            cnt++;
            a[i] /= 2;
        }
        prime.insert(cnt);
        if(L > M){
            cout << 0 << endl;
            return 0;
        }
    }
    if(prime.size() != 1) cout << 0 << endl;
    else cout << (M / L + 1) / 2 << endl;
}


Measured memory_bytes: 1024
N,M=map(int,input().split())
ac=[0]*N
pn=[0]*N
for i in range(M):
  p,s=input().split()
  p=int(p)
  if ac[p-1]==0:
    if s=="AC":
      ac[p-1]=1
    else:
      pn[p-1]+=1

pna=0
for i in range(N):
  if ac[i]==1:
    pna+=pn[i]
print(sum(ac),pna)

Measured memory_bytes: 4596
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=A.copy()
for i in range(N):
    if A[i]-B[i]>=0:
        A[i]=A[i]-B[i]
    elif A[i]+A[i+1]-B[i]>=0:
        A[i+1]=A[i]+A[i+1]-B[i]
        A[i]=0
    else:
        A[i]=0
        A[i+1]=0
#print(A)
print(sum(ans)-sum(A))

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
#define int ll
const int MOD = 1000000007;

bool isAuspicious(int a, int b, int l, int r, int x) {
	x >>= 21;
	int x1 = (a-l) >> 21;
	int x2 = (a-r) >> 21;
	
	int y1 = (b+l) >> 21;
	int y2 = (b+r) >> 21;
	return ((x1^y1)==x) || ((x1^y2)==x) || ((x2^y1)==x) || ((x2^y2)==x);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int a, b, x = 0; cin >> a >> b;
    rep(i, n-2) {
    	int p; cin >> p;
    	x ^= p;
    }
    for(int l = 0; l < a; l += (1 << 20)) {
    	int r = min(l + (1 << 20) - 1, a - 1);
    	if(!isAuspicious(a, b, l, r, x)) continue;
    	iter(ct, l, r+1) {
    		if(((a-ct) ^ (b+ct)) == x) {
    			cout << ct << endl;
    			return 0;
    		}
    	}
    }
    cout << -1 << endl;
}



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

#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 ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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


int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  ll ans = 0;
  REP(i, A+1){
    REP(j, B+1){
      REP(k, C+1){
        if(500*i+100*j+50*k==X){
          ans++;
          break;
        }else if(500*i+100*j+50*k>X){
          break;
        }
      }
    }
  }
  cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
		try {
			line = br.readLine();
		} catch (IOException e) {
			System.err.println("The input is missing. " + e.getMessage());
			return;
		}

        int x, y;
        try {
        	String[] fields = line.split(" ");
        	x = Integer.parseInt(fields[0]);
        	y = Integer.parseInt(fields[1]);
        } catch(Throwable e) {
			System.err.println("The input is in an illegal form. " + line);
			return;
        }

        StringBuilder b = new StringBuilder();
        b.append(x*y);
        b.append(' ');
        b.append(2*(x+y));
        System.out.println(b.toString());
    }
}

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

using namespace std;

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

    n=n%k;
    if(n==0||(n<k && n<abs(n-k)))
    {

        cout<<n<<endl;
        return 0;
    }
    else
    cout<<abs(n-k)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
    int n,a,b,i,j,flg;
    cin>>n;
	flg=0;
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			if(7*i+4*j==n) flg=1;
		}
	}
	if(flg==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}

int32_t main()
{
    //codeforces();
    // int t;cin>>t;
    // while(t--) {
        
    // }
    int n;cin>>n;
    vector<vi> dp(n,vi(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>dp[i][j];
            if(i>0){
                if(j==0){
                    dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j+2]);
                }else if(j==1){
                    dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j-1]);
                }else if(j==2){
                    dp[i][j]+=max(dp[i-1][j-2],dp[i-1][j-1]);
                }
            }
        }
    }
    int m=max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    cout<<m<<'\n';
    return 0;
}

Measured memory_bytes: 5760
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;

#define loop(i,n) for(int i=0;i<(n);i++)
#define pool(i,n) for(int i=(n)-1;i>=0;i--)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define tnoc(i,n) for(int i=(n);i>=1;i--)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define cric(i,a,b) for(int i=(b);i>=(a);i--)
#define sub(i,a) for(int i=a;i;i=((i-1)&(a)))
#define subs(i,a) for(int i=a;i>=0;i=(!i?-1:((i-1)&(a))))
#define subt(i,a) for(int i=((a-1)&a);i;i=((i-1)&(a)))
#define subst(i,a) for(int i=((a-1)&a);i>=0;i=(!i?-1:((i-1)&(a))))
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define parse(i,s) for(int i=0;s[i];i++)

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mak make_pair

#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define ws WSrAkIoi2333wSraKIoIWSraKiOi
#define left left_jTjTJtJtIoiiOiioIAuaU66666jtIOIau
#define hash whYusEthiSnamE_caNyoUusEothERnaMesliKeHSH

#define Mask(a) (1ll<<(a))
#define Maskx(a,x) ((a)<<(x))
#define Full(a) ((1ll<<(a))-1)
#define Bit(a,x) (((a)>>(x))&1)
#define all(a) (a).begin(),(a).end()
#define SZ(a) ((int)((a).size()))

typedef long long ll;
typedef long double lf;

const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const lf inF=11451419198101145141919810.1145141919810;
const lf pi=acosl(-1);
/* Source code starts here */

int n,a,b;
const int jt=1000000007;
int dp[5005][5005][2],qzh1[5005],qzh2[5005][5005];
void inline add(int &a,int b){a+=b;if(a>=jt)a-=jt;if(a<0)a+=jt;}

int main(){
	scanf("%d%d%d",&n,&a,&b);
	if(a<b)swap(a,b);
	dp[0][0][1]=1;
	loop(i,n+1){
		if(i)add(qzh1[i],qzh1[i-1]);
		add(dp[i][0][0],qzh1[i]);
		loop(j,i+1){
			if(i)add(qzh2[i-j][i],qzh2[i-j][i-1]);
			add(dp[i][j][0],qzh2[i-j][i]);
			if(j==a){
				add(dp[i][j][1],dp[i][j][0]);dp[i][j][0]=0;
				add(dp[i+1][j][1],dp[i][j][1]);
				add(dp[i+1][j][1],dp[i][j][1]);
				break;
			}
			add(dp[i+1][j+1][1],dp[i][j][0]);
			add(dp[i+1][j+1][1],dp[i][j][1]);
			add(qzh1[i+1],dp[i][j][1]);
			if(i+b<=n){
				add(qzh1[i+b],-dp[i][j][1]);
				if(j+b<=a)add(qzh2[i-j][i+b],dp[i][j][1]);
				else add(dp[i+b][a][1],dp[i][j][1]);
			}
		}
	}
	add(dp[n][a][1],dp[n][a][0]);
	printf("%d\n",dp[n][a][1]);
	return 0;
}

Measured memory_bytes: 187324
# import bisect
from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from math import gcd
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        A = list(map(int, input().split()))

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            if AAA[0][1] != N * 2 // 3:
                return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3 or k1 ^ k3 == k2 or k2 ^ k3 == k1

    print('Yes' if main() else 'No')


resolve()

Measured memory_bytes: 60784
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    char a[20];
    scanf("%s",a);
    if(a[1] == 'B'){
        cout<<"ARC";
    }
    else{
        cout<<"ABC";
    }
    return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll a, b, c, d; cin >> a >> b >> c >> d;
  cout << max({a*c,a*d,b*c,b*d}) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
class Book{
public:
    string title,author;
    int date;
};
 
int getDate(string &s){
    for(int i = 0 ; i < (int)s.size() ; i++){
	if(s[i] == '/'){
	    s[i] = ' ';
	}
    }
    int y,m,d;
    stringstream ss(s);
    ss >> y; ss >> m; ss >> d;
    return y*10000 + m*100 + d;
}
 
int main(){
    int N;
    string str;
    bool blank = false;
    cin >> N;
    vector<Book> books(N);
    for(int i = 0 ; i < N ; i++){
	cin >> books[i].title >> books[i].author >> str;
	books[i].date = getDate(str);
    }
    int Q;
    cin >> Q;
    while(Q--){
	if(blank) cout << endl;
	blank = true;
	string s[4];
	int S = 0;
	for(int i = 0 ; i < 4 ; i++){
	    cin >> s[i];
	    if(s[i] == "*"){
		S |= (1<<i);
	    }
	}
	vector<string> res;
	for(int i = 0 ; i < N ; i++){
	    bool ok = true;
	    for(int j = 0 ; j < 4 ; j++){
		if(S >> j & 1) continue;
		if(j == 0){
		    if(books[i].title.find(s[j]) == string::npos){
			ok = false;
		    }
		}else if(j == 1){
		    if(books[i].author.find(s[j]) == string::npos){
			ok = false;
		    }
		}else if(j == 2){
		    int date = getDate(s[j]);
		    if(date > books[i].date){
			ok = false;
		    }
		}else{
		    int date = getDate(s[j]);
		    if(books[i].date > date){
			ok = false;
		    }
		}
	    }
	    if(ok){
		res.push_back(books[i].title);
	    }
	}
	for(auto x : res){
	    cout << x << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3184
#selection sort
N = int(input())
nums = list(map(int,input().split()))

count = 0 #交換回数
for i in range(N):
    minj = i
    for j in range(i+1,N): #配列を探索し、最小値を見つける
        if nums[minj] > nums[j]:
            minj = j
    if i != minj:
        temp = nums[i] #iの値を一時保管
        nums[i] = nums[minj] #iの位置に最小値を入れて交換する
        nums[minj] = temp
        count = count + 1

print(' '.join(map(str,nums)))
print(count)


Measured memory_bytes: 5596
import sys
N = int(sys.stdin.readline().rstrip())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a = set(a)
    if len(a) == 1:
        return True
    else:
        return False

divisors = make_divisors(N)
ans = 0
for d in divisors:
    if prime_factorize(d) and N % d == 0:
        N //= d
        ans += 1
print(ans)

Measured memory_bytes: 9496
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
int main(void){
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    
    for (int i = 0; i < N; i++) {
        std::cin >> v[i];
    }
    
    std::sort(v.begin(), v.end());
    double results = 0.0;
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            results = v[i];
        }
        results = (results + v[i]) / 2;
    }
    
    std::cout << std::setprecision(5) << results << std::endl;
}


Measured memory_bytes: 632
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }.toIntArray()

    var finish = false
    var ans = 0

    while(!finish) {
        var begin = false
        var did = false
        for (i in 0 until n) {
            if (a[i] == 0) {
                if (begin) ans++
                begin = false
            } else {
                begin = true
                did = true
                a[i]--
            }
        }
        if (did && begin) ans++
        if (!did) finish = true
    }
    println(ans)
}


Measured memory_bytes: 38180
from sys import stdin


def main() -> int:
    n = next_int()
    for i in range(n, 0, -1):
        if judge(i):
            print(i)
            break
    return 0


def judge(n: int) -> bool:
    while n % 2 == 0 and n != 0:
        n //= 2
    if n == 1:
        return True
    return False


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;




int main(){
    ll n, dist, atk;
    cin >> n >> dist >> atk;

    vector<P> p;
    rep(i, n){
        ll x, h;
        cin >> x >> h;
        p.emplace_back(x, h);
    }
    sort(ALL(p));

    ll res = 0;
    ll tot = 0;
    queue<P> que;
    rep(i, n){
        ll x = p[i].first, h = p[i].second;
        while(!que.empty() && que.front().first < x){
            tot += que.front().second;
            que.pop();
        }

        h = max(h - tot, (ll)0);
      //cout << h << endl;
        ll a = h / atk + (h % atk == 0 ? 0 : 1);
        res += a;
        tot += a * atk;
        que.emplace(x + 2 * dist, -a * atk);
    }
    cout << res << endl;
}


Measured memory_bytes: 7020
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        Integer[] li = new Integer[n];
        int min = 1000;
        int sum = 0;

        for(int i = 0; i < n;i++) {
        	li[i] = scanner.nextInt();
        	if(min > li[i]) {
        		min = li[i];
        	}
        	sum += li[i];
        }
        System.out.println( ((x-sum)/min) + n );
    }

	private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
bool check(vll &a, ll lim, ll k){
  	ll n = a.size();
  	ll cnt = 0; 
  	for (ll i = 0; i<n; i++){
	    ll x = a[i];
	    if (x > 0){
	      	ll l = -1, r = n;
	      	while (r - l > 1){
	      		ll mid = (l + r) / 2;
	      		if (a[mid] * x < lim) l = mid;
	      		else r = mid;
			}
			cnt += (l + 1);
	    } 
		else if (x == 0){
	      	if (lim > 0) cnt += n;
	    } 
		else{
	      	ll l = -1, r = n;
	      	while (r - l > 1){
	      		ll mid = (l + r) / 2;
	      		if (a[mid] * x < lim) r = mid;
	      		else l = mid;
			}
	      	cnt += (n - r); 
		}
  	}
  	for (ll i = 0; i<n; i++){
  		if (a[i] * a[i] < lim) cnt--;
	}
	cnt /= 2; 
  	return cnt < k;
}
 
int main(){
	fastio;
	ll n, k; cin >> n >> k;
	vll a(n); for (ll i = 0; i<n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	ll l = -1e18 - 1, r = 1e18 + 1;
	while (r - l > 1){
		ll mid = (l + r) / 2;
		if (check(a, mid, k)) l = mid;
		else r = mid;
	}
  	cout << l << endl;
}

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

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int c = s[i] - 'A';
        c = (c + n) % 26;
        s[i] = c + 'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n,k,a[5005],res;
bool f[5005];

bool solve(int x){
    //printf("%d\n",x);
    memset(f,false,sizeof f);
    f[0]=true;
    for(int i=0;i<n;i++)if(i!=x){
        assert(a[i]<k);
        for(int j=k-1;j>=0;j--)if(f[j] && j+a[i]<k)f[j+a[i]]=true;
    }
    int curr=k;
    for(int j=0;j<k;j++)if(f[j]){
        curr=min(curr,k-j);
        //printf(" %d",j);
    }
    //printf(" = %d\n",curr);
    return a[x]<curr; // Un
}

int main(){
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    sort(a,a+n);
    while(n>0 && a[n-1]>=k)n--;
    int first=0,last=n-1;
    while(first<=last){
        int mid=(first+last)/2;
        if(solve(mid))first=mid+1;else last=mid-1;
    }
    printf("%d\n",first);
    return 0;
}


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

int main(){
  int n; cin >> n;
  int d, x; cin >> d >> x;
  int a[101];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int choco = 0;
  int day = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j*a[i] + 1 <= d; j++){
      choco++;
    }
  }

  cout << choco + x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #pragma comment(linker, "/STACK:2000000")
  #pragma comment(linker, "/HEAP:2000000")
  #define db long double
  #define trace1(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 trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  int32_t main()
  {        

    IOS
    int x;
    cin>>x;
    cout<<3*x*x;
    return 0;     
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
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;
}

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

    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (auto &i : h) {
        cin >> i;
    }

    vector<int> dp(N);
    dp[0] = 0;
    FOR(i, 1, N) {
        dp[i] = (int)1E9;
        FOR(j, 1, K + 1) {
            if (0 <= i - j)
                chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    std::cout << dp[N - 1] << '\n';

    return 0;
}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  map<ll, ll> cnt;
  cnt[0] = 1;
  ll sum = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    if (cnt.count(sum)) {
      ans += cnt[sum];
    }
    cnt[sum]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using namespace atcoder;
int main(){
  int n;
  cin >> n;
  dsu d(n);
  int q;
  cin >> q;
  while(q--){
    int t, a, b;
    cin >> t >> a >> b;
    if(t == 0){
      d.merge(a, b);
    }else{
      if(d.same(a, b))
        cout << 1;
      else
        cout << 0;
      cout << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String s = scan.next();

	boolean b = (s.length() % 2 == 0) ^ (s.charAt(0) == s.charAt(s.length()-1));
	System.out.println(b ? "Second" : "First");
	scan.close();
    }
}


Measured memory_bytes: 26788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> Pair;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll INFL = 1e18;


int main(){
    priority_queue<int> que;
    int n,m; cin >> n >> m;
    for(int i=1; i<=n; i++){
        int a; cin >> a;
        que.emplace(a);
    }
    for(int i=1; i<=m; i++){
        int now = que.top();
        que.pop();
        now /= 2;
        que.emplace(now);
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3808
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
H = read_ints()

# https://atcoder.jp/contests/dp/tasks/dp_a
# 全探索ではナンセンス(というより処理が終わらない)
# i+1 or i+2のうち小さい方を選びつづければいいということにすぐに気がつく
# こういったように、今の状態から次の状態が決まるときはDPが使えることがおおい(この問題はgreedy気味にも捉えることができるが。)
# 途中までの状態が決まれば、最善手を選ぶことで次の状態が決定できるのを実装する。
# 今回の場合だったらhまでの最善の状態というのはmin(2つ前までの最善の状態+差, 1つ前までの最善の状態+差)なのでこれでdpテーブルを埋めていくことができる。

import numpy as np
dp = np.zeros((N), dtype='int64')
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(H[i - 1] - H[i]),
                dp[i - 2] + abs(H[i] - H[i - 2]))

print(dp[-1])


Measured memory_bytes: 17208
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int N=205;
const ll INF=1e18;
ll dis[N][N],ans=INF,maxn;
int n,sx[9],m,r;
bool vis[N];
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void dfs(int dep,int now,ll len){
	if(dep==r){
		ans=min(ans,len);
		return;
	}
	for(int i=1;i<=r;++i){
		if(vis[i]) continue;
		vis[i]=1;
		dfs(dep+1,i,len+dis[sx[now]][sx[i]]);
		vis[i]=0;
	}
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();m=read();r=read();
	for(int i=1;i<=r;++i) sx[i]=read();
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j) dis[i][j]=INF;
	for(int i=1;i<=m;++i){
		int a=read(),b=read();ll c=(ll)read();
		dis[a][b]=dis[b][a]=c;
	}
	for(int k=1;k<=n;++k){
		for(int i=1;i<=n;++i){
			for(int j=1;j<=n;++j){
				if(dis[i][j]>dis[i][k]+dis[k][j]) dis[i][j]=dis[i][k]+dis[k][j];
			}
		}
	}
	for(int i=1;i<=r;++i) vis[i]=1,dfs(1,i,0),vis[i]=0;
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;
string s;
int was[26];

int go (int i) {
	if (i == n) {
		for (int i = 0; i < 26; i++)
			if (!was[i]) {
				s += char (i + 'a');
				re 1;
			}
		re 0;
	}
	was[s[i] - 'a'] = 1;
	if (go (i + 1)) re 1;
	for (int j = s[i] - 'a' + 1; j < 26; j++)
		if (!was[j]) {
			s.erase (i, sz (s) - i);
			s += char (j + 'a');
			re 1;
		}
	was[s[i] - 'a'] = 0;
	re 0;
}

int main () {
	cin >> s;
	n = sz (s);
	if (!go (0)) cout << "-1" << endl; else cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k, x, y, ans = 0, aa, bb;
	cin >> n;
	vector<pair<int, int>> a(n), b(n);
	for (i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
	for (i = 0; i < n; i++) cin >> b[i].first >> b[i].second;
	set<int> s;
	set<int>::iterator it;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	aa = 0; bb = 0;
	while ((aa < n) || (bb < n)) {
		if ((bb == n) || ((aa < n) && (a[aa].first < b[bb].first))) {
			s.insert(a[aa].second);
			aa++;
		}
		else {
			if (!s.empty() && (*s.begin() < b[bb].second)) {
				ans++;
				it = s.lower_bound(b[bb].second);
				it--;
				s.erase(it);
			}
			bb++;
		}
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func main() {
	input := scanIntNum()

	var happiness int

	// 500
	happiness += (input / 500) * 1000
	rem := input % 500

	// 5
	happiness += (rem / 5) * 5

	fmt.Println(happiness)
}


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

using namespace std;

using i64 = long long;

template <i64 mod>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<1000000007>;

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

    int m = int(sqrt(n)) + 1;
    deque<vector<mint>> dp(5, vector<mint>(m + 1, 0));
    dp[2][1] = 1;
    dp[2][2] = mint(-1);
    for(int i = 0; i <= k + 1; ++i){
        for(int j = 1; j <= m; ++j)
            dp[0][j] += dp[0][j - 1];
        for(int j = 1; j <= m; ++j)
            dp[2][j] += dp[2][j - 1];
        for(int j = 1; j < m; ++j){
            int bound = int(n) / j;
            int ad = bound - m + 1;
            if(i >= 2)
                dp[2][j] += dp[0][j] * ad;
            mint val = dp[2][j];
            dp[3][1] += val;
            dp[4][1] += val * ad;
            dp[3][m] -= val;
            dp[4][j] -= val * ad;
        }
        dp.pop_front();
        dp.emplace_back(m + 1, 0);
    }
    cout << dp[1][1] << endl;

    return 0;
}


Measured memory_bytes: 1752