akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mod 1000000007
vector<vector<int> > dp(3001,vector<int> (3001,-1));
string s,t;int siz;
vector<char> ans;
int lcs(int i,int j)
{
     if(i<0 || j<0)
     return 0;
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    if(s[i]==t[j])
       {
        return dp[i][j] = 1 + lcs(i-1,j-1);

       }
    return dp[i][j]= max(lcs(i-1,j),lcs(i,j-1));


}
void st(int i,int j)
{
      if(i== 0 && j == 0 )
        {
            if(s[i]==t[j])
                {   if(siz>ans.size())
                    ans.pb(s[i]);
                }
            return;
        }
      if(i==0)
        {    if(s[i]==t[j])
            {
                if(siz > ans.size())
                    ans.pb(s[i]);
            }
            return st(i,j-1);

        }
        if(j == 0)
        {
            if(s[i]==t[j])
            {
                if(siz > ans.size())
                    ans.pb(s[i]);
            }
            return st(i-1,j);
        }
        if(s[i]==t[j])
        {
            ans.pb(s[i]);
            return st(i-1,j-1);
        }
        if(dp[i-1][j]>dp[i][j-1])
        {  return st(i-1,j);

        }
        else
        {
            return st(i,j-1);
        }
}
int main() {
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        cin>>s>>t;
        if(s[0]==t[0])
        {
            dp[0][0]=1;

        }
        else
        {
          dp[0][0]=0;
        }
         siz =  lcs(s.size()-1,t.size()-1);

         st(s.size()-1,t.size()-1);
         /*for(int i=0;i<s.size();i++)
         {
             for(int j=0;j<t.size();j++)
             {
                 cout<<dp[i][j]<<"  ";
             }
             cout<<endl;
         }*/
         for(int i=ans.size()-1;i>=0;i--)
            cout<<ans[i];





}


Measured memory_bytes: 37888
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var k = o.a();
  var a = o.l().map(a=>a-1);
  var b = Array(n+1);
  b[0] = 0;
  for(var i = 0; i < n; i++){
    b[i+1] = (b[i]+a[i])%k;
  }
  var ans = 0;
  var c = {};
  for(var i = 0; i <= n; i++){
    if(k <= i)c[b[i-k]]--;
    if(c[b[i]])ans += c[b[i]]++;
    else c[b[i]] = 1;
  }
  return ans;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll h,w;cin>>h>>w;
    if(h%3==0||w%3==0){
        cout<<0<<endl;
    }
    else if(h%2!=0&&w%2!=0){
        ll m=min(h,w),M=max(h,w);
        ll d=min(h,w);
        for(int i=1;i<=M;++i){
            ll MS=max({m*i,(m/2)*(M-i),(m/2+1)*(M-i)});
            ll ms=min({m*i,(m/2)*(M-i),(m/2+1)*(M-i)});
            d=min(d,(MS-ms));
        }
        for(int i=1;i<=m;++i){
            ll MS=max({M*i,(M/2)*(m-i),(M/2+1)*(m-i)});
            ll ms=min({M*i,(M/2)*(m-i),(M/2+1)*(m-i)});
            d=min(d,(MS-ms));
        }
        cout<<d<<endl;
    }
    else{
        ll ans=min(h,w);
        if(h%2==0){
            ll d=1e18;
            for(int i=1;i<=w;++i){
                ll MS=max({h*i,(h/2)*(w-i),(h/2)*(w-i)});
                ll ms=min({h*i,(h/2)*(w-i),(h/2)*(w-i)});
                d=min(d,(MS-ms));
            }
            ans=min(ans,d);
        }
        if(w%2==0){
            ll d=1e18;
            for(int i=1;i<=h;++i){
                ll MS=max({w*i,(w/2)*(h-i),(w/2)*(h-i)});
                ll ms=min({w*i,(w/2)*(h-i),(w/2)*(h-i)});
                d=min(d,(MS-ms));
            }
            ans=min(ans,d);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

bool other;
bool vis[5000];
vector<int> win[5000], lose[5000], ord;
int depth[5000];

void dfs(int v)
{
	vis[v] = true;
	for (int i = 0; i < win[v].size(); i++){
		if (!vis[win[v][i]]) dfs(win[v][i]);
	}
	ord.push_back(v);
}

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		win[--a].push_back(--b);
		lose[b].push_back(a);
	}
	
	int cnt = 0;
	memset(depth, 0, sizeof(depth));
	for (int i = 0; i < n; i++){
		if (lose[i].size() == 0) dfs(i);
	}
	
	for (int i = n - 1; i >= 0; i--){
		printf("%d\n", ord[i] + 1);
		if (i){
			bool ok = true;
			for (int j = 0; j < win[ord[i]].size(); j++)
				if (win[ord[i]][j] == ord[i - 1]) ok = false;
			other |= ok;
		}
	}
	printf("%d\n", other);
	
	return (0);
}

Measured memory_bytes: 2792
N = int(input())
S = input().split()
S.sort()
ans = 1
#float
for i in range(N):
    A = int(S[i])
    if(A==0):
        ans = 0
        break
    else:
        ans *= A
    if ans>1000000000000000000:
        ans = -1
        break
print (ans)

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

int main() {
  int N;
  cin >> N;
  int c[N], s[N], f[N];
  for (int i = 0; i < N - 1; i++) cin >> c[i] >> s[i] >> f[i];

  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N - 1; j++) {
      if (t < s[j]) t = s[j];
      else if (t % f[j] == 0);
      else t = t + f[j] - t % f[j];
      t+=c[j];
    }
    cout << t << endl;
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int N = sc.nextInt();
        int m = (int)Math.pow(100, D);
        int counter = 0;
        int res = 0;
        while (counter != N) {
            res += m;
            if (res % (m * 100) == 0) {
                continue;
            }
            counter++;
        }
        System.out.println(res);
        sc.close();
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <map>

using namespace std;

int main () {
    int N;
    cin >> N;
    map<int, int> freq;
    for (int i = 0; i < N; i++) {
        int n;
        cin >> n;
        if (freq.count(n) == 0) {
            freq[n] = 1;
        } else {
            freq[n]++;
        }
    }
    cout << freq.size() << endl;
}


Measured memory_bytes: 256
from collections import deque

A = deque(list(input()))
B = deque(list(input()))
C = deque(list(input()))

tmp = A.popleft()
while True:
    if tmp == 'a':
        if len(A) == 0:
            print('A')
            break
        else:
            tmp = A.popleft()

    elif tmp == 'b':
        if len(B) == 0:
            print('B')
            break
        else:
            tmp = B.popleft()

    else:
        if len(C) == 0:
            print('C')
            break
        else:
            tmp = C.popleft()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        if(n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int x,a,b,ans;
    cin>>x>>a>>b;
    ans=x-a;
    while(ans>=b)ans=ans-b;
    cout<<ans<<endl;
}

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

int main(){
	int H, W;
	char S[26][26][6];
	int i, j;
	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++)
		for (j = 0; j < W; j++){
			scanf("%s", S[i][j]);
			if (!strcmp(S[i][j], "snuke")){
				printf("%c%d\n", 'A' + j, i + 1);
				return 0;
			}
		}
	return -1;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Powerful Discount Tickets
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  priority_queue<int> q;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    q.push(ai);
  }

  while (! q.empty() && m--) {
    int ai = q.top(); q.pop();
    ai >>= 1;
    if (ai > 0) q.push(ai);
  }

  ll sum = 0;
  while (! q.empty()) {
    sum += q.top(); q.pop();
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

string m;
int n;
int a=0;
int s=0;
int o=0;
int p=0;

int main()
{
	cin>>n;
    for(int i=0;i<n;i++)
	{
	int f=0;
	p=0;
	o=0;
	
	while(true)
	{
	cin>>m;
	
	if(m=="OUT")o++;
	
	if(o==3)break;
	
	if(m=="HIT")
	{
	
	if(f==3)p++;
	if(f==2)f++;
	if(f==1)f++;
	if(f==0)f++;
	}//HIT

	if(m=="HOMERUN")
	{
	if(f==0){p=p+1;}
	if(f==1)
	{
	p=p+2;
	f=0;
	}
	if(f==2)
	{
	p=p+3;
	f=0;
	}
	if(f==3)
	{
	p=p+4;
	f=0;
	}
	}//HOMERUN


	}
	 cout<<p<<endl;

	
	
	


	}


	return 0;
}

Measured memory_bytes: 1208
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    
    for c in s.chars() {
        let x = match c {
            t @ 'a'...'z' => t.to_uppercase().to_string(),
            t @ 'A'...'Z' => t.to_lowercase().to_string(),
            t => t.to_string(),
        };

        print!("{}", x);
    }
}



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

int A, B, C, K;

int main()
{
	scanf("%d%d%d%d", &A, &B, &C, &K);
	printf("%d\n", max({A, B, C}) * ((1 << K) - 1) + (A + B + C));
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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

const int N = (int)1e6;

int main() {
  ll n;
  cin >> n;
  int c[N];
  rep(i,N) c[i] = 0;
  
  rep(i,N) {
    while(i >= 2 && n % i == 0) {
      n = n / i;
      c[i]++;
    }
  }
  
  int s = 0;
  if(n != 1) s += 1;
  rep(i,N) {
    int j = 0;
    for(; c[i] >= j * (j + 1) / 2; j++);
    s += j - 1;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    rep(i, 0, n) {
        if (i == k-1) {
            if (s[i] == 'A') cout << 'a';
            if (s[i] == 'B') cout << 'b';
            if (s[i] == 'C') cout << 'c';
        }
        else cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]

A.sort()

X = deque(A.copy())

B = deque([X.pop()])
flg = True
while X:
    if flg:
        B.append(X.popleft())
        if X:
            B.appendleft(X.popleft())
    else:
        B.append(X.pop())
        if X:
            B.appendleft(X.pop())
    flg = not flg

X = deque(A.copy())
C = deque([X.popleft()])
flg = True
while X:
    if flg:
        C.append(X.pop())
        if X:
            C.appendleft(X.pop())
    else:
        C.append(X.popleft())
        if X:
            C.appendleft(X.popleft())
    flg = not flg

print(max(sum([abs(B[i]-B[i-1]) for i in range(1,N)]), sum([abs(C[i]-C[i-1]) for i in range(1,N)])))

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

int main(){
    long long int n;
    int k;
    scanf("%lld %d",&n,&k);
    long long int keta = 1;
    while(n / k > 0){
        n /= k;
        keta++;
    }
    printf("%lld",keta);
    return 0;
}


Measured memory_bytes: 128
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\A'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:
    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index - 1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class A(Common):

    def resolve(self):

        r = int(self.input_data())
        print(str(3*r*r))


solver = A(REL_PATH)
solver.exec_resolve()


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

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ll;
typedef pair<uint, uint> Pos;

static const uint m_max = 500;
static const uint mod = 1000000007;

// bool m[m_max+2][m_max+2];
// uint c[m_max+2][m_max+2];

const uint dx[] = { 2, 1, 0, 1 };
const uint dy[] = { 1, 2, 1, 0 };

int a[2];
int b[2];
int c[2];

int main(int, char**)
{
	int n;
	cin >> n;

	a[1] = b[1] = c[1];
	int i;
	for (i = 0; i < n; i++) {
		int x, y, z;
		cin >> x >> y >> z;

		a[i%2] = x + max(b[(i+1)%2], c[(i+1)%2]); 
		b[i%2] = y + max(a[(i+1)%2], c[(i+1)%2]); 
		c[i%2] = z + max(a[(i+1)%2], b[(i+1)%2]); 
       //  cerr << a[i%2] << " " << b[i%2] << " " << c[i%2] << "\n";
	}

	int ans = max(a[(n-1)%2], b[(n-1)%2]);
	cout << max(ans, c[(n-1)%2]) << endl;

	return 0;
}



Measured memory_bytes: 384
N=1000000
n=int(N**0.5)
prime=[True for i in range(N)]
prime[0],prime[1]=False,False
for i in range(4,N,2):
    prime[i]=False
for i in range(3,n,2):
    if prime[i]==True:
        for j in range(i*2,N,i):
            prime[j]=False
prime_number=[i for i,j in enumerate(prime) if j==True]
while 1:
    try:
        number=int(input())
        count=0
        for i in prime_number:
            if number<i:break
            else:count +=1
        print(count)
    except:break


Measured memory_bytes: 16644
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;
  if(A%2==0 && B%2==0) {
    cout << (A+B)/2 << endl;
  }
  else if(A%2==1 && B%2==1) {
    cout << (A+B)/2 << endl;
  } 
  else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (b + min(c - 1, a + b) + 1) << endl;
    return 0;
}

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

#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define pb  push_back
#define clr(a, n) memset(a, n, sizeof a)

typedef vector<int> vi;
typedef long long ll;
const int mod = 1e9+7;
const int N = 3e5 + 9;
const int MAXNODES = 1e5+9;



int main() {

	ll h;
	cin >> h;
	ll ans = 1, pos = 1;
	while(h > 1) {
		h /= 2;
		ans += pow(2, pos);
		pos++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();

        if(a==b&&b==c){
            System.out.println("No");
        }
        else if(a==b){
            System.out.println("Yes");
        }
        else if(b==c){
            System.out.println("Yes");
        }
        else if(c==a){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        sc.close();
    }
}

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

using namespace std;


int main(){
    int k;
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> k;
    cout << arr[k-1] << "\n";
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)
	var b = make([]int, m)
	var a = make([][]int, n)

	for i := range b {
		fmt.Scan(&b[i])
	}
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		temp := 0
		for j := 0; j < m; j++ {
			temp += a[i][j] * b[j]
			if j == m-1 {
				temp += c
				if temp > 0 {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}

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

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    if (A <= B) {
        cout << 0 << endl;
    } else if (A < 2 * B) {
        cout << 0 << endl;
    } else {
        cout << A - B - B << endl;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   ll x;
   cin>>x;
   
   if(x>29)
        cout<<"Yes\n";
   else cout<<"No\n";        
   
   
   return 0;        
}  
  
          
   

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

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] sortedArr = new int[n];

		for (int i = 0; i < n; i++) {
			sortedArr[i] = s.nextInt();
		}

		int[]originArr=sortedArr.clone();
		Arrays.sort(sortedArr);

		int firstNum=sortedArr[(n/2)-1];
		int secondNum=sortedArr[n/2];

		for(int j=0;j<n;j++){
			if(originArr[j]<secondNum){
				System.out.println(secondNum);
			}
			else{
				System.out.println(firstNum);
			}
		}

	}
}


Measured memory_bytes: 91072
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

const int mod = 1000000007;
class mint {
  long long x;

 public:
  mint(long long n = 0) : x((n % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};

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

  mint tenn = ((mint)10).pow(n);
  mint ninen = ((mint)9).pow(n);
  mint eightn = ((mint)8).pow(n);

  mint ret = tenn - ninen * 2 + eightn;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3604
# N, L = 3, 3
# SRR = [
#     "dxx",
#     "axx",
#     "cxx"
# ]

N, L = map(int,input().split())
SRR = []

for i in range(N):
    SRR.append(input())


srr2 = sorted(SRR)


result = "".join(srr2)

print(result)




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

int main() {
  ll n;
  cin >> n;
  string ans;
  while (n > 0) {
    n--;
    ans.push_back(char((n % 26LL) + 'a'));
    n /= 26LL;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ss = input()

    N2 = 2*N
    LRs = [0] * N2
    numL = 0
    for i, S in enumerate(Ss):
        if numL == 0:
            if S == 'W':
                return 0
            LRs[i] = 'L'
            numL += 1
        else:
            if S == 'W':
                if numL % 2:
                    LRs[i] = 'L'
                    numL += 1
                else:
                    LRs[i] = 'R'
                    numL -= 1
            else:
                if numL % 2:
                    LRs[i] = 'R'
                    numL -= 1
                else:
                    LRs[i] = 'L'
                    numL += 1
#    print(LRs)

    ans = 1
    numL = 0
    for LR in LRs:
        if LR == 'L':
            numL += 1
        else:
            if numL <= 0:
                return 0
            ans *= numL
            ans %= MOD
            numL -= 1
#    print(ans)

    if numL != 0:
        return 0

    fact = 1
    for i in range(1, N+1):
        fact = (fact*i) % MOD

    return ans*fact%MOD


ans = solve()
print(ans)


Measured memory_bytes: 4968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    int ans = 0;
    rep(i, 0, n) {
        if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
            ans += 2;
        } else if (a[i] == b[i] && b[i]== c[i]) {
            continue;
        } else {
            ans++;
        }
    }

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


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def readInt():
    return int(input())

def readList():
    return list(input().split())

def readListI():
    return list(map(int, input().split()))

def check(s, x_from, x_to):
    for x in range(x_from, x_to):
        can_jump = False
        for dx in range(0, 2):
            if s[x+dx] == '.':
                can_jump = True
                break
        if not can_jump:
            return False
    return True


def main():
    n, a, b, c, d = readListI()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    s = input()

    if c > d:
        # 抜く必要があり、...がb-1<=x<=dにないといけないのでその判定をする
        can_swap = False
        for x in range(b-1, d):
            can_swap_here = True
            for dx in range(0, 3):
                if s[x+dx] == '#':
                    can_swap_here = False
                    break
            if can_swap_here:
                can_swap = True
                break
        if not can_swap:
            print("No")
            return

    # それぞれがたどりつけるか (##がないか) を調べれば良い
    if not check(s, a, c):
        print("No")
        return
    if not check(s, b, d):
        print("No")
        return
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
// 16:12 from

int main(){
//the biggest power of 2 that doesnot exceed n
	ll h;
	cin>>h;
	ll b=1;
	while(2*b<=h) b*=2;
	cout<<2*b-1;

}
// int h;
// 	cin>>h;
// 	vector<int> dp(h+1);
// 	dp[0]=0;
// 	dp[1]=1;
// 	for(int i=2;i<=h;i++){
// 		dp[i]=1+2*dp[i/2];
// 	}
// 	cout<<dp[h];
// 	return 0;

// #include <bit>
// This containe __builtin
// look at the video from 16:12

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

int pownew(int m, int n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int inf=100000000;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int p,q,r; cin>>p>>q>>r;
    cout<<min({p+q,q+r,r+p})<<endl;

    return  0;
}


Measured memory_bytes: 892
class Dijkstra():
    """ ダイクストラ法
    重み付きグラフにおける単一始点最短路アルゴリズム

    * 使用条件
        - 負のコストがないこと
        - 有向グラフ、無向グラフともにOK

    * 計算量はO(E*log(V))

    * ベルマンフォード法より高速なので、負のコストがないならばこちらを使うとよい
    """
    class Edge():
        """ 重み付き有向辺 """
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        """ 重み付き有向辺
        無向辺を表現したいときは、_fromと_toを逆にした有向辺を加えればよい

        Args:
            V(int): 頂点の数
        """
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数

    @property
    def E(self):
        """ 辺数
        無向グラフのときは、辺数は有向グラフの倍になる
        """
        return self._E

    @property
    def V(self):
        """ 頂点数 """
        return self._V

    def add(self, _from, _to, _cost):
        """ 2頂点と、辺のコストを追加する """
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        """ 始点sから頂点iまでの最短路を格納したリストを返す
        Args:
            s(int): 始点s
        Returns:
            d(list): d[i] := 始点sから頂点iまでの最短コストを格納したリスト。
                     到達不可の場合、値はfloat("inf")
        """
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [float("inf")] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
        return d

N,M,S=map(int,input().split())
pro=Dijkstra(N*5001)
for i in range(0,M):
    u,v,a,b=map(int,input().split())
    for j in range(a,5001):
        pro.add(N*j+u-1,N*(j-a)+v-1,b)
        pro.add(N*j+v-1,N*(j-a)+u-1,b)

for i in range(0,N):
    c,d=map(int,input().split())
    for j in range(0,5000):
        to=min(5000,j+c)
        pro.add(N*j+i,N*to+i,d)

S=min(5000,S)
ans=pro.shortest_path(N*S)
for i in range(1,N):
    p=float("inf")
    for j in range(0,5001):
        p=min(p,ans[N*j+i])
    print(p)

Measured memory_bytes: 241672
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];

    ll ans = 0;
    ll sum = 0;
    int right = 0; 
    REP(left, n) {
        while(right < n && (sum ^ a[right]) == sum + a[right]) {
            sum += a[right];
            right++;
        }
        ans += right - left;
        // if(left == right) right++; 
        sum -= a[left];
    }

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


Measured memory_bytes: 1024
import math
 
R,G,B,N = map(int,input().split())
 
maxRBox = math.ceil(3000/R)
maxGBox = math.ceil(3000/G)
maxBBox = math.ceil(3000/B)
 
ans = 0
for ri in range(maxRBox+1):
	if N < ri*R:
		break
	for gi in range(maxGBox+1):
		if N < ri*R+gi*G:
			break
			
		if (N - (ri*R+gi*G)) % B == 0:
			bi = (N - (ri*R+gi*G)) // B
			if ri*R+gi*G+bi*B == N:
				ans +=1
				#print(ri,gi,bi,ri*R+gi*G+bi*B)
				
print(ans)

Measured memory_bytes: 40684
import java.io.*;

class Main {
	public static void main(String[] args){
		double r, m, l;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String buf = br.readLine();
			
			m = 0; 
			l = 0;
			r = Double.parseDouble(buf);
			m = Math.PI*r*r;
			l = 2*Math.PI*r;
			
		System.out.printf("%f %f\n", m, l);			
		}catch(Exception e){
		}
	}
}

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

int main() {

	ll n; cin >> n;
	vector<ll> c(n - 1), s(n - 1), f(n - 1);
	for (ll i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}

	for (ll start = 0; start < n - 1; start++) {
		ll ans = 0;
		ans += s[start];
		ans += c[start];
		for (ll i = start + 1; i < n - 1; i++) {			
			ll mod = ans % f[i];
			if (mod != 0) {
				ll diff = f[i] - mod;
				ans += diff;
			}			
			if (!(s[i] <= ans)) ans = s[i];
			ans += c[i];
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
char a;
char c[]={'a','e','o','u','i'};
cin>>a;
for (int i=0;i<5;i++)
    if (a==c[i]){
        cout<<"vowel";
        return 0;}
cout<<"consonant";
return 0;
}

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

void rotate(char* s, int d)
{
    int i, n=strlen(s);
    if (d>0) {
        char t=s[n-1];
        for(i=n-1;i>0;--i) s[i]=s[i-1];
        s[0]=t;
    }
    else if (d<0) {
        char t=s[0];
        for(i=0;i<n-1;++i) s[i]=s[i+1];
        s[n-1]=t;
    }
}

void swap(char* s)
{
    char t[32];
    int n=strlen(s);
    strncpy(t, s, n/2);
    strncpy(s, s+(n+1)/2, n/2);
    strncpy(s+(n+1)/2, t, n/2);
}

void reverse(char* s)
{
    int i, n=strlen(s);
    for(i=0;i<n/2;++i) {
        char t=s[i];
        s[i]=s[n-1-i];
        s[n-1-i]=t;
    }
}

void increment(char* s, int d)
{
    int i, n=strlen(s);
    for(i=0;i<n;++i) if (isdigit(s[i]))
        s[i]=(s[i]-'0'+d+10)%10+'0';
}

int main(void)
{
    int n;
    scanf("%d", &n);
    while (n--) {
        char order[32], message[32];
        int i;
        scanf("%s%s", order, message);
        reverse(order);
        for(i=0;order[i];++i) {
            switch (order[i]) {
                case 'J': rotate(message, 1); break;
                case 'C': rotate(message, -1); break;
                case 'E': swap(message); break;
                case 'A': reverse(message); break;
                case 'P': increment(message, -1); break;
                case 'M': increment(message, 1); break;
            }
        }
        puts(message);
    }
    return 0;
}

Measured memory_bytes: 600
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H = INT()
W = INT()
N = INT()
c = 0
ans = 0
while N > c:
    c += max(H, W)
    ans += 1
print(ans)

Measured memory_bytes: 5944
package main
import "fmt"

func main(){

        var N int
        fmt.Scan( &N )

	ret := 0.0

        for i := 0; i < N; i ++ {
                var v int
                fmt.Scan( &v )
		ret += 1/float64( v )
	}

        fmt.Println( 1/ret )
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>

struct E {
  int t,x,y;
};
int main()
{
  int N;
  std::cin >> N;
  std::vector<E> v;
  v.push_back(E{0,0,0});
  for (int i=0; i<N; ++i) {
    int t, x, y;
    std::cin >> t >> x >> y;
    v.push_back(E{t,x,y});
  }
  for (int i=0; i<N; ++i) {
    for (int j=i+1; j<i+2; ++j) {
      if (std::abs(v[j].x - v[i].x) + std::abs(v[j].y - v[i].y) > v[j].t - v[i].t) {
        std::cout << "No" << std::endl; return 0;
      }
      if ((std::abs(v[j].x - v[i].x) + std::abs(v[j].y - v[i].y)) % 2 !=
          (v[j].t - v[i].t) % 2) {
        std::cout << "No" << std::endl; return 0;
      }
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 1912
X=int(input())
if   X >= 400 and X< 600:
    print(8)
elif X >= 600 and X< 800:
    print(7)
elif X >= 800  and X<1000:
    print(6)
elif X >= 1000 and X<1200:
    print(5)
elif X >= 1200 and X<1400:
    print(4)
elif X >= 1400 and X<1600:
    print(3)
elif X >= 1600 and X<1800:
    print(2)
elif X >= 1800 and X<2000:
    print(1)

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

int main(){
  int N,M; cin>>N>>M;
  intmax_t ans;
  if(N==1){
    if(M==1){
      ans = 1;
    }else{
      ans = M-2;
    }
  }else if(M==1){
    ans = N-2;
  }else{
    ans = N-2;
    ans *= M-2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
double tag;
double n,m;
ll ans;
ll num;
double a[1000010];
int main(){
	cin>>n>>m;
	tag=1.0/(m*4.0);
	f(i,1,n){
		cin>>a[i];
		num+=a[i];
	}
	tag*=num;
	f(i,1,n){
		if(a[i]>=tag)ans++;
		if(ans>=m){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<=(int)(b);++i)
#define per(i, a, b) for(int i=(a);i>=(int)(b);--i)
#define debug(x)   cout << #x << ' ' << x << endl;
#define one(x) __builtin_popcount(x)
using namespace std;

int a[233333];
int main(){
    int n;
    cin >> n;
    rep(i, 1, n)    cin >> a[i];
    rep(i, 2, n){
        if(a[i] > a[i-1])   a[i]--;
    }
    bool flag = 1;
    rep(i, 2, n){
        if(a[i] < a[i-1])   flag = 0;
    }
    if(flag)    cout << "Yes" << endl;
    else    cout << "No" << endl;
    return 0;
}

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

int main(){
	int cards[4][14],n,t,num;
	char c,ws[5]="SHCD";
	memset(cards,0,sizeof(cards));
	scanf("%d",&n);
 	while(n--){
	scanf("%*c%c",&c);
 		scanf("%d",&num);
		if(c=='S')t=0;
		if(c=='H')t=1;
		if(c=='C')t=2;
		if(c=='D')t=3;
 		cards[t][num]=1;
	}
 	for(int i=0;i<4;i++){
		for(int j=1;j<=13;j++)if(cards[i][j]==0)printf("%c %d\n",ws[i],j);
	}
}



Measured memory_bytes: 2092
import Data.List
main = getLine >>= main' . map read . words
    where
        main' (w : h : _) = getContents >>= print . calc . solve (0, w, 0, h) . map (map read . words) . lines
        solve = foldl' ff
        ff (x1, x2, y1, y2) (x : y : a : _)
            | a == 1 = (max x1 x, x2, y1, y2)
            | a == 2 = (x1, min x x2, y1, y2)
            | a == 3 = (x1, x2, max y1 y, y2)
            | otherwise = (x1, x2, y1, min y y2)
        calc (x1, x2, y1, y2)
            | x1 < x2 && y1 < y2 = (x2 - x1) * (y2 - y1)
            | otherwise = 0


Measured memory_bytes: 1020
#include <iostream>

using namespace std;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    int L = A % K;
    if(L == 0 || ((A/K)*K+ K) <= B){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, w;

    while (cin >> n >> w && n) {
        double h[11] = {};
        while (n--){
            int v;
            cin >> v;
            h[v/w]++;
        }
        double ma = 0;
        REP(i,11){
            ma = fmax(ma, h[i]);
            if (h[i] > 0) n = i;
        }
        double ans = 0.01;
        REP(i,11) ans += h[i]/ma * (1.0 - 1.0*i/n);
        printf("%.10f\n", ans);
    }

    return 0;
}

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

const int N=1e6;

char Istr[N+3];
int Ncnt[3],posA[N+3];
int n,Nn;
stack< pair<int,int> > Smod;

void fSwap(int Ca,int Cb){
	swap(Ncnt[Ca],Ncnt[Cb]);
	for(int i=1;i<=n;i++)
		if(Istr[i]=='A'+Ca) Istr[i]='A'+Cb;
		else if(Istr[i]=='A'+Cb) Istr[i]='A'+Ca;
}
void SurA(){
	int Ctb=0,Ctc=0,Cta=0;
	for(int i=1;i<=n;i++)
		if(Istr[i]=='A')
			posA[++Cta]=i;
	posA[++Cta]=n+1;
	for(int i=1;i<=Cta;i++){
		bool Bb=false;
		for(int j=posA[i-1]+1;j<=posA[i]-1;j++)
			Bb|=Istr[j]=='B';
		Ctb+=Bb;
	}
	Cta--;
	for(int i=1;i<=Cta-1;i++)
		if(posA[i]+1==posA[i+1]-1 && Istr[posA[i]+1]=='C')
			Ctc++;
	int Vmor=Ctc-Ctb;
	Nn=n;n=0;
	for(int i=1;i<=Nn;i++)
		if(Istr[i]=='A')
			if(Vmor>0 && n>=2 && Istr[n]=='C' && Istr[n-1]=='A') Vmor--;
			else Istr[++n]=Istr[i];
		else
			if(Istr[n]!=Istr[i]) Istr[++n]=Istr[i];
	if(Vmor>0) exit(0);
}
void DelC(){
	int Vdel=0;
	for(int i=1;i<=n;i++){
		if(Istr[i]=='C') Vdel++;
		if(Istr[i]=='B') Vdel--;
	}
	if(Vdel<0) exit(0);
	Nn=n;n=0;Istr[Nn+1]='-';
	for(int i=1;i<=Nn;i++)
		if(Istr[i]=='C')
			if(Vdel && (!n || Istr[n]!=Istr[i+1])) Vdel--;
			else Istr[++n]=Istr[i];
		else Istr[++n]=Istr[i];
	if(Vdel) exit(0);
}
void DelBC(){
	int Cta=0,Ctb=0,Ctc=0;
	for(int i=1;i<=n;i++){
		if(Istr[i]=='A') Cta++;
		if(Istr[i]=='B') Ctb++;
		if(Istr[i]=='C') Ctc++;
	}
	if(Ctb<Cta) exit(0);
	int Nn=n;n=0;Istr[Nn+1]='-';
	for(int i=1;i<=Nn;i++)
		if(Istr[i]=='A') Istr[++n]=Istr[i];
		else if(Ctb>Cta && n && ((Istr[n]=='B' && Istr[i]=='C') || (Istr[n]=='C' && Istr[i]=='B')) && Istr[i+1]!=Istr[n-1])
			Ctb--,n--;
		else Istr[++n]=Istr[i];
	Istr[n+1]='\0';
}
int main(){
	scanf("%s",Istr+1);
	Nn=strlen(Istr+1);n=0;
	for(int i=1;i<=Nn;i++)
		if(Istr[n]!=Istr[i]){
			Istr[++n]=Istr[i];
			Ncnt[Istr[i]-'A']++;
		} 
	Istr[Nn+1]=0;
	if(Ncnt[0]>Ncnt[1]) fSwap(0,1),Smod.push(make_pair(0,1));
	if(Ncnt[1]>Ncnt[2]) fSwap(1,2),Smod.push(make_pair(1,2));
	if(Ncnt[0]>Ncnt[1]) fSwap(0,1),Smod.push(make_pair(0,1));
	if(!Ncnt[0]) exit(0);
	SurA();DelC();DelBC();
	while(!Smod.empty()){
		fSwap(Smod.top().first,Smod.top().second);
		Smod.pop();
	}
	printf("%s\n",Istr+1);
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  rep(i, sz(s)) if (s[i] != t[i]) cnt++;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3848
/* ***********************************************
Author        :yang12138
Created Time  :2017年12月11日 星期一 16时14分35秒
File Name     :E.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;
const int mod=1e9+7;

struct Edge{
	int to,nex;
}e[N];

int head[N],cnt;
void add_edge(int u,int v){
	e[cnt].to=v,e[cnt].nex=head[u],head[u]=cnt++;
}

deque<int>dp[3][N];
int md,num[N];
void dfs(int u,int d){
	md=max(md,d);
	num[d]++;

	int sz=0;
	for(int i=head[u];~i;i=e[i].nex){
		int v=e[i].to;
		dfs(v,d+1);

		if(dp[0][v].size()>dp[0][u].size()){
			for(int j=0;j<3;j++) swap(dp[j][v],dp[j][u]);
		}

		int s=dp[0][v].size();
		sz=max(sz,s);

		for(int j=0;j<s;j++){
			ll tmp[3]={};
			for(int a=0;a<3;a++){
				for(int b=0;b<3;b++){
					int c=min(2,a+b);
					tmp[c]+=1LL*dp[a][v][j]*dp[b][u][j];
					tmp[c]%=mod;
				}
			}
			for(int k=0;k<3;k++) dp[k][u][j]=tmp[k];
		}
		for(int j=0;j<3;j++){
			deque<int>tmp;
			dp[j][v].swap(tmp);
		}
	}

	dp[0][u].push_front(1);
	dp[1][u].push_front(1);
	dp[2][u].push_front(0);

	for(int i=0;i<=sz;i++){
		dp[0][u][i]=(dp[0][u][i]+dp[2][u][i])%mod;
		dp[2][u][i]=0;
	}
}

ll pw[N];
void solve(){
	mem(head,-1),cnt=0;

	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int f;
		scanf("%d",&f);
		add_edge(f,i);
	}

	dfs(0,0);
	pw[0]=1;
	for(int i=1;i<N;i++) pw[i]=pw[i-1]*2%mod;

	ll ans=0;
	for(int i=0;i<=md;i++){
		ans+=dp[1][0][i]*pw[n+1-num[i]];
		ans%=mod;
	}
	printf("%lld\n",ans);
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


Measured memory_bytes: 457472
s = input()
k = int(input())

if k == 1:
    print(int(s[0]))
elif s[0] == "1":
    cnt = 0
    while  cnt < len(s) and s[cnt] == "1" :
        cnt += 1
    if cnt >= k:
        print(1)
    elif cnt == len(s):
        print("1")
    else:
        print(s[cnt])
else:
    print(int(s[0]))

Measured memory_bytes: 9104
#include<stdio.h>

#define NMAX 10000
#define QMAX 500

int main(){
  int i,j,n,q,N[NMAX],Q[QMAX],cnt=0;

  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&N[i]);

  scanf("%d",&q);

  for(i=0; i<q; i++){
    scanf("%d",&Q[i]);
    for(j=0; j<n; j++)
      if(Q[i] == N[j]){
	cnt++;
	break;
      }
  }

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

  return 0;
}
  



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

int main() {
  int h, w;

  cin >> h >> w;

  string s[h];

  rep(i, h) {
    cin >> s[i];
  }

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      int count = 0;
      if (s[i].at(j) != '#') {

        if (i > 0) {
          if (j > 0) {
            if (s[i-1].at(j-1) == '#')
              count++;
          }

          if (s[i-1].at(j) == '#')
            count++;

          if (j < w -1) {
            if (s[i-1].at(j+1) == '#')
              count++;
            }
        }

        if (j > 0) {
          if (s[i].at(j-1) == '#')
            count++;
        }

        if (j < w -1) {
          if (s[i].at(j+1) == '#')
            count++;
        }

        if ( i != h - 1) {
          if (j > 0) {
            if (s[i+1].at(j-1) == '#')
              count++;
          }

          if (s[i+1].at(j) == '#')
            count++;

          if (j < w -1) {
            if (s[i+1].at(j+1) == '#')
              count++;
          }
        }
        s[i].at(j) = to_string(count).at(0);
      }
    }
    cout << s[i] << endl;
  }
  return 0;
}

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

bool scom(int i, int j) {
    return (i > j);
}

int main() {
    int k, t, tmp;
    vector<int> r;
    cin >> k >> t;
    for(int i = 0; i < t; i++) {
        cin >> tmp;
        r.push_back(tmp);
    }
    sort(r.begin(), r.end(), scom);
    tmp = r[0];
    for(int i = 1; i < r.size(); i++) {
        tmp -= r[i];
        if(tmp < 0) break;
    }
    if(tmp > 0) {
        cout << (tmp - 1) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		sc.close();
		
		int time;
		
		if(a<=c) {
			time = Math.min(b-c, d-c);
		}else {
			time = Math.min(b-a, d-a);
		}
		
		if(time<0) {
			time = 0;
		}
		System.out.println(time);
	}

}

Measured memory_bytes: 21716
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i;
    int cnt = 0;
    int ans;
    char str[101];
    int len;
    while(1){
        if(scanf("%s",str) == -1)break;
        len = strlen(str);
        ans = 1;
        for(i = 0;i < len / 2;i++){
            if(str[i] != str[len - 1 - i]){
                ans = 0;
            }
        }
        if(ans)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 540