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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }

void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const ll MOD =1000000007;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m);
}

int main(void){
	int N,K,Q,a,score[100000];
	cin>>N>>K>>Q;

	REP(i,N) score[i]=0;

	REP(i,Q){
		cin>>a;
		score[a-1]++;
	}

	REP(i,N){
		if((K+score[i]-Q)>0) print("Yes");
		else print("No");
	}
}


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

const int maxn = 100 + 5;
const int maxm = 10000 + 5;

int v[maxn],w[maxn];
int f[maxm];

int main()
{
    int N,W;
    scanf("%d%d",&N,&W);
    for(int i = 1;i <= N; i++)scanf("%d%d",&v[i],&w[i]);
    for(int i = 1;i <= N; i++)
    {
        for(int j = W;j >= w[i]; j--)
        {
            f[j] = max(f[j],f[j-w[i]] + v[i]);
        }
    }
    printf("%d\n",f[W]);
}

Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main() {
	int N,sum,i;
	i = 0;
	char d[100000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sum = 0;


	for (i; i < N -1; i++) {
		if (d[i] != d[i + 1])sum++;
	}
	cout << sum+1;
	return 0;

}

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

int main()
{
	int A;
	int B;
	cin >> A;
	cin >> B;
	if (A + B < 24)
	{
		cout << A + B << endl;
	}
	else 
	{
		cout << (A + B)-24 << endl;
	}
}


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

#define INF 100000000

using namespace std;
char O[114], E[114];
char result[514];
int main(){
  scanf("%s%s", O, E);
  for(int i = 0; i < strlen(O); i++){
    result[2 * i] = O[i];
    result[2 * i + 1] = E[i];
  }
  printf("%s\n", result);
}



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

string s;
long long sum, a[500005], b[500005];
int main() {
	int i;
	cin>> s;
	s = '.' + s;
	for(i=1; i<=s.size(); i++) {
		if(s[i]=='<') a[i] = a[i-1] + 1;
	}
	for(i=s.size(); i; i--) {
		if(s[i]=='>') b[i-1] = b[i] + 1;
	}
	for(i=0; i<=s.size(); i++) {
		sum += max(a[i], b[i]);
	}
	cout<< sum;
	return 0;
}

Measured memory_bytes: 8728
function Main(s) {
  var n = s.split("\n")[0]*1;
  ans = 1;
  for (var i = 1; i <= n; i++) {
    ans = (ans * i) % 1000000007;
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8908
use std::collections::BTreeSet;
use std::io::*;
use std::ops::Bound::Excluded;
use std::ops::Bound::Included;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let mut ps = vec![(0, 0); n];
    for i in 0..n {
        ps[i].0 = read::<usize>();
        ps[i].1 = i;
    }
    ps.sort();
    ps.reverse();
    let mut items = BTreeSet::<i64>::new();
    let mut ans = 0;
    for i in 0..n {
        let v = ps[i].0 as i64;
        let pos = ps[i].1 as i64;
        let mut lefts = vec![];
        let mut rights = vec![];
        for index in items.range((Included(&0), Excluded(&(pos as i64)))).rev() {
            lefts.push(*index);
            if lefts.len() == 2 {
                break;
            }
        }
        for index in items.range((Excluded(&(pos as i64)), Included(&(n as i64)))) {
            rights.push(*index);
            if rights.len() == 2 {
                break;
            }
        }
        while lefts.len() <= 1 {
            lefts.push(-1);
        }
        while rights.len() <= 1 {
            rights.push(n as i64);
        }
        ans += v * (pos - lefts[0]) * (rights[1] - rights[0]);
        ans += v * (lefts[0] - lefts[1]) * (rights[0] - pos);
        items.insert(pos as i64);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6496
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.LinkedList;

public class Main {

	
	

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

		int n=scn.nextInt();
		int k=scn.nextInt();
		int cost[]=new int[n];
		for(int i=0;i<n;i++){
			cost[i]=scn.nextInt();
		}
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE/2);
		dp[0]=0;
		for(int i=0;i<n;i++){
			for(int j=i-1;j>=i-k && j>=0;j--){
				dp[i]=Math.min(dp[i], Math.abs(cost[i]-cost[j])+dp[j]);
			}
		}
		
		
		
		
		System.out.println(dp[n-1]);

	}

}

Measured memory_bytes: 50892
n = int(input())
a = list(map(int,input().split()))

c = 0
x = True
while x == True:
    if all([i%2 == 0 for i in a]) == True:
        c += 1
        for j in range(len(a)):
            a[j] = a[j]//2
    else:
        x = False

print(c)

Measured memory_bytes: 3316
N=int(input())

if(N<=111):    print(111)
elif(N>111 and N<=222):    print(222)
elif(N>222 and N<=333):    print(333)
elif(N>333 and N<=444):    print(444)
elif(N>444 and N<=555):    print(555)
elif(N>555 and N<=666):    print(666)
elif(N>666 and N<=777):    print(777)
elif(N>777 and N<=888):    print(888)
else:    print(999)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for (int x=y; x<=z; x++)
#define downrep(x,y,z) for (int x=y; x>=z; x--)
#define ms(x,y,z) memset(x,y,sizeof(z))
#define LL long long
#define repedge(x,y) for (int x=hed[y]; ~x; x=edge[x].nex)
inline int read(){
	int x=0; int w=0; char ch=0;
	while (ch<'0' || ch>'9') w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w? -x:x;
}
int a[5];
int main(){
	rep(i,1,3) a[i]=read(); sort(a+1,a+4);
	printf("%d\n",a[3]*10+a[1]+a[2]);
	return 0;
}

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

int main(){
    ll h;
    cin >> h;
    ll cnt=0;
    ll i=0;
    while(h>0){
        h /= 2;
        cnt += pow(2,i);
        i++;
    }
    cout << cnt << endl;
}

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

#define pb     push_back
#define mp     make_pair
#define all(v) v.begin() , v.end()
#define allr(v) v.rbegin(), v.rend()
const ll INF =  0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAX = 1e5+5;

int n;
map<double, bool> exist;

int main(int argc, char const *argv[])
{
  ios_base::sync_with_stdio(false);

  scanf("%d" , &n);
  if(n%2 == 0)
  	printf("%d %d %d" , n/2, n, n);
  else{
  	for(int i = 1 ; i <= 3500 ; i++){
      for(int j = i ; j <= 3500 ; j++){
        ll num = 1ll*n*i*j;
        ll den = 4ll*i*j - n*i - n*j;
        if(den != 0 && num%den == 0){
          if(num/den > 0){
            printf("%lld %d %d" , num/den, i, j);
            return 0;
          }
        }
      }
    }  	
  }



  return 0;
}  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
  string s = "CODEFESTIVAL2016";
  string tmp;

  cin >> tmp;

  int ans = 0;
  for(int i = 0; i < tmp.size(); i++) {
    if(tmp[i] != s[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){

	string s;
	char tmp;
	int counter[26],i;

	for(i=0;i<26;i++){
		counter[i] = 0;
	}

	while(getline(cin,s)){

		for(i=0;i<s.length();i++){
			if(s[i] >= 65 && s[i] <= 90){
				counter[s[i]-65]++;
			}
			else if(s[i] >= 97 && s[i] <= 122){
				counter[s[i]-97]++;
			}
		}
	}
	for(i=0;i<26;i++){
			tmp = 'a' + i;
			cout << tmp << " : " << counter[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3144
#coding:utf-8
s=input()
count=True
dumy=0
for i in range(len(s)):
  if(s[i]>="A" and s[i]<="Z"):
    dumy+=1
if(dumy!=2):
  count=False
dumy=0
if(s[0]=="A"):
  for i in range(2,len(s)-1):
    if(s[i]=="C"):
      dumy+=1
else:
  count=False
if(dumy!=1):
  count=False
if(count==False):
  print("WA")
else:
  print("AC")

Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
 
int main() {
  int N;
  while(cin >>N && N){
    map<int, int> M;
    REP(i, N){
      int a, b, c; cin >>a >>b >>c;
      M[a] = b + c;
    }
    int tar = M.begin()->first;
    for(pair<const int, int> p : M) if(M[p.first] > M[tar]) tar = p.first;
    cout <<tar <<" " <<M[tar] <<endl;
  }
  return 0;
}

Measured memory_bytes: 1668
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = int(input())
    y = (S+10**9-1)//(10**9)
    x = y*(10**9)-S
    print(' '.join(map(str,[0,0,10**9,1,x,y])))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Random;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int D;
	int[] c;
	int[][] s;

	int[] ans;

	long score(int[] a, int dd) {
		int[] last = new int[26];

		long res = 0;

		for (int d = 0; d < dd; d++) {
			res += s[d][a[d]];
			last[a[d]] = d + 1;

			for (int j = 0; j < 26; j++) {
				res -= (c[j] * (d + 1 - last[j]));
			}
//			System.err.println(res);
		}
		return res ;
	}

	public void _main(String[] args) {
		long st = System.currentTimeMillis();
		Scanner sc = new Scanner(in);

		D = sc.nextInt();
		c = new int[26];
		for (int i = 0; i < 26; i++) {
			c[i] = sc.nextInt();
		}

		s = new int[D][26];
		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				s[i][j] = sc.nextInt();
			}
		}

		sc.close();

		ans = new int[D];


		for(int d=0;d<D;d++) {
			long max = score(ans, d+1);
			
			for(int i=0;i<26;i++) {
				int t = ans[d];
				ans[d] = i;
				long s = score(ans, d+1);
				
				if(s > max) {
					max = s;
				}else {
					ans[d] = t;
				}
			}
		}
		Random random = new Random();
		long max = score(ans, D);
		while (System.currentTimeMillis() - st < 1900) {
			int d = random.nextInt(D);
			int i = random.nextInt(26);
			
			int t = ans[d];
			if(t==i) continue;
			ans[d] = i;
			
			long s = score(ans, D);
			if(s > max) {
				max = s;
			}else {
				ans[d] = t;
			}
		}

//		System.err.println(max);

		StringBuilder sb = new StringBuilder();
		
		for (int x : ans) {
			sb.append(x+1);
			sb.append("\n");
		}
		out.print(sb.toString());

	}

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


Measured memory_bytes: 55200
#include<set>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 0x7fffffff
#define lli long long int
int n,len;
char c[50];

vector<set<pair<int,int> > > trie;
vector<lli> s;

inline int fd(int now,int k){
	if(trie[now].empty()) return 0;
	set<pair<int,int> >::iterator it=trie[now].lower_bound(make_pair(k,0));
	if(it==trie[now].end()) return 0;
	if(it->first!=k) return 0;
	return it->second;
}
inline int upd(){
	set<pair<int,int> > sss;
	sss.clear();
	trie.push_back(sss);
	s.push_back(0);
	return trie.size()-1;
}

int t[50],cnt;
inline void add(){
	int now=0,temp=0;
	for(int i=1;i<=n;i++){
		int pos=t[i],nxt=fd(now,pos);
		if(!nxt) nxt=upd(),trie[now].insert(make_pair(pos,nxt));
		now=nxt;
	}
	s[now]++;
	return;
}
inline unsigned lli query(){
	int now=0;
	for(int i=1;i<=n;i++){
		int pos=t[i],nxt=fd(now,pos);
		if(!nxt) return 0;
		now=nxt;
	}
	return s[now];
}

unsigned lli ans=0;
const lli vl[20]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144};

int main(){
	scanf("%d",&n);
	len=n<<1;
	cin>>c+1;
	upd();
	for(int i=0;i<=vl[n+1]-1;i++){
		cnt=0;
		for(int j=1;j<=n;j++) if((i&vl[j])==vl[j]) t[++cnt]=c[j]-'a';
		for(int j=1;j<=n;j++) if((i&vl[j])==0) t[++cnt]=c[j]-'a'+26;
		add();
	}
	for(int i=0;i<=vl[n+1]-1;i++){
		cnt=0;
		for(int j=1;j<=n;j++) if((i&vl[j])==0) t[++cnt]=c[len-j+1]-'a';
		for(int j=1;j<=n;j++) if((i&vl[j])==vl[j]) t[++cnt]=c[len-j+1]-'a'+26;
		ans+=query();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 312988
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int dp[N];
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(i==1)    continue;
        if(i==2)    dp[i] = abs(a[i]-a[i-1]);
        else        dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    printf("%d\n",dp[n]);
    return 0;
}


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

using namespace std;

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


const int MAX_STRING_SIZE = 1000000;

ll base = 1007;

vector<ll> MODS({2147483647, 6700417, 524287, 1000000007}

);

vector<vector<ll>> invs(MODS.size()), pows(MODS.size());

ll powm(ll e, ll x, ll m) {
  if (x == 0) return 1;
  if (x == 1) return e;
  if (x % 2 == 0) return powm((e * e) % m, x / 2, m);
  return (e * powm(e, x - 1, m)) % m;
}

void RHinit() {
  int i = 0;
  for (auto &p : MODS) {
    invs[i].resize(MAX_STRING_SIZE + 1);
    invs[i][0] = 1;
    ll inv = powm(base, p - 2, p);
    for (int j = 1; j <= MAX_STRING_SIZE; j++) {
      invs[i][j] = (invs[i][j - 1] * inv) % p;
    }
    pows[i].resize(MAX_STRING_SIZE + 1);
    pows[i][0] = 1;
    for (int j = 1; j <= MAX_STRING_SIZE; j++) {
      pows[i][j] = (pows[i][j - 1] * base) % p;
    }
    i++;
  }
}

struct RH {
  int n;
  string s;
  vector<vector<ll>> hs;

  RH(string &s) : s(s) {
    if (pows[0].empty()) {
      RHinit();
    }
    n = s.size();
    hs.resize(MODS.size());
    for (int i = 0; i < MODS.size(); i++) {
      hs[i].resize(n + 1);
      hs[i][0] = 0;
      for (int j = 0; j < n; j++) {
        hs[i][j + 1] = (hs[i][j] + pows[i][j] * s[j]) % MODS[i];
      }
    }
  }

  vector<ll> substr(int l, int r) {
    vector<ll> ret(MODS.size());
    for (int i = 0; i < MODS.size(); i++) {
      ret[i] = (hs[i][r] - hs[i][l] + MODS[i]) % MODS[i];
      ret[i] *= invs[i][l];
      ret[i] %= MODS[i];
    }
    return ret;
  }
};


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  string s;
  cin >> n >> s;
  s.push_back('$');
  RHinit();
  RH rh(s);

  ll l = 0, r = n;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    vector<vector<ll>> hss;
    for (int i = 0; i < n; i++) {
      if (i + m > n) continue;
      hss.push_back(rh.substr(i, i + m));
    }
    multiset<vector<ll>> lms, rms;
    for (int i = m; i < hss.size(); i++) rms.insert(hss[i]);
    bool breaked = false;
    for (int i = 0; i < hss.size(); i++) {
      if (i >= m) {
        lms.insert(hss[i - m]);
      }
      if (rms.find(hss[i]) != rms.end()) {
        breaked = true;
        break;
      }
      if (lms.find(hss[i]) != lms.end()) {
        breaked = true;
        break;
      }
      if (i + m < hss.size())
        rms.erase(rms.find(hss[i + m]));
    }
    if (breaked) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 65216
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll M = 200 + 10;
const ll N = 100 * 1000 + 10;

ll dp[N][2], a[N];
int n;

int main()	
{
	faster();
	int k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if(i >= a[j])
			{
				dp[i][0] = max(dp[i][0], 1 - dp[i - a[j]][1]);
				dp[i][1] = max(dp[i][1], 1 - dp[i - a[j]][0]);
			}
		}
	}
	if(dp[k][0])
		cout << "First\n";
	else
		cout << "Second\n";
}

Measured memory_bytes: 1792
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 8/28/2020
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
const double PI = acos(-1);
const int MOD = 1000000007;

const int mxN = 1e5+20;
int n;
ll dp[mxN+1][3];
ll arr[mxN+1][3];

ll go(int i, int lastAct) { // min cost starting from stone i to reach stone n;
	if(i == n) {
		if(lastAct == 0) {
			return max(arr[i][1], arr[i][2]);
		} else if(lastAct == 1) {
			return max(arr[i][0], arr[i][2]);
		} else {
			return max(arr[i][0], arr[i][1]);
		}
	}
	if(i > n) {
		return (ll)-1e17;
	}
	if(dp[i][lastAct] != -1) {
		return dp[i][lastAct];
	}
	ll ans = (ll)-1e17;
	if(lastAct != 0) ans = max(ans, go(i+1, 0) + arr[i][0]);
	if(lastAct != 1) ans = max(ans, go(i+1, 1) + arr[i][1]);
	if(lastAct != 2) ans = max(ans, go(i+1, 2) + arr[i][2]);

	return dp[i][lastAct] = ans;
}

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

	cin >> n;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << go(1, -1);

	return 0;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        switch(N){
            case 25:
                System.out.println("Christmas");
                break;
            case 24:
                System.out.println("Christmas Eve");
                break;
            case 23:
                System.out.println("Christmas Eve Eve");
                break;
            case 22:
                System.out.println("Christmas Eve Eve Eve");
                break;

        }
    }
}

Measured memory_bytes: 19924
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
#define ll long long
#define repX(i,j,n)for (ll i = j; i < n; i++)
#define rep(i, n) repX(i,0,n)

bool yymm=false,mmyy=false;
void check(bool x,ll y)
{
    if(x)
    {
        if(y>=100 && y<0)
        {
            yymm = false;
            mmyy = false;
        }
    }
    
}
int main()
{
    string s;
    cin >>s;
    
    ll a = 0,b = 0;
    rep(i,1+1)
    {
        string s4a(1,s[i]);
        string s4b(1,s[i+2]);
        a+= stoi(s4a)*(pow(10,1-i));
        b+= stoi(s4b)*(pow(10,1-i));
    }
    
    if(b>=1 && b<=12)
        yymm = true;
    if(a>=1 && a<=12)
        mmyy = true;
    
    check(mmyy,b);
    check(yymm,a);
    
    if(yymm && mmyy)
        cout << "AMBIGUOUS" << endl;
    else if(mmyy)
         cout << "MMYY" << endl;
    else if(yymm)
        cout << "YYMM" << endl;
    else
        cout <<"NA"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
<?php
list($n, $q) = array_map("intval", explode(" ", trim(fgets(STDIN))));
for($i = 0; $i < $n - 1; $i++){
  list($a, $b) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $v[$a][] = $b;
  $v[$b][] = $a;
}
for($i = 1; $i <= $n; $i++){
  $s[$i] = 0;
}
for($i = 0; $i < $q; $i++){
  list($p, $x) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $s[$p] += $x;
}
dfs(1,0);
echo implode(" ", $s),"\n";
function dfs($c, $p){
  global $v, $s;
  $s[$c] += ($s[$p]??0);
  foreach($v[$c] ?? [] as $n){
    if($p!=$n){
      dfs($n, $c);
    }
  }
}


Measured memory_bytes: 162292
S = input()
S += '_'
a = 0
cnt = 0
if S[0] == "0":
    for i in range(0, len(S), 2):
        if S[i] == '1':
            cnt += 1
    for i in range(1, len(S), 2):
        if S[i] == '0':
            cnt += 1
if S[0] == "1":
    for i in range(0, len(S), 2):
        if S[i] == '0':
            cnt += 1
    for i in range(1, len(S), 2):
        if S[i] == '1':
            cnt += 1
print(cnt)

Measured memory_bytes: 3188
n = gets.chomp.to_i
x = []
y = []
dis = []
n.times do |ni|
  dis[ni] = ni
  x[ni],y[ni] = gets.chomp.split.collect{ |item| item.to_i}
end
disxy = Hash.new(0.0)
n.times do |ni|
  n.times do |nii|
    disxy["#{ni}-#{nii}"] = Math.sqrt(((x[ni] - x[nii]) **2) + ((y[ni] - y[nii]) ** 2))
  end
end

arr = dis.permutation(n)
sum = 0.0
cnt = arr.size.to_f
arr.each do |one|
  onedis = 0.0
  (n-1).times do |ni|
    onedis += disxy["#{one[ni]}-#{one[ni+1]}"]
  end
  sum += onedis
end

puts sum/cnt


Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n; 
int cnt[maxn]; 
int calc[maxn];  

void solve() { 
    cin >> n;
    n = (1ll << n); 
    for (int i = 0; i < n; ++i) {
        cin >> cnt[i]; 
    }    
    sort(cnt, cnt + n); 
    vector<int> have; 
    for (int i = 0; i < n; ++i) have.pb(cnt[i]); 
    have.erase(unique(all(have)), have.end()); 
    int p = have.size(); 
    for (int i = 0; i < n; ++i) {
        cnt[i] = lower_bound(all(have), cnt[i]) - have.begin();  
    }
    for (int i = 0; i < n; ++i) {
        calc[cnt[i]]++; 
    }
    if (calc[p - 1] > 1) {
        cout << "No"; 
        return; 
    }
    multiset<int> cur;
    multiset<int> del; 
    for (int i = 0; i < n; ++i) {
        del.insert(cnt[i]);         
    }
    del.erase(p - 1); 
    cur.insert(p - 1); 
    while (cur.size() != n) { 
/*        for (auto v : cur) cout << v << " "; 
        cout << endl; 
        for (auto v : del) cout << v << " "; 
        cout << endl; */
        vector<int> add; 
        for (auto v : cur) {
            auto kek = del.lower_bound(v); 
            if (kek == del.begin()) {
                cout << "No";
                return; 
            }
            --kek; 
            add.pb(*kek); 
            del.erase(kek);
        }        
        for (auto v : add) {
            cur.insert(v);
        }
    }
    cout << "Yes"; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 20080
import itertools

n = int(input())
p = input().replace(" ", "")
q = input().replace(" ", "")
m = ""
for i in range(1, n + 1):
    m += str(i)
anagram_list = ["".join(v) for v in itertools.permutations(m)]

pa = 0
qa = 0

for i in range(len(anagram_list)):
    if anagram_list[i] == p:
        pa = i+1
    if anagram_list[i] == q:
        qa = i+1
print(abs(pa-qa))

Measured memory_bytes: 6040
import sys
x,y=map(int,input().split())
MOD=10**9+7
if (2*y-x)%3!=0 or 2*y-x<0 or 2*x-y<0:
  print(0)
  sys.exit()
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
a=(2*x-y)//3
if (a+1)*3<=(2*x-y):
  a+=1
b=(2*y-x)//3
if (b+1)*3<=(2*y-x):
  b+=1
p=1
for i in range(1,a+b+1):
  p=(p*i)%MOD
q=1
for i in range(1,a+1):
  q=(q*i)%MOD
q=pow(q,MOD-2,MOD)
r=1
for i in range(1,b+1):
  r=(r*i)%MOD
r=pow(r,MOD-2,MOD)
print((p*q*r)%MOD)


Measured memory_bytes: 40044
n, m = map(int, input().split())
e = [[int(x) for x in input().split()] for _ in range(m)]

u = [-1]*(n+1)

def find(x):
  return x if u[x] < 0 else find(u[x])

t = n*(n-1)// 2
s = [t]

for i in range(m-1,0,-1):
  a = find(e[i][0])
  b = find(e[i][1])
  if a > b:
    a, b = b, a
  if a != b:
    t -= u[a]*u[b]
    u[a] += u[b]
    u[b] = a
  s.append(t)

for i in reversed(s):
  print(i)


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



public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int r=scan.nextInt();
		int c=scan.nextInt();
		int[][] matrix_rc=new int[r+1][c+1];
		int sum_r;
		int[] sum_c=new int[c+1];
		Arrays.fill(sum_c, 0);
		for(int i=0;i<r;i++){
			sum_r=0;//??????????????§?????????
			for(int j=0;j<c+1;j++){
				if(j!=c){
				matrix_rc[i][j]=scan.nextInt();
				sum_r+=matrix_rc[i][j];}
				else if(j==c){
					matrix_rc[i][j]=sum_r;
				}//c+1????????§??????????????????
				sum_c[j]+=matrix_rc[i][j];//j????????????????¶???????????????????????????£??\
			}
		}
		for(int j=0;j<c+1;j++){
			matrix_rc[r][j]=sum_c[j];
		}//r+1?????????????????£??\
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				System.out.print(matrix_rc[i][j]);
				if(j<c){System.out.print(" ");}
			}System.out.println();
		}
		scan.close();
}


}

Measured memory_bytes: 42108
mod = 10**9 + 7
import math 
from bisect import bisect_left 
from collections import Counter
from itertools import combinations
 
def ain():
    return map(int, input().split())
def fain():
    return map(float, input().split())
 
def mc2(s):
    return (s*(s-1))//2 + s
    
# for tc in range(int(input())):
#     n = int(input())
    
#     print(ans)

k = int(input())
sum=0
for a in range(1,k+1):
    for b in range(1,k+1):
        g1 = math.gcd(a,b)
        for c in range(1,k+1):
            sum += math.gcd(g1,c)
print(sum)
# python3 pan3.py

Measured memory_bytes: 9480
import scala.io.StdIn.readLine
import scala.io.StdIn.readInt
import java.util.Scanner
import java.util.ArrayList

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  var s = Set[String]()
  for(i <- 1 to N){
    val str = sc.next()
    s += str
  }
  println(s.size)

  
}

Measured memory_bytes: 96844
#include <iostream>
#include <vector>
#include <map>
#include <utility>

using namespace std;

int main()
{
    int N ;
    cin >> N;
    int ans = 0;
    map<pair<int,int>,int> mp;
    for(int i = 1;i <= N;i++){
        int a,b;
        int tmp = i;
        if(tmp % 10 == 0)continue;
        a = tmp % 10;
        while(tmp >= 10){
            tmp /= 10;
        }
        b = tmp % 10;
        if(a == b){
            ans += 2 * mp[make_pair(a,b)] + 1;
            mp[make_pair(a,b)]++;
        }else{
            ans += 2*mp[make_pair(a,b)];
            mp[make_pair(b,a)]++;
        }
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll LINF=1e18;
const int INF=1e9;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

ll N;

int main() {
    cin >> N;
    ll ans=LINF;
    for(ll i=1;i<=ceil(sqrt(N));i++)
    {
        ll pre=0;
        for(ll j=N;j>=floor(sqrt(N));j = (i==1?j-1:j/i))
        {
            if(pre>i*j)break;
            if(i*j==N && ans > i+j-2){ ans = i+j-2;pre=i*j;}
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [1e5 for n in range(n)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2,n):
  dp[i] = min(dp[i-2]+abs(h[i-2] - h[i]),
               dp[i-1]+abs(h[i-1] - h[i]))
print(dp[-1])

Measured memory_bytes: 55024
import kotlin.math.min

fun main() {
  val input = readLine()!!.split(" ").map { it.toInt() }
  val a = input[0]
  val b = input[1]
  val k = input[3]

  val t = k - (a + b)
  val result = if (t > 0) a - t else min(a, k)
  print(result)
}

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

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

    vector<string> vecs(N);
    for (int i = 0; i < N; i++) {
        cin >> vecs.at(i);
    }

    int M;
    cin >> M;

    vector<string> vect(M);
    for (int i = 0; i < M; i++) {
        cin >> vect.at(i);
    }

    vector<int> sum(N + M);
    for (int i = 0; i < N; i++) {
        int sum0 = 0;
        for (int j = 0; j < N; j++) {
            if (vecs.at(i) == vecs.at(j)) {
                sum0++;
            }
        }
        for (int j = 0; j < M; j++) {
            if (vecs.at(i) == vect.at(j)) {
                sum0--;
            }
        }
        sum.at(i) = sum0;
    }

    for (int i = 0; i < M; i++) {
        int sum0 = 0;
        for (int j = 0; j < N; j++) {
            if (vect.at(i) == vecs.at(j)) {
                sum0++;
            }
        }
        for (int j = 0; j < M; j++) {
            if (vect.at(i) == vect.at(j)) {
                sum0--;
            }
        }
        sum.at(i + N) = sum0;
    }

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

    if (sum.at(N + M - 1) > 0) {
        cout << sum.at(N + M - 1) << endl;
    }
    else {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	int max = 0, min = 1001;
	for(int i = 0; i < N; ++i){
		int input;
		cin >> input;
		max = MAX(max, input);
		min = MIN(min, input);
	}

	cout << max - min << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

ll modpow(ll base, ll exp, ll mod) {
  base%=mod;
  ll res=1;
  while(exp>0) {
    if (exp&1) res=(res*base)%mod;
    base=(base*base)%mod;
    exp>>=1;
  }
  return res;
}

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	ll n;
	cin >> n;
	ll ans = modpow(10,n,MOD);
	ans = (ans - (modpow(9,n,MOD)*2LL)%MOD+MOD)%MOD;
	ans = (ans + modpow(8,n,MOD))%MOD;
	OUT(ans%MOD);
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
#define ALL(x) (x).begin(),(x).end()
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

vector<ll> A, B, C;
vector<ll> D;

signed main() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    A.resize(X);
    B.resize(Y);
    C.resize(Z);
    REP(i, X) cin >> A[i];
    REP(i, Y) cin >> B[i];
    REP(i, Z) cin >> C[i];
    sort(ALL(A));
    reverse(ALL(A));
    sort(ALL(B));
    reverse(ALL(B));
    sort(ALL(C));
    reverse(ALL(C));

    D.reserve(1000*1000);
    REP(x, X) {
        REP(y, Y) {
            D.push_back(A[x] + B[y]);
        }
    }
    sort(ALL(D));
    reverse(ALL(D));

    ll cnt = 0;
    vector<ll> Ans;
    Ans.reserve(K*1000);
    for (ll i=0; i<K; i++) {
        REP(z, Z) {
            Ans.push_back(D[i]+C[z]);
        }
    }

    sort(ALL(Ans));
    reverse(ALL(Ans));
    REP(i, K) cout << Ans[i] << LF;
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
bool cmp(vector<int> tsk1, vector<int> tsk2)
{
    return tsk1[1] < tsk2[1];
}
int main(void){
    int N;
    cin>>N;
    vector<vector<int>> tsk(N);
    for (int i = 0; i < N; i++)
    {
        vector<int> dat(2);
        tsk[i] = dat;
    }
     
    for (int i = 0; i < N; i++)
    {
        cin>>tsk[i][0]>>tsk[i][1];
    }
    sort(tsk.begin(),tsk.end(),cmp);
    
    int workingTime = 0;
    for (int i = 0; i < N; i++)
    {
        // cout<<tsk[i][0]<<" "<<tsk[i][1]<<endl;
        int spr = tsk[i][1] - (tsk[i][0] + workingTime);
        if(spr >= 0) workingTime += tsk[i][0];
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N){
    ll alp = 'z'-'a'+1;
    ll len = 1;
    while (pow(alp, len) < N) {
        N -= pow(alp, len);
        len++;
    }
    string answer = "";
    rrep(i,1,len+1) {
        ll num = (N-1) / pow(alp, i-1);
        answer += ('a' + num);
        N -= num * pow(alp, i-1);
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main(){

	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for(int i = 0; i <= a; i++)
	{	
		if(i*500 > x) break;
		for(int j = 0; j <= b; j++)
		{	
			if(j*100 > x) break;
			int yen = i*500 + j*100;
			if(x-yen < 0) continue;
			if((x-yen) <= 50*c) ans++;

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

Measured memory_bytes: 256
def main():
    from bisect import bisect_left

    n = int(input())
    a = list(map(int, input().split()))

    # cumulative sum
    # cs[i] = sum(a[:i+1])
    cs = [0] * n
    for i in range(n):
        cs[i] = cs[i-1] + a[i]

    # search all possible indexes of middle split
    ans = 10**15
    for middle in range(2, n-1):
        # first_half = a[:middle]
        first = bisect_left(cs, cs[middle-1]//2, lo=1, hi=middle)
        if abs((cs[middle-1] - cs[first-1]) - cs[first-1]) < abs((cs[middle-1] - cs[first]) - cs[first]):
            p = cs[first-1]
            q = cs[middle-1] - cs[first-1]
        else:
            p = cs[first]
            q = cs[middle-1] - cs[first]

        # latter_half = a[middle:]
        last = bisect_left(cs, (cs[-1] + cs[middle-1])//2, lo=middle+1, hi=n)
        if abs((cs[-1] - cs[last-1]) - (cs[last-1] - cs[middle-1])) < abs((cs[-1] - cs[last]) - (cs[last] - cs[middle-1])):
            r = cs[last-1] - cs[middle-1]
            s = cs[-1] - cs[last-1]
        else:
            r = cs[last] - cs[middle-1]
            s = cs[-1] - cs[last]
        
        diff = max(p, q, r, s) - min(p, q, r, s)
        if diff < ans:
            ans = diff
    
    print(ans)

main()

Measured memory_bytes: 32816
#include<stdio.h>
int main()
{
   int n,m,res,r,a,b,d,i;
    scanf("%d%d",&n,&m);
    if(n>m)
    {
        a=m;
        b=n;
    }
    else
    {
        a=n;
        b=m;
    }
        while(a!=0)
        {
            res=b%a;
            b=a;
            a=res;
        }
        printf("%d\n",b);


    return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  if( a<=8 && b<=8)cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> X(N);
	vector<int> B(N);

	REP(i, N) {
		int tmp;
		cin >> tmp;
		X[i].first = tmp;
		X[i].second = i;
	}

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

	REP(i, N) {
		if (i < (N / 2)) {
			B[X[i].second] =  X[N / 2].first;
		}
		else {
			B[X[i].second] = X[N / 2 - 1].first;
		}
	}

	REP(i, N) {
		cout << B[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <cstdio>
#include <cmath>
#define R (3.1415926535898/180.0)
using namespace std;

int main(){
	int go,turn;
	double x=0,y=0,cur=0;
	
	while(scanf("%d,%d\n",&go,&turn) , (go || turn) ){
		y += cos(cur * R) * go;
		x += sin(cur * R) * go;
		cur += turn;
	}
	cout << (int)x << endl << (int)y << endl;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

const debug = false

func (p *problem) solve() {
	var count int
	in := p.nextSSLine()
	a, b := stoi(in[0]), stoi(in[1])
	log.Printf("%v->%v", rank(in[0], 0), rank(in[1], 0))
	for i := rank(in[0], 0); i <= rank(in[1], 0); i++ {
		for j := 0; j <= 9; j++ {
			for k := 0; k <= 9; k++ {
				n := stoi(fmt.Sprintf("%d%d%d%d%d", i, j, k, j, i))
				log.Printf("n: %d", n)
				if between(n, a, b) {
					count++
				}
			}
		}
	}
	p.printf("%d", count)
}

func between(x, a, b int) bool {
	ok := a <= x && x <= b
	log.Printf("a(%v) <= x(%v) <= b(%v) = %v", a, x, b, ok)
	return ok
}

func rank(s string, i int) int {
	return stoi(string([]rune(s)[i]))
}

func main() {
	if debug {
		log.SetOutput(os.Stdout)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) printi(d int) {
	if err := p.out.WriteByte(byte(d)); err != nil {
		panic(err)
	}
}

func (p *problem) printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) nextInt() int {
	return stoi(p.next())
}

func (p *problem) nextInts() []int {
	line := p.nextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) nextSSLine() []string {
	return strings.Split(p.next(), " ")
}

// Next reads line and return string.
func (p *problem) next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 768
import sys

def solve():
    input = sys.stdin.readline
    I, O, T, J, L, S, Z = map(int, input().split())
    Ans = O
    six = min([I, J, L])
    Ans += 3 * six
    I -= six
    J -= six
    L -= six
    Ans += 2 * (I // 2 + J // 2 + L // 2)
    rem = I % 2 + J % 2 + L % 2
    if six > 0 and rem == 2: Ans += 1
    print(Ans)
    
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mo 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    ll ans = 0;
    ll l,r;cin >> l >> r;
    ll d;cin >> d;
    ll cnt = 1;
    while(1)
    {
        ll r1 = d*cnt;
        if(r1>r) break;
        if(r1>=l && r1<=r) ans++;
        cnt++;
    }
    cout << ans << endl;
   
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]*=-1;
	}
	ll d[n];
	for(int i=0; i<n; i++) d[i]=1;
	for(int i=0; i<n; i++){
		*upper_bound(d, d+n, a[i])=a[i];
	}
	cout << lower_bound(d, d+n, 1)-d << endl;

	return 0;
}

Measured memory_bytes: 1792
fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun main() {
	readLine()
	val a = list()
	val m = mutableMapOf<Int,Long>()
	a.withIndex().reversed().map {(i,v)->
		m[i-v] = (m[i-v] ?: 0)+1
		m[i+v] ?: 0L
	}.sum().let(::println)
}


Measured memory_bytes: 85296
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <bitset>
#include <functional>

using namespace std;

#define FOR(i,n) 		for(int(i)=0;(i)<(int)(n);(i)++)
#define FORN(i,a,b,c) 	for(int(i)=a;i<(int)(b);i+=(c))
#define RES(x,nilai)	memset(x,nilai,sizeof(x));
#define pb              push_back
#define mp              make_pair
#define INF				1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

inline string IS(int a){
    char x[100];
    sprintf(x,"%d",a); string s = x;
    return s;
}

inline int SI(string a){
    char x[100]; int res;
    strcpy(x,a.c_str()); sscanf(x,"%d",&res);
    return res;
}

//==============================================

bool cmp(int x,int y) {return x>y;}

int arr[100];

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("13.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	for(int i =0 ;i < 10; i++) cin >> arr[i];
	sort(arr,arr+10);
	cout << arr[9] << endl << arr[8] << endl << arr[7] << endl;
		
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, k);
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];

  sort(all(l), [](int a, int b) { return a > b; });

  int ans = 0;
  for (int i = 0; i < k; ++i) ans += l[i];

  cout << ans << endl;

  return 0;
}

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

int main()
{
	
	int n,l;
	cin>>n>>l;
	string s[n];
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	string res;
	for(int i=0;i<n;i++)
	{
		res+=s[i];
	}
	cout<<res<<endl;
	return 0;
	
}

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

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

const int mod = 1000*1000*1000+7;

ll fibo[90];
vector<vector<pll> > prec;

ll X, Y;

void main2() {
    scanf("%lld %lld", &X, &Y);
    if(X > Y) swap(X, Y);

    if(X == 1 && Y == 1) {
        printf("1 1\n");
        return;
    }

    int K;
    for(K = 1; K < 90; K++) {
        if(fibo[K] <= X && fibo[K + 1] <= Y) continue;
        K--;
        break;
    }

    if(K == 1) {
        printf("1 %d\n", (2*X + Y - 2) % mod);
        return;
    }

    int cnt = 0;
    for(int i = 0; i < prec[K - 1].size(); i++) {
        pll t = prec[K - 1][i];

        if(t.second <= X && t.first + t.second <= Y) {
            cnt += (Y - t.first) / t.second % mod;
            cnt %= mod;
        }
        if(t.second <= Y && t.first + t.second <= X) {
            cnt += (X - t.first) / t.second % mod;
            cnt %= mod;
        }
    }

    printf("%d %d\n", K, cnt);
}

int TC;
int main() {
    fibo[0] = 1;
    fibo[1] = 1;
    for(int i = 2; i < 90; i++) {
        fibo[i] = fibo[i - 1] + fibo[i - 2];
    }

    prec.resize(90);
    prec[1].push_back(pll(1, 2));
    prec[1].push_back(pll(1, 3));

    for(int i = 1; i < 90; i++) {
        for(int j = 0; j < prec[i - 1].size(); j++) {
            pll t = prec[i - 1][j];

            for(int k = 1;; k++) {
                if(t.first + t.second * k > fibo[i + 2]) break;
                if(fibo[i] <= t.second) prec[i].push_back(pll(t.second, t.first + t.second * k));
            }
        }
    }

    scanf("%d", &TC);
    while(TC--) main2();
}


Measured memory_bytes: 4096