akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	n := make([]int, N)
	for i := 0; i < N; i++ {
		n[i] = i
	}
	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i], &y[i])
	}
	a := NextPermutation(n)
	var sum float64
	for i := 0; i < len(a); i++ {
		for j := 0; j < len(a[i])-1; j++ {
			f := a[i][j]
			t := a[i][j+1]
			sum += calc(x[f], y[f], x[t], y[t])
		}
	}
	fmt.Println(sum / float64(len(a)))

}
func calc(fx, fy, tx, ty int) float64 {
	w := math.Sqrt(math.Pow(float64(tx-fx), 2) + math.Pow(float64(ty-fy), 2))
	return w
}
func NextPermutation(x []int) [][]int {
	var p [][]int
	z := make([]int, len(x))
	copy(z, x)
	p = append(p, z)
	for i := 1; NextPermutationSub(sort.IntSlice(x)); i++ {
		y := make([]int, len(x))
		copy(y, x)
		p = append(p, y)
	}
	return p
}

func NextPermutationSub(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}


Measured memory_bytes: 8192
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    vector<pll> dif(n);
    for(int i=0;i<n;i++){
        dif[i]={abs(sum-a[i]*n),i};
    }
    sort(dif.begin(),dif.end());
    cout<<dif[0].S<<endl;
    
    
    
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0, pre = a[0];
    for(int i = 0; i < n; i++){
        if(pre > a[i]){
            ans += pre - a[i];
        }
        else{
            pre = a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
string s;
int main(){
	cin>>s;
	if(s=="SUN")puts("7");
	if(s=="MON")puts("6");
	if(s=="TUE")puts("5");
	if(s=="WED")puts("4");
	if(s=="THU")puts("3");
	if(s=="FRI")puts("2");
	if(s=="SAT")puts("1");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int A,B;
    cin >> A >> B ;
    int bigB,smallB;
    if(A>=B){
        bigB=A;
        smallB=B;
    }
    else{
        bigB=B;
        smallB=A;
    }
    if(bigB==smallB)
    {
        int sumCoins;
        sumCoins = bigB+smallB;
        cout << sumCoins << endl;
    }
    else{
        int sumCoins;
        sumCoins = bigB+(bigB-1);
        cout << sumCoins << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<ll> x(n), y(n), z(n);
    
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    
    ll ans = 0;
    
    for(int i = 0; i < 1 << 3; i++) {
        vector<ll> w(n);
        for(int j = 0; j < n; j++) {
            w[j] = (i & 1 ? -1 : 1) * x[j] + (i & 2 ? -1 : 1) * y[j] + (i & 4 ? -1 : 1) * z[j]; 
        }
        
        sort(w.begin(), w.end(), greater<>());
        
        ll sum = 0;
        for(int j = 0; j < m; j++) {
           sum += w[j];
        }
        
        ans = max(ans, sum);
    }
    
    cout << ans << endl;
};

Measured memory_bytes: 256
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int x = n;
    int sum = 0;
    while(x > 0){
      sum += x % 10;
      x /= 10;
    }
    if(n%sum == 0){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

    sc.close();
  }
}

Measured memory_bytes: 23892
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 2):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 2):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)

Measured memory_bytes: 3064
k, a, b = gets.split(' ')
k = k.to_i ; a = a.to_i ; b = b.to_i
cookie = 1
if (b - a) <= 1 || (a - k) >= 0
  cookie = cookie + k
elsif (a - k) == -1
  cookie = [b,k+1].max
else
  # step 1
  k = k - (a - 1)
  cookie = cookie + (a - 1)
  
  # step 2
  k = k - 1

  # step 3
  k = k - 1
  cookie = b
  
  # step 3
  cookie = cookie + ((b - a) * (k / 2))
  cookie = cookie + 1 if k.odd?
end

puts cookie

Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000000)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    k = []
    alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g',
             'h', 'i', 'j', 'k', 'l', 'm', 'n',
             'o', 'p', 'q', 'r', 's', 't', 'u',
             'v', 'w', 'x', 'y', 'z']

    n -= 1
    while True:
        if n < 0:
            break
        _ = n % 26
        k.append(alpha[_])
        n = (n - _) // 26 - 1

    k.reverse()
    for i in k:
        print(i, end='')
    print('')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()


int main(){
  ll N,K;
  cin >> N >> K;
  vector<string> A(N);
  rep(i,N){
    ll a;
    cin >> a;
    string S;
    rep(j,40){
      if(a>=(ll)pow(2,39-j)){
        a-=(ll)pow(2,39-j);
        S+='1';
      }else{
        S+='0';
      }
    }
    A.at(i)=S;
  }
  ll x=0,X=0,Y=0;
  rep(i,40){
    if(x==0){
      if(K>=(ll)pow(2,39-i)){
        x=(ll)pow(2,39-i);
        rep(j,N){
          if(A.at(j).at(i)=='0'){
            X+=(ll)pow(2,39-i);
          }
        }
        rep(j,N){
          if(A.at(j).at(i)=='1'){
            Y+=(ll)pow(2,39-i);
          }
        }
      }else{
        rep(j,N){
          if(A.at(j).at(i)=='1'){
            Y+=(ll)pow(2,39-i);
          }
        }
        X=Y;
      }
    }else{
      if(K>=x+(ll)pow(2,39-i)){
        ll a=0;
        rep(j,N){
          if(A.at(j).at(i)=='1'){
            a++;
          }
        }
        Y=max(Y+a*(ll)pow(2,39-i),max(Y+(N-a)*(ll)pow(2,39-i),X+a*(ll)pow(2,39-i)));
        x+=(ll)pow(2,39-i);
        X+=(N-a)*(ll)pow(2,39-i);
      }else{
        ll a=0;
        rep(j,N){
          if(A.at(j).at(i)=='1'){
            a++;
          }
        }
        Y=max(Y+a*(ll)pow(2,39-i),Y+(N-a)*(ll)pow(2,39-i));
        X+=a*(ll)pow(2,39-i);
      }
    }
  }
  cout << max(X,Y) << endl;
        
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    string s[3];
    cin >> n;
    for(int i = 0; i < 3; i++) {
        cin >> s[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        set<char> se;
        for(int j = 0; j < 3; j++) {
            se.insert(s[j][i]);
        }
        ans += se.size() - 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int k,s;
	cin>>k>>s;
	int ans = 0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			int tmp = s-i-j;
			if(tmp < 0) continue;
			if(tmp > k) continue;
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

using ll = long long;

int main() {
    int x, y, z, k; cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    for(int i = 0; i < x; ++i) cin >> a[i];
    for(int i = 0; i < y; ++i) cin >> b[i];
    for(int i = 0; i < z; ++i) cin >> c[i];
    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));

    auto check = [&] (ll v) {
        ll cnt = 0;
        for(int i = 0; i < x; ++i) {
            for(int j = 0; j < y; ++j) {
                cnt += c.end() - lower_bound(begin(c), end(c), v - a[i] - b[j]);
            }
        }
        return cnt >= k;
    };
    ll lb = 0, ub = 1e18;
    while(ub - lb > 1) {
        const ll mid = (ub + lb) >> 1;
        (check(mid) ? lb : ub) = mid;
    }
    vector<ll> ans;
    for(int i = 0; i < x; ++i) {
        for(int j = 0; j < y; ++j) {
            const int fst = upper_bound(begin(c), end(c), lb - a[i] - b[j]) - begin(c);
            for(int l = fst; l < z; ++l) {
                ans.push_back(a[i] + b[j] + c[l]);
            }
        }
    }
    while((int)ans.size() < k) ans.push_back(lb);
    sort(rbegin(ans), rend(ans));

    for(auto t : ans) {
        cout << t << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, k;
  cin>>n>>k;
  LL v[n];
  REP(i, n){
    cin>>v[i];
  }
  LL lsum[n+1];
  LL rsum[n+1];
  lsum[0]=0;
  rsum[0]=0;
  REP(i, n){
    lsum[i+1]=lsum[i]+v[i];
    rsum[i+1]=rsum[i]+v[n-i-1];
  }

  LL ans=0;
  LL work=-1;
  REP(i, k+1){
    if(i>n) break;
    REP(j, k-i+1){
      if(i+j>n) break;
      if(j>n) break;
      work = lsum[i] + rsum[j];
      priority_queue<LL> q;
      for(int x=0; x<n; ++x){
        if(x>=i) break;
        if(v[x]<0) {
          q.push(-v[x]);
          //cout<<v[x]<<endl;
        }
      }
      for(int x=0;x<n ; ++x){
        if(x>=j) break;
        if(v[n-x-1]<0) {
          q.push(-v[n-x-1]);
          //cout<<v[n-x-1]<<endl;
        }
      }
      int count=0;
      while (!q.empty() && count<k-i-j) {
        LL w = -q.top();
        q.pop();
        work -=w;
        ++count;
      }
      //cout<<i<<j<<" "<<work<<" "<<ans<<endl;
      ans=max(ans, work);
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
int num[3];
cin>>num[0]>>num[1]>>num[2];
int num5,num7;
num5=0;
num7=0;
for(int i=0;i<3;i++){
if(num[i]==5){
num5++;
}
else if(num[i]==7){
num7++;
}
}
if(num5==2 && num7==1){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int x1, y1, x2, y2, x, y;

	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	x = x2 - x1;
	y = y2 - y1;
	printf("%d %d %d %d\n", x2 - y, y2 + x, x1 - y, y1 + x);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
	bool a,b,c;//グーチョキパー
	int hand[5];
	while(cin>>hand[0], hand[0]){
		for(int i=1;i<5;i++)
			cin>>hand[i];
		a=b=c=false;
		for(int i=0;i<5;i++){
			if(hand[i]==1)a=true;
			else if(hand[i]==2)b=true;
			else c=true;
		}
		for(int i=0;i<5;i++){
			if(a&&b&&c || a&&!b&&!c || !a&&b&&!c || !a&&!b&&c){
				cout<<3<<endl;
				continue;
			}
			if(hand[i]==1){
				if(b)cout<<1;
				else cout<<2;
			}
			else if(hand[i]==2){
				if(c)cout<<1;
				else cout<<2;
			}
			else{
				if(a)cout<<1;
				else cout<<2;
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 0
N = int(input())
D = list(map(int,input().split()))

DC = {}
for d in D:
  if d == 0:
    print(0)
    exit()
  if d in DC:
    DC[d] += 1
  else:
    DC[d] = 1

def Gap(T):
  res = 10**18
  mn = 0
  for i in range(1,len(T)):
    if T[i]:
      res = min(res,i-mn)
      mn = i
  return res

T = [True] + [False for _ in range(23)] + [True]
DD = []
for k,v in DC.items():
  if v == 1:
    DD.append(k)
  elif v == 2:
    T[k] = True
    T[24-k] = True
  else:
    print(0)
    exit()

if len(DD) == 0:
  print(Gap(T))
else:
  ans = 0
  for i in range(1<<len(DD)):
    TT = T[:]
    for j in range(len(DD)):
      if (i>>j)&1 == 1:
        TT[DD[j]] = True
      else:
        TT[24-DD[j]] = True
    ans = max(ans,Gap(TT))
  print(ans)


Measured memory_bytes: 40432
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=100001;
int n,p[M],a[M];

int main(){
	fill(p,p+M,1);
	p[0]=p[1]=0;
	for(int i=2;i<M;i++) if(p[i]){
		for(int j=2*i;j<M;j+=i) p[j]=0;
	}
	for(int i=1;i<M;i++) if(p[i]&&p[(i+1)/2]) a[i]++;
	for(int i=1;i<M;i++) a[i]+=a[i-1];
	cin>>n;
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		cout<<a[r]-a[l-1]<<endl;
	}
}

Measured memory_bytes: 1408
use std::collections::BinaryHeap;
use std::collections::VecDeque;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut degrees = vec![0; n];
    let mut values = vec![0; n];
    let mut edges: Vec<Vec<usize>> = vec![vec![]; n];
    for i in 0..n - 1 {
        let a: usize = sc.read();
        let b: usize = sc.read();
        degrees[a - 1] += 1;
        degrees[b - 1] += 1;
        edges[a - 1].push(b - 1);
        edges[b - 1].push(a - 1);
    }
    let mut c: Vec<usize> = sc.vec(n);
    c.sort();
    c.reverse();
    let cost = c.iter().skip(1).fold(0, |sum, a| sum + a);
    let mut heap = BinaryHeap::new();
    for i in 0..n {
        heap.push((degrees[i], i));
    }
    let root = heap.peek().unwrap();
    let mut que = VecDeque::new();
    que.push_back(root.1);
    let mut c_idx = 0;
    while let Some(index) = que.pop_front() {
        //println!("{} {}", degree, index);
        if values[index] != 0 {
            continue;
        }
        values[index] = c[c_idx];
        c_idx += 1;
        for &x in edges[index].iter() {
            if values[x] != 0 {
                continue;
            }
            que.push_back(x);
        }
    }
    println!("{}", cost);
    for &i in values.iter() {
        print!("{} ", i);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a + b;
  int right = c + d;
  if (left > right) 
  {
    cout << "Left" << endl;
  }
  else if (left < right) 
  {
    cout << "Right" << endl;
  }
  else
  {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    VSORTR(a);
    ll ans=0;
    REP(i,n-1){
        if (i==0)ans+=a[0];
        else{
            ans+=a[i/2 + i%2];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4780
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	string t;
	for (int i = 0; i < q; i++) {
		int ty;
		cin >> ty;
		if (ty == 1) {
			swap(s, t);
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f == 1) {
				t += c;
			}
			else {
				s += c;
			}
		}
	}
	reverse(t.begin(), t.end());
	t += s;
	cout << t << endl;
	return 0;
}



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

using namespace std;

int dp[100007][3] = {};
int a[100007] = {};
int b[100007] = {};
int c[100007] = {};

int main() {
	
	int i,j;
	int N;
	
	cin >> N;
	for( i=1; i<=N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for( i=1; i<=N; i++) {
		dp[i][0] = max( dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max( dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max( dp[i-1][0], dp[i-1][1]) + c[i];
	}
	cout << max( { dp[N][0], dp[N][1], dp[N][2] });
	
	return 0;
}

Measured memory_bytes: 5900
N = int(input())
H = [int(i) for i in input().split()]


for i in range(1, N-1):
    if H[i-1] <= H[i] - 1 <= H[i+1]:
        H[i] -= 1
        continue
    
    if H[i-1] <= H[i]<= H[i+1]:
        continue

    print("No")
    break

else:
    print("Yes")

Measured memory_bytes: 14396
import collections
a = int(input())
line = [input() for k in range(a)]
c = collections.Counter(line)
common = c.most_common()
max_number = common[0][1]
a = len(common)
max_common = []
for k in range(a):
  if common[k][1] == max_number:
    max_common.append(common[k][0])
  else:
    break
for k in sorted(max_common):
  print(k)

Measured memory_bytes: 49268
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    S = []
    for _ in range(M):
        _, *s = map(int, readline().rstrip().split())
        S.append(set(s))
    P = list(map(int, readline().rstrip().split()))

    ans = 0
    for i in range(2**N):
        b = bin(i)[2:].zfill((N))
        b = set([i+1 for i, e in enumerate(b) if e == '1'])
        flg = True
        for j, s in enumerate(S):
            if len(s&b) % 2 != P[j]:
                flg = False
                break
        if flg:
            ans += 1
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    rep(i, 0, sz(s) - 2) {
        if(s.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, K;
long long dfs(int i, long long score) {
    if(i >= N) return score;
    return std::min(
        dfs(i+1, score * 2),
        dfs(i+1, score + K)
    );
}
int main() {
    std::cin >> N >> K;
    std::cout << dfs(0,1) << std::endl;
}

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

using namespace std;

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

#define pb push_back
#define mp make_pair

ll n, a, b;
ll mas[100010];
pii d[100010];

bool solve(ll v){
    ll tmp[100010];
    for(int i = 0; i < n; i++){
        tmp[i] = mas[i] - b * v;
    }
    ll cnt = 0;
    ll diff = a - b;
    for(int i = 0; i < n; i++){
        if(tmp[i] > 0){
            cnt += (tmp[i] + diff - 1) / diff;
        }
    }
    return cnt <= v;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++) cin >> mas[i];
    sort(mas, mas + n, greater<int>());
    ll lo = 1, hi = 1000000000;
    while(lo != hi){
        ll mi = (lo + hi) / 2;
        if(solve(mi)) hi = mi;
        else lo = mi + 1;
    }
    cout << lo << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int n,m,q,a,b,c,d,rui[1005][1005][3],ret[3];char f[1005][1005],e[3]={'J','O','I'};
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=0;i<n;i++) scanf("%s",&f[i]);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int k=0;k<3;k++)
rui[i][j][k]=rui[i-1][j][k]+rui[i][j-1][k]-rui[i-1][j-1][k]+(f[i-1][j-1]==e[k]);
for(int i=0;i<q;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
for(int j=0;j<3;j++) ret[j]=rui[c][d][j]-rui[c][b-1][j]-rui[a-1][d][j]+rui[a-1][b-1][j];
printf("%d %d %d\n",ret[0],ret[1],ret[2]);
}
}

Measured memory_bytes: 13672
use proconio::*;

fn main() {
    input!{
        n: usize,
        xy: [(i64, i64); n],
    }

    let mut r_x = Vec::new();
    let mut r_y = Vec::new();
    for (i, &(x, y)) in xy.iter().enumerate() {
        r_x.push((x+y, i));
        r_y.push((x-y, i));
    }

    r_x.sort();
    r_y.sort();

    let x1 = r_x[0].1;
    let x2 = r_x[n-1].1;
    let y1 = r_y[0].1;
    let y2 = r_y[n-1].1;
    let ans = ((xy[x1].0-xy[x2].0).abs() + (xy[x1].1-xy[x2].1).abs())
        .max((xy[y1].0-xy[y2].0).abs() + (xy[y1].1-xy[y2].1).abs());

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


Measured memory_bytes: 16784
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> b(n);
  rep(i, n) cin >> b.at(i);
  ll pl = 0, mi = 0;
  rep(i, n){
    if(a.at(i) >= b.at(i)){
      pl += a.at(i) - b.at(i);
    }else{
      mi += (b.at(i) - a.at(i))/2;
    }
  }
  if(pl <= mi) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3688
#include<stdio.h>
const int MAX_V=10000;
int prime[MAX_V+1];
int main(){
  int i,k,n,v;
  for(i=2;i<=MAX_V;i++){
    prime[i]=1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k=2*i;k<=MAX_V;k+=i){
        prime[k]=0;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(v=n-2;v>=2;v--){
      int isprime=prime[v]*prime[v+2];
      if(isprime){
        printf("%d %d\n",v,v+2);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2608
/*

by.YXH_XianYu
   2018.6.15
 */
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 1010
#define LLI long long

int n,m;
LLI a[MXN][3],
	c[3],
	f[MXN],
	ans;


int main(){
	//freopen("mothergoose.in","r",stdin);
	//freopen("mothergoose.out","w",stdout);

	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld%lld",&a[i][0],&a[i][1],&a[i][2]);
	for(c[0]=-1;c[0]<=1;c[0]+=2)
	for(c[1]=-1;c[1]<=1;c[1]+=2)
	for(c[2]=-1;c[2]<=1;c[2]+=2){
	for(int i=1;i<=m;i++)
		f[i]=-1000000000000000000;
	for(int i=1;i<=n;i++)
		for(int j=m;j>=1;j--)
			f[j]=std::max(f[j],f[j-1]+a[i][0]*c[0]+a[i][1]*c[1]+a[i][2]*c[2]);
	ans=std::max(ans,f[m]);
	}
	printf("%lld\n",ans);

	return 0;
}


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

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

    ll u = 0;
    rep(i, n) {
        ll h;
        cin >> h;
        if(h+2 <= u) {
            out("No");
            re0;
        }
        chmax(u, h);
    }

    out("Yes");
    re0;
}

Measured memory_bytes: 256
S = input()
if S=='MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
elif S=='FRI':
    print(2)
elif S=='SAT':
    print(1)
else:
    print(7)

Measured memory_bytes: 2940
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String str = sc.nextLine();
		int j = 0;

	    for(char x: str.toCharArray()) {
	        if(x == '1') {
	            j++;
	        }
	    }
		// 出力
		System.out.println(j);
	}
}


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


int main(int argc, char const *argv[])
{
    int A;
    int B;
    int C;
    int D;
    cin>>A>>B>>C>>D;
    
    
    if (A*B==C*D) {
        cout<<A*B||C*D;
    }else 
    if (A*B<C*D) {
        cout<<C*D;
    }
    else
    {
        cout<<A*B;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int k, a, b, i;
    scanf("%d %d %d", &k, &a, &b);

    for (i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            printf("OK");
            return 0;
        }
    }
    printf("NG");
    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
int dp[maxn], h[maxn];
int main(){
	ios::sync_with_stdio ( false );
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	for ( int i=0; i<n; ++i ) cin >> h[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	for ( int i=1; i<n; ++i )
		for ( int j=1; i-j>=0&&j<=k; ++j )
			dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
	cout << dp[n-1] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<cstdio>
using namespace std;

int main(){
    int n,m;cin>>n>>m;
    int l,r;
    int maxl=-1;
    int minr=1000000;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        maxl=max(maxl,l);
        minr=min(minr,r);
    }
    if(minr>=maxl) cout<<minr-maxl+1<<endl;
    else cout<<0<<endl;
}



Measured memory_bytes: 256
s = str(input())
t = str(input())
flag = False
"""
文字列の回数文だけ回転させる処理をして比較
"""
for i in range(len(s)):
    s = s[len(s)-1] + s[:len(s)-1]
    if s == t:
        flag = True
        break
    else:
        continue

if flag == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
N = int(input())
S = [input() for _ in range(2)]
MOD = 1000000007

ans = 1
status = 0
i = 0
while (i < N):
  if S[0][i] == S[1][i]:
    if status == 0:
      ans *= 3
    elif status == 1:
      ans *= 2
    status = 1
    i += 1
  else:
    if status == 0:
      ans *= 6
    elif status == 1:
      ans *= 2
    else:
      ans *= 3
    status = 2
    i += 2
  ans %= MOD
print(ans)

Measured memory_bytes: 38384
// Wrong Answer

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

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

    long long answer = 0;

    int people_list[total_people];

    for(int i = 0; i < total_people; i ++)
    {
        int height;
        cin >> height;

        people_list[i] = height;

        if(i != 0)
        {
            if(people_list[i-1] > people_list[i])
            {
                answer += people_list[i-1] - people_list[i];
                people_list[i] += people_list[i-1] - people_list[i];
            }
        }
    }

    cout << answer << endl;

    return 0;
}



Measured memory_bytes: 4368
n,c=map(int,input().split())
a=[]
tf=0
for _ in range(n):
  s,t,ch=map(int,input().split())
  a+=[(ch,s,t)]
a=sorted(a)
flag=a[0][0]
ans=[0]*(10**5+1)
tf=0
for ch,s,t, in a:
  if ch==flag and tf==s:ans[s]+=1
  else:ans[s-1]+=1
  ans[t]-=1
  tf=t
  flag=ch
for i in range(10**5):
  ans[i+1]+=ans[i]
print(max(ans))

Measured memory_bytes: 92800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
ll gcd(ll x, ll y) {
    if(y==0) return x;
    else return gcd(y , x%y);
}

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

    int n;
    cin >> n;
    vl x(n+1) ;
    rep(i,n+1){
        cin >> x[i];
    }
    sort(all(x));
    vl sa(n,0);
    rep(i,n){
        sa[i] = x[i+1] - x[i];
    } 
    ll tmp = sa[0];
    if(n==1){cout << tmp << endl;return 0;}
    rep1(i,n){
        tmp = gcd(sa[i],tmp);
    }

    cout << tmp << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll N;
	cin >> N;
	
	ll arr[N], tmp;
	REP(i, 0, N){
		cin >> tmp;
		if( i == 0) arr[0] = tmp;
		else arr[i] =  arr[i-1] + tmp;
	}
	
	ll ans = pow(10, 18);
	REP(i, 0, N-1){
		ans = min(ans, abs(arr[N-1] - 2*arr[i]));
	}
	cout << ans;
		

}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main (String args[]) {
		Scanner lector=new Scanner (System.in);
		int m=0;
		double H=lector.nextDouble();
		double A=lector.nextDouble();
		do {
			m++;
			H=( H-A);
		} while (H>0);
		System.out.print (m);
     }
}


Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>
#include <stack>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli mod197 = 1000000007LL;
constexpr lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	string str;
	cin >> str;

	stack<char> s;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'B' && !s.empty()) {
			s.pop();
		}
		else if(str[i] != 'B'){
			s.push(str[i]);
		}
	}


	string ans = "";
	while (!s.empty()) {
		ans = s.top() + ans;
		s.pop();
	}

	COUT(ans);

	return 0;
}

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

using namespace std;

int main(void) {
	string s;
	int first = -1;
	int second = -1;

	cin >> s;

	for (int i = 0; i < s.size() - 1;i++) {
		if (s[i] == s[i + 1]) {
			first = i + 1;
			second = i + 2;
		}
	}

	for (int i = 0; i < s.size() - 2;i++) {
		if (s[i] == s[i + 2]) {
			first = i + 1;
			second = i + 3;
		}
	}

	cout << first << " " << second << endl;

	return 0;
}

Measured memory_bytes: 512
from itertools import permutations

l = [int(input()) for _ in range(5)]
res = 10**9
for r in permutations(l, r=5):
    x = 0
    for i in range(4):
        x += r[i]
        if r[i]%10>0:
            x += 10-r[i]%10
    x += r[-1]

    res = min(res, x)
print(res)

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var A = Number(line[0].split(" ")[0]);
	var B = Number(line[0].split(" ")[1]);
	var S = line[1];

	var isPostalCode = function(A,B,S){
		var regA = new RegExp('^[0-9]{' + A + '}$');
		var regB = new RegExp('^[0-9]{' + B + '}$');
		return (regA.test(S.slice(0,A)) && S[A] === "-" && regB.test(S.slice(A+1)));
	}

	if(isPostalCode(A,B,S)) console.log("Yes");
	else console.log("No");

	return false;

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine

getString = readString <$> BS.getLine

getNString n = map readString <$> replicateM n BS.getLine

calc :: String -> [[Char]] -> Int -> String -> String -> String
calc a [] d fs rs'
  | d == 1 = fs ++ a ++ reverse rs'
  | d == (-1) = rs' ++ reverse a ++ reverse fs
calc a (q : qs) d fs rs'
  | q' == '1' = calc a qs (- d) fs rs'
  | d == 1 && f == '1' = calc a qs d (c : fs) rs'
  | d == 1 && f == '2' = calc a qs d fs (c : rs')
  | d == (-1) && f == '1' = calc a qs d fs (c : rs')
  | d == (-1) && f == '2' = calc a qs d (c : fs) rs'
  where
    q' = head q
    f = if q' == '2' then head (tail q) else '0'
    c = if q' == '2' then head (tail (tail q)) else '_'

main = do
  [a] <- getString
  n <- getInt
  qs <- getNString n
  let qs' = map (\q -> map head q) qs
  putStrLn $ calc a qs' 1 "" ""


Measured memory_bytes: 133628
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N;
  std::cin>>N;
  std::vector<long long> A(N);
  int cnt[60];
  long long ans=0;
  for (int i=0;i<60;++i) cnt[i]=0;
  for (int i=0;i<N;++i) {
    std::cin>>A[i];
  }
  for (int shift=0;shift<60;++shift) {
    for (int i=0;i<N;++i) {
      if ((A[i]&(1LL<<shift))>0) ++cnt[shift];
    }
    if (cnt[shift]%2==1) {
      ans+=1LL<<shift;
      for (int i=0;i<N;++i) if ((A[i]&(1LL<<shift))>0) A[i]-=1LL<<shift;
      cnt[shift]=0;
    }
  }
  std::sort(A.begin(), A.end());
  int p=0;
  for (int shift=59;shift>=0;--shift) {
    if (cnt[shift]==0) continue;
    for (int i=p;i<N;++i) {
      if (((1L<<shift)&A[i])>0) {
	if (i!=p) {
	  A[i]^=A[p];
	  A[p]^=A[i];
	  A[i]^=A[p];
	}
	for (int j=0;j<N;++j) {
	  if (j==p) continue;
	  if ((A[j]&(1LL<<shift))>0) A[j]^=A[p];
	}
	++p;
	break;
      }
    }
  }
  long long a=0;
  for (int i=0;i<N;++i) {
    a^=A[i];
  }
  ans+=2*a;
  std::cout<<ans<<std::endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.lang.Math;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		// スペース区切りの整数の入力
		int B = sc.nextInt();

		int values[] = {A+B, A-B, A*B};
		int max = values[0];
		for(int i = 1; i < 3; i ++){
			max = Math.max(max, values[i]);
		}

		System.out.println(max);
	}
}

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

int main() {
        string s,t;
        cin >> s >> t;
        t.pop_back();
        if (s==t)cout << "Yes" << endl;
        else cout << "No" <<endl;
        return 0;
}

Measured memory_bytes: 3640
import itertools
 
numA = int(input().rstrip())
listA = list(map(int,input().rstrip().split(" ")))
numQ = int(input().rstrip())
listQ = list(map(int,input().rstrip().split(" ")))
 
sumA = set([])
cnt = 0
 
 
for i in range(1,numA+1):
    tmpComb = list(itertools.combinations(listA, i))
    for nums in tmpComb:
        sumA.add(sum(nums))
 
 
for i in range(numQ):
    if listQ[i] in sumA:
        print("yes")
    else:
        print("no")

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

using namespace std;

#define int long long
int a[81];
int dp[81];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dp[0] = 1000;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        for (int j = 0; j < i - 1; ++j) {
            vector < int > oks;
            for (int pos = j + 1; pos < i; ++pos) oks.push_back(a[pos]);
            sort(oks.begin(), oks.end());
            if (oks[0] <= a[i]) {
                dp[i] = max(dp[i], dp[j] / oks[0] * a[i] + dp[j] % oks[0]);
            }
        }
    }
    cout << dp[n] << '\n';
    return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>

int main(){
  int N,X,T;
  scanf("%d %d %d",&N,&X,&T);
  
  int C=0;
  while(N > 0){
    N = N - X;
    C = C + 1;
  }
  
  printf("%d\n", C * T );
  return 0;
}

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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

void solve() {
    int A, B;
    cin >> A >> B;

    int minValue = min(100 * A / 8, 10 * B);
    int maxValue = max(100 * (A+1) / 8, 10 * (B+1));
    //print(minValue << " " << maxValue);
    bool flag = false;
    int ans = -1;
    while (true) {
        if (maxValue < minValue) {
            break;
        }
        int a = minValue * 0.08;
        int b = minValue * 0.1;
        if (a == A && b == B) {
            ans = minValue;
            flag = true;
            break;
        }
        minValue++;
    }

    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc100c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);

            int count = 0;
            foreach(var i in a)
            {
                count += DevideBy2(i);
            }
            Console.WriteLine(count);
        }
        static int DevideBy2(int k)
        {
            if (k % 2 != 0)
                return 0;
            else
                return 1+ DevideBy2(k / 2);
        }
    }
}


Measured memory_bytes: 14048
def main():
    from collections import deque

    N, L = map(int, input().split())
    *a, = map(int, input().split())

    def solve(a):
        dq = deque()
        s = 0
        ans = 0
        for x in a:
            if len(dq) > 1:
                t = dq.popleft()
                s -= t
            eat = max(0, s + x - L)
            if eat:
                x -= eat
                ans += eat
            s += x
            dq.append(x)
        return ans

    ans = min(solve(a), solve(reversed(a)))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14636
#include<stdio.h>

int main(void) {

	int n, i, j;
	char symbol;
	int snum;
	int number;
	int ALL[52];
	int cards[52];
	int a;

	for (i = 0; i < 52; i++) {
		ALL[i] = 1;
	}

	scanf("%d\n", &n);

	for (j = 0; j < n; j++) {
		scanf("%c %d\n", &symbol, &number);
		
		switch (symbol) {
		case 'S':
			snum = 0;
			break;
		case 'H':
			snum = 1;
			break;
		case 'C':
			snum = 2;
			break;
		case 'D':
			snum = 3;
			break;
		}

		cards[j] = snum * 13 + number - 1;

	}

	for (j = 0; j < n; j++) {

		a = cards[j];

		
			ALL[a] = 0;
		

	}

	for (a = 0; a < 52; a++) {

		if (ALL[a] == 1) {
			
			if ((a + 1) % 13 == 0) {
				
				number = 13;
				snum = (a + 1 - number) / 13;
			}
			else {
				snum = (a + 1) / 13;
				number = (a + 1) % 13;
			}
			
			switch (snum) {
			case 0:
				symbol = 'S';
				break;
			case 1:
				symbol = 'H';
				break;
			case 2:
				symbol = 'C';
				break;
			case 3:
				symbol = 'D';
				break;
			}

			printf("%c %d\n", symbol, number);

		}
		
	}
	

	return(0);
}


Measured memory_bytes: 2048
const input = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');
const n = Number(input.shift());
let ac = 0;
let wa = 0;
let tle = 0;
let re = 0
for (let i = 0; i < n; i++){
    if (input[i] === 'AC') {
        ac++;
    } else if (input[i] === 'WA') {
        wa++;
    } else if (input[i] === 'TLE') {
        tle++;
    } else if (input[i] === 'RE') {
        re++
    } else {
        continue;
    }
}
console.log(`AC x ${ac}`);
console.log(`WA x ${wa}`);
console.log(`TLE x ${tle}`);
console.log(`RE x ${re}`);

Measured memory_bytes: 37288
require 'pp'

N, M= gets.split.map(&:to_i)

d = Array.new(N){ Array.new(N,1e9) }
(0...N).each{ |i| d[i][i] = 0 }

edges = []

M.times do |i|
  a, b, c = gets.split.map(&:to_i)
  a-=1
  b-=1
  d[a][b] = d[b][a] = c
  edges.push( [a, b, c] )
end

N.times do |k|
  N.times do |i|
    N.times do |j|
      v = d[i][k]+d[k][j]
      d[i][j] = v if d[i][j] > v
    end
  end
end

ans = 0
edges.each do |e|
  f = false
  (0...N).each do |i|
    f = true if d[i][e[0]] + e[2] == d[i][e[1]]
  end
  ans += 1 unless f
end

puts ans

Measured memory_bytes: 2428
# 2020/08/22
# AtCoder Beginner Contest 176 - B

# Input
n = input()
nlen = len(n)

# Calc
nsum = 0
for i in range(nlen):
    nsum = nsum + int(n[i])

if nsum % 9 == 0:
    ans = 'Yes'
else:
    ans = 'No'

# Output
print(ans)


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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<ll> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        while (i < n - 1 && h[i + 1] <= h[i]) {
            cnt++;
            i++;
        }
        ans = max(cnt, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M, X; cin >> N >> M >> X;

  int h1 = 0, h2 = 0;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    if (A[i] < X) {
      h1++;
    } else {
      h2++;
    }
  }

  cout << min(h1, h2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100001
int main(){
  int N,T;
  cin>>N>>T;
  int price[MAX];
  int prof[MAX];
  int i;
  for(i=0;i<N;i++){
    cin>>price[i];
  }
  int min=1000000000;
  
  for(i=0;i<N;i++){
    if(price[i]<min){
      min=price[i];
    }
    prof[i]=price[i]-min;
  }
  int max=0;
  for(i=0;i<N;i++){
    //cout<<prof[i];
    if(prof[i]>max){
      max=prof[i];
    }
  }
  int nmax=0;
  for(i=0;i<N;i++){
    if(prof[i]==max){
      nmax++;
    }
  }
  
  cout<<nmax<<endl;
  return 0;

}


Measured memory_bytes: 1024