akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<pair<pii,int>>a;
    rep(i,n){
        int s,t,x;
        cin >> s >>t >> x;
        a.emplace_back(pii(s-x,t-x-1),x);
    }
    sort(a.begin(),a.end());
    show(a);
    int pos = 0;
    set<pii>st;
    multiset<int>st2;
    rep(i,q){
        int d;
        cin >> d;
        while(pos < n){
            if(a[pos].first.first <= d){
                st.emplace(a[pos].first.second, a[pos].second);
                st2.insert(a[pos].second);
                pos++;
            }else{
                break;
            }
        }
        if(st.size()==0){
            cout << - 1<< "\n";
            
            continue;
        }
        auto it1 = st.lower_bound(pii(d,-1));
        show(st.size());
        show(*it1);
        for(auto it2 = st.begin(); it2 != it1;){
            st2.erase(st2.find((*it2).second));
            it2 = st.erase(it2);
        }
        if(st2.size()){
            cout << *st2.begin() << "\n";
        }else{
            cout << -1 << "\n";
        }
    }
}

Measured memory_bytes: 22384
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

		String str = sc.next();
		//0を北とする
		int dir = 0;

		//一周したかの判定にスタックを使う
		//Rでpush, Lでpopとすることで
		//sizeが5になったら1周完了、0なら回転失敗と判断
		Stack<Integer> stack = new Stack<Integer>();
		stack.add(0);
		int result = 0;

		for(int i = 0; i < str.length(); i++){

			char command = str.charAt(i);

			//コマンドに応じて方向を計算する
			if(command == 'R'){
				dir++;
			}
			else {
				dir += 3;
			}
			dir %= 4;

			//北を向いているとき
			//ここが回転の起点なのでスタック生成
			if(dir == 0 && stack == null){
				stack = new Stack<Integer>();
				stack.add(0);
			}
			else if(stack != null){
				//左回転
				if(command == 'L'){
					stack.pop();
					if(stack.size() == 0){
						stack = null;
					}
				}
				//右回転
				else{
					stack.push(0);
					if(stack.size() == 5){
						result++;
						stack.removeAllElements();
						stack.add(0);
					}
				}
			}
		}

		System.out.println(result);
	}

}



Measured memory_bytes: 26336
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	string S;
	cin >> S;

	vector<int> cnt(N + 1, 0);
	char prev = '\n';
	for (int i = 0; i < N; i++) {
		cnt[i + 1] = cnt[i];
		if (prev == 'A' && S[i] == 'C')
			cnt[i + 1]++;

		prev = S[i];
	}

	int l, r;
	for (int i = 0; i < Q; i++) {
		cin >> l >> r;

		l--;
		int n = cnt[r] - cnt[l];
		if (l > 0 && S[l] == 'C' && S[l - 1] == 'A')
			n--;

		cout << n << endl;
	}

	return 0;
}


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

int gcd(int a, int b){
    if (a < b){
        int tmp;
        tmp = b;
        b = a;
        a = tmp;
    }
    if (a % b == 0){
        return b;
    }
    int c, r;
    while(true){
        c = a / b;
        r = a % b;
        if (r==0){
            break;
        }else{
            a = b;
            b = r;
        }
    }
    return b;
}

int main(){
    int K;
    long long int result=0;

    cin >> K;
    
    for (int i=1; i<=K; i++){
        for (int j=1; j<=K; j++){
            for (int k=1; k<=K; k++){
                result += gcd(i, gcd(j, k));
            }
        }
    }
    cout << result << endl;
    
}

Measured memory_bytes: 3672
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 100000000
int max(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}

int main(){
	while(1){
		int n,k,s[101],b,flg=1;
		cin>>n>>k;
		if(n==0&&k==0)break;
		for(int i=0;i<k;i++){
			cin>>s[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<k;j++){
				cin>>b;
				if(s[j]<b){
					flg=0;
				}else{
					s[j]-=b;
				}
			}
		}
		if(flg==1){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}	

Measured memory_bytes: 1152
n = gets.to_i
$a = [0] + gets.split.map(&:to_i)

$road = Array.new(n+1) {[]}
(n-1).times do
    u, v = gets.split.map(&:to_i)
    $road[u] << v
    $road[v] << u
end

$dp = Array.new(n+1, 10**10)
$r = 0
$ans = Array.new(n+1)

def dfs(i, pre)
    j = $dp.bsearch_index {|e| $a[i] <= e}
    x = $dp[j]
    $dp[j] = $a[i]
    $r += 1 if j == $r
    $ans[i] = $r

    $road[i].each do |k|
        next if k == pre
        dfs(k, i)
    end

    $dp[j] = x
    $r -= 1 if x == 10**10
end

dfs(1, 0)
$ans.shift
puts $ans

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

int d;
vector<int> c(26);
vector<vector<int>> s;
int score;

void input() {
    cin >> d;
    s = vector<vector<int>>(d, vector<int>(26));

    for (int& i : c) cin >> i;
    for (auto& v : s)
        for (int& i : v) cin >> i;
}

int _f(int contest, int day, vector<int>& last) {
    int k = 0;

    for (int i = 0; i < 26; ++i) {
        if (i == contest)
            k += s[day][i];
        else
            k -= c[i] * (day - last[i]);
    }
    return k;
}

int f(vector<int>& schedule) {
    int k = 0;
    vector<int> last(26, -1);
    for (int day = 0; day < d; ++day) {
        int dk = _f(schedule[day], day, last);
        k += dk;
        last[schedule[day]] = day;
    }
    return k;
}

vector<int> greedy() {
    vector<int> last(26, -1), t(d);
    for (int day = 0; day < d; ++day) {
        int opt = 0, optv = _f(opt, day, last);
        for (int i = 1; i < 26; ++i) {
            int iv = _f(i, day, last);
            if (optv < iv) opt = i, optv = iv;
        }
        t[day] = opt;
    }
    return t;
}

int main() {
    input();
    vector<int> t(greedy());
    for (int i : t) cout << i + 1 << endl;
}

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

using namespace std;

int main()
{
  int W, a, b; cin >> W >> a >> b;
  if (max(a, b) - min(a+W, b+W) > 0) cout << max(a, b) - min(a+W, b+W);
  else cout << 0;
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    
    ll N, x; cin >> N >> x;
    if(x==1 || x==2*N-1){
        cout << "No" << endl; return 0;
    }
    cout << "Yes" << endl;
    vl ans(2*N-1); REP(i, 2*N-1) ans[i] = i+1;
    swap(ans[x-1], ans[N-1]);
    swap(ans[0], ans[N-2]);
    swap(ans[2*N-2], ans[N]);
    REP(i, 2*N-1) cout << ans[i] << endstr;
    return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  int key;
  struct node *r;
  struct node *l;
  struct node *p;
};
typedef struct node *Node;

Node root;

Node treeMinimum(Node x){
  while(x->l != NIL)x=x->l;
  return x;
}

Node find(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key)u=u->l;
    else u=u->r;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->r!=NIL)return treeMinimum(x->r);
  y=x->p;
  while(y!=NIL && x == y->r){
    x=y;
    y=y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node x;
  Node y;
  
  if(z->l==NIL || z->r==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->l!=NIL)x=y->l;
  else x=y->r;

  if(x!=NIL)x->p=y->p;
  
  if(y->p==NIL)root=x;
  else if(y==y->p->r)y->p->r=x;
  else y->p->l=x;

if(y!=z)z->key=y->key;
 
free(y);
}

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key=k;
  z->r=NIL;
  z->l=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NIL)root=z;
  else if(z->key < y->key) y->l=z;
  else y->r=z;
}

void inorder(Node u){
  if(u!=NIL){
    if(u->l!=NIL)inorder(u->l);
    printf(" %d",u->key);
    if(u->r!=NIL)inorder(u->r);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    if(u->l != NIL)preorder(u->l);
    if(u->r != NIL) preorder(u->r);
  }
}

int main(){
  int n, i, x;
  char com[8];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", com);
    if(com[0]=='f'){
      scanf("%d",&x);
      Node t=find(root, x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0]=='d'){
      scanf("%d", &x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}

Measured memory_bytes: 19364
#include <stdio.h>

void selectionSort(int x[], int N)
{
	int i, j, minj, tmp;
	int cnt = 0;
	for(i=0; i<N; i++){
		minj = i;
		for(j=i; j<N; j++){
			if(x[j] < x[minj])
			{
				minj = j;
			}
		}
		tmp = x[i];
		x[i] = x[minj];
		x[minj] = tmp;
		if(i != minj) cnt++;
	}
	for(i=0; i<N; i++){
		if(i != N-1)
		{
			printf("%d ", x[i]);
		}
		else printf("%d", x[i]);
	}
	printf("\n");
	printf("%d\n", cnt);
}


int main(void)
{
	int n;
	scanf("%d", &n);
	
	int i, x[n];
	for(i=0; i<n; i++){
		scanf("%d", &x[i]);
	}
	
	selectionSort(x, n);
	
	return 0;
}



Measured memory_bytes: 2092
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next()), temp, max = 1, maxtmp = 0;
            int[] num = new int[n];
            
            for(int i=0; i<n; i++){
            	temp = Integer.parseInt(sc.next());
            	num[temp-1] = i;
            }
            
            temp = num[0];
            
            for(int i=1; i<n; i++){
            	maxtmp = 1;
            	while(i < n && temp < num[i]){
            		maxtmp++;
            		temp = num[i];
            		i++;
            	}
            	if(i < n){
            		temp = num[i];        		
            	}
            	
            	if(max < maxtmp){
            		max = maxtmp;
            	}
            }
            
            System.out.println(n - max);     
            sc.close();
        }
    }
	

Measured memory_bytes: 63656
<?php

const MOD = 1000000007;

fscanf(STDIN, "%d", $N);
$list = explode(" ", trim(fgets(STDIN)));
function eratosthenes5($max) {

    $sqrt = floor(sqrt($max));

    $lists = array_fill(2, $max-1, 0);

    for ($i=2; $i<=$sqrt; $i++) {
        if (isset($lists[$i])) {
            for ($j=$i*2; $j<=$max; $j+=$i) {
                unset($lists[$j]);
            }
        }
    }

    return $lists;
}
$map = eratosthenes5(1000000);
$data = array_keys($map);
foreach($list as $value){
    if(isset($map[$value])){
        if($map[$value] ==0){
            $map[$value] = 1;
        }
    }else{
        $temp = [];
        foreach($data as $d_value){
            while($value % $d_value == 0){
                $value /= $d_value;
                @$temp[$d_value] += 1;
            }
            if($value == 1){
                foreach($temp as $key => $value){
                    $map[$key] = max($map[$key], $value);
                }
                break;
            }
        }
    }
}
$sum = 1;
foreach ($map as $key => $value){
    for($i=0;$i<$value;$i++){
        $sum = $sum * $key % MOD;
    }
}
$ans = 0;
foreach($list as $value){
    $temp = ($sum * pow_mod($value,MOD-2, MOD)) % MOD;
    $ans = ($ans + $temp) % MOD;
}
echo $ans % MOD;


function pow_mod($x, $n, $mod){
    $ans = 1;
    $bin = decbin($n);
    $pos = strlen($bin);
    while ($pos > 0) {
        if ($bin[$pos - 1] == 1) {
            $ans = ($ans * $x) % $mod;
        }
        $x = ($x * $x) % $mod;
        $pos--;
    }
    return $ans;
}

Measured memory_bytes: 41592
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

l=list(map(int,input().split()))
for i in range(10**6):
    for k in range(3):
        if l[k]%2:
            print(i)
            exit()
    a=[0]*3
    for k in range(3):
        a[k]=(l[(k+1)%3]+l[(k+2)%3])//2
    l=a
print(-1)

Measured memory_bytes: 73744
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j,n;
	char s[102];
	char sum;
	while(scanf("%s",&s)!=EOF)
	{
		n=0;
		for(i=0;i<strlen(s);i++)
		{
			if(s[i]=='C')
			{
				for(j=i+1;j<strlen(s);j++)
				{
					if(s[j]=='F')
					{
						n++;
						break;
					}
				}
				if(n!=0)
				{
					printf("Yes\n");
					break;
				}
			}
		}
		if(n==0)
			printf("No\n");
	}
	return 0;
}

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

int gcd(int A,int B){
  if(B>A)swap(A,B);
  if(B==0)return A;
  return gcd(B,A%B);
}

int main(){
  int N,Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int>c(N+1);
  for(int i=0;i<N-1;i++){
    c[i+1]=c[i]+(S[i]=='A'&&S[i+1]=='C');
  }
  while(Q--){
    int l,r;cin >> l >>r,l--,r--;
    cout << c[r]-c[l] << endl;
  }
}
  
  

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 int main() {
int a,b,c;
   cin >> a>>b;
   int flag=0;
   if(a%3==0)flag=1;
   else if(b%3==0)flag=1;
   else if((a+b)%3==0)flag=1;
   
   if(flag==1) cout <<"Possible"<<endl;
   else if(flag==0)cout <<"Impossible"<<endl;

   }
   


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int a, b, c;
  cin >> a >> b >> c;

  rep(i, b) {
    if (a * i % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pll;
const int maxn=212345;
long long n,x,d,dd;
int cnt;
map<int,int> mp;
vector<pll> vec[maxn];
inline long long get(long long x,long long y) {
    if (x>y) return 0;
    return ((y-1)*y/2-(x-2)*(x-1)/2)*d;
}
int main()
{
    cin>>n>>x>>d;
    if (d==0) {
        if (x==0) cout<<1<<endl;
        else cout<<n+1<<endl;
        return 0;
    }
    dd=d+d;
    if (dd<0) dd=-dd;
    for (int i=0;i<=n;++i) {
        long long a=x*(i+i-n);
        long long rev=(a%dd+dd)%dd;
        if (mp.find(rev)==mp.end()) mp[rev]=++cnt;
        long long lo=a+get(1,i)-get(i+1,n);
        long long hi=a+get(n-i+1,n)-get(1,n-i);
        if (lo>hi) swap(lo,hi);
        vec[mp[rev]].push_back(pll(lo,hi));
    }
    long long res=0;
    for (int i=1;i<=cnt;++i) {
        sort(vec[i].begin(),vec[i].end());
        res+=(vec[i][0].second-vec[i][0].first)/dd+1;
        long long r=vec[i][0].second;
        for (int j=1;j<(int)vec[i].size();++j) {
            if (vec[i][j].first>r) {
                res+=(vec[i][j].second-vec[i][j].first)/dd+1;
                r=vec[i][j].second;
            }
            if (vec[i][j].second>r) {
                res+=(vec[i][j].second-r)/dd;
                r=vec[i][j].second;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 20864
#include<bits/stdc++.h>
#define MOD 998244353
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define ll long long
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
using namespace std;
int main()
{
	ll n,cnt=0,ans=0;
	cin>>n;
	ll val=n-1;
	ans=(val+1)*(val);
	cout<<ans/2<<endl;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end


def half_search(target,l,r,a)
    50.times do
        mid=(l+r)/2
        if target==a[mid]
            return true
        elsif target>a[mid]
            l=mid
        else
            r=mid
        end
    end
    return false
end
N=gets.to_i
S=get_nsp
r=[]
b=[]
#g=[]
g={}
S.each_with_index do|s,i|
  case s
  when "R" then
      r.push(i)
  when "B" then
      b.push(i)
  when "G" then
      #g.push(i)
      g[i]=1
  end
end
ng=g.size
ans=0
r.each do|x|
    b.each do|y|
      res=ng
      l=x<y ? x : y
      r=x>y ? x : y
      #if half_search(l+l-r,0,ng-1,g) 
      unless g[l+l-r].nil?
        res-=1
      end
      #if half_search(r-(l-r),0,ng-1,g)
      unless g[r-(l-r)].nil?
          res-=1
      end
      if (x+y).even?
        mid=(x+y)/2
        #if half_search(mid,0,ng-1,g)
        unless g[mid].nil?
            res-=1
        end
      end
      ans+=res
    end
end
puts ans

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

using namespace std;

using ll = long long;

const int maxN = 2e5 + 10;
const ll inf = 1e18;

int n;
ll a[maxN];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    ll ans = inf, total_sum = 0, cur_sum = 0;
    for (int i = 1; i <= n; ++i)
    {
        total_sum += a[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        cur_sum += a[i];
        if (i < n)
        {
            ans = min(ans, abs(cur_sum - (total_sum - cur_sum)));
        }
    }
    cout << ans;
    return 0;
}


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

int d[1000001];
int main()
{
string s;int an=753;
cin>>s;
for(int i=2;i<(int)s.size();i++){
an=min(an,abs(753-(s[i]+s[i-1]*10+s[i-2]*100-5328)));}
cout<<an<<endl;

}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010], b[100010];
vector<pair<int, int>>v;
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d%d",a+i, b+i);
            v.push_back(mk(b[i]+a[i], a[i]-b[i]));
        }
        sort(v.begin(), v.end());
        pair<int, int> tmp=v[0];ans=1;
        for(int i=1; i<v.size(); ++i){
            if(v[i].sc>=tmp.fs){
                ++ans;
                tmp=v[i];
            }
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 1912
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);

  rep(i,N){
    cin >> a[i] >> b[i] >> c[i];
  }

  int **dp=(int **)malloc(sizeof(int *)*N);
  rep(i,N){
    dp[i]=(int *)calloc(3,sizeof(int));
  }
  dp[0][0]+=a[0];
  dp[0][1]+=b[0];
  dp[0][2]+=c[0];

  srep(i,1,N){
    dp[i][0]=max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
    dp[i][1]=max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
    dp[i][2]=max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
  }

  int ans=0;
  rep(j,3){
    ans=max(ans, dp[N-1][j]);
  }

  printf("%d\n", ans);
}


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

int kaijo(int x) {
    if(x != 0) return x*kaijo(x-1);
    return 1;
}

int main() {
    int n, x, y;
    cin >> n;
    vector<pair<int, int>> v;
    for(int i = 0; i < n; ++i) {
        cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    vector<double> dist;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(i != j)
                dist.push_back(pow(pow(v[i].first - v[j].first, 2) + pow(v[i].second - v[j].second, 2), 0.5)); 
        }
    }
    
    double ans = 0.0;
    for(int i = 0; i < dist.size(); ++i) {
        ans += dist[i]*kaijo(n-1);
    }
    ans /= kaijo(n);
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		if(n==1&&m==1) System.out.println(1);
		else if(n==1||m==1) System.out.println(Math.max(n, m)-2);
		else System.out.println((n-2)*(m-2));
	}
}


Measured memory_bytes: 23764
#include<stdio.h>
#define MAX 100001

int A[MAX];

int partion(int n){
    int i,j,tmp;
    int key=A[n-1];
    i=0;
    j=i-1;
    while(i<n-1){
          if(A[i]>key){i++;}
          else {
                j++;
                tmp=A[j];A[j]=A[i];A[i]=tmp;
                i++;
                }
          }
    j=j+1;
    tmp=A[j];A[j]=A[n-1];A[n-1]=tmp;
    return j;
    }



int main(){
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
                scanf("%d",&A[i]);
                }
    int key=partion(n);
    for(i=0;i<key;i++){
                printf("%d ",A[i]);
                }
    printf("[%d] ",A[key]);
    for(i=key+1;i<n;i++){
                printf("%d%c",A[i],i==n-1?'\n':' ');
                }
    return 0;
    }
              








Measured memory_bytes: 2240
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxn = 15;
#define INF 0xfffff
int d[maxn][maxn];
int V, ans_num, ans_dis;
void init(){
    ans_dis = INF;
    for(int i = 0; i < maxn; i++){
        fill(d[i], d[i] + maxn, INF);
        d[i][i] = 0;
    }
}
void Floyd(){
    for(int k = 0; k <= V; k++)
        for(int i = 0; i <= V; i++)
            for(int j = 0; j <= V; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
//                printf("d[%d][%d] = %d\n",i,j,d[i][j]);
            }
}
void solve(){
    Floyd();
    for(int i = 0; i <= V; i++){
        int sum_dis = 0;
        for(int j = 0; j <= V; j++)
            sum_dis += d[i][j];
        if(sum_dis < ans_dis){
            ans_dis = sum_dis;
            ans_num = i;
        }
    }
}
int main(){_
    int n;
    while(~scanf("%d",&n)){
        if(!n) break;
        V = 0;
        init();
        for(int i = 0; i < n; i++){
            int x, y, val;
            scanf("%d%d%d",&x, &y, &val);
            d[x][y] = d[y][x] = val;
//            printf("--d[%d][%d] = %d\n",x, y, d[x][y]);
            V = max(V, max(x, y));
        }
        solve();
        printf("%d %d\n",ans_num, ans_dis);
    }

    return 0;
}



Measured memory_bytes: 3236
from collections import deque
s = input()
q = int(input())
qu = [input().split() for _ in range(q)]
le = deque()
ri = deque()
for i in range(len(s)):
    le.append(s[i])
    ri.appendleft(s[i])
x = 1
for i in range(q):
    if qu[i] == ['1']:
        x *= -1
    elif x == 1:
        ci = qu[i][2]
        if qu[i][1] == '1':
            le.appendleft(ci)
            ri.append(ci)
        else: 
            le.append(ci)
            ri.appendleft(ci)
    else: 
        ci = qu[i][2]
        if qu[i][1] == '1':
            le.append(ci)
            ri.appendleft(ci)
        else: 
            le.appendleft(ci)
            ri.append(ci)
y = ''
if x == 1:
    for i in le:
        y += i
else: 
    for i in ri:
        y += i
print(y)

Measured memory_bytes: 45580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int r, g;
  cin >> r >> g;

  cout << 2*g - r  << endl;

  return 0;
}


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

int main(){
  string S;
  cin>>S;
  vector<bool> c(26,false);
  int n=S.size();
  for(int i=0;i<n;i++){
    int x=S.at(i)-'a';
    c.at(x)=true;
  }
  bool flag=true;
  for(int i=0;i<26;i++){
    if(!c.at(i)){
      cout<<(char)('a'+i)<<endl;
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<"None"<<endl;
  }
}


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

int main(void){
  int N, Y, sum;
  bool flag = false;
  int cash[3] = {0};
  cin >> N >> Y;
  for(int a = 0; a <= N; a++){
    for(int b = 0; b <= N - a; b++){
      int c = N - a - b;
      sum = a*10000 + b*5000 + c*1000;
      if(Y == sum){
        cash[0] = a, cash[1] = b, cash[2] = c;
        flag = true;
        break;
      }
    }
  }
  //出力
  if(flag){
    cout << cash[0] << " " << cash[1] << " " << cash[2] <<endl;
  }
  else{
    cout << -1 << " " << -1 << " " << -1 <<endl;
  }
  return 0;
}


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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

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

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {
    int ans=0;
    rep(i,4){
        char c;
        cin>>c;
        if(c=='+')ans++;
        else ans--;
    }

    cout<<ans<<endl;
}


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

typedef std::pair<std::string,int> sale;

int main()
{
	
	
	while (true) {
		int n;
		std::vector<sale> sale_vec;
		
		std::cin >> n;
		
		if (n==0) break;
		
		std::string id;
		int unit_price;
		int quantity;
		
		for (int i=0; i<n; i++) {
			std::cin >> id >> unit_price >> quantity;
			bool id_exists = false;
			for (std::vector<sale>::iterator it = sale_vec.begin(); it != sale_vec.end(); ++it) {
				if (it->first == id) {
					id_exists = true; it->second += unit_price * quantity; break;
				}
			}
			if (!id_exists) {
				sale_vec.push_back( sale(id, unit_price * quantity) );
			}
		}
		
		bool output = false;
		for (std::vector<sale>::iterator it = sale_vec.begin(); it != sale_vec.end(); ++it) {
			if (it->second >= 1000000) {
				std::cout << it->first << std::endl;
				output = true;
			}
		}
		if (!output) std::cout << "NA" << std::endl;
	}
	
	return 0;
}
	



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


int main() {
  char s;
  cin >> s;
  if (isupper(s))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }
}

Measured memory_bytes: 3592
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
   ll x,y;
   cin>>x>>y;
   bool f=false;
   ll j=0;
   for(ll i=x;i>=0;i--)
   {
           if((2*i+4*j)==y)
           {
               f=true;
               break;
           }
       j++;
   }
   if(f)
   cout<<"Yes"<<endl;
   else
   cout<<"No"<<endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
///use less_equal in pbds template to work as multiset...................................................
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};
vector<int>adj[200005];
int cnt;
vector<int>vis(200005,0);
void dfs(int node)
{
    if(!vis[node])
    {
        ++cnt;
        vis[node]=1;
        for(int son:adj[node])
            dfs(son);
    }
}
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int n,m;
     cin>>n>>m;
     for(int i=0; i<m; i++)
     {
         int x,y;
         cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
     }
     int ans=0;
     for(int i=1; i<=n; i++)
     {
         cnt=0;
         if(!vis[i])
         {
             dfs(i);
             ans=max(ans,cnt);
         }
     }
     cout<<ans<<endl;

}




Measured memory_bytes: 21076
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

long long gcd(long long a, long long b) {
    return b ? gcd(b, a % b) : a;
}

int n, m;
string s;

int main() {
    cin >> n;

    Vi v(n);
    REP(i, n) cin >> v[i];

    Vi l(n), r(n);
    l[0] = v[0];
    r.back() = v.back();
    REP2(i, 1, n) {
        l[i] = gcd(l[i-1], v[i]);
    }
    RREP(i, n-2, 0) {
        r[i] = gcd(r[i+1], v[i]);
    }

    int maxi = max(l[n-2], r[1]);
    REP2(i, 1, n-1) {
        int val = gcd(l[i-1], r[i+1]);
        if (maxi < val) maxi = val;
    }

    std::cout << maxi << '\n';

    return 0;
}


Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, x;
    cin >> n;
    if(n%2==1){
        cout << 0;
        return 0;
    }
    vi v;
    for(int i = 0; i < n; i++){
        cin >> x;
        v.pb(x);
    }
    sort(all(v));
    int ans = 0;
    ans = v[n/2]-v[(n/2)-1];
    cout << ans;
    
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

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

void solve() {
    cin >> N >> S;
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
    return;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, a, b; cin >> n >> a >> b;
  string s; cin >> s;
  int c = 0;
  int d = 1;
  for (int i = 0; i < s.length(); i++){
    if(s[i] == 'a'){
      if(c < a+b){
        say("Yes")
        c++;
      }else{
        say("No")
      }
    }else if(s[i] == 'b'){
      if(c < a+b && d <= b){
        say("Yes")
        c++;
      }else{
        say("No")
      }
      d++;
    }else{
      say("No")
    }
  }
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
int main()
{
	ll int n,c=7;
	cin>>n;
	
	ll int i;
	for(i=1;i<=1e7;i++)
	{
		
		if (c%n==0)
		{
			cout<<i<<endl;
			return 0;
		}
		c=(c*10+7)%n;
		
	}
	cout<<-1<<endl;
	
}

    
	
		

	
			

		


 






Measured memory_bytes: 3528
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

K, X = LI()

for i in range(X-K+1, X+K):
    print(i, end=' ')


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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  rep(i, n) cin >> a[i + 1];

  vector<int> b(n + 1);
  int m = 0;
  for (int i = n; i >= 1; --i) {
    int cnt = 0;
    for (int j = 2 * i; j <= n; j += i) {
      cnt += b[j];
    }
    cnt %= 2;
    b[i] = a[i] ^ cnt;
    m += b[i];
  }

  cout << m << endl;
  rep(i, n) if (b[i + 1]) cout << i + 1 << endl;
  return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        string S;
        cin >> S;
        if (len(S) < 4) {
                cout << "No" << endl;
                return 0;
        }

        string fs(S.begin(), S.begin()+4);
        if (fs == "YAKI") {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    string s;
    cin >> n >> s;
    ll r=0;
    ll g=0;
    ll b=0;

    for(int i = 0; i < n; i++) {
        if(s[i]=='R')      r++;
        else if(s[i]=='G') g++;
        else               b++;
    }
    ll ans=r*g*b;
//    cout << rs << " " << bs << " " << gs << "\n";
    for(ll w = 1; 2*w < n; w++) {
        for(ll m = w; m+w <n ; m++) {
//        cout << m << " " << w << "\n";
            if(s[m]!=s[m-w]&&s[m]!=s[m+w]&&s[m-w]!=s[m+w]){
                ans--;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int A=0,B=0,C=0,D=0;
  vector<string>data(N);
  for (int i=0; i<N; i++) {
    cin >> data.at(i);
    if (data.at(i) == "AC") {
     A++;
    }
    else if (data.at(i) == "WA") {
     B++;
    }
    else if (data.at(i) == "TLE") {
     C++;
    }
    else if (data.at(i) == "RE") {
     D++;
    }
  }
  cout << "AC x " << A << endl << "WA x " << B << endl;
  cout << "TLE x " << C << endl << "RE x " << D << endl;
}

Measured memory_bytes: 6352
#include <stdio.h>
#include <string.h>

char S[100000], s[4][10] = { "dream", "dreamer", "erase", "eraser" };

int hikaku(int n) {
	int i, j, len;

	for (i = 0; i < 4; i++) {
		len = strlen(s[i]);
		for (j = 1; j <= len; j++) {
			if (s[i][len - j] != S[n - j]) break;
		}
		if (j > len) {
			break;
		}
	}

	if (j > len) {
		return n - j + 1;
	}
	else {
		return -1;
	}
}

int main() {
	int len;

	scanf("%s", S);

	len = strlen(S);

	do {
		len = hikaku(len);
	} while (len != -1 && len != 0);

	if (len == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 12
int k;
int dp[MN][MN][MN];
int sm[MN][MN];
int calc(int st, int nd){
    //memset(dp, 0, sizeof dp);
    //cout << "doing " << st << " " << nd << "\n";
    dp[1][st][st] = 1;
    FOR(i, 2, nd){
        F0R(d, 10){
            if(d != 0) dp[i][st][d] += dp[i-1][st][d-1];
            dp[i][st][d] += dp[i-1][st][d];
            if(d != 9) dp[i][st][d] += dp[i-1][st][d+1];
        }
    }
    FOR(i, 1, nd){
        F0R(j, 10){
            //cout << dp[i][st][j] << " ";
            sm[i][st] += dp[i][st][j];
        }
        //cout << "\n";
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> k; --k;
    F0R(j, 10){
        calc(j, 10);
    }
    /*FOR(i, 1, 10){
        F0R(j, 10){
            cout << sm[i][j] << " ";
        }
        cout << "\n";
    }*/
    int nd = 1;
    int std = -1;
    while(nd != 0){
        bool ok = false;
        F0R(i, 10){
            if(std == -1 && i == 0) continue;
            else if(std != -1 && abs(std-i)>1) continue;
            if(sm[nd][i] > k){
                cout << i;
                //cout << "pairing " << i << "\n";
                --nd;
                ok = true;
                std = i;
                break;
            } else{
                k -= sm[nd][i];
            }
        }
        if(!ok){ ++nd; }
        //cout << "now k " << k << "\n";
    }
 
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h> 
int main() 
{
 int n, a[100]; 
 scanf("%d", &n); 
 for(int i = 0; i < n; ++i) 
 {
  scanf("%d", &a[i]); 
  } 
  for(int i = n-1; i >= 0; --i) 
  { 
  printf("%d", a[i]); 
  if(i != 0) 
  {
   printf(" "); 
   } 
   else 
   { 
   printf("\n"); 
   } 
   } 
   return 0; 
}


Measured memory_bytes: 2084
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

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

int main(void) {
  double d, a, x = 0.0, y = 0.0, t = 90.0;

  while (1) {
    scanf("%lf,%lf", &d, &a);
    if (d == 0 && a == 0) break;
    
    x += d * cos(3.141592 * t / 180.0);
    y += d * sin(3.141592 * t / 180.0);
    t -= a;
  }
  printf("%d\n", (int)x);
  printf("%d\n", (int)y);

  return 0;
}

Measured memory_bytes: 632