akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  string T="CODEFESTIVAL2016";
  int ans=0;
  rep(i,0,N){
    if(S[i]!=T[i]) ans++;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,h,w = IR(3)
    print((n-h+1)*(n-w+1))
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38512
// dp[i][j] := i???????????§????????£?????????j??\??????????¨????????????????????????????????????§????????\??¬???????????????i???
#include <iostream>
using namespace std;

int dp[105][10005], v[1001], w[1001];

int main(void) {
  int N, W;

  cin >> N >> W;
  for (int i = 0; i < N; i++) cin >> v[i] >> w[i];

  for (int i = 0; i < N; i++) {
    for (int j = 1; j < W + 1; j++) {
      if (!i) {
        if (j - w[i] >= 0) dp[i][j] = dp[i][j - w[i]] + v[i];
      } else {
        if (j - w[i] >= 0) {
          dp[i][j] = max(dp[i-1][j], dp[i][j - w[i]] + v[i]);
        } else {
          dp[i][j] = dp[i-1][j];
        }
      }
    }
  }

  cout << dp[N-1][W] << endl;
  return 0;
}

Measured memory_bytes: 5256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;
 
lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a);
        b >>= 1;
        if (!b)
            break;
        a = (a*a);
    }
    return result;
}
int main()
{
	IOS;
	lli n,m;
	cin>>n>>m;
	lli a[n], sum = 0;
	for(lli i = 0; i<n; i++)
	cin>>a[i], sum += a[i];
	lli k = 4*m;
	lli temp = sum/k + (sum%k > 0);

	sort(a, a+n);
	if(a[n-m] >= temp)
	cout<<"Yes\n";
	else
	cout<<"No\n";
}


Measured memory_bytes: 384
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    cout << (n*(n-1))/2LL << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

const int MAX_N=1000000;

typedef long long ll;

using namespace std;

ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
	for(int i=0;i<2*n-1;i++)dat[i]=0;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in+1,0,0,n));
		//ans=max(ans,dat[in+n-1]);
	}
	cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	
	return 0;
}

Measured memory_bytes: 5252
#include<bits/stdc++.h>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin),freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 5500010
#define v_n 5005
#define LL long long
#define ULL unsigned long long 
#define e_n 50005
#define eps 0.000000001
#define Blen 31 
const LL MOD = 998244353;
using namespace std;
int main(void)
{
	int i, j, k;
	//Relocate;
	FAST_IO;
	int A, B, T;
	cin >> A >> B >> T;
	int now = 0;
	LL ans = 0;
	while (now <= T)
	{
		ans += B;
		now += A;
	}
	ans -= B;
	cout << ans << endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// くそ雑魚回答
/*
int color(char c){
	if(c == 'R') return 0;
	else if(c == 'G') return 1;
	else return 2;
}

vector<bool> flg(3,true);
int flg_check(){
	if(flg[0]) return 0;
	else if(flg[1]) return 1;
	else return 2;
}
*/

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int N;
	cin >> N;

	ddvi C(3,vi(0));
	string S;
	cin >> S;
	REP(i,N){
		if(S[i] == 'R'){
			C[0].eb(i);
		}
		else if(S[i] == 'G'){
			C[1].eb(i);
		}
		else{
			C[2].eb(i);
		}
	}

/*
	if(C[0].size() == 0 || C[1].size() == 0 || C[2].size() == 0){
		cout << "0" << "\n";
	}
*/
	// すべての文字が異なり('R', 'G', 'B'が揃う)
	// その配置が等間隔でない
	ll ans = 0;

	// くそ雑魚回答
	/*
	REP(i,N-1){
		flg[color(S[i])] = false;
		FOR(j,i+2,N){
			flg[color(S[j])] = false;
			if(S[i] == S[j]) continue;
			// 残った色の配列についてにぶたんで上界下界を探索
			auto left = upper_bound(C[flg_check()].begin(), C[flg_check()].end(), i);
			int left_pos = distance(C[flg_check()].begin(), left);
			auto right = upper_bound(C[flg_check()].begin(), C[flg_check()].end(), j);
			int right_pos = distance(C[flg_check()].begin(), right);
			if(right_pos == 0) continue;

			// cout << "[" << i << "," << j << "]" << "\n";
			// cout << left_pos << "," << right_pos << "\n";
			if((i+j)%2 == 0 && S[(i+j)/2] != S[i] && S[(i+j)/2] != S[j]){
				// cout << "ouch!\n";
				ans -= 1;
			}

			ans += right_pos - left_pos;
			flg[color(S[j])] = true;
		}
		flg[color(S[i])] = true;
	}
	*/

	REP(i,C[0].size()){
		REP(j,C[1].size()){
			int big = max(C[0][i],C[1][j]);
			int small = min(C[0][i],C[1][j]);
			ans += C[2].size();

			// B---small---bigの場合
			if(small - (big - small) >= 0){
				if( binary_search(C[2].begin(), C[2].end(), small - (big - small)) ){
					ans -= 1;
				}
			}
			// small---B---bigの場合
			if((small + big) % 2 == 0){
				int mid = (small + big) / 2;
				if( binary_search(C[2].begin(), C[2].end(), mid) ){
					ans -= 1;
				}
			}
			// small---big---Bの場合
			if(big + (big - small) < N){
				if( binary_search(C[2].begin(), C[2].end(), big + (big - small)) ){
					ans -= 1;
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

map<char, ll> mp;
ll a[30];
ll b[30];

int main()
{
	fill(a, a + 30, 1000);
	cin >> n;
	REP(i, n)
	{
		fill(b, b + 30, 0);
		for (char j = 'a'; j <= 'z'; j++) {
			mp[j] = 0;
		}
		cin >> s;
		REP(j, s.size())
		{
			mp[s[j]]++;
		}
		for (char j = 'a'; j <= 'z'; j++) {
			b[j - 'a'] = mp[j];
		}
		REP(j, 30)
		{
			a[j] = min(a[j], b[j]);
		}
	}

	REP(i, 30)
	{
		if (a[i] != 0) {
			REP(j, a[i])
			{
				c = i + 'a';
				cout << c;
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)

exist = True
if N%2 == 0:
    for i in range(N):
        if A[i] != (i // 2)*2 + 1:
            exist = False
            break
    
    if exist == True:
        ans = 1
        for i in range(N//2):
            ans *= 2
            ans %= 10**9 + 7
        print(ans)
    else:
        print(0)
else:
    for i in range(N):
        if A[i] != ((i + 1) // 2)*2:
            exist = False
            break
    if exist == True:
        ans = 1
        for i in range((N-1)//2):
            ans *= 2
            ans %= 10**9 + 7
        print(ans)
    else:
        print(0)

Measured memory_bytes: 14008
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        string ans = "";
        if(s[0] == s[1])ans = s[2];
        else if(s[1] == s[2])ans = s[0];
        else ans = s[1];
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
	int H,W;
	while(cin>>H>>W){
		if(H==0&&W==0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if((i+j)%2==0){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<endl;
		}
	cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int64_t dp[5001][5001];
int main(){
	while(true){
		int64_t ans=1,bans=1;
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		int64_t a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		for(int j=1;j<=n;j++){
			for(int k=j;k<=n;k++){
				dp[j][k]=dp[j][k-1]+a[k-1];
				if(dp[ans][bans]<dp[j][k]){
					ans=j;
					bans=k;
				}
			}
		}
		cout << dp[ans][bans] << endl;
	}
}
// a[n]={1,2,3,100,200};
// dp[n]={1, 1+2, 1+2+3, 1+2+3+100, 1+2+3+200};



Measured memory_bytes: 50204
N=int(input())
S=input()
V=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            s=""
            a=str(i)
            b=str(j)
            c=str(k)
            s=a+b+c
            V.append(s)
ans=0
for i in range(len(V)):
    v=V[i]
    flag1=False
    flag2=False
    flag3=False
    for j in range(N):
        if not flag1:
            if S[j]==v[0]:
                flag1=True
                continue
        if not flag2:
            if flag1:
                if S[j]==v[1]:
                    flag2=True
                    continue
        if flag2:
            if S[j]==v[2]:
                flag3=True
        if flag3:
            ans+=1
            break
print(ans)

Measured memory_bytes: 42588
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAXOP 100
#define NUMBER '0'

int getop(char []);
void push(double);
double pop(void);

int main(){
  int type;
  double op2;
  char s[MAXOP];

  while((type = getop(s)) != EOF) {
    switch (type) {
    case NUMBER:
      push(atof(s));
      break;
    case '+':
      push(pop() + pop());
      break;
    case '*':
      push(pop() * pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case '/':
      op2 = pop();
      if (op2 != 0.0)
	push(pop() / op2);
      else
	printf("error: zero divisor\n");
      break;
    case '\n':
      printf("%.8g\n", pop());
      break;
    default:
      printf("error: unknown command %s\n", s);
      break;
    }
    if(type=='\n')break;
  }
  return 0;
}

#define MAXVAL 100

int sp = 0;
double val[MAXVAL];

void push(double f){
  if (sp < MAXVAL) val[sp++] = f;
  else printf("error: stack full, can't push %g\n", f);
}

double pop(void){
  if (sp > 0) return val[--sp];
  else {
    printf("error: stack empty\n");
    return 0.0;
  }
}

#include <ctype.h>

int getch(void);
void ungetch(int);

int getop(char s[]){
  int i, c;

  while ((s[0]= c = getch()) == ' ' || c == '\t')
    ;
  s[1] = '\0';
  if (!isdigit(c) && c != '.')
    return c;
  i = 0;
  if (isdigit(c))
    while (isdigit(s[++i] = c = getch()))
      ;
  if (c == '.')
    while (isdigit(s[++i] = c = getch()))
      ;
  s[i] = '\0';
  if (c != EOF)
    ungetch(c);
  return NUMBER;
}

#define BUFSIZE 100

char buf[BUFSIZE];
int bufp =0;

int getch(void){
  return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c){
  if (bufp >= BUFSIZE)
    printf("ungetch: too many characters\n");
  else buf[bufp++] = c;
}



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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e3 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (fat[i-1] * i) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll dp[maxn][3][5];
string s;
int k;


  
ll solve(int pos, bool tight , int cnt)
{

  if(cnt == k)
    return 1;
  if(pos == s.size())
    return 0;
  ll &ans = dp[pos][tight][cnt];
  if(ans != -1)
    return ans;
  ans = 0;
  int qt = tight ? s[pos] - '0' : 9;
  for(int i = 0; i <= qt; i++)
  {
    int newTight = (s[pos] - '0' == i)? tight : 0; 
    ans += solve(pos + 1, newTight, cnt + (i > 0));
  }
  return ans;
}

int main()
{
  ios::sync_with_stdio(false);
  MSET(dp, -1);
  cin >> s;
  cin >> k;
  cout << solve(0,1,0) << endl;
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> A( N );
	for( auto& v: A ) { cin >> v; }

	int64_t result = 1;
	vector<int> x( N );

	for( int i = 0; i < N; ++i ) {
		x[A[i]] += 1;

		if( x[A[i]] >= 3 ) {
			result = 0;
			break;
		}
	}

	if( x[0] != (N&1) ) { result = 0; }

	if( result ) {
		int m = 1000000007;
		for( int i = 0; i < N/2; ++i ) {
			result = result * 2 % m;
		}
	}

	cout << result << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
pair<ll,ll> p[100010];
ll dp[100010];
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		ll x,l; cin >> x >> l;
		p[i] = {x + l,x - l};
	}
	sort(p,p + n);
	ll mx = -100000000000000000;
	int cnt = 0;
	for(i=0;i<n;i++){
		if(p[i].second>=mx){
			cnt++;
			mx = p[i].first;
		}
	}
	cout << cnt << endl;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

void solve(string s) {
  int n = s.size();
  vector<string> st;
  rep (mask, 1 << n) {
    string t = s;
    bool flag = true;
    rep (j, n) {
      if (mask & (1 << j)) {
        if (t[j] == 'z') {
          flag = false;
          break;
        }
        t[j] = t[j] + 1;
      }
    }
    if (!flag) continue;
    string t2 = t;
    int used = 0;
    rep (j, n) {
      if ((used & (1 << (t[j] - 'a'))) == 0) {
        if (t[j] != 'a') {
          t[j] = t[j] - 1;
        }
        used |= (1 << (t2[j] - 'a'));
      }
      if (s[j] != t[j]) {
        flag = false;
        break;
      }
    }
    if (!flag) continue;
    st.push_back(t2);
  }
  cout << st.size() << endl;
  sort(all(st));
  if (st.size() <= 10) {
    for (auto itr = st.begin(); itr != st.end(); itr++) {
      cout << *itr << endl;
    }
  }
  else {
    int cnt = 0;
    rep (i, 5) {
      cout << st[i] << endl;
    }
    rrep (i, 5) {
      cout << st[st.size() - 1 - i] << endl;
    }
  }
      
}

int main() {
  while (true) {
    string s;
    cin >> s;
    if (s == "#") return 0;
    solve(s);
  }
}



Measured memory_bytes: 4080
/// Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int n;
    cin>>n;
    int arr[200005];
    ms(arr);
    for(int i=0;i<n-1;i++){
        int x;
        cin>>x;
        arr[x]++;
    }
    for(int i=1;i<=n;i++)cout << arr[i] << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 4432
n = gets.to_i
dp = Array.new(10) { Array.new(10, 0) }

n.times do |i|
  next if i % 10 == 9

  a = (i + 1).to_s
  dp[a[0].to_i][a[-1].to_i] += 1
end

res = 0
1.step(9) do |a|
  1.step(9) do |b|
    res += dp[a][b] * dp[b][a]
  end
end
puts res

Measured memory_bytes: 14444
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int a[50] = { 0 };
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int t,s;
		cin >> t >> s;
		a[--t]++;
		a[--s]++;
	}

	rep(i, n) {
		cout << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
	int n,i,j,l,ans;
	char s[9],st[2][9],temp;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",s);
		
		strcpy(st[0],s);
		strcpy(st[1],s);
		
		for(j=7;j>0;j--){
			for(l=0;l<j;l++){
				if(st[0][l] < st[0][l+1]){
					temp=st[0][l];
					st[0][l]=st[0][l+1];
					st[0][l+1]=temp;
				}
				if(st[1][l] > st[1][l+1]){
					temp=st[1][l];
					st[1][l]=st[1][l+1];
					st[1][l+1]=temp;
				}
			}
		}
		
		ans=atoi(st[0])-atoi(st[1]);
		
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int a, b;
    cin >> a >> b;
    
    cout << a / b << ' ' << a % b << ' ' << fixed << setprecision(10) << 1.0 * a / b << endl;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int v, e;
int dp[1<<15][15];
int G[15][15];

int dfs(int s, int t){
    // cout << bitset<3>(s) << ": " << t << ": " << dp[s][t] << endl;

    if(dp[s][t]>=0) return dp[s][t];
    
    if(s==(1<<v)-1 && t==0){
        return dp[s][t] = 0;
    } 

    int m = INF;
    // pr(v);
    rep(i, v){
        if(!((s>>i)&1) && G[t][i]!=INF){
            m = min(m, dfs(s|(1<<i), i) + G[t][i]);
        }
    }
    return dp[s][t] = m;
}

int main()
{
    cin >> v >> e;
    rep(i, 15) rep(j, 15) G[i][j] = INF;
    rep(i, 1<<15) rep(j, 15) dp[i][j] = -1;
    rep(i, e){
        int a, b, c;    
        cin >> a >> b >> c;
        G[a][b] = c; 
    }
    // rep(i, v){
    //     if(G[0][i]==INF) continue;
    //     dp[1<<i][i] = G[0][i];
    //     cout << "dp[" << bitset<3>(1<<i) << "][" << i << "]=" << G[0][i] << endl;
    // }
    int ans = dfs(0, 0);
    if(ans==INF) pr(-1);
    else pr(ans);
    return 0;}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  int power;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      power += d[i]*d[j];
    }
  }
  cout << power << endl;
}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int A[3][3];
  cin >> A[0][0] >> A[0][1] >> A[0][2]
      >> A[1][0] >> A[1][1] >> A[1][2]
      >> A[2][0] >> A[2][1] >> A[2][2];
  int N;
  cin >> N;
  for (int n = 0; n < N; n++)
  {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++)
    {
      for (int j = 0; j < 3; j++)
      {
        if (A[i][j] == b)
        {
          A[i][j] = -1;
        }
      }
    }
  }
  cout << ((A[0][0] + A[0][1] + A[0][2] == -3
            || A[1][0] + A[1][1] + A[1][2] == -3
            || A[2][0] + A[2][1] + A[2][2] == -3
            || A[0][0] + A[1][0] + A[2][0] == -3
            || A[0][1] + A[1][1] + A[2][1] == -3
            || A[0][2] + A[1][2] + A[2][2] == -3
            || A[0][0] + A[1][1] + A[2][2] == -3
            || A[2][0] + A[1][1] + A[0][2] == -3)
           ? "Yes" : "No")
       << endl;
  return 0;
}


Measured memory_bytes: 256
# input
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

A = []
a_append = A.append
for i in range(N):
    a = list(map(int, input().split()))
    a_append(a)

success_source_cnt = sum(
    [
        1
        for a in A
        if sum(
            [
                a[i] * B[i]
                for i in range(M)
            ] + [C]
        ) > 0
    ]
)

print(success_source_cnt)

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

using namespace std;

int main()
{
    string s;
    int count=0;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        s[i]-'0';
        if(s[i]==s[i+1])
        {
            count='1';
            break;
        }
    }
    if(count=='1')
    {
        cout<<"Bad";
    }
    else cout<<"Good";
}


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

int main(){
    string s;
    cin >> s;

    int cnt = 0;
    // 奇数
    if(s.length() % 2){
        for(int i = 0; i < (int)s.length() * .5; i++){
            if(s[i] != s[s.length() - 1 - i]) cnt++;
        }
    }
    else{// 偶数
        for(int i = 0; i < (int)s.length() * .5; i++){
            if(s[i] != s[s.length() - 1 - i]) cnt++;
        }
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int a, b, c, d, e, k;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
    if(e-a > k) printf(":(");
    else printf("Yay!");
}

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

int64_t zyo = 1000000007;

int main(){
    int64_t N;
    cin >> N;
    vector<int64_t> A(N,0);
    for (int64_t i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int64_t sum = 0,sum_2 = 0,ans;
    for (int64_t i = 0; i < N; i++){
        sum += A.at(i);
        sum = sum % zyo;
        sum_2 += A.at(i) * A.at(i) % zyo;
        sum_2 = sum_2 % zyo;
    }
    ans = sum*sum%zyo;
    ans -= sum_2;
    if(ans < 0){
        ans += zyo;
    }
    if(ans % 2 == 0){
        ans = ans/2;
    }else{
        ans += zyo;
        ans = ans/2;
    }
    cout << ans << endl;
}

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

int main(){
  std::string s, t;

  while(std::cin >> s >> t){
    int ans = 0;
    for(int i = 0; i < (int)s.size(); ++i){
      if(s[i] != t[i]) ++ans;
    }
    std::cout << ans << "\n";
  }

  return 0;
}


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

using namespace std;
const int MAXN = 105;
int arr[2][MAXN];
int n;

int main(){
	cin >> n;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n; j++){
			cin >> arr[i][j];
		}
	}
	if(n == 1){
		cout << arr[0][0] + arr[1][0];
		return 0;
	}
	for(int i = 1; i < n; i++){
		arr[0][i] += arr[0][i-1];
	}
	for(int i = 0; i < n; i++){
		arr[1][i] = max(arr[0][i]+arr[1][i],arr[1][i-1]+arr[1][i]);
	}
	cout << arr[1][n-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n, k;
    cin >> n >> k;
    double p[n];
    rep(i, n) {
        cin >> p[i];
        p[i] = (p[i] + 1) * p[i] / 2.0 / p[i];
    }
    double rp[n + 1];
    rp[0] = 0;
    rep(i, n) rp[i + 1] = rp[i] + p[i];
    double ans = 0;
    for(int i = 0; i + k < n + 1; i++) chmax(ans, rp[i + k] - rp[i]);
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 3328
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A, B = (int(_) for _ in input().split())
    S = input()
    if S.count('-') != 1:
        print('No')
        return
    before_str, after_str = S.split('-')
    if len(before_str) == A and len(after_str)  ==B:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
def printAnsewer(ans):
    print(ans)


def calc(num) :
    for index, num_for_divide in enumerate(num):
        if int(num_for_divide) % 2 != 0 :
            return False
            break
        num[index] = int(num_for_divide) / 2
    return True

num_of_number = int(input())
num = input().split()

count = 0

while calc(num) == True:
    count += 1


printAnsewer(count)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		
		int cnt = 1;
		while (x * 2 <= y) {
			cnt++;
			x *= 2;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
}


Measured memory_bytes: 23124
// 問題名: Area of Polygon
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0079&
// 所要時間: 25分
// --感想--
// 幾何問題にほとんど触れてこなかったので、勉強になった。
// 入力の個数が与えられない問題も初めて体験した。

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

typedef complex<double> point;

// 内積
double dot(point a, point b) { return (conj(a) * b).real(); }
// 外積(符号付き面積の2倍)
double cross(point a, point b) { return (conj(a) * b).imag(); }

#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)

int main(){
    vector<point> v;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        double x, y;
        cin >> x >> y;
        v.pb(point(x, y));
    }
    double ans = 0;
    for (int i = 0; i + 2 < n;i++)
        ans += cross(v[i + 1] - v[0], v[i + 2] - v[0]) / 2;
    cout << fixed << setprecision(1) << abs(ans) << endl;
}


Measured memory_bytes: 3256
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 2e5 + 5, M = N , mo = 1e9 + 7 ;
const ll inf = 1e17 ;
using namespace std ;

struct poi {
    int l, r, ans ;
} a[N], b[N] ;
multiset <int> S ;
int n, bit[N] ;

bool cmpl(poi a, poi b) {
    return a.l < b.l ;
}

bool cmpr(poi a, poi b) {
    return a.r < b.r ;
}

int solve() {
    rep(i, 0, M - 5) bit[i] = 0 ;
    rep(i, 1, n) ++ bit[a[i].l], -- bit[a[i].r] ;
    rep(i, 1, M - 5) bit[i] += bit[i - 1] ;
    int res = 0 ;
    rep(i, 0, M - 5) res = max(res, bit[i]) ;
    return res ;
}

void put(int x) {
    for ( ; x <= M - 5 ; x += x & (- x)) bit[x] ++ ;
}

int get(int x) {
    int res = 0 ;
    for ( ; x ; x -= x & (- x)) res += bit[x] ;
    return res ;
}

int l[N],r[N];

int SOLVE() {
	rep(i,1,M-5) bit[i]=0;
    sort(a + 1, a + n + 1, cmpl) ;
    rep(i, 1, n) a[i].ans = n ;
    rep(i, 1, n) {
        a[i].ans -= get(a[i].l) ;
        put(a[i].r) ;
    }
    rep(i, 0, M - 5) bit[i] = 0 ;
    sort(a + 1, a + n + 1, cmpr) ;
    for (int i = n ; i; -- i) {
        a[i].ans -= get(M - 5 - a[i].r) ;
        put(M - 5 - a[i].l) ;
    }
    int res = 0 ;
    rep(i, 1, n) res = max(res, a[i].ans) ;
    return res ;
}

int main() {
    scanf("%d", &n) ;
    rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r) ;
    int r=SOLVE();
    printf("%d %d\n", r, solve()) ;
    return 0 ;
}


Measured memory_bytes: 6380
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




typedef long long ll;
#define INF INT_MAX/2
string S; int N;
int dp[201010];
unordered_map<ll, int> dp2;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S; N = S.length();

    ll x = 0;
    dp[0] = 0;
    dp2[0] = 0;
    int ans = 0;
    rep(i, 0, N) {
        x ^= 1LL << (S[i] - 'a');
        
        int ma = INF;
        if (!dp2.count(x)) dp2[x] = INF;
        ma = min(ma, dp2[x]);

        rep(i, 0, 26) {
            ll xx = x ^ (1LL << i);
            if (!dp2.count(xx)) dp2[xx] = INF;
            ma = min(ma, dp2[xx]);
        }

        dp2[x] = min(dp2[x], ma + 1);
        dp[i] = ma + 1;
    }

    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 171116
import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
A = list(map(int, input().split()))

for i in range(N):
	A[i] -= i + 1
A.sort()

med = A[N//2]

ans = 0
for i in range(N):
	ans += abs(A[i] - med)
print(ans)

Measured memory_bytes: 80080
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,m,k=MI()
A=[0]+LI()
B=[0]+LI()
for i in range(1,n+1):
  A[i]+=A[i-1]
for i in range(1,m+1):
  B[i]+=B[i-1]
j=m
ans=0
for i in range(n+1):
  if A[i]>k:
    break
  while A[i]+B[j]>k:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 119692
#include "bits/stdc++.h"
using ll = long long;
using namespace std;

int main() {
	int n;
	ll ans = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	map<int, int> mp;

	for (int i = 0; i < n; i++) {
		int sa = i - a[i];
		ans += mp[sa];
		int wa = i + a[i];
	    mp[wa]++;
	}

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

Measured memory_bytes: 21112
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    ma = 0
    idx = 0
    for i in range(n):
        cur = abs(a[i])
        if cur > ma:
            ma = cur
            idx = i

    if a[idx] == 0:
        print(0)
        sys.exit()

    procedures = []
    for i in range(n):
        a[i] += a[idx]
        procedures.append('{0} {1}'.format(idx+1, i+1))

    if a[idx] > 0:
        for i in range(n-1):
            if a[i] > a[i+1]:
                a[i+1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i+2))
    else:
        for i in range(n-1, 0, -1):
            if a[i] < a[i-1]:
                a[i-1] += a[i]
                procedures.append('{0} {1}'.format(i+1, i))

    procedures = [len(procedures)] + procedures
    return procedures
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 3188
void main(){
	string input;
	input = readln().chomp().dup;
	string ans;
	foreach(elm; input){
		if(elm == 'B'){
			if( ans.length==0 )continue;
			ans.popBack();
		}else{
			ans ~= elm;
		}
	}
	writeln(ans.length==2? ans[$-2..$]: ans[0..$] );
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2600
from collections import deque
import math
n, d, a = map(int, input().split())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
dam = 0
ans = 0
q = deque()
for i in range(n):
    x,h = data[i]
    while q:
        k = q.popleft()
        if k[1] >= x:
            q.appendleft(k)
            break
        else:
            dam -= k[0]
    h -= dam
    h = max(h, 0)
    count = math.ceil(h / a)
    dam += count * a
    q.append([count * a, x + 2*d])
    ans += count
print(ans)



Measured memory_bytes: 107480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans;
  if(a+b>=c*2){
    if(x>=y){
      ans = min(c*x*2,c*y*2+a*(x-y));
    }
    else ans = min(c*y*2,c*x*2+b*(y-x));                                                                         
  }
  else ans = a*x + b*y;
  cout << ans << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  QS_
//
//  Created by ptyuan on 2018/10/30.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
struct Element {
    char c;
    long number;
};

void swap(Element &a, Element &b) {
    Element temp = a;
    a = b;
    b = temp;
}


int partition(Element *A, int p, int r) {
    Element x = A[r];
    int i = p - 1;
    for (int j = p; j <= r - 1; j++) {
        if (A[j].number <= x.number) {
            i++;
            Element temp = A[j];
            A[j] = A[i];
            A[i] = temp;
        }
    }
    A[r] = A[i + 1];
    A[i + 1] = x;
    return i + 1;
}


void qs(Element *A, int left, int right) {
    if (left < right) {
        int mid = partition(A, left, right);
        qs(A, left, mid - 1);
        qs(A, mid + 1, right);
    }
}

const long kMaxValue = 10000000000;
const int kMax = 1000000;


Element L[kMax / 2 + 2];
Element R[kMax / 2 + 2];
int cmpCount = 0;

void _merge(Element *A, int n, int left, int mid, int right) {
    int n1 = mid - left;
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    
    int n2 = right - mid;
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    Element temp;
    temp.number = kMaxValue;
    L[n1] = temp;
    R[n2] = temp;
    int l1 = 0;
    int l2 = 0;
    for (int k = left; k < right; k++) {
        ++cmpCount;
        if (L[l1].number <= R[l2].number) {
            A[k] = L[l1++];
        } else {
            A[k] = R[l2++];
        }
    }
}

void mergeSort(Element *A, int n, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        _merge(A, n, left, mid, right);
    }
}

bool isStable(Element *e1, Element *e2, int n) {
    for (int i = 0; i < n; i++) {
        if (e1[i].c != e2[i].c) {
            return false;
        }
    }
    return true;
}


int main(int argc, const char * argv[]) {
    Element A[100000];
    Element B[100000];
    int n = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        Element temp;
        scanf(" %c", &temp.c);
        scanf("%ld", &temp.number);
        A[i] = temp;
        B[i] = temp;
    }
    qs(A, 0, n - 1);
    mergeSort(B, n, 0, n);
    if (isStable(A, B, n)) {
        printf("Stable");
    } else {
        printf("Not stable");
    }
    printf("\n");
    for (int i = 0; i < n; i++) {
        Element temp = A[i];
        printf("%c %ld\n", temp.c, temp.number);
    }
    
    return 0;
}




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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 高州・橋州に属する街の数がx,y個のとき、題意の道の本数はx(x-1)/2 + y(y-1)/2
// これを最小化するにはなるべく均等に分けた方が良い
// 問題文を言い換えると、補グラフになるべく多くの辺を足して完全二部グラフが作れればいい
// まず初期状態の補グラフが二部グラフじゃなかったら無理
// 二部グラフだったら各連結成分がSとTに分けられ、どっちをどっちの州にするか自由に決められる
// これをなるべく均等に分ければいいから答えを部分和dp?で探す

int n, m, a, b, d[777][777], c[777], s[777], t[777], k, res = inf;
bool u[777], dp[777][777];

bool col(int v, int x) {
	c[v] = x;
	rep(i,n) {
		if (i==v || d[v][i]) continue;
		if (c[i]==x) return 0;
		if (!c[i] && !col(i,-x)) return 0;
	}
	return 1;
}

void rec(int v) {
	u[v] = 1;
	(c[v]==1 ? s : t)[k]++;
	rep(i,n) if (!d[v][i] && !u[i]) rec(i);
}

int main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> a >> b;
		a--, b--;
		d[a][b] = d[b][a] = 1;
	}
	rep(i,n) if (!c[i] && !col(i,1)) return cout << -1, 0;
	rep(i,n) if (!u[i]) rec(i), k++;
	dp[0][0] = 1;
	rep(i,k) rep(j,n) if (dp[i][j]) dp[i+1][j+s[i]] = dp[i+1][j+t[i]] = 1;
	rep(i,n) if (dp[k][i]) chmin(res, i*(i-1)/2 + (n-i)*(n-i-1)/2);
	cout << res;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define sz(x) (int)x.size()
#define db(x) cerr << #x << ": " << x << "\n";

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

    string S, T;
    cin >> S >> T;
    if(sz(T) == sz(S) + 1 && T.substr(0, sz(S)) == S)
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

const ll maxs = 5e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll bit[maxs][26];
ll n;
char a[maxs];

void add(ll ind,ll pos,ll val){
    while(ind <= n ){
        bit[ind][pos] += val;
        ind += ind&-ind;
    }
}

ll get(ll ind,ll pos){
    ll sum=0;
    while(ind){
        sum += bit[ind][pos];
        ind -= ind&-ind;
    }
    return sum;
}

void solve(){
    cin >> n;
    for(ll i=1;i<=n;i++){
        cin >> a[i];
        add(i,a[i]-'a',1);
    }    
    ll q;
    cin >> q;
    while(q--){
        ll ty;
        cin >> ty;
        if(ty==2){
            ll l,r;
            cin >> l >> r;
            ll ans=0;
            for(ll i=0;i<26;i++){
                ll cnt = get(r,i) - get(l-1,i);
                if(cnt) 
                    ans++;
            }
            cout << ans << endl;
        }else{
            ll i;
            char ch;
            cin >> i >> ch;
            add(i,a[i]-'a',-1);
            a[i] = ch;
            add(i,a[i]-'a',1);
        }
    }
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 102400
from collections import Counter
x,n = map(int,input().split())
p = list(map(int,input().split()))
 
num_list = list(range(0,102))
y = (num_list + p)
 
counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]
 

ans = 10 *100000000000
 
for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

Measured memory_bytes: 9424