akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

#define NMAX 6
#define XMAX 10
#define MMAX 10

using namespace std;

struct data{
	int st,en,num;
};

int n,x,m;
int l,r,s;
int gaze[NMAX+1];
int ans[NMAX+1];
int mx=-1;
data rion[MMAX];

void search(int d){
	if(d==n+1){
		bool f=true;
		int sum=0;
		for(int i=0;i<m;i++){
			sum=0;
			for(int j=rion[i].st;j<=rion[i].en;j++){
				sum+=gaze[j];
			}
			if(sum!=rion[i].num) f=false;
		}
		if(f){
			sum=0;
			for(int i=1;i<=n;i++){
				sum+=gaze[i];
			}
			if(mx<sum){
				mx=sum;
				for(int i=1;i<=n;i++){
					ans[i]=gaze[i];
				}
			}
		}
	}
	else{
		for(int i=0;i<=x;i++){
			gaze[d]=i;
			search(d+1);
		}
	}
}

int main(){

	cin>>n>>x>>m;

	for(int i=0;i<m;i++){
		cin>>l>>r>>s;
		rion[i].st=l;
		rion[i].en=r;
		rion[i].num=s;
	}

	search(1);

	if(mx==-1) cout<<"-1"<<endl;
	else{
		for(int i=1;i<n;i++){
			cout<<ans[i]<<" ";
		}
		cout<<ans[n]<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n;
int a[22][22];
int dp[22][(1 << 22)];
const int MOD = 1e9 + 7;

int recur(int i, int mask){
    if(i == n && mask == (1<<n) - 1) return 1;
    if(i == n) return 0;
    if(dp[i][mask] != -1) return dp[i][mask];
    else{
        int ans = 0;
        for(int j = 0; j < n; j++){
            if(a[i][j] == 1 && (mask & (1<<j)) == 0){
                int mask2 = (mask ^ (1<<j));
                ans += recur(i+1,mask2);
                ans %= MOD;
            }
        }
        return dp[i][mask] = ans;
    }
}

int main(){
    cin>>n;
    for(int i = 0; i <n; i++){
        for(int j  = 0 ; j < n; j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<recur(0,0);
}


Measured memory_bytes: 360832
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

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

  intmax_t res = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) res += i;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void){
    LL N;
    cin >> N;

    //負の値が偶数個→絶対値の和
    //負の値が奇数個→一番絶対値が小さい数字のみマイナス
    LL negative_num_count = 0;
    vector<LL> A(N);
    rep(i, N) {
        cin >> A[i];
        if(A[i] < 0) negative_num_count++;
        A[i] = abs(A[i]);
    }
    sort(ALL(A));

    if(negative_num_count%2 == 1){
        A[0] = -A[0];
    }
    cout << accumulate(ALL(A), 0LL) << endl;
    return 0;
}

Measured memory_bytes: 1024
N, M, *L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a].append(b)
  dic[b].append(a)

log = set([1])
pre = [1]
p = 1
while True:
  for v in dic[p]:
    if v not in log:
      break
  else:
    break
  p = v
  pre.append(v)
  log.add(v)
ans = pre[::-1]
p = 1
while True:
  for v in dic[p]:
    if v not in log:
      break
  else:
    break
  p = v
  ans.append(v)
  log.add(v)
print(len(ans))
print(*ans)

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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  
  int cnt=0;
  for(int i=min(A,B); i>0; i--){
    if(A%i==0 && B%i==0){
      cnt++;
      if(cnt==K) cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

#pragma endregion 

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

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

	int n, m;
	cin >> n >> m;
	vi x(m);
	f_vI(x, m);
	if (n >= m) {
		cout << 0;
		return 0;
	}
	sort(all(x));
	vi d(m - 1);
	f(i, 0, m - 1) {
		d[i] = x[i + 1] - x[i];
	}
	sort(all(d),greater<LL>());
	f(i, 0, n-1) {
		d[i] = 0;
	}
	LL ans = 0;
	f(i, 0, m - 1) {
		ans += d[i]; 
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
s = input()
k = int(input())
if s[0] != "1":
  print(s[0])
  quit()
c = 0
while s[c] == "1":
  c += 1
  if c == len(s):
    print(1)
    quit()
if c < k:
  print(s[c])
else:
  print(s[k-1])

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[1005];
double sum;
int main(){
	cin >> n;
	sum = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a ,a + n);
	sum = (a[0] + a[1]) / 2.0;
	for(int j = 2; j < n; j++){
		sum += a[j];
		sum = sum / 2.0;
	}
	cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int h, w;
    while (cin >> h >> w && h) {
        for (int j=0; j<w; j++) cout << '#';
        cout << endl;
        for (int i=0; i<h-2; i++) {
            cout << '#';
            for (int j=0; j<w-2; j++) cout << '.';
            cout << '#' << endl;
        }
        for (int j=0; j<w; j++) cout << '#';
        cout << endl << endl;
    }
    return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  int Nagasa = S.size();
  for( int i = 0; i < Nagasa; i++ ){
    if( S.at(i) != T.at(i) ){
      cout << "No" << endl;
      break;
    }else if ( i == Nagasa - 1 ){
          cout << "Yes" << endl;
    }
  }
}



Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long FizzBuzz = -1;
        long Buzz = -2;
        long Fizz = -3;
        long sum = 0;
        for(long i = 1; i <= N; i++){
            if(i%3 != 0 && i%5 != 0){
                sum = sum + i;
            }else{

            }
        }
        System.out.println(sum);
    }
} 

Measured memory_bytes: 35848
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
#include <map>
using namespace std;
long long INF = 1000000009;
map<int, int> mp;
int main()
{
	int s;
	cin >> s;
	for (int i = 1; ; i++) {
		if (mp.count(s)) {
			cout << i << endl;
			return 0;
		}
		mp[s] = i;
		if (s % 2 == 0) {
			s /= 2;
		}
		else {
			s = 3 * s + 1;
		}
	}
}

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

using namespace std;

int main(void){
    int a,b,c;

    cin >> a >> b >> c;

    if(!(a == b && b==c) && (a==b || b==c || a==c)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <typeinfo>
#include <functional>
#include <iomanip>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;



char S[300][300];//itigo
bool Ku[300];//itigo

int kai[300][300];

int main()
{
	ll H, W, K;

	cin >> H >> W >> K;


	for (int h = 0; h < H; h++)
	{
		Ku[h] = true;
		for (int w = 0; w < W; w++)
		{
			cin >> S[h][w];
			if (S[h][w] == '#')
			{
				Ku[h] = false;
			}
		}
	}

	int a = 0;
	for (int h = 0; h < H; h++)
	{
		//空行はひとまず飛ばす.
		if (Ku[h])
			continue;

		bool first = true;
		a += 1;

		for (int w = 0; w < W; w++)
		{


			if (S[h][w] == '#')
			{
				if (first)
				{
					first = false;
				}
				else
				{
					a += 1;
				}
			}

			kai[h][w] = a;
		}
	}

	//kuu0
	if (Ku[0])
	{
		for (int h = 0; h < H; h++)
		{
			if (Ku[h])
				continue;

			for (int w = 0; w < W; w++)
			{
				kai[0][w] = kai[h][w];
			}
			break;
		}
	}

	//kuuwoumeru
	for (int h = 1; h < H; h++)
	{
		if (!Ku[h])
			continue;

		for (int w = 0; w < W; w++)
		{
			kai[h][w] = kai[h - 1][w];
		}
	}


	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{
			cout << kai[h][w];

			if (W - 1 != w)
			{
				cout << " ";
			}
		}

		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll n, m;    cin >> n >> m;
    ll *h = new ll[n];
    for (int i = 0; i < n; i++)   {
        cin >> h[i];
    }

    vector<bool> flag(n, true);

    for (int i = 0; i < m; i++) {
        ll a, b;    cin >> a >> b;
        a--, b--;
        if (h[a] > h[b])
            flag[b] = false;
        else if (h[a] < h[b])
            flag[a] = false;
        else  {
            flag[a] = false;
            flag[b] = false;
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (flag[i])
            ans++;
    }

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

Measured memory_bytes: 4424
#include <iostream>
#include <string>
using namespace std;
int main(){
string a,b;
cin>>a>>b;
a=a+a;
 string::size_type idx;
 idx=a.find(b);
if(idx==string::npos){
	cout<<"No"<<endl;
}else
	cout<<"Yes"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    bool ok = false;
    REP(i,0,3)
    {
      if(n%10 == 7) ok = true;
      n /= 10;
    }
    if(ok) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<int> a,b,c,d;
int n,m,q,ans=0;

void dfs(vector<int>A){
    if(A.size() == n+1){//n+1?
        int now = 0;
        rep(i,q) if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        ans = max(ans,now);
        return;
    }
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1,1));

    cout << ans << endl;

}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ c.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/

Measured memory_bytes: 3492
n=int(input())
l=list(map(int,input().split(" ")))

min_v=l[0]
max_v=l[0]

for i in range(n):
  if min_v > l[i]:
    min_v=l[i]
  if max_v < l[i]:
    max_v=l[i]

print(max_v-min_v)

Measured memory_bytes: 9108
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
  string s,t;
  cin>>s>>t;
  int ns = s.length();
  int nt = t.length();

  vector<vector<int>> dp =
    vector<vector<int>>(nt+1, vector<int>(ns+1,0));

  for(int ti=0;ti<nt;ti++){
    for(int si=0;si<ns;si++){
      int add = 0;
      if(t[ti]==s[si]){
        add = 1;
      }

      dp[ti+1][si+1] = max(
        dp[ti][si]+add,
        max(
          dp[ti+1][si],
          dp[ti][si+1]
        )
      );
    }
  }

  string res = "";
  int ti = nt;
  int si = ns;
  while(ti>0 && si>0){
    if(t[ti-1]==s[si-1]){
      res = s[si-1]+res;
      si -= 1;
      ti -= 1;
    }else if(dp[ti][si-1]>dp[ti-1][si]){
      si -= 1;
    }else{
      ti -= 1;
    }
  }

  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 35584
N = int(input())

uvw = []
Nlis = [-1] * N
Ndic = {}

for i in range(N-1):

    u,v,w = map(int,input().split())
    
    if u not in Ndic:
        Ndic[u] = [[v,w]]

    else:
        Ndic[u].append([v,w])

    if v not in Ndic:
        Ndic[v] = [[u,w]]

    else:
        Ndic[v].append([u,w])


ends = set([1])
Q = [1]
Q_cnt = 0
Nlis[0] = 0

while len(Q) > Q_cnt and N != 1:

    now = Q[Q_cnt]
    Q_cnt += 1

    for nw in Ndic[now]:

        if nw[0] not in ends:

            Q.append(nw[0])
            ends.add(nw[0])

            if nw[1] % 2 == 0:
                Nlis[nw[0]-1] =  Nlis[now-1]

            else:
                Nlis[nw[0]-1] = (Nlis[now-1] + 1) % 2

            #Ndic[nw[0]].remove([now,nw[1]])

for i in Nlis:
    print(i)


Measured memory_bytes: 98008
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int n,a[N],sol = 0;
int derang[N];
int swaps = 0;

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%d",a+i);a[i]--;
        if(i == a[i]) derang[i] = 1;
    }
    for(int i = 1;i<n;i++){
        int ol = swaps;
        if(derang[i] && derang[i-1]){
            derang[i] = 0;derang[i-1] = 0;
            a[i - 1] ^= a[i];
            a[i] ^= a[i-1];
            a[i - 1] ^= a[i];
            swaps++;
        }
        /**
        if(ol-swaps){
            for(int i = 0;i<n;i++)
                printf("%d ",a[i]);
            printf("\n");
        }
        **/
    }
    for(int i = 0;i<n;i++){
        if(derang[i]){
            swaps++;
        }
    }
    printf("%d\n",swaps);
}


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

using namespace std;

#define int long long

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	solve();
	return 0;
}

int n, m;
const int maxn = 2e5;
int have[maxn];
void solve() {
	cin >> n >> m;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> have[i];
		ans += have[i];
	}
	sort(have + 1, have + n + 1);
	vector<pair<int, int>> offers;
	for (int i = 1; i <= m; i++) {
		int a, b; cin >> a >> b;
		offers.push_back(make_pair(b, a));
	}
	sort(offers.begin(), offers.end());
	int r = (int) offers.size() - 1;
	for (int i = 1; i <= n; ++i) {
		if (r < 0) 
			break;
		if (offers[r].first > have[i] and r >= 0 and offers[r].second > 0) {
			ans += (offers[r].first - have[i]);
			offers[r].second--;
			while (r >= 0 and offers[r].second == 0) r--;
		} 
	}
	cout << ans;
}

Measured memory_bytes: 3188
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n;
  cin >> n;
  vector<int> c(n), s(n), f(n);
  REP(i, n-1) {
    cin >> c[i] >> s[i] >> f[i];
  }

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

  return 0;
}


Measured memory_bytes: 256
from collections import deque
def bfs(A,H,W,D):
    que = deque(D)
    cnt = 0
    d = [-1,1]
    tmp = set()
    flag = 0
    while que:
        u = que.popleft()
        
        y,x = u
        for k in range(2):
            s = y + d[k]
            t = x + d[k]
            if 0 <= s < H:
                if A[s][x] == '.':
                    A[s][x] = '#'
                    tmp.add((s,x))
                    flag = 1
              
            if 0 <= t < W:
                if A[y][t] == '.':
                    A[y][t] = '#'
                    tmp.add((y,t))
                    flag = 1

            
        if not que:
            que = deque(tmp) 
            tmp = set()
            if flag:
                cnt += 1
            flag = 0
    return cnt

def main():
    H,W = map(int,input().split(" "))
    A = []
    D = []
    D_append = D.append
    for i in range(H):
        tmp = []
        for j,s in enumerate(input()):
            tmp.append(s)
            if s == '#':
                D_append((i,j))
        A.append(tmp)

    ans = bfs(A,H,W,D)
    print(ans)


if __name__ == "__main__":
    main()
            

Measured memory_bytes: 136104
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int ans=0;
		n=1000-n;
		ans+=n/500;n%=500;
		ans+=n/100;n%=100;
		ans+=n/50;n%=50;
		ans+=n/10;n%=10;
		ans+=n/5;n%=5;
		ans+=n;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAX 255
#define NIL -1

typedef struct{ 
	int pk, lk, rk, key;
}node;

node T[MAX];
int i, h, id;

int parent(int x){
	return floor(x/2);
}
	
int left(int x){
	return 2*x;
}

int right(int x){
	return 2*x + 1;
}


int main(void) {
	scanf("%d", &h);
	
	//initialize
	for (i=1; i<=h; i++){
		T[i].pk = T[i].lk = T[i].rk = T[i].key = NIL;
	}
	
	for(i=1; i<=h; i++){
		scanf("%d", &id);
		T[i].key = id;
		T[i].pk = T[parent(i)].key;
	}

	
	for(i=1; i<=h; i++){
		T[i].lk = T[left(i)].key;
		T[i].rk = T[right(i)].key;
		printf("node %d: key = %d, ", i, T[i].key);
		if (i/2 > 0)
			printf("parent key = %d, ", T[i].pk);
		if (i*2 <= h)
			printf("left key = %d, ", T[i].lk);
		if ((i*2 + 1) <= h)
			printf("right key = %d, ", T[i].rk);
		printf("\n");
	}
	
	return 0;
}






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

int main() {
    /*変数定義，入力*/
    ll N;
    cin >> N;
    
    //ll A, B;cin >> A >> B;
    //vector<ll> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    
    /*出力*/
    cout << N / 2 + N % 2 << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func sepWords(n string) []string {
	temp := strings.Split(n, "")
	return temp
}
func countNum(n []string, num string) int {
	count := 0
	for _, v := range n {
		if v == num {
			count++
		}
	}
	return count
}
func main() {
	var n string
	fmt.Scan(&n)
	mat := sepWords(n)
	numZ := countNum(mat, "0")
	numO := countNum(mat, "1")
	if numZ > numO {
		fmt.Println(numO * 2)
	} else {
		fmt.Println(numZ * 2)
	}
}

Measured memory_bytes: 2944
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    int C=scan.nextInt();

    if(A+B+C>=22){
      System.out.println("bust");
    }else{
      System.out.println("win");
    }
  }
}

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

typedef long long ll;

ll a, b, c, d, ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> a >> b >> c >> d;
	a--;
	ll g = c * d / __gcd(c, d);
	ans = b - a;
	
	ans -= b / c;
	ans -= b / d;
	ans += b / g;
	
	ans += a / c;
	ans += a / d;
	ans -= a / g;
	
	cout << ans;
	return 0;
}

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

sushi_front = [0]
sushi_back = [0]
sushi_front2 = [0]
sushi_back2 = [0]
sushi = []

c= 0
d = 0
max_ = 0
max_2 = 0
for _ in range(N):
    sushi.append(list(map(int,input().split())))
    
    c += sushi[-1][1]
    d = sushi[-1][0]
    max_ = max(max_,c-d)
    max_2 = max(max_2, c-2*d)
    sushi_front.append(max_)
    sushi_front2.append(max_2)

sushi.reverse()
c = 0
d = 0
max_ = 0
max_2 = 0
for x in sushi:
    
    c += x[1]
    d = C -x[0]
    max_ = max(max_,c-d)
    max_2 = max(max_2, c-2*d)
    sushi_back.append(max_)
    sushi_back2.append(max_2)

ans = 0
for i in range(N+1):
    ans = max(ans,sushi_front[i]+sushi_back2[N-i],sushi_front2[i]+sushi_back[N-i])
print(ans)

Measured memory_bytes: 39952
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;
const int MOD = 998244353;

struct E {
  int a, b, c;
};

int main(void) {
  int L;
  scanf("%d", &L);
  L--;
  int n = 2;
  for(; L > (1<<n)-1;) {
    ++n;
  }
  vector<E> es;
  for(int i = 1; n-i >= 1; ++i) {
    es.push_back((E){n-i, n-i+1, 0});
    es.push_back((E){n-i, n-i+1, 1<<(i-1)});
  }
  if(L > 1) {
    for(int i = n-2; i >= 0; --i) {
      if(L & (1 << i)) {
        int mask = (1 << (i+1))-1;
        int c = L & ~mask;
        es.push_back((E){1, n-i, c});
      }
    }
    es.push_back((E){1, n, L});
  }
  printf("%d %d\n", n, (int)es.size());
  REP(i, es.size()) {
    printf("%d %d %d\n", es[i].a, es[i].b, es[i].c);
  }
  
  return 0;
}


Measured memory_bytes: 256
def resolve():
	n=int(input())
	a,b=map(int,input().split())
	p=list(map(int,input().split()))
	l=[0,0,0]
	for i in p:
		if i<=a:
			l[0]+=1
		elif i<=b:
			l[1]+=1
		else:
			l[2]+=1
	print(min(l))
resolve()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define NIN -100000000
#define EPS 0.0000000001
int main()
{
    long long n,i;
    scanf("%lld",&n);
    int cnt,sum;
    int ans=0;
    int j;
    for(i=2;i*i<=n;i++)
    {
        if(n%i) continue;
        cnt=0;
        while(n%i==0)
        {
            n=n/i;
            cnt++;
        }
        sum=0;
        for(j=1;sum+j<=cnt;j++)
        {
            ans++;
            sum=sum+j;
        }
    }
    if(n>1) ans++;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>

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

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

int main (){
  int N, x, y;
  cin >> N;
  for (int i = 0; ; i++ ){
    y = 1;
    for (int j  = 0; j < i; j++){
      y *= 10;
    }
    if (N / y == 0){
      break;
    }
    x += N / y % 10;
  }
  if (N % x == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int x = in.i();
        double root = Math.sqrt(x);
        while(true){
            int i = 2;
            for( ; i <= root; i++){
                if(x%i == 0){
                    break;
                }
            }
            if(i > root){
                break;
            } else {
                x++;
                if(root*root < x){
                    root++;
                }
            }
        }
        out.println(x);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

int main() {

        int x, y, z ;
        int A, B, C ;
        cin >> x >> y >> z;

        A = z;
        B = x;
        C = y;

        cout << A << " " << B << " "<< C << endl;

        return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(1,n-1):
    if p[i-1] > p[i] and p[i] > p[i+1]:
        cnt += 1
    elif p[i-1] < p[i] and p[i] < p[i+1]:
        cnt += 1
    
print(cnt)

Measured memory_bytes: 38384
use proconio::input;
use std::cmp::Ordering;

fn main() {
    input! {
        s: usize,
        w: usize,
    }

    solve(s, w);
}

fn solve(s: usize, w: usize) {
    match s.cmp(&w) {
        Ordering::Greater => println!("safe"),
        _ => println!("unsafe"),
    }
}


Measured memory_bytes: 2136
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())
d = [int(x) for x in input().split()]

d.sort()

print(d[N // 2] - d[N // 2 - 1])


Measured memory_bytes: 15036
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int n, m;
vector<ll> x(100001, 0), y(100001, 0);

int main(void){
    
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i) scanf("%lld", &x[i]);
    for(int i = 0; i < m; ++i) scanf("%lld", &y[i]);
    
    vector<ll> v(n); v[n - 1] = n - 1; 
    for(int i = n - 1; i > 0; --i) v[i - 1] = v[i] - 2; 
    vector<ll> w(m); w[m - 1] = m - 1;
    for(int i = m - 1; i > 0; --i) w[i - 1] = w[i] - 2; 
    
    ll a = 0, b = 0;
    for(int i = 0; i < n; ++i) a += x[i] * v[i] % MOD, a %= MOD;
    for(int i = 0; i < m; ++i) b += y[i] * w[i] % MOD, b %= MOD;
    printf("%lld\n", (a * b) % MOD);
    
    return 0;
}

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

const long long MOD = 1000000007;

void solve(long long N, long long M, std::vector<long long> a){
    long long dp[N+1] = {0};
    dp[0] = dp[1] = 1;
    bool flag[N + 1] = {false};
    for(long long i = 0;i<M;i++) flag[a[i]] = true;
    for(int i = 2;i <= N;i++){
        if (flag[i]) continue;
        if (flag[i - 1] and flag[i - 2]){
            cout << 0 << endl;
            return;
        }else if (flag[i - 1]) dp[i] += dp[i-2] % MOD;
        else if (flag[i - 2]) dp[i] += dp[i-1] % MOD;
        else dp[i] += (dp[i - 1] + dp[i - 2]) % MOD;
    }
    cout << dp[N] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, M, std::move(a));
    return 0;
}


Measured memory_bytes: 1920
<?php
$array = explode(" ",  fgets(STDIN));



// $f = range($array[0],$array[1]);
// $s = range($array[2],$array[3]);

$f_max = $array[0];
$s_max = $array[2];
$f_min = $array[1];
$s_min = $array[3];

$ints = [];



$ints[] = $f_max * $s_min;
$ints[] = $s_max * $f_min;
$ints[] = $f_min * $s_min;
$ints[] = $f_max * $s_max;

echo max($ints);
?>


Measured memory_bytes: 16252
N, K = map(int,input().split())
A = list(map(int, input().split()))
V = [-1]*N

X = 0
V[0] = 0
T = 0

while T < K:
  T += 1
  X = A[X]-1
  if V[X] != -1:
    t = T - V[X]
    k = (K - T) % t
    for i in range(k):
      X = A[X]-1
    break
  V[X] = T

print(X+1)

Measured memory_bytes: 32380
n=int(input())
a=list(map(lambda x:int(x)%4,input().split()))
for i,j in enumerate(a):
	if j==0:
		a[i]=2
	elif j==2:
		a[i]=1
	else:
		a[i]=0
if sum(a)<(n//2)*2:
	print('No')
else:
	print('Yes')

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

int main() {
  int p[5];
  while(cin >> p[0], p[0]) {
    for(int i = 1; i < 5; i++) cin >> p[i];
    
    bool flag[3] = {};
    for(int i = 0; i < 5; i++) {
      flag[p[i]-1] = true;
    }

    int win = 0, lose = 0;
    if(flag[0] && flag[1] && flag[2]) {
      win = lose = 0;
    } else if(flag[0] && flag[1]) {
      win = 1, lose = 2;
    } else if(flag[1] && flag[2]) {
        win = 2, lose = 3;
    } else if(flag[2] && flag[0]) {
        win = 3, lose = 1;
    }  
    for(int i = 0; i < 5; i++) {
      if(p[i] == win) p[i] = 1;
      else if(p[i] == lose) p[i] = 2;
      else p[i] = 3;
    }

    for(int i = 0; i < 5; i++) cout << p[i] << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<complex>
#include<fstream>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

//
int main()
{
	int n, r;
	cin >> n >> r;
	if (n >= 10)cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
ll s,t, d;
};
typedef vector<vector<Edge> > Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}

signed main()
{
    string a,b;
    cin>>a>>b;
    UM<char,int> lsta;
  UM<char,int> lstb;
    int key;
  key = 0;
    REP(i,a.size()){
        if(lsta.find(a[i])==lsta.end()){
            lsta[a[i]]=key;
            key++;
        }
        a[i]=lsta[a[i]];
    }
  key = 0;
    REP(i,b.size()){
        if(lstb.find(b[i])==lstb.end()){
            lstb[b[i]]=key;
            key++;
        }
        b[i]=lstb[b[i]];
    }
    if(a==b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 776
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,h[100000]={0},ans=0,i,a=0;
scanf("%d%d",&n,&h[0]);
for(i=1;i<n;i++){
scanf("%d",h+i);
if(h[i-1]>=h[i])
a++;
else{
ans=max(a,ans);
a=0;
}
}
ans=max(a,ans);
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 640
s = input()
s = list(s)
t = input()
t = list(t)
ans = 10**9
k = 0
for i in range(len(s)-len(t)+1):
    k = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            k += 1
    ans = min(ans,k)
print(ans)

Measured memory_bytes: 65220
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int q = scan.nextInt();
		for(int i = 0; i < q; i++){
			String s1 = scan.next();
			String s2 = scan.next();
			System.out.println(lcs(s1,s2));
		}

		scan.close();
		System.exit(0);
	}

	private static int lcs(String x, String y){
		int max = Math.max(x.length(), y.length());
		int[][] c = new int[max+1][max+1];
		int m = x.length(); // ??????????????????
		int n = y.length();
		int maxl = 0;
		x = ' ' + x; // 0?????????????????????????????\
		y = ' ' + y;
		for(int i = 1; i <= m; i++){ // 1???????????????m??????????????§
			for(int j = 1; j <= n; j++){ // 1???????????????n??????????????§
				if(x.charAt(i) == y.charAt(j)){
					c[i][j] = c[i-1][j-1] + 1; // ?????????0??§????????????????????????
				}else{
					c[i][j] = Math.max(c[i-1][j], c[i][j-1]);
				}
				maxl = Math.max(maxl, c[i][j]);
			}
		}
		return maxl;
	}
}

Measured memory_bytes: 65248
#include<iostream>
using namespace std;
int main()
{
	int n, in, sum, max;
	max = sum=0;
	cin >> n;
	while (n--)
	{
		cin >> in;
		sum += in;
		if (in > max) max = in;
	}
	sum -= max;
	if (max < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3092
import collections

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

c = collections.Counter(A).most_common()
c = sorted(c, key=lambda x: x[1])

count = 0
for i in range(len(c) - K):
    count += c[i][1]
print(count)

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

#define INF 99999999

using namespace std;

const int MAX_V = 100;

struct edge{
	int to,cap,cost,rev; //?????????,??????,?????¨,??????
};

vector<edge> G[MAX_V];

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back((edge){to,cap,cost,G[to].size()});
	G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}	

int min_cost_flow(const int n,const int s,const int t,int f)
{
	int res =0;
	int dist[MAX_V];
	int prevv[MAX_V];
	int preve[MAX_V];
	while(f>0){
		fill(dist,dist+n,INF);
		dist[s] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int v=0;v<n;v++){
				if(dist[v] == INF)	continue;
				for(int i=0;i<G[v].size();i++){
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;	//??????????????????????¨???¶
						preve[e.to] = i;	//????????????????¨???¶
						update = true;
					}
				}
			}
		}
		
		if(dist[t] == INF){
			return -1;
		}
		
		int d = f;
		for(int v=t;v!=s;v=prevv[v]){
			d = min(d,G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	
	return res;
}
		

int main()
{
	int n,m,s,t,f,result;
	cin >> n;	//????????°
	cin >> m;	//?????°
	cin >> f;	//??????
	for(int i=0;i<m;i++){
		int from,to,cap,cost;
		cin >> from; //????????????
		cin >> to; //?????????
		cin >> cap; //??????
		cin >> cost; //?????¨
		add_edge(from,to,cap,cost);
	}
	result = min_cost_flow(n,0,n-1,f);
	cout << result << "\n";
}

Measured memory_bytes: 3184
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val S = sc.next()
  val keyence = "keyence"
  val value = keyence.inits.toList.tail.init.zip(
    keyence.tails.toList.tail.init.reverse)
  val isExists = S.startsWith(keyence) ||
    S.endsWith(keyence) ||
    value.exists { case (l, r) => S.startsWith(l) && S.endsWith(r) }
  println(if (isExists) "YES" else "NO")
}


Measured memory_bytes: 55452
import itertools;n,m,q,*l=map(int,open(0).read().split());print(max(sum(d for a,b,c,d in[l[j*4:j*4+4]for j in range(q)]if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

Measured memory_bytes: 9208
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void) {
	int A,B;
	scanf("%d %d",&A,&B);
	
	if (A<=5) {
	  printf("0\n");
	} else if (6<=A && A<=12) {
	  printf("%d\n",B/2);
	} else {
	  printf("%d\n",B);
	 }
	 return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		String S=sc.next();
		int K=sc.nextInt();
		String ans="";
		for(int i=0; i<N; i++) {
			if(S.charAt(i)!=S.charAt(K-1)) {
				ans=ans+"*";
			}
			else {
				ans=ans+((char)S.charAt(K-1));
			}
		}
		pl(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 20692
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

template<unsigned long long mod>
class basic_mod_int{
private:
    unsigned long long num;
public:
    static basic_mod_int pow(basic_mod_int x,unsigned long long y)
    {
        return y==0?1:y%2==0?pow(x*x,y/2):x*pow(x,y-1);
    }
    basic_mod_int()=default;
    basic_mod_int(unsigned long long n):num(n%mod)
    {
    }
    explicit operator unsigned long long()const
    {
        return num;
    }
    bool operator==(const basic_mod_int&mi)const
    {
        return num==mi.num;
    }
    bool operator!=(const basic_mod_int&mi)const
    {
        return !operator==(mi);
    }
    basic_mod_int operator~()const
    {
        return pow(*this,mod-2);
    }
    basic_mod_int operator+(const basic_mod_int&mi)const
    {
        return num+mi.num;
    }
    basic_mod_int operator-(const basic_mod_int&mi)const
    {
        return num+mod-mi.num;
    }
    basic_mod_int operator*(const basic_mod_int&mi)const
    {
        return num*mi.num;
    }
    basic_mod_int operator/(const basic_mod_int&mi)const
    {
        return num*(~mi).num;
    }
    basic_mod_int&operator+=(const basic_mod_int&mi)
    {
        return*this=operator+(mi);
    }
    basic_mod_int&operator-=(const basic_mod_int&mi)
    {
        return*this=operator-(mi);
    }
    basic_mod_int&operator*=(const basic_mod_int&mi)
    {
        return*this=operator*(mi);
    }
    basic_mod_int&operator/=(const basic_mod_int&mi)
    {
        return*this=operator/(mi);
    }
};
template<unsigned long long mod>
class combination_modulo:basic_mod_int<mod>{
    using mod_int=basic_mod_int<mod>;
private:
    std::vector<mod_int>factorial_mod;
public:
    combination_modulo(unsigned long long max_n):factorial_mod(max_n+1)
    {
        factorial_mod[0]=1;
        for(unsigned long long i=1;i<=max_n;++i)factorial_mod[i]=factorial_mod[i-1]*i;
    }
    mod_int operator()(unsigned long long n,unsigned long long r)
    {
        return n<r?0:factorial_mod[n]/(factorial_mod[r]*factorial_mod[n-r]);
    }
};
int main()
{
    ll x=in(),y=in();
    if((2*y-x)%3!=0||(2*x-y)%3!=0){
        cout<<0<<endl;
    }else{
        ll a=(2*y-x)/3,b=(2*x-y)/3;
        if(a<0||b<0){
            cout<<0<<endl;
        }else{
            combination_modulo<static_cast<unsigned long long>(1e9+7)>cm(a+b);
            cout<<(unsigned long long)cm(a+b,a)<<endl;
        }
    }
}


Measured memory_bytes: 5504
def partiton(A, p, r):
    x = A[-1]
    i = p - 1

    for j in range(p, r):
        if A[j] <= x:
            i = i + 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


_ = int(input())
li = [int(x) for x in input().split(' ')]
q = partiton(li, 0, len(li) - 1)


li[q] = "[%s]" % (li[q])
print(" ".join([str(i) for i in li]))

Measured memory_bytes: 16368
n = int(input())
s = list(input())
if n % 2 == 0:
	a1 = ""
	a2 = ""
	for i in range(int(n / 2)):
		a1 += s[i]
		a2 += s[int(i + n / 2)]
	if a1 == a2:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int N; cin >> N;
	vector<long long>A(N);
	long long ans = 99999999999, left = 0, right = 0;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		right += A.at(i);
	}
	for (int i = 0; i < N; i++)
	{
		left += A.at(i);
		right -= A.at(i);
		ans = min(ans, abs(right - left));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<vector<int>> c(2,vector<int>(b));
  rep(i,2){
    rep(j,b)
      cin>>c.at(i).at(j);
      }
  for(int k=1;k<=a;k++){
    int e=0;
    rep(i,2){
      rep(j,b){
      if(c.at(i).at(j)==k)
        e++;
         }
      }
    cout<<e<<endl;
    }
}

Measured memory_bytes: 256
s=input()
K=int(input())
l=[]
for i in range(5):
    for j in range(len(s)):
        if j+i>=len(s):
            break
        l.append(s[j:j+i+1])
#print(l)
#print("A")
l=sorted(set(l))
#print(l)
print(l[K-1])

Measured memory_bytes: 5068
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int op(int lhs, int rhs, int ope){
	if(ope == 0) return lhs+rhs;
	if(ope == 1) return lhs-rhs;
	if(ope == 2) return lhs*rhs;
}

int calc(int a, int b, int c, int d, int o1, int o2, int o3){
	if( op(op(op(a, b, o1), c, o2), d, o3) == 10) return 0; // 1->2->3
//	if( op(op(a, op(b, c, o2), o1), d, o3) == 10) return 1; // 2->1->3
//	if(	op(a, op(op(b, c, o2), d, o3), o1) == 10) return 2; // 2->3->1
//	if(	op(a, op(b, op(c, d, o3), o2), o1) == 10) return 3; // 3->2->1
	if(	op(op(a, b, o1), op(c, d, o3), o2) == 10) return 4; // 1->3->2 (== 3->1->2)
	return -1;
}

void output(int a, int b, int c, int d, int o1, int o2, int o3, int type){
	string ope = "+-*";
	if(type == 0) printf("(((%d %c %d) %c %d) %c %d)\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
	if(type == 1) printf("((%d %c (%d %c %d)) %c %d)\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
	if(type == 2) printf("(%d %c ((%d %c %d) %c %d))\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
	if(type == 3) printf("(%d %c (%d %c (%d %c %d)))\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
	if(type == 4) printf("((%d %c %d) %c (%d %c %d))\n", a, ope[o1], b, ope[o2], c, ope[o3], d);
}

bool solve(int a, int b, int c, int d){
	rep(o1, 3) rep(o2, 3) rep(o3, 3){
		int res = calc(a, b, c, d, o1, o2, o3);
		if(res != -1){
			output(a, b, c, d, o1, o2, o3, res);
			return true;
		}
	}
	return false;
}

int main(){
	vi a(4);
	while(1){
		rep(i, 4) cin >> a[i];
		if(!a[0]) break;
		sort(all(a));
		bool ok;
		do{
			ok = solve(a[0], a[1], a[2], a[3]);
		}while(!ok && next_permutation(all(a)));
		if(!ok) cout << "0" << endl;
	}

	return 0;
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    char a;
    cin >> a;
    if((int)a<97)
        cout << 'A';
    else
        cout << 'a';
	return 0;

}



Measured memory_bytes: 5420
from itertools import product
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

# 全て試す。
li = list(product([0, 1], repeat=10))

ans = - 10 ** 19
for i in li[1:]:
  cnt = 0
  for f, p in zip(F, P):
    opendays = sum([a * b for a, b in zip(i, f)])
    cnt += p[opendays]
  ans = max(ans, cnt)
print(ans)

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

typedef struct{
	int amt;
	int sta;
} iland;

int main(void){
	int n;
	int havin;
	
	int comp(const void *a,const void *b);
	
	while(1){
		scanf("%d",&n);
		if(n == 0) break;
		iland arr[100];
		havin = 0;
		for(int i = 0;i < n;i ++){
			scanf("%d %d",&arr[i].amt,&arr[i].sta);
		}
		qsort(arr,n,sizeof(iland),comp);
		for (int j = 0;j < n;j ++) {
			havin += arr[j].amt;
			if(havin > arr[j].sta) {
				printf("No\n");
				break;
			}
			if(j == n - 1) printf("Yes\n");
		}
		
	}
	return 0;
}

int comp(const void *a,const void *b){
	return ((iland*)a)->sta-((iland*)b)->sta;
}


Measured memory_bytes: 1988