akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t,ans="";
  int n;
  cin >> n >> s >> t;
  for(int i=0; i<n; i++) {
    ans.push_back(s[i]);
    ans.push_back(t[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<set>
#include<algorithm>
#define int long long int
int Xor(int left,int right)
{
	if(right<left)
	   return 0;
	if(right-left>=10)
	{
		int answer=0;
		int i=left;
		int j=right;
		while(1)
		{
			if(i%4==0)
			   break;
			answer=answer^i;
			i++;
		}
		while(1)
		{
			if(j%4==3)
			  break;
			answer=answer^j;
			j--;
		}
		return answer;
	}
	else
	{
		int answer=0;
		int j;
		for(j=left;j<=right;j++)
		    answer^=j;
		return answer;
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
    int prefix[n+1]={0};
    int j,arr1[n+1];
    for(j=1;j<=n;j++)
    {
		cin>>arr1[j];
	}
	for(j=1;j<=n;j++)
	   prefix[j]=arr1[j]+prefix[j-1];
    int arr2[n+1];
    for(j=1;j<=n;j++)
      cin>>arr2[j];
    int suffix[n+1];
    suffix[n]=arr2[n];
    for(j=n-1;j>=1;j--)
       suffix[j]=arr2[j]+suffix[j+1];
    int answer=0;
    for(j=1;j<=n;j++)
    {
		int val=prefix[j]+suffix[j];
		answer=max(answer,val);
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<iostream>
//#include<string>
using namespace std;
int main() {
	int a,b,n,s,t,k,r=0;
	cin >>a>>b;
	for (int i = a; i<=b; i++) {
		
		n = i % 10;
		s = i /10%10;
		t = i /1000%10;
		k = i /10000%10;
		if (n == k && s == t) {
			r++;
		}

	}
	
	cout << r << endl;
	
	//system("pause");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#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 ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;

int main(){
    double x=0,y,d=0,n,h,w,k,m,ans=0,ptr=0;
    string s,s1,s2;
    cin >> s;
    VI a(3);
    for(int i=0;i<s.size();i++){
        a[s[i]-'a']++;
    }
    sort(ALL(a));
    if(a[2]-a[0]<=1)
        cout << "YES" << endl;
    else  cout << "NO" << endl;
    return 0;
}

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

int main(){
    int N, sum = 0, k;
    cin >> N;
    vector<int> p;
    for(int i = 0; i < N; i++){
        cin >> k;
        p.push_back(k);
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < N ; i++){
        if(i != N -1)sum += p[i];
        else sum += p[i] / 2;
    }
    cout << sum << endl;

    return 0;
}

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

int main() {
	int N,K,X;
	cin >>N>>K;
	X=1;
	for(int i=0;i<N;i++){
		if (X<K){
			X = X*2;
		}
		else{
			X=X+K;
		}
	}
	cout <<X<<endl;

	
	return 0;
}

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

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    cin >> S;

    VEC(int) cnt(2);
    FOR(i, 0, S.size()) {
        if (i % 2 == 0) {
            cnt['1' - S[i]]++;
        } else cnt[S[i] - '0']++;
    }

    cout << min(cnt[0], cnt[1]) << endl;
    return 0;
};


Measured memory_bytes: 512
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define left adifojwaigunh
#define right afsdads
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll w,h,n,left,right,up,down;
ll x,y,val;
int main()
{
	cin>>w>>h>>n;
	left=down=0;
	up=h;
	right=w;
	for(ll i=0;i<n;i++){
		cin>>x>>y>>val;
		if(val==1){
			left=max(left,x);
		}
		else if(val==2){
			right=min(right,x);
		}
		else if(val==3){
			down=max(down,y);
		}
		else{
			up=min(up,y);
		}
	}
	if(down>=up||right<=left){
		puts("0");
	}
	else{
		printf("%lld\n",(right-left)*(up-down));
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
		printf("Yes\n");
		}
		else {
		printf("No\n");
		}
	return 0;
}

Measured memory_bytes: 584
n, k = [int(v) for v in input().split()]
a_s = [int(v) for v in input().split()]

c1 = 1
n1 = k
c2 = (n - n1) // (k - 1)
n2 = c2 * (k-1)
n3 = n - n1 - n2
c3 = 1 if (n3 > 0) else 0
ans = c1 + c2 + c3
print(ans)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a%b);
}

int main() {
    int N;
    LL sum;

    cin >> N;
    sum = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3636
n = int(input())
t = [int(input()) for _ in range(n)]

# 最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)
res = 1
for i in range(n):
    res = lcm(res, t[i])
print(res)

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

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  
  vector<long long> ans(N);
  if(N%2==0){
    for(int i=0;i<N/2;i++){
      ans.at(i) = a.at(N-2*i-1);
    }
    for(int i=0;i<N/2;i++){
      ans.at(i+N/2) = a.at(2*i);
    }
  }else{
    for(int i=0;i<N/2+1;i++){
      ans.at(i) = a.at(N-2*i-1);
    }
    for(int i=0;i<N/2;i++){
      ans.at(i+N/2+1) = a.at(2*i+1);
    }
  }
  
  for(int i=0;i<N;i++){
    cout << ans.at(i) << " " ;
  }
  cout << endl;
}

Measured memory_bytes: 5248
#include <cstdio>
#include <cmath>
#include <cstring>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <set>
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
int d[10001];
int main() {
	int N,M,p;
	scanf("%d %d %d",&N,&M,&p);
	for(int i=0;i<M;i++) {
		scanf("%d",&d[i]);
		d[i]-=p;
		if(d[i]<0) d[i]+=N;
	}
	sort(d,d+M);
	d[M]=N;
	int ans=N-d[0];
	for(int i=0;i<M;i++) {
		int r=d[i],l=N-d[i+1];
		ans=min(ans,l+r+min(l,r));
	}
	printf("%d\n",ans*100);
}

Measured memory_bytes: 1244
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, x = 0, res = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') x++;
        else x--;
        res = (res < x ? x : res);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
<?php
    fscanf(STDIN,"%d%d",$N,$M);
    
    $array_A = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    $sum = array_sum($array_A);
    
    $sum_quart = $sum/(4*$M);
    
    rsort($array_A);
    array_unshift($array_A,0);
    
    // var_dump($array_A);
    // var_dump($array_A[$M]);
    // var_dump($sum_quart);
    
    if($array_A[$M] < $sum_quart){
        echo "No";
    }else{
        echo "Yes";
    }

    
?>

Measured memory_bytes: 16240
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll n;

void sosu(ll x, ll y){
    if (y == n) return;
    ll ans = 0;
    for (ll i = 2; i <= sqrt(x); i++) {
        if (x % i == 0) ans++;
    }
    if (ans || x % 10 != 1) {
        sosu(x + 1, y);
    } else {
        cout << x << endl;
        sosu(x + 1, y + 1);
    }
    return;
}

int main(void){
    // Your code here!
    cin >> n;
    sosu(2, 0);
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def div_mod(a, b, mod):
    """
    (a // b) % mod
    mod は 3 以上の素数を指定
    フェルマーの小定理より mod p の世界で b^(p-1) は必ず 1 になるので
    b の逆元 (b と掛けると 1 になる数) は b^(p-2)
    :param int a:
    :param int b:
    :param int mod:
    :return:
    """
    return a * pow(b, mod - 2, mod) % mod


def mod_inv(a, mod):
    """
    a の逆元
    :param int a:
    :param int mod:
    :return:
    """
    return pow(a, mod - 2, mod)


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    :return:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret


def mod_invs(max, mod):
    """
    逆元のリスト 0 から max まで
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def factorial_invs(max, mod):
    """
    階乗 0!, 1!, 2!, ..., max! の逆元
    :param int max:
    :param int mod:
    """
    ret = []
    r = 1
    for inv in mod_invs(max, mod):
        r = r * inv % mod
        ret.append(r)
    return ret


class Combination:
    def __init__(self, max, mod):
        """
        :param int max:
        :param int mod: 3 以上の素数であること
        """
        self._factorials = get_factorials(max, mod)
        self._finvs = factorial_invs(max, mod)
        self._mod = mod

    def ncr(self, n, r):
        """
        :param int n:
        :param int r:
        :rtype: int
        """
        if n < r:
            return 0
        return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod


X, Y = list(map(int, sys.stdin.readline().split()))

if (X + Y) % 3 != 0:
    print(0)
    exit()

X, Y = min(X, Y), max(X, Y)
if X * 2 < Y:
    print(0)
    exit()

comb = Combination(max=(X + Y) // 3, mod=MOD)
print(comb.ncr((X + Y) // 3, X - (X + Y) // 3))

# dp = np.zeros((X + 1, Y + 1), dtype=int)
# dp[0][0] = 1
# for x, y in itertools.product(range(X), range(Y)):
#     if x + 1 <= X and y + 2 <= Y:
#         dp[x + 1, y + 2] += dp[x, y]
#     if x + 2 <= X and y + 1 <= Y:
#         dp[x + 2, y + 1] += dp[x, y]
# print(dp)


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

signed main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		vector<int>c1(26), c2(26);
		rep(j, i)c1[s[j] - 'a']++;
		for (int j = i; j < n; j++)c2[s[j] - 'a']++;
		int res = 0;
		rep(j, 26)if (c1[j] && c2[j])res++;
		ans = max(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	final int INF = 1 << 24;
	int [] xdis = {0,1,0,-1};
	int [] ydis = {1,0,-1,0};
	class C implements Comparable<C>{
		int v,town,lasttown;
		double time;
		public C(int v, int town, int lasttown, double time) {
			this.v = v;	this.town = town;this.lasttown = lasttown;this.time = time;
		}
		@Override
		public int compareTo(C o) {
			if(time < o.time) return -1;
			if(time > o.time) return 1;
			return 0;
		}
	}
	
	private double getT(int dis, int v){
		double res = (double) dis / v;
		return res;
	}

	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;
			int s = sc.nextInt();
			int g = sc.nextInt();
			int [][] pass = new int[n+1][n+1];
			int [][] maxs = new int[n+1][n+1];
			for(int i=1; i <= n; i++){
				Arrays.fill(pass[i], INF);
				Arrays.fill(maxs[i], INF);
			}
			for(int i=0; i < m; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				int d = sc.nextInt();
				int c = sc.nextInt();
				pass[x][y] = d; pass[y][x] = d;
				maxs[x][y] = c; maxs[y][x] = c;
			}
			PriorityQueue<C> open = new PriorityQueue<C>();
			open.add(new C(1,s,-1,0.0));
			double [][][] close = new double[n+1][n+1][31];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					Arrays.fill(close[i][j], INF);
				}
			}
			close[0][0][0] = 0.0;
			double ans = INF;
			while(! open.isEmpty()){
				C now = open.poll();
				
				for(int speed = -1; speed <= 1; speed++){
					int v = now.v + speed;
					if(now.lasttown == -1 && v != 1) continue;
					if(! (0 < v && v < 31)) continue;
					for(int i = 1; i <= n; i++){
						if(pass[now.town][i] == INF) continue;
						if(i == now.lasttown) continue;
						if(maxs[now.town][i] < v) continue;
						int dis = pass[now.town][i];
						double nexttime = now.time + getT(dis,v);
						if(close[now.town][i][v] <= nexttime) continue;
						if(i == g && v == 1){
							ans = Math.min(ans, nexttime);
							continue;
						}
						open.add(new C(v, i, now.town, nexttime));
						close[now.town][i][v] = nexttime;
					}
				}
			}
			
			//System.out.print("ANS=");
			if(ans == INF){
				System.out.println("unreachable");
				continue;
			}
			System.out.printf("%1.5f\n",ans);
		}
	}

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

Measured memory_bytes: 14000
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(ll p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<=p; i++){
		fac[i] = fac[i-1]*i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}


ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

/*vvl invmat(vvl &c, int p){
	vvl ret(p,vl(p));
	int buf;
	rep(i,p) rep(j,p) ret[i][j] = (i==j) ? 1 : 0;
	rep(i,p){
		buf = inv[c[i][i]];
		rep(j,p){
			c[i][j] *= buf; c[i][j] %= p;
			ret[i][j] *= buf; ret[i][j] %= p;
		}
		rep(j,p){
			if(i!=j){
				buf = c[j][i];
				rep(k,p){
					c[j][k] -= c[i][k] * buf % p;
					if(c[j][k] < 0) c[j][k] += p;
					ret[j][k] -= ret[i][k] * buf % p;
					if(ret[j][k] < 0) ret[j][k] += p; 
				}
			}
		}
	}
	return ret;
}*/

int main(){
	int p; cin >> p;
	vl a(p); rep(i,p) cin >> a[i];
	comInit(p);
	vvl c(p,vl(p));
	rep(i,p) c[i][0] = 1;
	rep(i,p){
		rep(j,p-1) c[i][j+1] = (c[i][j] * i) % p;
	}
	vvl d(p,vl(p,0));
	d[0][0] = 1;
	REP(i,1,p) d[i][1] = p-1;
	rep(j,p) d[p-1][j] = p-1;
	REP(j,1,p-1){
		REP(i,2,p){
			d[p-1-j][i] = p - c[i][j];
		}
	}
	rep(i,p){
		int ans = 0;
		rep(j,p){
			ans += d[i][j] * a[j] % p;
		}
		ans %= p;
		cout << ans << " ";
	}
	cout << "\n";
}

Measured memory_bytes: 156080
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        pq.push(a);
    }
    for(int i=0; i<m; ++i){
        int a=pq.top();
        pq.pop();
        pq.push(a/2);
    }
    long long ans=0;
    for(int i=0; i<n; ++i){
        int a=pq.top();
        pq.pop();
        ans+=a;
    }
    cout << ans << endl;
    return 0;
}


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

const int N = 10005;
int n, c[N], d[N], out[N], dep[N];
vector<int> g[N];

void dfs(int u) {
	for (int v : g[u]) if (!dep[v]) { dep[v] = dep[u] + 1; dfs(v); };
}

int main() {
	scanf("%d", &n);
	for (int i = 1, x, y; i < n; ++i)
		scanf("%d%d", &x, &y), g[x].push_back(y), g[y].push_back(x);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		scanf("%d", c + i), ans += c[i], d[i] = i;
	sort(c + 1, c + 1 + n), ans -= c[n];
	dep[1] = 1, dfs(1);
	sort(d + 1, d + 1 + n, [](int x, int y) { return dep[x] < dep[y]; });
	for (int i = 1; i <= n; ++i) out[d[i]] = c[n - i + 1];
	printf("%d\n", ans);
	for (int i = 1; i <= n; ++i) printf("%d%c", out[i], " \n"[i == n]);
	return 0;
}


Measured memory_bytes: 1280
n1 = int(input())
nums1 = list(map(int, input().split(' ')))
n2 = int(input())
nums2 = list(map(int, input().split(' ')))
sum = 0
for i in range(n2):
    j = 0 
    nums1.append(nums2[i])
    while nums1[j] != nums2[i]:
        j += 1
    if j != n1:
        sum += 1
    nums1.pop()
print(sum)



Measured memory_bytes: 6552
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
        
        String S = scan.next();
        
        boolean isBetween = false;
        int topA = 0;
        int bottomZ = 0;
        int cnt = 0;
        
        int i = 0;
        
        for(i = 0 ; ; i++){
          if(S.substring(i,i+1).charAt(0) == 'A'){
            topA = i;
            break;
          }
        }
        
        for(i = S.length() ; ; i--){
          if(S.substring(i-1,i).charAt(0) == 'Z'){
            bottomZ = i-1;
            break;
          }
        }
        
        /* //MLE, TLEが起きる愚直なやり方
        int i = 0;//for iの代り
        
        String[] strArray = S.split("");
		for(String s_one : strArray) {
          
          i++;
          
		  if(s_one.charAt(0) == 'A' && isBetween == false){
            isBetween = true;
            count++;
          }
          else if(isBetween == true){
            count++;
          }
          
          if(s_one.charAt(0) == 'Z' && isBetween == true && S.substring(i, S.length() ).contains("Z") == false  ){
            isBetween = false;
            if(cnt < count)cnt = count;
            count = 0;
          }
		}
        */
        
        cnt = bottomZ - topA + 1;
        
        System.out.println(cnt);
	  }
}

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

int main() {
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>
#define MAX (ll)(1e6)
#define MOD (ll)(1e9 + 7)

ll fac[MAX];

ll binpow(ll a, ll p = MOD - 2) {
    a %= MOD;
    ll ans = 1;
    while (p > 0) {
        if (p & 1) {
            ans *= a;
            ans %= MOD;
        }
        p >>= 1;
        a *= a;
        a %= MOD;
    }

    return ans;
}

void precalc() {
    fac[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fac[i] = i * fac[i - 1];
        fac[i] %= MOD;
    }
}

ll ways(ll x1, ll y1, ll x2, ll y2) {
    ll a = x2 - x1;
    ll b = y2 - y1;

    ll c = fac[a + b];
    ll d = fac[a] * fac[b];
    d = binpow(d);

    ll ans = c * d;
    ans %= MOD;
    return ans;
}

ll mod(ll a) {
    return ((((a) % MOD) + MOD) % MOD);
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h, w, n;
    cin >> h >> w >> n;

    precalc();

    vii arr;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;

        arr.pb({x, y});
    }

    arr.pb({h, w});
    sort(all(arr));

    vi ans(n + 1);
    for (int i = 0; i <= n; i++) {
        ll a = ways(1, 1, arr[i].ff, arr[i].ss);
        ll b = 0;
        for (int j = 0; j < i; j++) {
            if (arr[j].ff <= arr[i].ff && arr[j].ss <= arr[i].ss) {
                b += ans[j] * ways(arr[j].ff, arr[j].ss, arr[i].ff, arr[i].ss);
                b = mod(b);
            }
        }

        ans[i] = mod(a - b);
    }

    cout << ans[n] << "\n";
}


Measured memory_bytes: 8192
#include <stdio.h>

int N;
int main(int argc, char *argv[])
{
    int table[100] = {0, };
    for(int i=1;i<=9;i++) {
        for(int j=1;j<=9;j++) {
            table[i * j] = 1;
        }
    }
    scanf("%d", &N); 

    if (table[N] == 1)
       printf("Yes\n"); 
    else
       printf("No\n"); 

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> X(5);
  for (int i = 0; i < 5; i++) {
  cin >> X.at(i);
    if(X.at(i) ==0) {
      cout << i+1 << endl;
    }
  }
}

Measured memory_bytes: 3628
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        a: usize, b: usize, c: usize, k: u32,
    }

    let v = vec![a * 2usize.pow(k) + b + c, a + b * 2usize.pow(k) + c, a + b + c * 2usize.pow(k)];
    let ans = v.iter().max().unwrap();

    println!("{}", ans)
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2112
N = int(input())
li = [ int(it) for it in input().split() ]

import collections as col
c = col.Counter(li)

s2=0
s1=0

for k,v in c.items():
  if ( v%2==0):
    s2 += 1
  else:
    s1 += 1
if ( s2%2==0):
  print ( s1+s2)
else:
  print ( s1+s2-1)

Measured memory_bytes: 62124
n = int(input())
s = input()
list = []
E = s.count("E")
L = 0
check = 0 # 直前がWだったかの記憶装置

for i in s:
    if i == "E":
        E -= 1
        if check == 0:
            list.append(E+L) # E+Lが答えの候補
        elif check == 1:
            check = 0
            L += 1
            list.append(E+L)
    elif i == "W":
        if check == 0: # 一つ前がEのとき
            check = 1
            list.append(E+L)
        elif check == 1: # 一つ前がWのとき
            L += 1
            list.append(E+L)

print(min(list))

Measured memory_bytes: 15520
c=input()
b=c.split()
N=int(b[0])
Z=int(b[1])
W=int(b[2])
A=input().split()
ans1=abs(int(A[N-1])-W)
ans2=abs(int(A[N-1])-int(A[N-2]))
print(max(ans1,ans2))

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 4000000000; //4*10^9
constexpr auto MOD = 1000000007; //10^9+7

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

	sort(all(a));

	int remv = 0;
	rep(i, n - 1) {
		if (a[i] == a[i + 1])remv++;
	}
	
	cout <<n- 2*((remv + 1) / 2) << endl;

}

Measured memory_bytes: 640
#include<math.h>
#include<stdio.h>
#define abs(x) (x>0 ? x : -x)

int main(){
  double A,B,H,M;
  scanf("%lf %lf %lf %lf",&A,&B,&H,&M);
  double thetaH,thetaM,ans2;
  thetaH = 2*M_PI/12*(H + M/60);
  thetaM = 2*M_PI/60*M;
  
  ans2 = A*A + B*B - 2*A*B*cos(thetaH - thetaM);
  printf("%.20lf\n",sqrt(ans2));
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int vpa[300*300+1],vpb[300*300+1],vl[300*300+1],answer[100000];
int h,w,d,q;

int inline dist(int i){
    return abs(vpa[i]-vpa[i-d]) + abs(vpb[i]-vpb[i-d]);
}

int main(){
    scanf("%d %d %d",&h,&w,&d);
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            int a;
            scanf("%d",&a);
            vpa[a] = i;
            vpb[a] = j;
        }
    }

    scanf("%d",&q);
    FOR(i,1,d+1) vl[i] = 0;
    FOR(i,d+1,h*w+1) vl[i] = vl[i-d] + dist(i);

    REP(i,q){
        int l,r;
        scanf("%d %d",&l,&r);
        answer[i] = vl[r] - vl[l];
    }
    REP(i,q) printf("%d\n",answer[i]);
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

ld getheight(const vector<pair<int, int>>&pot, ld water) {
	ld h = 0;
	for (int i = 0; i < pot.size(); ++i) {
		if (water > pot[i].first*pot[i].second) {
			h += pot[i].second;
			water -= pot[i].first*pot[i].second;
		}
		else {
			return h + water / pot[i].first;
		}
	}
	return h;
}

int main() {
	int N;ld M; cin >> N >> M;
	vector<vector<pair<int, int>>>pots;
	for (int i = 0; i < N; ++i) {
		int K; cin >> K;
		vector<pair<int, int>>pot;
		for (int j = 0; j < K; ++j) {
			int s, h; cin >> s >> h;
			pot.push_back(make_pair(s, h));

		}
		pots.emplace_back(pot);
	}
	vector<vector<ld>>dp(N + 1, vector<ld>(M + 1));
	for (int i = 0; i < N; ++i) {
		const vector<pair<int, int>>apot(pots[i]);
		for (int j = 0; j <= M; ++j) {

			for (int use = 0; use <= M - j; ++use) {
				dp[i + 1][j + use] = max(dp[i][j] + getheight(apot, use), dp[i + 1][j + use]);
			}
		}
	}
	cout << setprecision(10) << fixed << dp[N][M] << endl;
	
	return 0;
}

Measured memory_bytes: 3404
#include <iostream>

using namespace std;

int main() {
    int h, w, n;
    int map[16][16];
    while (true) {
        cin >> w >> h;
        if (h == 0) {
            return 0;
        }
        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                map[x][y] = 0;
            }
        }
        cin >> n;
        for (int i=0; i<n; i++) {
            int x, y;
            cin >> x >> y;
            map[x-1][y-1] = -1;
        }
        for (int x=0; x<w; x++) {
            if (map[x][0] < 0) {
                break;
            }
            map[x][0] = 1;
        }
        for (int y=0; y<h; y++) {
            if (map[0][y] < 0) {
                break;
            }
            map[0][y] = 1;
        }
        for (int y=1; y<h; y++) {
            for (int x=1; x<w; x++) {
                int a = max(0, map[x-1][y]);
                int b = max(0, map[x][y-1]);
                if (map[x][y] >= 0) {
                    map[x][y] = a+b;
                }
            }
        }
        cout << max(0, map[w-1][h-1]) << endl;
    }
}

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

#define ll  long long

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

    int n,k;
    cin>>n>>k;

    int ans=0;
    while(n){
        n/=k;
        ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

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

    cout << fixed << std::setprecision(12) << pow(l/3.0,3) << endl;
}

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

int main(void){
	double s[11];
	while(cin>>s[1]){
		for(int i=2;i<11;i++)s[i]=((i%2==0)?(s[i-1]*2):(s[i-1]/3));
		double sum=0;
		for(int i=1;i<11;i++)sum+=s[i];
		printf("%.8lf\n",sum);
	}
	return 0;
}

Measured memory_bytes: 3116
N = int(input())
x = []
y = []
for i in range(N):
    a,b = map(int, (input().split()))
    x.append(a)
    y.append(b)
aaa = 0
for i in range(N):
    for k in range(N):
        aaa += ((x[i] - x[k])**2+(y[i] - y[k])**2)**0.5
print(aaa/N)

Measured memory_bytes: 3064
fun main(args : Array<String>) {
    var S = readString()
    var chars = S.toCharArray()

    var reverseIndex = chars.size - 1
    var correctionCount = 0
    for (i in 0 until chars.size / 2){
        if(chars[i] != chars[reverseIndex]){
            correctionCount++
        }
        reverseIndex--
    }

    print(correctionCount)

}

fun readString() = readLine()!!

Measured memory_bytes: 33736
#include <iostream>
#include <utility>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cmath>
using namespace std;

int main (){
    int A,B,C;
    int flag=0;
    cin >> A >> B>>C;
    if(C>=A)
        flag++;
    if(C<=B)
        flag++;
    if(flag==2)
        cout<< "Yes";
        else
            cout<<"No";
    return 0;
            }



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B, change;
	int yen[3];
	int i;
	
	while (1){
		scanf("%d %d", &A, &B);
		if (A == 0 && B == 0){
			break;
		}
		
		yen[0] = yen[1] = yen[2] = 0;
		
		change = B - A;
		
		while (change >= 1000){
			yen[2]++;
			change -= 1000;
		}
		while (change >= 500){
			yen[1]++;
			change -= 500;
		}
		while (change >= 100){
			yen[0]++;
			change -= 100;
		}
		
		for (i = 0; i < 3; i++){
			if (i != 0){
				printf(" ");
			}
			printf("%d", yen[i]);
		}
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 616
package main

import "fmt"

func main() {
	d := int(1e9) + 7

	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)

	var min, max, count int

	for i := k; i <= n+1; i++ {
		min = ((i - 1) * i) / 2
		max = (2*n - i + 1) * i / 2
		count += max - min + 1
		count %= d
	}
	fmt.Println(count)

}


Measured memory_bytes: 1756
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String[] array = input.split(",");
        for(int i=0; i<array.length; i++) {
            if(i==(array.length-1)) {
                System.out.println(array[i]);
            } else {
                System.out.print(array[i]+" ");
            }
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int  i = a; i < b; ++i)
#define fr2(i, b, a) for (int i = b; i >= a; --i)
#define set0(a) memset(a, 0, sizeof(a))
#define setneg(a) memset(a, -1, sizeof(a))
#define mod 1000000007
#define ll long long




int main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int n1,n2;
        if(c%b==0)
        {
                n1=c/b;
        }
        else
                n1=(c/b)+1;
        if(a%d==0)
        {
                n2=a/d;
        }
        else
                n2=(a/d)+1;
        if(n1<=n2)
                cout<<"Yes"<<endl;
        else
                cout<<"No"<<endl;

        return 0;
}





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

using namespace std;

int main() {
	int n, r = 0, b = 0;

	string s;
	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'B') b++;
		else r++;
	}

	if(r>b) cout << "Yes";
	else cout << "No";

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int inv[N],jc[N],jcn[N],n,m,a[20],f[20][N],ans;
int C(int n,int m){
	if(n<m)return 0;
	return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;
}
int main(){
	inv[1]=jc[0]=jcn[0]=1;
	for(int i=2;i<N;++i)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1;i<N;++i)jc[i]=1ll*jc[i-1]*i%mod,jcn[i]=1ll*jcn[i-1]*inv[i]%mod;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d",&a[i]),a[i];
	sort(a+1,a+m+1);f[m][0]=1;
	for(int i=m;i;--i)
		for(int j=0;j<1<<n;++j)
			if(f[i][j]){
				f[i-1][j]=(f[i-1][j]+f[i][j])%mod;
				for(int k=0;k<n;++k)
					if(~j>>k&1)
						f[i-1][j|1<<k]=(f[i-1][j|1<<k]+1ll*f[i][j]*C((1<<n)-j-a[i],(1<<k)-1)%mod*jc[1<<k])%mod;
			}
	for(int i=0;i<1<<n;++i)
		if(__builtin_popcount(i)&1)
			ans=(ans+1ll*f[0][i]*(mod-jc[(1<<n)-1-i]))%mod;
		else
			ans=(ans+1ll*f[0][i]*jc[(1<<n)-1-i])%mod;
	ans=(1ll*ans<<n)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8448
//Code taken from geeksforgeeks

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// int fact(int n);
// int nCr(int n, int r) 
// { 
//     return fact(n) / (fact(r) * fact(n - r)); 
// } 
  
// // Returns factorial of n 
// int fact(int n) 
// { 
//     int res = 1; 
//     for (int i = 2; i <= n; i++) 
//         res = res * i; 
//     return res; 
// } 

int main()
{
// 	string s, str, a1, a="", b1, b="";
// 	cin>>s;
// 	str=s;

// 	reverse(str.begin(), str.end()); 
// 	for(int i = 0; i < (s.size()-1)/2; i++)
// 	{
// 		a+=s[i];
// 	}
// 	a1=a;
// 	reverse(a1.begin(), a1.end());

// 	for(int i = (s.size()+3)/2 -1; i < s.size(); i++)
// 	{
// 		b+=s[i];
// 	}
// 	b1=b;
// 	reverse(b1.begin(), b1.end());
// 	if(s==str and b1==b and a1==a)
// 		cout<<"Yes"<<endl;
// 	else cout<<"No"<<endl;
	ll l;
	cin>>l;
	double div=(l*1.0)/3;
	double ans = pow(div, 3);
	// cout<<ans<<endl;
	// int n, m;
	cout <<fixed << setprecision(10)<<ans;
	// cin>>n>>m;
	// cout << nCr(n, 2)+nCr(m, 2); 
	return 0;
}

Measured memory_bytes: 384
# ALDS1_10_A.py
N = int(input())
fib_list = [0]*(N+1)
def fib(n):
    if n<=1:
        fib_list[n] = 1
    else:
        if fib_list[n] == 0:
            fib_list[n] = fib(n-1) + fib(n-2)
    return fib_list[n]
fib(N)
print(fib_list[N])



Measured memory_bytes: 5600
import java.util.*;

public class Main{
  
  public static void main (String []args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N];
    for(int i = 0; i<N; i++){
      a[i]=sc.nextInt();
    }
    Arrays.sort(a);
    //System.out.println(a[0]);
    int Alice = 0;
    int Bob = 0;
    for(int i = N-1; i>=0; i-=2){
      Alice += a[i];
    }
    for(int i = N-2; i>=0; i-=2){
      Bob += a[i];
    }
    System.out.println(Alice-Bob);
  }
}
   

Measured memory_bytes: 35808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int i = kb.nextInt();
		int j = kb.nextInt();
		int count = 0;
		while (i > 0) {
			count += 1;
			i = i - j;
		}
		kb.close();
		System.out.println(count);
	}

}


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

long long ara[200003],val[200003],len=1,mx=1,vis[200003];
vector<long long>adj[200003];

long long binsrc(long long zz,long long nm)
{

    long long lo,hi,mid; lo=1; hi=zz;

    while(lo<hi)
    {

        mid=(lo+hi)/2LL;

        if(ara[mid]>=nm){  hi=mid;  }
        else{  lo=mid+1;  }

    }


    return lo;


}

void dfs(long long src)
{

    long long sz=adj[src].size();

    for(long long lp=0;lp<sz;lp++)
    {
        long long u=adj[src][lp];

        if(vis[u]==0)
        {

            long long p,q,r,s,t=len,z; p=val[u];

            if(p>ara[len])
            {
                len++;
                q=len; r=0;
                ara[q]=p;

            }
            else if(p<ara[len])
            {
                z=binsrc(len,p);
                q=z; r=ara[z];

                ara[q]=p;
            }
            else
            {
                q=t; r=ara[q];
            }

            vis[u]=len;

            dfs(u);

            len=t; ara[q]=r;


        }

    }


}

int main()
{

    long long n,m,i,j,k,a,b;
    scanf("%lld",&n);

    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a); val[i]=a;
    }

    for(i=1;i<=n-1;i++)
    {
        scanf("%lld %lld",&a,&b); adj[a].push_back(b);  adj[b].push_back(a);
    }

    ara[1]=val[1]; vis[1]=1;

    dfs(1);

    for(i=1;i<=n;i++)
    {
        printf("%lld\n",vis[i]);
    }



    return 0;
}


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

int main(){
  string S, T;
  int ans = 0;
  cin >> S;
  T = "CODEFESTIVAL2016";
  for(int i=0;i<16;i++){
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(void)
{
char s[200000];
/*int as[20000];
int as2[20000];*/
int i;
int d;
int a=0;
int ab=0;
int ab2=0;
int g=0;
int g2=0;
scanf("%s",s);
d=strlen(s);
for(i=0;i<d;i++){
	if(s[i]=='A'){
		
		ab=i;
	break;
	}

	
}
for(i=0;i<d;i++){
	if(s[i]=='Z'){
		
		ab2=i;
	
		
		
	}
	
	
}
	
printf("%d",(ab2+1)-(ab+1)+1);

}

Measured memory_bytes: 384
//
//  main.cpp
//  ITP1_5-D
//
//  Created by ?????¶??? on 15/8/14.
//  Copyright (c) 2015??´ ?????¶???. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;

int main(int argc, const char * argv[]) {

    int num;
    
    cin >> num;
    
    for (int i = 1; i <= num; i++) {
        
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
            
        }else if (i % 10 == 3){
            cout << " " << i;
            continue;
        }
        
        int temp = i / 10;
        while (temp){
            
            if (temp % 10 == 3) {
                cout << " " << i;
                break;
            }
            
            temp /= 10;
        }
    }
    
    cout << endl;
    
    
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

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

    if(count(s.begin(), s.end(), 'W') == N) {
        cout << 0 << endl;
        return 0;
    }

    s.insert(0, "_");

    vector<int> left(N+2), right(N+2);
    for(int i=1; i<=N; i++) {
        left[i] = left[i-1];
        if(s[i] == 'W') left[i]++;
    }
    for(int i=N; i; i--) {
        right[i] = right[i+1];
        if(s[i] == 'R') right[i]++;
    }

    int ans = numeric_limits<int>::max();
    for(int i=1; i<=N; i++) {
        ans = min(ans, max(left[i], right[i+1]));
    }

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


Measured memory_bytes: 5240
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	String S;
	Deque<Character> deque;
	Deque<Character> result;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		S = in.readLine();
		this.deque = new ArrayDeque<>(S.length());
		for (int i = 0; i < S.length(); ++i) {
			deque.addLast(S.charAt(i));
		}
		result = new ArrayDeque<>();
	}

	void calc() {
		int score = 0;
		while (!deque.isEmpty()) {
			char c = deque.pollFirst();
			if (c == '(') {
				result.addLast(c);
				++score;
			} else {
				if (score > 0) {
					--score;
					result.addLast(c);
				} else {
					result.addFirst('(');
					result.addLast(c);
				}
			}
		}
		for (int i = 0; i < score; ++i) {
			result.addLast(')');
		}
	}

	void showResult() {
		while (!result.isEmpty()) {
			System.out.print(result.poll());
		}
		System.out.println("");
	}
}

Measured memory_bytes: 25356
/* ex4_3
   tamayama */

#include<stdio.h>

int snow(int west,int east);

int main(void){
    int a,b;
    int x;
    scanf("%d %d",&a,&b);
    x = snow(a,b);
    printf("%d\n",x);
    return 0;
}

int snow(int west,int east){
    int snow_height;
    int east_tower;
    east_tower = (east - west) * (east - west + 1) / 2;    /*1からb-aまでの総和の式*/
    snow_height = east_tower -east;    /*雪の高さを求める式*/
    return(snow_height);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;


int main() {
	long long int N, sum[2] = {0,0},min;
	cin >> N;
	vector<long long int> a(N);

	for (int i = 0; i < N;i++) {
		cin >> a[i];
		sum[1] += a[i];
	}
	sum[0] += a[0];
	sum[1] -= a[0];
	min = abs(sum[0] - sum[1]);

	for (int i = 1; i < N-1;i++) {
		sum[0] += a[i];
		sum[1] -= a[i];
		if (abs(sum[0] - sum[1]) < min) {
			min = abs(sum[0] - sum[1]);
		}
		
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int k;
  cin >> k;
  int ans = 1, m = 7;

  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 1 || k == 7) {
    cout << 1 << endl;
    return 0;
  }
  while (m != 0) {
    ans++;
    m = (10 * m + 7) % k;
  }

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    int n;cin>>n;
    vector<P>res;
    vector<P> ans;
    if(n%2){
        n--;
        rep(i,n)ans.push_back({n+1,i+1});
    }
    int want =1+n;
    rep(i,n){
        rep2(j,i+1,n){
            if(i+1+j+1==want)continue;
            ans.push_back({i+1,j+1});
        }
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].first<<' '<<ans[i].second<<endl;
    }
}

Measured memory_bytes: 3728
from itertools import accumulate
from collections import defaultdict
class Bit:
  def __init__(self,n):
    self.size = n
    self.tree = [0]*(n+1)
 
  def sum(self,i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self,i,x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i
n = int(input())
a = list(map(int,input().split()))
def jdg(x):
  b = [0 for i in range(n)]
  for i in range(n):
    if a[i] >= x:
      b[i] = 1
    else:
      b[i] = -1
  acc = [0]+list(accumulate(b))
  mn = min(acc)
  mx = max(acc)
  dif = mx-mn
  bit = Bit(dif+2)
  ret = 0
  for i in range(n+1):
    p = acc[i]-mn+1
    ret += bit.sum(p)
    bit.add(p,1)
  return ret
l = 0
r = max(a)+1
while l+1 < r:
  x = (l+r)//2
  if jdg(x) >= (n+1)*n//4:
    l = x
  else:
    r = x
print(l)

Measured memory_bytes: 120264
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<i64> A(Q), B(Q), C(Q), D(Q);
    rep(i, Q) cin >> A[i] >> B[i] >> C[i] >> D[i]; 

    i64 ans = 0;

    auto dfs = [&](auto&& dfs_, vector<int>& a) -> void {
        if(a.size() == N) {
            i64 score = 0;
            for(int i = 0; i < Q; i++){
                if(a[B[i] - 1] - a[A[i] - 1] == C[i]) score += D[i];
            }
            ans = max(ans, score);
            return;
        }
        
        //for(auto& i : a) cout << i << " "; cout << "\n";

        int m = (a.size() == 0 ? 1 : a.back());
        for(int n = m; m <= M; m++){
            a.emplace_back(m);
            dfs_(dfs_, a);
            a.pop_back();
        }

    };

    vector<int> a;
    dfs(dfs, a);

    cout << ans << endl;

}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        char s[] = sc.next().toCharArray();
        int len = s.length;

        int a = -1;
        int b = -1;
        for (int i = 0; i < len - 1; i++) {
            if (s[i] == s[i + 1]) {
                a = i + 1;
                b = i + 2;
                break;
            }
            if (i + 2 < len && s[i] == s[i + 2]) {
                a = i + 1;
                b = i + 3;
                break;
            }
        }

        System.out.println(a + " " + b);
    }

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


Measured memory_bytes: 28312