akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll u[4010];
	bool flag;
	vector<int> v;
	while(1)
	{
		for(int i=0;i<4010;i++)
		{
			u[i]=0;
		}
		flag=true;
		int n;
		cin >> n;
		if(n==0)break;
		v.clear();
		for(int i=0;i<n;i++)
		{
			int x;
			ll y,z;
			cin >> x >> y >> z;
			if(!(u[x]))
			{
				v.pb(x);
			}
			u[x]+=y*z;
		}
		for(int i=0;i<v.size();i++)
		{
			if(u[v[i]]>=1000000)
			{
				flag=false;
				cout << v[i] << endl;
			}
		}
		if(flag)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1268
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int p = 0;
		while(sc.nextInt()!=1) p++;
		int left = Math.max(0,p-K+1);
		int ans = Integer.MAX_VALUE;
		for(int i=left;i<=p;++i){
			int times = 1;
			times += (int)Math.ceil((double)i/(double)(K-1));
			if(i+K-1 < N-1) times += (int)Math.ceil((double)(N-i-K)/(double)(K-1));
			ans = Math.min(ans,times);
		}
		System.out.println(ans);
		return;
	}
}

Measured memory_bytes: 46300
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    edges=[[] for _ in range(n)]
    for _ in range(m):
        s,t=map(int,input().split())
        s-=1; t-=1
        edges[s].append(t)

    # 確率DP
    p=[0]*n
    p[0]=1.0
    for v in range(n):
        for nv in edges[v]:
            p[nv]+=p[v]/len(edges[v])

    # 期待値DP
    E=[0]*n
    for v in range(n-2,-1,-1):
        for nv in edges[v]:
            E[v]+=E[nv]
        E[v]=1+E[v]/len(edges[v])

    ans=E[0]
    for v in range(n):
        if(len(edges[v])<=1): continue
        # 各vに対して、辺vwのうちE[w]が最大のものを削除する
        w=max(*((E[w],w) for w in edges[v]))[1]
        E_dash=0
        for nv in edges[v]:
            if(nv==w): continue
            E_dash+=E[nv]
        E_dash=1+E_dash/(len(edges[v])-1)
        dE=E_dash-E[v]
        ans=min(ans,E[0]+p[v]*dE)

    print(ans)
resolve()

Measured memory_bytes: 53468
from sys import stdin
from bisect import bisect
input = stdin.readline

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

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

for i in range(1, M):
    B[i] += B[i - 1]

ans = 0

for i, a in enumerate(A):
    time = K - a
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(B, time)
        cnt += tmp
    ans = max(ans, cnt)

for i, b in enumerate(B):
    time = K - b
    if time < 0:
        break
    cnt = i + 1
    if time != 0:
        tmp = bisect(A, time)
        cnt += tmp
    ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 41412
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin >> x;
    int bcoin = x / 500;
    int amari = x % 500;
    int scoin = amari / 5;
    cout << bcoin * 1000 + scoin * 5;
    return 0;
}


Measured memory_bytes: 256
number = input().split()
num = 0
answer = 0
count = 0

for i in range(int(number[0])):
    num = i + 1
    while num < int(number[1]):
        num *= 2
        count += 1
    answer += 1 / int(number[0]) * (0.5)**count
    count = 0

print(answer)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(long long int i=0;i<n;i++)
#define lli long long int
#define ll long long 
#define dd double
#define endl "\n"
#define mod 1000000007
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define limit 1000000000000000000
const double pi=3.14159265358;
const double pie=2*acos(0.0);
	
using namespace std;
lli power(lli a,lli b)
{
	lli res=1;
	while(b>0)
	{
		if(b%2!=0)
		{
			b--;
			res=(res%mod*a%mod)%mod;
		}
		else
		{
			a=(a%mod*a%mod)%mod;
			b/=2;
		}
	}
	return res%mod;
}
bool sortinrev(const pair<lli,lli> &a,  
               const pair<lli,lli> &b) 
{ 
       return (a.first > b.first); 
}

int main() {
	fast
	lli cnt=0;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<t.length();i++)
	{
		if(s[i]!=t[i])cnt++;
	}
	cout<<cnt<<endl;
	
		
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
const int mxn = 2*1e3+5;
int ar[mxn] , n;
int sum;
bitset< mxn*mxn > b;

int main()
{
	cin>>n;
	sum  = 0;
	b.set(0);
	for(int i  = 1;i <= n;i++)
	{
		cin>>ar[i];
		sum +=ar[i];
		b = b|(b<<ar[i]);
	}
	for(int i = (sum+1)/2; i <= sum; i++)
	{
		if(b[i])
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int  a[10000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += (a[i] - 1);
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    *alist, = map(int, input().split())

    aset = list(set(alist))
    if len(aset) == 1 and aset[0] == 0:
        print('Yes')
        return

    if len(aset) == 2:
        a, b = aset
        acnt = {a: 0, b: 0}
        for aa in alist:
            acnt[aa] += 1

        if a ^ b == a:
            if acnt[a] == acnt[b] * 2:
                print('Yes')
                return
        if b ^ a == b:
            if acnt[a] * 2 == acnt[b]:
                print('Yes')
                return
        print('No')
        return

    if len(aset) != 3:
        print('No')
        return
    else:
        a, b, c = aset
        if a ^ b != c:
            print('No')
            return

        acnt = {a: 0, b: 0, c: 0}
        for aa in alist:
            acnt[aa] += 1

        if acnt[a] != acnt[b] or acnt[b] != acnt[c]:
            print('No')
            return

        print('Yes')
        return


main()


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%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(ll 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;
  }
};

mint calcNumOfCombination_mint(mint n, mint r){
  mint num = 1;
  for(mint i = 1; i.x <= r.x; i.x++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int k, n;
  cin >> n >> k;
  rep2(i, 1, k+1){
    mint ans = calcNumOfCombination_mint(n-k+1, i);
    ans = ans * calcNumOfCombination_mint(k-1, i-1);
    cout << ans.x << endl;
  }
  return 0;
}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    string S;
    int x,y;
    cin >> S;
    cin >> x>>y;
    vector<int> que_x,que_y;

    int mode=2;//0x 1y 2x+
    int cnt=0;
    int cnt_x,cnt_y;
    cnt_x=0;
    cnt_y=0;
    REP(i,S.size()){
        if(S[i]=='T'){
            if(cnt>0){
                if(mode==0){
                    que_x.push_back(cnt);
                    cnt_x+=cnt;
                }else if(mode==1){
                    que_y.push_back(cnt);
                    cnt_y+=cnt;
                }else{
                    x-=cnt;
                }
            }
            mode++;
            mode%=2;
            cnt=0;
        }else{
            cnt++;
            if(i==S.size()-1){
                if(mode==0){
                    que_x.push_back(cnt);
                    cnt_x+=cnt;
                }else if(mode==1){
                    que_y.push_back(cnt);
                    cnt_y+=cnt;
                }else{
                    x-=cnt;
                }
            }
        }
    }

    if(cnt_x<abs(x)||cnt_y<abs(y)||(cnt_x-abs(x))%2!=0||(cnt_y-abs(y))%2!=0){
        cout << "No" << endl;
    }else{
        int target_x=(cnt_x-abs(x))/2;
        int target_y=(cnt_y-abs(y))/2;

        vector<vector<bool>> dp_x(que_x.size()+1,vector<bool>(target_x+1,false));
        vector<vector<bool>> dp_y(que_y.size()+1,vector<bool>(target_y+1,false));
        REP(i,que_x.size()+1) dp_x[i][0]=true;
        REP(i,que_y.size()+1) dp_y[i][0]=true;
        REP(i,que_x.size()){
            REP(j,target_x+1){
                if(j-que_x[i]<0) dp_x[i+1][j]=dp_x[i][j];
                else dp_x[i+1][j]=dp_x[i][j-que_x[i]]||dp_x[i][j];
            }
        }

        REP(i,que_y.size()){
            REP(j,target_y+1){
                if(j-que_y[i]<0) dp_y[i+1][j]=dp_y[i][j];
                else dp_y[i+1][j]=dp_y[i][j-que_y[i]]||dp_y[i][j];
            }
        }
        if(dp_x[que_x.size()][target_x]&&dp_y[que_y.size()][target_y]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }

    
    
}

Measured memory_bytes: 640
/*
 * Author:  heyuhhh
 * Created Time:  2020/3/8 20:01:22
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

char s[N];

void run() {
    cin >> (s + 1);
    int n = strlen(s + 1);
    if(n & 1) {
        cout << "No" << '\n';
        return;   
    }
    for(int i = 1; i <= n; i += 2) {
        if(s[i] == 'h' && s[i + 1] == 'i') {}
        else {
            cout << "No" << '\n';
            return;   
        }
    }
    cout << "Yes" << '\n';
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>

#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)

using namespace std;

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




const ll INF = 1e18+7;


/******************************************************************************************/


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	cin >> n;
	set<string> st;
	for (int i = 0; i < n; i++)
	{
		string s, t;
		cin >> s >> t;
		if (s == "insert") {
			st.insert(t);
		}

		if (s == "find") {
			if (st.count(t)) {
				cout << "yes" << endl;
			}
			else
			{
				cout << "no" << endl;
			}
		}
	}


	return 0;
}



Measured memory_bytes: 29032
#include <iostream>

int main(int argc, char *argv[]) {
	std::string result;
	std::string input;

	std::cin >> input;

	for (int i = 0; i < input.size(); i++) {
		if (input[i] == '0' || input[i] == '1') {
			result += input[i];
		}
		if (input[i] == 'B') {
			if (!result.empty()) {
				result = result.substr(0, result.size() - 1);
			}
		}
	}
	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));

if ($a[0] > 0) {
	$s = [$a[0], -1];
	$x = [0, $a[0] + 1];
} elseif ($a[0] < 0) {
	$s = [1, $a[0]];
	$x = [1 - $a[0], 0];
} else {
	$s = [1, -1];
	$x = [1, 1];
}
$f = [-1, 1];
for ($i = 1; $i < $n; $i++) {
	foreach ([0, 1] as $j) {
		$t = $s[$j] + $a[$i];
		if ($t * $f[$j] <= 0) {
			$s[$j] = $f[$j];
			$x[$j] += abs($t - $f[$j]);
		} else {
			$s[$j] = $t;
		}
	}
	$f = [$f[1], $f[0]];
}
echo min($x[0], $x[1]);

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

int main() {
  string s, t;
  cin >> s >> t;
  int ss=s.size(), ts=t.size();
  int mi = 2000;
  rep(i,ss-ts+1) {
    int count=0;
    rep(j,ts) {
      if (s[i+j]!=t[j]) count++;
    }
    mi = min(mi, count);
  } 
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 3628
N,K,S = map(int,input().split())
MAX = 10**9
if K==N:
    ans = [S]*N
elif K==0:
    if S==MAX:
        ans = [S-1]*N
    else:
        ans = [S+1]*N
else:
    ans = [S]*K+[S+1 if S!=MAX else S-1]*(N-K)
print(*ans)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector< vector<int> > a(n, vector<int>(m));
  vector<int> b(m);
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) cin >> a.at(i).at(j);
  }
  for(int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  for(int i = 0; i < n; i++) {
    int c = 0;
    for(int j = 0; j < m; j++) c += a.at(i).at(j) * b.at(j);
    cout << c << endl;
  }
}


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

int main() {

  	int N,X,Y;
  cin >>N;
  	vector<int>V(N);
  	vector<int>C(N);
  
 	
   for(int x=0; x<N;x++){
  	cin >>V.at(x);
 }
     for(int x=0; x<N;x++){
  	cin >>C.at(x);
 }
     for(int x=0; x<N;x++){
  	if(V.at(x)>=C.at(x)){
    X+=V.at(x);
    Y+=C.at(x);
    }
     	
 }
	cout << X-Y << endl;	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int d, e;

int main(){
	while(cin >> d >> e){
		if(d == 0 && e == 0) break;
		double ans = 10000000.0;
		for(int i = 0; i <= d; i++){
			int j = d-i;
			ans = min(ans,abs(sqrt((double)i*i+(double)j*j)-e));
		}
		printf("%.9f\n",ans);
	}
}

Measured memory_bytes: 1196
n = gets.to_i
s = gets.chomp

ans = s.count("R") * s.count("G") * s.count("B")

n.times do |i|
    (1..).each do |j|
        break if i + 2 * j >= n
        ans -= 1 if s[i] != s[i+j] && s[i] != s[i+2*j] && s[i+j] != s[i+2*j]
    end
end

puts ans

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

#define INF INT32_MAX

int main()
{
	int V, E;
	cin >> V >> E;
	vector<vector<int>> g( V );
	vector<int> indeg( V );
	vector<int> color( V );
	for( int i = 0; i < E; i++ ) {
		int s, t;
		cin >> s >> t;
		g[s].push_back( t );
		indeg[t]++;
	}

	vector<int> out;
	for( int i = 0; i < V; i++ ) {
		if( color[i] || indeg[i] ) continue;
		queue<int> que;
		que.push( i );
		color[i] = 1;
		while( !que.empty() ) {
			int u = que.front();
			que.pop();
			out.push_back( u );
			for( int v : g[u] ) {
				indeg[v]--;
				if( indeg[v] || color[v] ) continue;
				color[v] = 1;
				que.push( v );
			}
		}
	}

	for( int i = 0; i < out.size(); i++ ) {
		cout << out[i] << endl;
	}
}



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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ll odp = 0;
    for (int l = 0; l < n; )
    {
        if (a[l] == 0)
        {
            ++l;
            continue;
        }
        int p = l;
        ll s = 0;
        while (p < n && a[p] != 0)
        {
            s += a[p];
            ++p;
        }
        --p;
        odp += s / 2;
        l = p + 1;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 640
/*
  Code By RyeCatcher
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <cmath>
#include <utility>
#define ri register int
#define ll long long
#define ull unsigned long long
#define pb push_back
#define DEBUG freopen("dat.in","r",stdin);freopen("wa.out","w".stdout);
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define SIZE 23333
using std::min;
using std::max;
using std::pair;
using std::queue;
using std::priority_queue;
using std::vector;
inline char gc(){
    static char buf[SIZE],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,SIZE,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
template <class T>inline void read(T &x){
	x=0;int ne=0;char c;
    while((c=gc())>'9'||c<'0')ne=c=='-';x=c-48;
    while((c=gc())>='0'&&c<='9')x=(x<<3)+(x<<1)+c-48;x=ne?-x:x;return ;
}
#define int ll
const int maxn=100155;
const int size=100150;
const int inf=0x7fffffff;
const ll P=1e9+7;
int n,m;
int c[maxn],tot=0;
ll fac[maxn],inv_fac[maxn];
ll C(int n,int m){
	return fac[m]*inv_fac[n]%P*inv_fac[m-n]%P;
}
ll ksm(ll a){
	ll ans=1;
	ll c=P-2;
	while(c){
		if(c&1)ans=ans*a%P;
		a=a*a%P;
		c=c>>1;
	}
	return ans%P;
}
#undef int 
int main(){
#define int ll
	int x,y,M;
	read(n),read(m);
	M=m;
	for(ri i=2;i*i<=M;i++){
		if(M%i==0){
			c[++tot]=1;
			M/=i;
			while(M%i==0){M/=i;c[tot]++;}
		}
	}
	if(M>1)c[++tot]=1;
	fac[0]=fac[1]=1;
	for(ri i=2;i<=size;i++)
		fac[i]=fac[i-1]*i%P;
	inv_fac[size]=ksm(fac[size]);
	for(ri i=size-1;i>=0;i--)
		inv_fac[i]=inv_fac[i+1]*(i+1)%P;
	ll ans=1;
	for(ri i=1;i<=tot;i++){
		ans=ans*C(n-1,n+c[i]-1)%P;
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;
vector<int> dp_arr;
int dist(vector<vector<int>>& G, int index, vector<int>& visited)
{
	if(dp_arr[index] != -1)
		return dp_arr[index];
	visited[index] = true;
	int dist_ = 0;
	for(auto i : G[index])
	{
		dist_ = max(dist_, 1+dist(G,i,visited));
	}
	dp_arr[index] = dist_;
	// cout << "index: " << index << " dist: " << dist_ << endl;
	return dist_;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> G(n);
	dp_arr.resize(n+1,-1);
	vector<int> visited(n,false);
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		G[x-1].push_back(y-1);
	}
	int max_ = 0;
	for(int i = 0; i < n; i++)
	{
		visited[i] = true;
		max_ = max(max_,dist(G,i,visited));
	}
	cout << max_ << endl;
	return 0;
}


Measured memory_bytes: 9216
#line 2 "cpplib/util/template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
struct __INIT__{__INIT__(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}__INIT__;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,...) for(auto i:range(__VA_ARGS__)) 
#define rrep(i,...) for(auto i:reversed(range(__VA_ARGS__)))
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
inline vector<long long> range(long long n){if(n<=0)return vector<long long>();vector<long long>v(n);iota(v.begin(),v.end(),0LL);return v;}
inline vector<long long> range(long long a,long long b){if(b<=a)return vector<long long>();vector<long long>v(b-a);iota(v.begin(),v.end(),a);return v;}
inline vector<long long> range(long long a,long long b,long long c){if((b-a+c-1)/c<=0)return vector<long long>();vector<long long>v((b-a+c-1)/c);for(int i=0;i<(int)v.size();++i)v[i]=i?v[i-1]+c:a;return v;}
template<typename T>inline T reversed(T v){reverse(v.begin(),v.end());return v;}
#define all(n) begin(n),end(n)
template<typename T,typename E>bool chmin(T& s,const E& t){bool res=s>t;s=min<T>(s,t);return res;}
template<typename T,typename E>bool chmax(T& s,const E& t){bool res=s<t;s=max<T>(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
//#include "../graph_tree/graph_template.hpp"
#line 2 "code.cpp"

int main(){
    lint n;
    cin>>n;
    lint ans=1;
    rep(i,n){
        lint x;
        cin>>x;
        ans=lcm(ans,x);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef long long ld;


int main() {
	// violinista forever xd
	ios::sync_with_stdio(0),cin.tie(0);
	string s;
	ll q;
	cin>>s>>q;
	ll f,t,m;
	string c;
	m=0;
	while(q--){
    cin>>t;
    if(t==2){
	cin>>f>>c;
	if(m%2){
	if(f==1)f=2;
	else f=1;
	}
	if(f==1)s.insert(0,c);
	else s.push_back(c[0]);
    }else m++;
	}
	if(m%2)reverse(s.begin(),s.end());
	
    cout<<s<<endl;
  
  
	return 0;
}

Measured memory_bytes: 3856
import java.util.Scanner;
class Main{
    
    static int[] A;

    public static void main(String[] args){
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    }
    


    public int bubblesort(int[] A){
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    }

    public void swap(int x,int y){
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    }

    public void call(int n){
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    }
    

}

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

int main() {
    int n; cin >> n;
    int a[105];
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) rep(j, n) {
        ans = max(ans, abs(a[i]-a[j]));
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
    string S, T;
    cin >> S >> T;

    int t_size = 0;
    int tmp = 0;
  	string ts = "";
    for (int i = 0; i <= S.size() - T.size() ; ++i) {
        ts = S.substr(i, T.size());
        for (int j = 0; j < ts.size() ; ++j) {
            if (ts.at(j) == T.at(j)) {
                ++tmp;
            }
        }
        if (tmp > t_size) t_size = tmp;
        tmp = 0;

    }

    cout << T.size() - t_size << endl;

}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=2e5+50;
int n;
char T[maxn];
int main() {
	scanf("%s",T),n=strlen(T);
	for(int i=0;i<n;++i) if(T[i]=='?') T[i]='D';
	puts(T);
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') 
      x++;
    else if (s[i] == 'D')
      x--;
    ans = max(ans, x);
  }
  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<n;++i)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;0<=i;--i)
#define rRep(i,n) for(int i=n;0<i;--i)
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define EPS 1e-8
#define INF 1e8

typedef double Real;
typedef int Int;
typedef vector<Int> vi;
typedef vector<vector<Int> > vvi;
typedef pair<Int,Int> pii;

inline Real sr(Real a) {return sqrt(max(a, (Real)0));}
const vi dy = {-1, 0, 1, 0}, dx = {0, -1, 0, 1};

template <typename K, typename V> ostream& operator<< (ostream& out, const pair<K, V>& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}

template <typename T> ostream& operator<< (ostream& out, const vector<T>& v) {
  out << '[';
  rep(i, v.size()) out << v[i] << ",";
  out << "\b], " << v.size();
  return out;
}

void solve(){
  Int H, W;
  cin >> H >> W;
  vvi board(H, vi(W));
  rep(y, H){
    string s; cin >> s;
    rep(x, W) board[y][x] = s[x] - '0';
  }

  // cout << board << endl;

  vvi dp(H, vi(W, 0));

  for(int x = 1; x < W; ++x){
    dp[0][x] = dp[0][x-1] + board[0][x];
  }
  for(int y = 1; y < H; ++y){
    dp[y][0] = dp[y-1][0] + board[y][0];
  }

  for(int y = 1; y < H; ++y){
    for(int x = 1; x < W; ++x){
      dp[y][x] = min(dp[y][x-1], dp[y-1][x]) + board[y][x];
    }
  }

  // cout << dp << endl;

  cout << dp[H-1][W-1] << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

  solve();

  return 0;
}

Measured memory_bytes: 3256
#include<stdio.h>
#include <sysexits.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int sum,N,i,max,k;
  sum=0;
  max=0;
  int p[10]={};
    if(scanf("%d",&N)>1){
    exit(0);
  }
    for(i=0;i<N;i++){
   if(scanf("%d",&p[i])>1){
    exit(0);
  }
    }
   for(i=0;i<N;i++){
     if(max<p[i]){
      max=p[i];
      k=i;
    }
   }
   p[k]=p[k]/2;
    for(i=0;i<N;i++){
      sum+=p[i];
    }
    printf("%d",sum);
  return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int k,x;
    scanf("%d%d",&k,&x);
    for(int i=x+1-k;i<=x+k-1;i++){
        printf("%d ",i);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- n := V.length v + 1
-- v ! i = 表が i 枚、裏が n - i 枚出る確率
solve :: [Double] -> U.Vector Double
solve ps = go ps (U.singleton 1)
  where
    go [] !vec = vec
    go (!p:ps) !vec = go ps $ U.zipWith (\u v -> p * u + (1 - p) * v) (0 `U.cons` vec) (vec `U.snoc` 0)

main = do
  n :: Int <- readLn
  -- 1 <= n <= 2999, n is odd
  ps :: [Double] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  let result = solve ps
  -- U.length result == n + 1
  print $ U.sum $ U.drop (n `quot` 2 + 1) result


Measured memory_bytes: 2556
// AtCoder Beginner Contest 138
// Practice
// A - Red or Not
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 1e5 + 15;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 7;
/******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
 
ll pow(ll x, ll n) {
  if (n == 0)
    return 1ll;
  ll temp;
  temp = pow(x, n / 2);
  if (n % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
 
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 
int sum_digit(int val) {
  if (val < 0)
    return -1;
  if (val == 0)
    return 0;
  int ans = 0;
  while (val > 0) {
    ans = ans + val % 10;
    val = val / 10;
  }
  return ans;
}
 
ll count_div(ll l, ll r, ll val) {
  if (l % val == 0)
    return (((r / val) - (l / val)) + 1);
  else
    return ((r / val) - (l / val));
}
 
int powmod(int x, int y, int m) {
  int res = 1;
  // x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    cout << res << endl;
    y = y / 2;
    cout << x << endl;
    x = (x * x) % m;
  }
  // cout << res << endl;
  return res;
}
/******************************************** CODE STARTS FROM HERE *************************************************/ 
 
int main()
{
  fastIO;
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0 ; i < n ; i++) cin >> arr[i];
  double ans;
  double sum = 0.0;
  for(int i = 0 ; i < n ; i++)
  {
    sum = sum + (double)(1.0 / arr[i]);
  }
  ans = 1.0 / sum; 
  cout << setprecision(12) <<  ans << endl;
}

Measured memory_bytes: 256
import itertools
import time
n = int(input())
names = []
ans = 0
ini = ["M", "A", "R", "C", "H"]
count = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
  name = input()
  if name[0] in ini:
    count[name[0]] += 1

combo = list(itertools.combinations(ini, 3))

for a, b, c in combo:
  ans += count[a]*count[b]*count[c]

print(ans)

Measured memory_bytes: 3188
k,c,i=11,j,y,z,p[2001],t[11][2000];f(int*x){z=*1[&x]-*x;}main(g){for(scanf(z="%d%d",t,&k);~scanf(z,&c,&g);)t[g][j++]=c;for(;--i;)for(qsort(t+i,j,4,f),z=k;z;--z)for(c=g=0;y=t[i][c];z>c++?p[z]=fmax(p[z],p[z-c]+g):0)g+=y+c+c;z=!printf("%d\n",p[k]);}

Measured memory_bytes: 560
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M), c(M, 0); // cの集合はbitで表す
    rep(i, M) {
        cin >> a[i] >> b[i];
        rep(j, b[i]) {
            int t;
            cin >> t;
            t--;
            c[i] |= (1 << t);
        }
    }

    vector<vector<ll>> dp(1100, vector<ll>(5000, INF));
    dp[0][0] = 0;

    rep(i, M) {
        rep(j, (1 << N)) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);

            int nj = j | c[i]; // i番目の鍵を使う時の次の集合をbitで

            dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + a[i]);
        }
    }

    cout << (dp[M][(1 << N) - 1] < INF ? dp[M][(1 << N) - 1] : -1) << endl;
}

Measured memory_bytes: 43264
# Aizu Problem 0068: Enclose Pins with a Rubber Band
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def distance(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

def is_to_the_left(p1, p2, p3):
    # determine whether point p3 is to the left from the line from p1 to p2
    position = (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0])
    return position < 0

def jarvis(points):
    # determine convex hull by Jarvis' algorithm:
    max_y = max([p[1] for p in points])
    pointOnHull = [p for p in points if p[1] == max_y][0]
    convex_hull = [pointOnHull]
    while len(convex_hull) == 1 or convex_hull[-1] != convex_hull[0]:
        p = convex_hull[-1]
        endpoint = points[0]
        for j in range(len(points)):
            if endpoint == pointOnHull or is_to_the_left(p, endpoint, points[j]):
                endpoint = points[j]
        pointOnHull = endpoint
        convex_hull.append(pointOnHull)
    return convex_hull[::-1]

while True:
    N = int(input())
    if N == 0:
        break
    points = [[float(_) for _ in input().split(',')] for __ in range(N)]
    print(N - (len(jarvis(points)) - 1))

Measured memory_bytes: 7920
#!/usr/bin/env python3

s = list(str(input()))

ans = [0 for _ in range(len(s))]

num_r = 0
num_l = 0
for i in range(len(s)-1):
    # print(s[i])
    if s[i] == "R":
        num_r += 1
    else:
        num_l += 1

    if s[i] == "R" and s[i+1] == "L":
        num_r_index = i
        num_l_index = i+1

    if s[i] == "L" and s[i+1] == "R":
        # print(num_r_index)
        # print(num_l_index)
        # print(num_r)
        # print(num_l)
        # print()
        right = (num_r+1)//2 + (num_l)//2
        left = (num_r)//2 + (num_l+1)//2
        ans[num_r_index] = right
        ans[num_l_index] = left
        num_r = 0
        num_l = 0

num_l += 1
right = (num_r+1)//2 + (num_l)//2
left = (num_r)//2 + (num_l+1)//2
ans[num_r_index] = right
ans[num_l_index] = left
num_r = 0
num_l = 0

# print(ans)
for i in ans:
    print(i, "", end="")
print()


Measured memory_bytes: 6208
#include<iostream>
#include<queue>
#include<set>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )

class Cube{
    public:
    string f, order;
    int y, x, p, c;
    Cube(int y=0, int x=0, string o=""):y(y), x(x), order(o){
	f = "rmbygc"; rep(i, 6) p = 0; c = 0;
    }
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
	char t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
    void rolld(int r){
	if ( r == 0 ) rep(i, 3) roll_y();
	else if ( r == 1 ) roll_x();
	else if ( r == 2 ) roll_y();
	else rep(i, 3) roll_x();
    }
    bool operator < ( const Cube &c) const{
	if ( x != c.x ) return x < c.x;
	if ( y != c.y ) return y < c.y;
	if ( p != c.p ) return p < c.p;
	if ( f != c.f ) return f < c.f;
	return false;
    }
};

#define MAX 32
int W, H;
char G[MAX][MAX];

int bfs(Cube s){
    queue<Cube> Q;
    set<Cube> V;
    Q.push(s);
    V.insert(s);

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

    Cube u, v;
    int ny, nx;
    while(!Q.empty()){
	u = Q.front(); Q.pop();
	if ( u.p == 6 ) return u.c;
	rep(r, 4){
	    ny = u.y + dy[r];
	    nx = u.x + dx[r];
	    if ( G[ny][nx] == 'k' ) continue;
	    v = u;
	    v.rolld(r);
	    if ( G[ny][nx] == 'w' || G[ny][nx] == u.order[u.p] && v.f[0] == G[ny][nx]){
		v.c++;
		v.y = ny;
		v.x = nx;
		if ( G[ny][nx] != 'w' ) v.p++;
		if ( V.find(v) == V.end() ) {
		    V.insert(v);
		    Q.push(v);
		}
	    }
	}
    }
    return -1;
}

main(){
    Cube init;
    int y, x;
    string order;
    while( cin >> W >> H && W ){
	rep(i, H+2) rep(j, W+2) G[i][j] = 'k';
	for ( int i = 1; i <= H; i++ ){
	    for ( int j = 1; j <= W; j++ ){
		cin >> G[i][j];
		if ( G[i][j] == '#' ) {
		    G[i][j] = 'w';
		    y = i; x = j;
		}
	    }
	}
	cin >> order;
	Cube init = Cube(y, x, order);
	int cost = bfs(init);
	if ( cost == -1 ) cout << "unreachable" << endl;
	else cout << cost << endl;
    }
}

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

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

  if (A+B<C+D) {
    cout << "Right" << endl;}
else if (A+B==C+D){cout << "Balanced";}
  else {cout << "Left" << endl;}}


Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abcdef
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input int array
            int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var x = inputArray[0];
            var y = inputArray[1];

            var found = false;
            for (int i = 0; i <= x; i++)
            {
                var t = x - i;

                if (2 * i + 4 * t == y) 
                {
                    found = true;
                    break;
                }
            }
            var str = found ? "Yes" : "No";
            Console.WriteLine(str);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28292
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        public static void main(String[] args){
          int x = getInt();
          int y = getInt();
          int mod = 1000000007;
          
          if(x > y){
            int t = y;
            y = x;
            x = t;
          }
          
          if(y > 2 * x){
            myout(0);
       		return;
          }
          if((x+y) % 3 != 0){
            myout(0);
      		return;
          }
          
          
	int tmpX = x;
	int tmpY = y;
	//原点に向かうべく、境界線のところ（y = 2x,またはy = x/2の座標）に帰れるか。帰れなかったら0
	int xLineCount = 0;
  int yLineCount = 0;
  while(true){
      if(tmpY / 2 == tmpX){
         break;
      }else if(tmpX < 0 || tmpY < 0){
               myout(0);
        return;
       }
    tmpX -= 2;
      tmpY -= 1;
      yLineCount++;
    }
   tmpX = x;
	 tmpY = y;
	while(true){
      if(tmpX / 2 == tmpY){
         break;
      }else if(tmpX < 0 || tmpY < 0){
            myout(0);
        return;
       }
      tmpX -= 1;
      tmpY -= 2;
      xLineCount++;
    }
          
          myout(originComb(xLineCount+yLineCount,xLineCount,mod));
        }
        //便利メソッド追加枠ここから

static long originComb(int n, int k, int m){
  long[] factrial = new long[n+1];
  long[] inverse = new long[n+1];
  factrial[0] = 1;inverse[0] = 1;
  for(int i = 1; i <= n; i++){
    factrial[i] = (factrial[i-1] * i) % m;
    inverse[i] = originPow(factrial[i], m-2,m) % m;
  }
  return factrial[n] * inverse[k] % m * inverse[n-k] % m;
}
  
static long originPow(long x, int n){
  return originPow(x,n,1000000007);
}
static long originPow(long x, int n,int m) {
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1)ans = ans * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return ans;
}

  
        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 32084
s = input()
n = int(input())
rev = 0
rev_check = False
first = list()
last = list()
for i in range(n):
    q = list(input().split())
    if q[0] == "1":
        rev += 1
        rev_check = not rev_check
    else:
        if rev_check ==  True:
            if q[1] == "1":
                last.append(q[2])
            else:
                first.append(q[2])
        else:
            if q[1] == "1":
                first.append(q[2])
            else:
                last.append(q[2])
if rev_check == False:
    print("".join(reversed(first)) + s + "".join(last))
else:
    print("".join(reversed(last)) + s[::-1] + "".join(first))

Measured memory_bytes: 72152
use std::io::*;
use std::str::FromStr;
use std::cmp::min;
use std::cmp::max;

fn main(){ 
    let (n,k) = (read::<i64>(),read::<i64>());
    let mut r=0;
    for b in 1..n+1{
        r += max(0,min(k,b)-1);
    }
    for q in 1..n+1{
        for b in 1..n/q+1{
            //println!("{},{}", q, b);
            r += min(min(k,b),n-q*b+1);
        }
    }
    println!("{}", n*n-r)
}
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("Error") as char) 
        .skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("Error")
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}

//高速nCk
// int MOD = 1000000007;
int N = 100000;
int fac[100001];
int inv[100001];

ll COM(ll n,ll k){
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}

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

    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(i,MOD-2)%MOD;
    }

    vector<int> a;
    REP(i,n){
        int x;
        cin >> x;
        a.pb(x);
    }

    int gsum[100001] = {0};
    for(int i = 1;i <= n;i++){
        gsum[i] = (gsum[i-1] + inv[i])%MOD;
    }

    int A[N+1];
    for(int i = 1;i <= n;i++){
        A[i] = (gsum[1+abs(1-i)] + gsum[1+abs(n-i)] - 1 + MOD)%MOD*fac[n]%MOD;
    }

    int ans = 0;
    REP(i,n){
        ans += a[i]*A[i+1];
        ans %= MOD;
    }



    cout << ans << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 4340
n = input()
s = input()
x = s
# '()' を取り除いておく.
while '()' in x:
    x = x.replace('()','')
# '(' はつけるとしても一番左
# ')' はつけるとしても一番右
print('(' * x.count(')') + s + ')' * x.count('('))

Measured memory_bytes: 2940
# 一般に偶奇のパリティで解ける
# 接するカードの数が奇数ならそのカードは表に偶数なら裏になる
# つまり接するカードの数が偶数となるカードを数え上げればよい
n,m = map(int,input().split())
# 3行3列以上の場合
# 全体 - (行の外枠) - (列の外枠) + 4(引きすぎた4隅を足す)
# さらに考察すると下になる
# 全体(n * m) - (2 * 列の数) - (行の数 * 2) + 4
if n >= 3 and m >= 3:
  print(n * m - (2 * m) - (n * 2) + 4)
elif n == 1 and m == 1:
  print(1)
# 1行の場合は両端のカード以外は偶数のカードと接するので列数 - 2が解
elif n == 1:
  print(m - 2)
# 2行の場合は全てのカードが奇数のカードと接するので答えは0
elif n == 2:
  print(0)
elif n >= 3 and m == 1:
  print(n - 2)
elif n >= 3 and m == 2:
  print(0)

Measured memory_bytes: 3064
import java.util.Scanner;


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

		int N = sc.nextInt();
		boolean result = true;

		int left = 0;
		int mid = sc.nextInt();	// 1個目
		int right = 0;

		for (int i = 0; i < N - 1; i++) {
			right = sc.nextInt();

			if (mid - 1 > right) {
				result = false;
				break;
			} else if (mid - 1 == right && left > mid - 1) {
				result = false;
				break;
			}

			if (left == mid) {
				left = mid;
				mid = right;
			} else {
				left = mid - 1;
				mid = right;
			}
		}

		System.out.println(result ? "Yes" : "No");
	}
}

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

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

sort(s.begin(), s.end()); 
sort(t.begin(), t.end()); 
reverse(t.begin(), t.end()); 

string ans = s < t ? "Yes" : "No";
 cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
using namespace std;
string a[30][30];
int main()
{
	int m,n;
	cin>>m>>n;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i][j]=="snuke")
			{
				cout<<char(j+64+1)<<i+1;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<map>
using namespace std;

string list[]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};


string s;
bool input(){
  s="";
  if(!(cin>>s)){
    return false;
  }
  return true;
}


string solve(){
  string res = "";
  int n=-1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      if(n==-1||i==0)continue;
      int tmp = s[i-1]-'0';
      res += list[tmp-1][n%list[tmp-1].size()];
      n=-1;
    }else{
      n++;
    }
  }
  return res;
}

int main(){
  int c;
  cin>>c;
  for(int i=0;i<c;i++){
    input();
    string ans = solve();
    if(ans.size()!=0)cout<<ans<<endl;
  }
}

Measured memory_bytes: 1216
n,x,y = map(int,input().split())
k = [0]*(n)

for i in range(1,n):
  for j in range(i+1,n+1):
    if i < x and j <= x:
      k[j-i] += 1
    elif i >= y and j > y:
      k[j-i] += 1
    elif x <= i < y and x< j <= y:
      ind = min(j-i,i-x+y-j+1)
      k[ind] += 1
    elif i < x and x < j <= y:
      ind = min(j-i,x-i+y-j+1)
      k[ind] += 1
    elif x <= i < y and y < j:
      ind = min(j-i,i-x+1+j-y)
      k[ind] += 1
    elif i< x and j > y:
      ind = x - i + 1 + j - y
      k[ind] += 1
      
for i in range(1,n):
  print(k[i])

Measured memory_bytes: 3444
#include <stdio.h>

double absd(double a){
  if(a>0){
    return a;
  }
  return -a;
}

int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  double ave=0;
  for(i=0;i<N;i++){
    ave=ave+a[i];
  }
  ave=ave/N;
  double min=absd(a[0]-ave);
  int ans=0;
  for(i=0;i<N;i++){
    if(min>absd(a[i]-ave)){
      min=absd(a[i]-ave);
      ans=i;
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int A,B,K;
    cin >> A >> B >> K;
    int c=0;
    ORREP(i,1000){
        if(A%i==0 && B%i==0)c++;
        if(c==K){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256