akhauriyash/Code-Regression huggingface dataset:
// Restricted.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <fstream>
using namespace std;

int BubSort(int x[], int n)
{
	int i, j, temp;

	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j > i; j--) {
			if (x[j - 1] > x[j]) {  /* 前の要素の方が大きかったら */
				temp = x[j];        /* 交換する */
				x[j] = x[j - 1];
				x[j - 1] = temp;
			}
		}
	}
	return 0;
}

/*


))))((((

())))(((()

(())))(((())

((())))(((()))


*/
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < 8; i++)
	{
		s.pop_back();
	}
	cout << s;
	system("pause");
	return 0;
}

int ColorfulLeaderboard()
{
	int n = 0;
	int a[4800];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int color[8] = { 0 };
	int over = 0;
	for (int j =0 ; j < n; j++)
	{
		if (1 <= a[j] && a[j] <= 399)color[0] = 1;
		if (400 <= a[j] && a[j] <= 799)color[1] = 1;
		if (800 <= a[j] && a[j] <= 1199)color[2] = 1;
		if (1200 <= a[j] && a[j] <= 1599)color[3] = 1;
		if (1600 <= a[j] && a[j] <= 1999)color[4] = 1;
		if (2000 <= a[j] && a[j] <= 2399)color[5] = 1;
		if (2400 <= a[j] && a[j] <= 2799)color[6] = 1;
		if (2800 <= a[j] && a[j] <= 3199)color[7] = 1;
		if (3200 <= a[j])over++;
	}
	//min
	int min = 0;
	for (int k = 0; k < 8; k++)
	{
		min += color[k];
	}
	if (min == 0)min = 1;
	
	//max
	int max = 0;
	for (int l = 0; l < 8; l++)
	{
		max += color[l];
	}
	max += over;
	cout << min << " " << max << endl;;

	return 0;
}
int TravelingAtCoDeerProblem()
{
	int n = 0;
	int a[1000];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	BubSort(a, n);
	cout << a[n-1] - a[0] << endl;
	system("pause");
	return 0;

}

int RGBCards()
{
	int r, g, b = 0;


	cin >> r>>g >> b;
	
	if ((100 * r + 10 * g + b) % 4 == 0)
	{
		cout<<"YES" << endl;

	}
	else
	{
		cout << "NO" << endl;

	}
	system("pause");
	return 0;
}


int Bugged()
{
	int n = 0;
	int s[100] = { 0 };
	int score = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}

	for (int j = 0; j < n; j++)
	{
		score += s[j];
	}

	int min = 0;
	bool first_flag = 0;

	//成績が10の倍数の場合
	if (score % 10 == 0)
	{
		for (int k = 0; k < n; k++)
		{

			if (s[k] % 10 != 0)
			{
				if (first_flag == 0)
				{
					min = s[k];
					first_flag = 1;
				}
				else
				{
					if (s[k] < min)
					{
						min = s[k];
					}
				}
			}
		}

	}
	else
	{
		cout << score << endl;
		return 0;
	}

	//10で割り切れない整数が存在する場合
	if (min != 0)
	{
		score -= min;
		cout << score << endl;
		return 0;
	}
	else
	{
		score = 0;
		cout << score << endl;

	}

	return 0;
}

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

	int a[1000] = { 0 };
	int n = 0;
	for (int i = 0; i < s.length(); i++)
	{
		n = (int)s[i];
		if (a[n] == 0)
		{
			a[n] = 1;
		}
		else
		{
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}

int Restricted()
{
	int x, y;
	cin >> x >> y;
	if (x + y < 10)
	{
		cout << x + y << endl;
	}
	else
	{
		cout << "error" << endl;
	}
	return 0;
}



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

int main(void) {
  int N, M, X;

  cin >> N >> M >> X;

  int left = 0;
  int right = 0;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    if (a < X) {
      left++;
    } else {
      right++;
    }
  }

  if (left > right) {
    cout << right << endl;
  } else {
    cout << left << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	int a,b,d;
	double s,ensyu,r;
	scanf("%lf",&r);
	s=r*r*M_PI;
	ensyu=r*2*M_PI;
	printf("%lf %lf\n",s,ensyu);
  
  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int table[300];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int x, n;
	cin >> x >> n;
	rep(i, n) {
		int a;
		cin >> a;
		table[a] = 1;
	}
	int ans = 0;
	rep(i, 220) {
		if(!table[i]) {
			if(abs(i - x) < abs(ans - x)) ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
from functools import reduce

def comb(n, r):
    if n < 0 or r < 0 or r > n:
        return 0
    r = min(r, n - r)
    if r == 0: return 1

    numer = [n - r + i + 1 for i in range(r)]
    denom = [i + 1 for i in range(r)]

    for i in range(1, r):
        divisor = denom[i]
        if divisor > 1:
            offset = (n - r) % (i + 1)
            for j in range(i, r, i+1):
                numer[j - offset] //= divisor
                denom[j] //= divisor

    return reduce(lambda x, y: x*y if y > 1 else x, numer)

def sieve(n):
    a = [1] * (n + 1)
    a[0] = a[1] = False
    for i in range(4, n+1, 2):
        a[i] = False
    lim = int(n**0.5) + 1
    for i in range(3, lim + 1, 2):
        if a[i]:
            for j in range(i + i, n + 1, i):
                a[j] = False
    return a

N = int(input())

factors = []
sv = sieve(N)
for p in range(2, N+1):
    if sv[p]:
        n = N
        x = 0
        while n // p > 0:
            n //= p
            x += n
        if x > 0:
            factors.append([p, x])

# print(factors)
ans = 0
for xx in [[[4,2],[2,1]],[[14,1],[4,1]],[[24,1],[2,1]],[[74,1]]]:
    c = 1
    done = 0
    for i, x in enumerate(xx):
        s = sum(f[1] >= x[0] for f in factors)
        s = max(0, s - done)
        if s < x[1]:
            c = 0
            break
        else:
            c *= comb(s, x[1])
            done += x[1]
    ans += c

print(ans)

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int S=scan.nextInt();
		int W=scan.nextInt();
		if (W>=S){
			System.out.println("unsafe");
		}else{
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35692
#include<bits/stdc++.h>
using namespace std;
typedef  int ll;
#define fr(i,k,n) for(ll i = k;i<n;i++)
#define mo map<ll,ll> 
int main(){
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n+2];
   
//ll ms[c];
unordered_map<ll,ll> ms;
   /*   fr(i,0,1e6+1){
    	ms[i] = 0;
    }*/
    //set<ll> sd;
   fr(i,0,n){
    	cin>>arr[i];
    //	sd.insert(arr[i]);
    //	ms[arr[i]]++;
    }
 
    ll ans = arr[0];
    fr(i,1,n){
    	ans = __gcd(ans,arr[i]);
    }
 if(ans >1){
 	cout<<"not coprime"<<"\n";
 }
 else{
 	ll au = 0;
 //	cout<<ms[3]<<"\n";
 	fr(i,0,n){
 		ll c = arr[i];
 		
 		fr(j,2,sqrt(arr[i])){
 			if(c%j == 0){
 				
 				ms[j]++;
 			}
 			while(c%j == 0){
 				c /= j;
 			}
 		
 			
 			if(ms[j]>1){
 		//		cout<<j<<"\n";
 				au = 1;
 				break;
 			}
 			
 		}
 		//cout<<ms[3]<<" "<<i<<"\n";
 		if(c>1){
 			ms[c]++;
 		//	cout<<ms[3]<<"\n";
 		}
 		if(ms[c]>1){
 			
 			//cout<<c<<"\n";
 			au = 1;
 			break;
 		}
 	}
 	if(au == 0){
 		cout<<"pairwise coprime"<<"\n";
 	}
 	else{
 		cout<<"setwise coprime"<<"\n";
 	}
 	
 }
}

Measured memory_bytes: 7572
n,a,b= map(int, input().split())
r=0
for i in range(n+1):
    s = 0
    t = str(i)
    k = len(t)
    for j in range(k):
        s +=int(t[j])
    if  a <= s <= b:
        r+=int(t)
print(r)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
long long arr[200005];
int MinimumNumIncreasingSubsequences( int n)
{
	multiset<int> last;


	for (int i = 0; i < n; i++) {


		multiset<int>::iterator it = last.lower_bound(arr[i]);



		if (it == last.begin())


			last.insert(arr[i]);

		else {
			it--;

			last.erase(it);
			last.insert(arr[i]);
		}
	}
	return last.size();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>arr[i];
	cout << MinimumNumIncreasingSubsequences(n)<<endl;
	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N;
int t[100005],x[100005],y[100005];

int main(){
	int T,X,Y;
	T=0;X=0;Y=0;
	cin >> N;
	for(int i=0;i<N;i++) cin >> t[i]>>x[i]>>y[i];
	for(int i=0;i<N;i++){
	 T=abs(t[i]-T);X=abs(x[i]-X);Y=abs(y[i]-Y);
	 if(T<(X+Y)){
	 	cout <<"No"<<endl;
	 	return 0;
	 }
	 T=T%2;X=X%2;Y=Y%2;
	 if(T!=((X+Y)%2)){
	 	cout << "No"<<endl;
	 	return 0;
	 }
	 T=t[i],X=x[i],Y=y[i];
	}
	cout <<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		System.out.println (str.toUpperCase());
	}

}

Measured memory_bytes: 24188
#http://abc078.contest.atcoder.jp/
# -*- coding: utf-8 -*-
n, z, w = map(int,input().split())
a = list(map(int,input().split()))

ans = []
ans.append( abs( a[-1] - w ) )
if len(a) > 1: ans.append( abs( a[-1] - a[-2] ) )

print(max(ans))


Measured memory_bytes: 3188
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//224
	int n,k;
	unordered_map<int,int> s;
	cin>>n>>k;
	REP(i,1,n) {
		int val;
		cin>>val;
		s[val]++;
	}
	vpii arr;
	arr.reserve((int)s.size());
	for(auto a:s) {
		arr.PUB({a.S,a.F});
	}
	sort(arr.begin(),arr.end());
	int kn = s.size();
	int cnt = 0;
	int i=0;
	while(kn>k) {
		kn--;
		cnt+=arr[i++].F;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 12924
N,A,B,C,D = map(int,input().split())
S = list(input())

ans = 'Yes'
if (C < D):
  for i in range(B-1,D-1):
    if (S[i] == '#' and S[i+1] == '#'):
      ans = 'No'
      break
  for i in range(A-1,C-1):
    if (S[i] == '#' and S[i+1] == '#'):
      ans = 'No'
      break
else:
  can_over = False
  for i in range(A-1,C-1):
    if (S[i] == '#' and S[i+1] == '#'):
      ans = 'No'
      break
    
  for i in range(B-1,D):
    if (S[i-1] == '.' and S[i] == '.' and S[i+1] == '.'):
      can_over = True
  if (can_over == False):
    ans = 'No'
print(ans)

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

const int maxn = 200005;

signed main() { 
    int n, k;
    scanf("%d %d", &n, &k);
	vector < int > p(n);
	for (int i = 0; i < n; ++i)
        scanf("%d", &p[i]);
	stack < int > min_p;
	int nearest = n, ans = 0, been_none = 0;
	stack < pair < int, int > > max_a, max_b;
	for (int j = p.size() - 1; j >= 0; --j) {
		while (min_p.size() > 0 && p[min_p.top()] >= p[j])
			min_p.pop();
		bool changes = 0;
		if (min_p.size() > 0 && p[j] > p[min_p.top()]) {
			changes = min_p.top() < j + k;
			nearest = min(nearest, min_p.top());
		}
		int curr_max = 0;
		if (max_a.size() > 0) curr_max = max(curr_max, max_a.top().second);
		if (max_b.size() > 0) curr_max = max(curr_max, max_b.top().second);
		if (j + k < n && p[j + k] < curr_max)
			changes = 1;
		min_p.push(j);
		if (j + k - 1 < n && nearest < j + k && (j + k==n || changes)) {
			++ans;
		}
		if (j + k - 1 < n && nearest >= (j + k))
			been_none = 1;
		if (k > 1) {
			if (max_a.size() > 0) max_a.push({ p[j], max(p[j],max_a.top().second) });
			else max_a.push({ p[j], p[j] });
			if (max_b.size() == 0) {
				int max_v = 0;
				while (max_a.size() > 0) {
					max_v = max(max_v, max_a.top().first);
					max_b.push({ max_a.top().first, max_v });
					max_a.pop();
				}
			}
			while (max_a.size() + max_b.size() > (k - 1))
				max_b.pop();
		}
	}
	printf("%d\n", ans + been_none);
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]%2!=0)
		{
			a[i]=15;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]%3!=0 and a[i]%5!=0)
		{
			cout<<"DENIED";
			return 0;
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
# Meaningful mean
N, K = map(int, input().split())
d = []
for _ in range(N):
    a = int(input())
    d.append(a-K)
b = [0 for i in range(N)]
b[0] = [d[0], 0]
for i in range(1, N):
    d[i] += d[i-1]
    b[i] = [d[i], i]
rev = 0
for i in range(N):
    if d[i] < 0:
        rev += 1
para = 1

b.sort()

b[0][0] = para

for i in range(1, N):
    now = b[i-1][1]
    next_ = b[i][1]
    if d[now] == d[next_]:
        b[i][0] = para
    else:
        para += 1
        b[i][0] = para
b.sort(key=lambda x: x[1])
for i in range(N):
    d[i] = b[i][0]

# 0<=i<=j<=Nで a_i<=a_jを満たす物の個数をカウントする


ans = N*(N+1)//2
# 反転すうを求める


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)

    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)


ans = N*(N+1)//2

tree = BIT(N+1)

for index, p in enumerate(d):
    tree.add(p, 1)
    rev += index+1-tree.to_sum(p)
    
ans -= rev
print(ans)


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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12


struct ten_t {
	int x;
	int y;
} ;

int compare_ten(const void *a, const void *b) {
  struct ten_t *A = (struct ten_t *)a;
  struct ten_t *B = (struct ten_t *)b;
  return A->x - B->x;
}

int main(void)
{
	//変数の宣言
	int h,w,n;
	static struct ten_t ten[200010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;

	//データの読み込み
	scanf("%d %d %d",&h,&w,&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&ten[i].x,&ten[i].y);
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	qsort(ten, n, sizeof(struct ten_t), compare_ten);
	
	j=0;
	temp=1;
	for(i=1;i<=h;i++){
		while(ten[j].x==i&&j<n){
			if(ten[j].y<temp){
				printf("%d",i-1);
				return 0;
			}else if(ten[j].y==temp){
				flag=1;
			}
			j++;
		}
		if(flag==1){
			flag=0;
		}else{
			temp++;
		}
	}
	
//	printf("計算部分終了\n");
	//出力
	printf("%d",h);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    int n;
    unordered_map<ll, ll> mp;

    cin >> n;

    ll tmp;
    REP(i, n) {
        cin >> tmp;
        mp[tmp]=i+1;
    }

    REP(i,n){
        cout << mp[i+1] << endl;
    }

    return 0;
}

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

bool used[200001];

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> e(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> e[i];
  }
  for (int i = m - 1; i >= 0; i--) {
    if (used[e[i]]) continue;
    cout << e[i] << endl;
    used[e[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 3492
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	if(65<=N && N<=90){
		printf("1\n");
	}
	else if(97<=N && N<=122){
		printf("2\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

stack<int> cs;
ll rem = 0;
ll cnum = 0;
int dfs(int digs_left, int ld = -1) {
    if (digs_left == 0) {
        rem--;
        if (rem == 0) {
            cout << cnum << endl;
            exit(0);
        }
        return 0;
    }

    if (ld == -1) {
        rep(i, 1, 10) {
            cnum = i;
            dfs(digs_left - 1, i);
        }
    } else {
        rep(i, 0, 10) if (abs(ld - i) <= 1) {
            cnum = cnum * 10 + i;
            dfs(digs_left - 1, i);
            cnum /= 10;
        }
    }

    return 0;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int x; cin >> x;
    rem = x;

    rep(i, 1, 15) dfs(i);
}

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

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

    for(int i = 0;i < n;i++){
        int k, p;
        cin >> k >> p;

        int ans = k % p;
        if(ans == 0)
            ans = p;

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







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

int a[100005],b[100005],c[100005];
int dp[100007][5];

int Solve(int idx, int n, int prev){
	
	if(idx == n)return 0;
	
	if(dp[idx][prev] != -1)return dp[idx][prev];
	
	int ans = -1;
	for(int i = 1; i <= 3; i++){
		if(i == prev)continue;
		if(i == 1)ans = max(ans, a[idx] + Solve(idx+1, n, i));
		else if(i == 2)ans = max(ans, b[idx] + Solve(idx+1, n, i));
		else ans = max(ans, c[idx] + Solve(idx+1, n, i));		
	}
	return dp[idx][prev] = ans;
}

int main(){
	int n; cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i = 0; i < n; i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	int ret = -1;
	for(int i = 1; i <= 3; i++){
		ret = max(ret, Solve(0,n,i));
	}
	cout<<ret<<endl;

//	cout<<Solve(0,n,0)<<endl;
	return 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	Scanner sc=new Scanner(System.in);
	while(true){
	int H=sc.nextInt();
	int W=sc.nextInt();
	if(H==0&&W==0) break;
        int k=0;
	for(int i=0;i<H;i++){
	    for(int j=0;j<W;j++){
		if(j==0){
		    if(i%2==0){
			System.out.print("#");k=1;
		    } else{
			System.out.print(".");k=0;
		    }
		}else	if(k%2!=0){
		System.out.print("#");
		}else{
		    System.out.print(".");
		}
		k++;
	    }
	    System.out.println();
	    
	}
	 System.out.println();
	}
    
    }
}


Measured memory_bytes: 35252
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;

int N, L;

int main() {
	cin >> N >> L;
	const int l = L;
	const int r = L + N - 1;
	int eat;
	if (l >= 0)
		eat = l;
	else if (r <= 0)
		eat = r;
	else eat = 0;
	const int ans = (l + r) * N / 2 - eat;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n,k;cin >> n>> k;
    vector<int> v(n);
    REP(i,n) cin >> v[i];

    int mx = 0;
    int md = 0;
    int cnt = 0;
    for(auto i = n-1;i>0;i--) {
        mx = max(v[i],mx);
        int d = mx - v[i-1];
        if (d > 0) {
            if (d > md) {
                md = d;
                cnt = 1;
            } else if (d == md) {
                cnt++;
            }
        }
    }


    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,l,a[210];

int main(){
	cin >> n;
	REP(i,0,2*n) cin >> a[i];
	sort(a,a+2*n); int s=0;
	REP(i,0,2*n-1) s+=min(a[i],a[i+1]),i++;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(C<=A){
        if(D<=A){
            cout << 0;
        }else{
            cout << min(B-A,D-A);
        }
    }else if(B<=D){
        if(B<=C){
            cout << 0;
        }else{
            cout << min(B-C,D-C);
        }
    }else if(C>A&&D<B){
        cout << D-C;
    }else{
        cout << 0;
    }
}

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

int main(){
    long long k;
    cin >> k;

    long long l;
    if(k % 7 == 0) l = 9*k/7;
    else l = 9*k;

    if(l % 2 == 0 || l % 5 == 0){
        printf("-1\n");
        return 0;
    }

    long long pow10 = 10;
    for(long long i = 1; i <= 1000000; i++){
        if(pow10%l == 1){
            printf("%lld\n", i);
            return 0;
        }
        pow10 = pow10 % l;
        pow10 = pow10*10;
    }
    return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>

int main(){
  char line[100];
  int n, x;
  int count;
  int i, j, k;
  int sum;
  while(1){
	count=0;
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%d %d", &n, &x);
	if((n==0)&&(x==0))
	  break;
	for(i=1; i<=(n-2); ++i){
	  for(j=i+1; j<=(n-1); ++j){
		for(k=j+1; k<=n; ++k){
		  sum=i+j+k;
		  if(sum==x)
			++count;
		}
	  }
	}
	printf("%d\n", count);
  }
	return 0;
}



Measured memory_bytes: 2032
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    w, h, x, y = map(int, input().split())

    print((w * h) / 2, 1 if float(x) == w / 2 and float(y) == h / 2 else 0)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29420
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<ll> tree[200010];
ll dist[200010] = {};
ll ans[200010] = {};
ll val[200010] = {};

struct Combination{
private:
    ll N;
    vector<ll> fac, facinv;

public:
    Combination(ll n){
        N = n;
        fac.push_back(1); fac.push_back(1);
        rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD);
        rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2));
    }
    ll power(ll x, ll n){
        if(n == 0) return 1LL;
        ll res = power(x * x % MOD, n/2);
        if(n % 2 == 1) res = res * x % MOD;
        return res;
    }
    ll nck(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
    }
    ll npk(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[n-k] % MOD;
    }
    ll get(ll x){return fac[x];};
    ll getinv(ll x){return facinv[x];};
};
ll cur_ans = 1;


void dfs(ll cur, ll par){
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        dist[cur] += dist[e];
    }
    dist[cur]++;
}
Combination cb(200010);


void dfs2(ll cur, ll par){
    ll sum = 0;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        sum += dist[e];
    }
    ll mul = 1;

    for(auto &e: tree[cur]){
        if(e == par) continue;
        cur_ans *= cb.nck(sum, dist[e]);
        mul *= cb.nck(sum, dist[e]);
        mul %= MOD;
        sum -= dist[e];
        cur_ans %= MOD;
        dfs2(e, cur);
    }
    val[cur] = mul; 

}
ll N;


void dfs3(ll cur, ll par){
    ans[cur] = cur_ans;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        ll v1 = cb.nck(N-1, N - dist[e]);
        cur_ans *= v1;
        cur_ans %= MOD;
        ll v2 = cb.nck(N-1, dist[e]);
        cur_ans *= cb.power(v2, MOD-2);
        cur_ans %= MOD;
        ll tmp = dist[e];
        dist[e] = N;
        dist[cur] = N - tmp;
        dfs3(e, cur);
        dist[e] = tmp;
        dist[cur] = N;
        cur_ans *= v2;
        cur_ans %= MOD;
        cur_ans *= cb.power(v1, MOD-2);
        cur_ans %= MOD;
    }
}

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

    cin >> N;
    ll a[200010], b[200010];


    rep(i,0,N-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
    }
    dfs(0, -1);
    dfs2(0, -1);
    // ans[0] = cur_ans;
    // print(cur_ans);
    dfs3(0, -1);
    rep(i,0,N) print(ans[i]);

    

}


Measured memory_bytes: 25816
import itertools

N = int(input())


As = []
xys = []
for i in range(N):
    tmp = []
    As.append(int(input()))
    for i in range(As[-1]):
        tmp.append(list(map(int, input().split())))
    
    xys.append(tmp)

#bit演算の準備
bit_list = list(itertools.product(range(2), repeat = N))

#loop
ans = 0 #ansの初期設定
for bit in bit_list:
    unkind_count = 0
    for Aindex, A in enumerate(As):
        if(bit[Aindex] == 0):
            continue #Unkindの意見は参考にしない
        for xy in xys[Aindex]:
#            print(xy)
            #真偽値を値化
            honest_to_unkind = (xy[1] == 0 and bit[xy[0]-1] == 1)
            unkind_to_honest = (xy[1] == 1 and bit[xy[0]-1] == 0)

            if(honest_to_unkind or unkind_to_honest):
                unkind_count +=1
    
    if(unkind_count == 0):
#       print("yatta")
        ans = max(ans, sum(bit))

print(ans)

Measured memory_bytes: 49628
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
    int to, cost;
};
// other libs
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}

class dijkstra {
  private:
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

    int find(int e) {
        return d[e];
    }
};
template<typename T>
class Union_Find {
  private:
    vector<T> t, s;

  public:
    Union_Find(T max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(T x, T y) {
        if (same(x, y))
            return;
        T tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    T Find(T n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(T x, T y) {
        return Find(x) == Find(y);
    }

    T get_Size(size_t a) {
        return s[a];
    }
};
bool ifPrime(int n){
    if(n==1)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main(signed argc, char* argv[]) {
    string s;
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    if(s=="Cloudy")cout<<"Rainy"<<endl;
    if(s=="Rainy")cout<<"Sunny"<<endl;
}

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

long n,a,x[100];

long dp[3000][100];

int main(int argc, char const *argv[])
{
    cin >> n >> a;
    
    for(int i = 0; i < n; i++)
    {
        cin >> x[i];
    }

    dp[0][0] = 1;

    for(int i = 0;i < n;i++) {
        for(int j = a*n;j >= x[i];j--) {
            for(int k = n;k > 0;k--) {
                dp[j][k] += dp[j-x[i]][k-1];
            }
        }
    }    
    long ans = 0;
    for(int j = 0;j <= a*n;j++) {
        for(int k = 1;k <= n;k++) {
            if(j % k == 0 && j / k == a)ans += dp[j][k];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

long long n, a, sum, i, j, t;
int l[100], mod = 1000000007, max;

int main() {
	
	int idx;
	
	scanf("%lld", &n);
	
	for (i = 0; i < n; i++)
	{
		scanf("%lld", &a);
		
		idx = 0;
		
		while (a)
		{
			l[idx] = (l[idx] + (a % 2)) % mod;
			idx++;
			a /= 2;
			
			if (idx > max)
				max = idx;
		}
	}
	
	idx = 1;
	
	for (i = 0; i < max; i++)
	{
		t = (l[i] * (n - l[i])) % mod;
		t = (t * idx) % mod;
		sum = (sum + t) % mod;
		idx *= 2;
		idx %= mod;
	}
	
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,d=0, e=0;
  for(int i=0; i<3; i++){
cin>>a;
    if(a==5)d++;
    if(a==7)e++;}
  if(d==2 and e==1)cout<<"YES";
  else cout<<"NO";}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int A, B;
  cin >> A >> B;
  if (A - 2 * B >= 0)
    cout << A - 2 * B << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  string str;
  cin>>str;
  if(str=="Sunny")
  {
    cout<<"Cloudy"<<endl;
  }
  else if(str=="Cloudy")
  {
    cout<<"Rainy"<<endl;
  }
  else if(str=="Rainy")
  {
    cout<<"Sunny"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
  char s[100015];
  int len;
  char c;
  int i;
  bool begin;

  fgets(s, 100015, stdin);
  len = strlen(s) - 1;

#if 0
  printf("string is %s\n", s);
  printf("len %d\n", len);
#endif

  begin = true;
  
  for (i = 0; i<len; i++) {
    if (begin) {
      if (s[i] == 'd') {
        if ((s[i+1] != 'r') ||
            (s[i+2] != 'e') ||
            (s[i+3] != 'a') ||
            (s[i+4] != 'm')) {
           printf("NO\n");
           return 0;
        }
        
        if ((s[i+5] == 'e') &&
            (s[i+6] == 'r') &&
            (s[i+7] != 'a')) {
          i+=6;
        } else {
          i+=4;
        }
      } else if (s[i] == 'e') {
        if ((s[i+1] != 'r') ||
            (s[i+2] != 'a') ||
            (s[i+3] != 's') ||
            (s[i+4] != 'e')) {
           printf("NO\n");
           return 0;
        }
        if (s[i+5] == 'r') {
          i+=5;
        } else {
          i+=4;
        }

      } else {
        printf("NO\n");
        return 0;
      }
    }
  }

  printf("YES\n");

  return 0;
}


Measured memory_bytes: 1592
#include<stdio.h>
#define INF 100000
int min(int a,int b){return a<b?a:b;}
int main(){
	while(1){
	int d[500];
	bool e[500][500];
	bool used[500];
	int i,j;
	int n,m;
	scanf("%d",&n);
	scanf("%d",&m);
	if(n==0&&m==0)return 0;
	for(i=0;i<n;i++)d[i]=INF;
	for(i=0;i<n;i++)for(j=0;j<n;j++)e[i][j]=false;
	for(i=0;i<n;i++)used[i]=false;
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		e[a-1][b-1]=true;
		e[b-1][a-1]=true;
	}
	d[0]=0;
	while(1){
		int ne=-1;
		for(i=0;i<n;i++){
			if(!used[i]&&(ne==-1||d[i]<d[ne]))ne=i;
		}
		if(ne==-1)break;
		used[ne]=true;
		for(i=0;i<n;i++)if(e[ne][i]){
			d[i]=min(d[i],d[ne]+1);
		}
	}
	int ans=0;
	for(i=1;i<n;i++)if(d[i]<=2)ans++;
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1276
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const cards = input[1].map(Number);

  cards.sort((a, b) => b - a);

  let Alice = 0;
  let Bob = 0;

  cards.forEach((card, index) => {
    if (index % 2 === 0) {
      Alice += card;
    } else {
      Bob += card;
    }
  });

  return Alice - Bob;
};

console.log(main(read()));


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

using namespace std;

pair<long long, long long> calc(map<int, int> odd) {
    pair<long long, long long> o1, o2;
    o1 = o2 = make_pair(int(), 0); // 0を-1にすると事故る 2種類以上なかったら0が答え
    for (auto e : odd) {
        if (e.second > o1.second) {
            if (o1.second > o2.second) o2 = o1;
            o1 = e;
        } else if (e.second > o2.second) {
            o2 = e;
        }
    }
    // cout << o1.first << " " << o1.second << endl;
    // cout << o2.first << " " << o2.second << endl;
    o1.first += o2.first * 1e6;
    o1.second += o2.second * 1e6;
    return o1;
}
int calc2(int n, int a, int b) {
    return n - a - b;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x[n];
    map<int, int> odd, even;
    for (int i = 0; i < n; ++i) { cin >> x[i]; if (i % 2 == 0) even[x[i]]++; else odd[x[i]]++; }
    if (n == 2) { // 第2候補までとれる条件
        if (x[0] == x[1]) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    } else if (n == 3) {
        if (x[0] == x[2] && x[0] != x[1]) cout << 0 << endl;
        else if (x[0] == x[2] && x[0] == x[1]) cout << 1 << endl;
        else if (x[0] != x[2] && x[0] != x[1]) cout << 1 << endl;
        else cout << 1 << endl;
        return 0;
    }
    pair<long long, long long> tmp = calc(odd);
    // cout << tmp.first << " " << tmp.second << endl;
    pair<int, int> o1, o2;
    o1 = make_pair(tmp.first % 1000000, tmp.second % 1000000);
    o2 = make_pair(tmp.first / 1000000, tmp.second / 1000000);
    tmp = calc(even);
    pair<int, int> e1, e2;
    e1 = make_pair(tmp.first % 1000000, tmp.second % 1000000);
    e2 = make_pair(tmp.first / 1000000, tmp.second / 1000000);
    if (o1.first != e1.first) {
        cout << calc2(n, o1.second, e1.second) << endl;
    } else {
        cout << min(calc2(n, o1.second, e2.second), calc2(n, o2.second, e1.second)) << endl;
    }
    // cout << o1.first << " " << o1.second << " " << o2.first << " " << o2.second << endl;
}


Measured memory_bytes: 7680
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1<<30
const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

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

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt< mod >;

int main(){
    ll n; cin >> n;
    vl a(n);
    vl bit(60,0);
    rep(i,n){
        cin >> a[i];
        rep(j,60){
            if(a[i] < (1LL<<j)) break;
            if(a[i] & (1LL<<j)) bit[j]++;
        }
    }
    mint ans = 0;
    rep(i,n){
        rep(j,60){
            if(a[i] & (1LL<<j)){
                bit[j]--;
                ans += (n-i-1-bit[j])*((1LL<<j)%mod);
            }else{
                ans += bit[j]*((1LL<<j)%mod);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int N;
int H[20];

bool solve(int i){
    Rep(j, 0, i){
        if(H[j] > H[i]) return false;
    }
    return true;
}

int main(){
    int ans = 0;
    cin >> N;
    Rep(i, 0, N) cin >> H[i];
    Rep(i, 0, N){
        if(solve(i)) ans++;
    }
    Print(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[105][105];
int l[105],r[105];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
	}
	for (int i=1;i<=n;i++){
		int t=0;
		for (int j=1;j<=m;j++){
			if(s[i][j]== '.'){
				t++;
			}
		}
		if(t==m) l[i]=1;
	}
	for (int i=1;i<=m;i++){
		int t=0;
		for (int j=1;j<=n;j++){
			if(s[j][i]=='.'){
				t++;
			}
		}
		if(t==n) r[i]=1;
	}
	for (int i=1;i<=n;i++){
		int flag=0;
		for (int j=1;j<=m;j++){
			if(l[i]||r[j]) continue;
			flag=1;
			printf("%c",s[i][j]);
		}
		if(flag) printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
x,y,p,q,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

i=0
j=0
k=0
s=0
for _ in range(x+y):
    u=[]
    if i<x and i<p:
        u.append([a[i],'a'])
    if j<y and j<q:
        u.append([b[j],'b'])
    if  k<r:
        u.append([c[k],'c'])
    u.sort(reverse=True)
    s+=u[0][0]
    if u[0][1]=='a':
        i+=1
    elif u[0][1]=='b':
        j+=1
    else:
        k+=1
print(s)

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

if __name__ == "__main__":
	N, M, X = list(map(int, input().split()))
	As = list(map(int, input().split()))
	cost = 0
	for A in As:
		if A > X:
			break
		cost += 1
	print(min(cost, M-cost))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
// #define mdfs
int N,M;

int main(void){
    // Your code here!
    cin >> N;
    int lt,lx,ly;
    lt = 0;lx = 0; ly = 0;
    for (int i = 0; i < N; i++) {
        int t,x,y;
        cin >> t >> x >> y;
        if ((t - lt) < (abs(x-lx) + abs(y-ly))) {
            // cout << t << endl;
            cout << "No" << endl;
            return 0;
        }
        
        if (((t - lt) % 2) != ((abs(x-lx + y-ly) % 2))) {
            cout << "No" << endl;
            return 0;
        }
        
        lt = t;
        lx = x;
        ly = y;
        
    }
    
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  dp[5][17][300007]; //i文字 jで終わる　

int main(){
  ll C=0;
  ll N;
  string S;
  cin >> N >> S;
  rep(i,N){
    rep(j,10){
      if(ctoi(S[i])==j){
        dp[1][j][i]=1;
        rep(k,10){
          if(i>0){
          dp[2][j][i]+=dp[1][k][i-1];
          dp[3][j][i]+=dp[2][k][i-1];
          }
        }
      }
      else{
        if(i>0){
        dp[1][j][i]=dp[1][j][i-1];
        dp[2][j][i]=dp[2][j][i-1];
        dp[3][j][i]=dp[3][j][i-1];
        }
      }
    }
  }
  rep(i,10){
    C+=dp[3][i][N-1];
  }
  cout << C <<  endl;
}

Measured memory_bytes: 69888