akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, Q, A[100000+1], B[50000+1];
	int counter = 0;
	
	cin >> N;
	for ( int i = 0; i < N; i++) scanf("%d", &A[i]);
	
	cin >> Q;
	for ( int i = 0; i < Q; i++) scanf("%d", &B[i]);
	
	int left, right, mid;
	for (int i = 0; i < Q; i++){
		left = 0;
		right = N;
		while (left < right) {
			mid = (left + right) / 2;
			if (B[i] == A[mid]) {
				counter++;
				break;
			} else if (B[i] < A[mid]) {
				right = mid;
			} else {
				left = mid + 1;
			}	
		}
	}
	
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 3844
N,K,Q = list(map(int,input().split()))
A = []
[A.append(int(input())) for i in range(Q)]

B = [K]*N

for a in A:
    B[a-1] += 1
B = list(map(lambda x:x-Q,B))
for b in B:
    if b>0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 13588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    vector<int> v;
    int N, X[8], Y[8];
    cin >> N;
    for(int i=0;i<N;i++) cin >> X[i];
    for(int i=0;i<N;i++) cin >> Y[i];
    for(int i=1;i<=N;i++) v.push_back(i);
    int a=0, b=0, id=0;
    do {
        id++;
        for(int i=0; i<v.size(); i++) {
            if(v[i]==X[i]){
                if(i==v.size()-1) a = id;
            }
            else break;
        }
        //cout << a << endl;
    } while (next_permutation(v.begin(), v.end()));
    /*
    while(!v.empty()){
        v.erase(v.begin());
    }
    for(int i=1;i<=N;i++) v.push_back(i);
    */
    //for(int i=0; i<v.size(); i++) cout << v[i];
    id=0;
    do {
        id++;
        for(int i=0; i<v.size(); i++) {
            if(v[i]==Y[i]){
                if(i==v.size()-1) b = id;
            }
            else break;
        }
        //cout << b << endl;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 10000000005
#define NIL -1
int main(){
    ll n, k; cin >> n >> k;
    ll h[n];
    ll mx = 0, mn = INF;
    for(ll i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h, h + n);
    for(ll i = 0; i < n - k + 1; i++){
        mn = min(mn, h[i+k-1] - h[i]);
    }
    cout << mn << endl;
}

Measured memory_bytes: 1024
def pow_mod(n, m, mod):
    if m == 0:
        return 1
    if m == 1:
        return n

    res = 1
    if m % 2 == 1:
        res = n

    return ((pow_mod(n * n % mod, m // 2, mod) % mod) * res) % mod


def frac_mod(n, mod):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % mod
    return ans


def cmb_mod(n, r, mod):

    mul1 = frac_mod(n, mod) % mod
    mul2 = pow_mod(frac_mod(r, mod), mod - 2, mod) % mod
    mul3 = pow_mod(frac_mod(n - r, mod), mod - 2, mod) % mod

    return (((mul1 * mul2) % mod) * mul3) % mod


x, y = map(int, input().split())

if (x + y) % 3 != 0 or (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    exit(0)


mod = 10 ** 9 + 7
a = (2 * y - x) // 3
b = (2 * x - y) // 3

if a < 0 or b < 0:
    print(0)
    exit(0)

print(cmb_mod(a + b, a, mod))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;

vector<ll> v;
queue<ll> que;

void fun(int n)
{
	que.push(3);
	que.push(5);
	que.push(7);
	while (que.size())
	{
		ll t = que.front();
		que.pop();
		if (t > n)
			continue;
		que.push(t * 10 + 3);
		que.push(t * 10 + 5);
		que.push(t * 10 + 7);
		if (t < 100)
			continue;
		bool i3 = false, i5 = false, i7 = false;
		for (ll i = t; i > 0; i /= 10)
		{
			if (i % 10 == 3)
				i3 = true;
			if (i % 10 == 5)
				i5 = true;
			if (i % 10 == 7)
				i7 = true;
		}
		if (i3 && i5 && i7)
			v.push_back(t);
	}
}

int main()
{
	ll n, ans = 0;
	cin >> n;
	fun(n);
	for (int i = 0; i < v.size(); i++)
	{
		if (v[i] <= n)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 892
n = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(n, 0, -1):
    ok = False
    for j in range(i, 0, -1):
        if b[j - 1] == j:
            ans.append(b.pop(j - 1))
            ok = True
            break
    if not ok:
        print(-1)
        exit()

for i in range(n):
    print(ans.pop())


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int b[n-1];
	for (int i=0; i<n-1; i++)
	{
		cin>>b[i];
	}
	int sum=0;
	n--;
	sum+=b[n-1]+b[0];
	for (int i=1; i<=n-1; i++)
	{
		sum+=min(b[i-1],b[i]);
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  long count=0,countA=0,countB=0;
  long doublecount=0;
  cin >> n;
  vector<string> data(n);
  for(int i=0; i<n; i++){
    cin >> data.at(i);
    if(data.at(i).at(0) == 'B'){
      countB++;
    }
    int length = data.at(i).length();
    if(data.at(i).at(length-1) == 'A'){
      countA++;
    }
    
    if(data.at(i).at(0) == 'B' && data.at(i).at(length-1) == 'A'){
      doublecount++;
    }
  }
  
  for(int i=0; i<n; i++){
    for(int j=0; j < data.at(i).length()-1; j++){
      if(data.at(i).at(j) == 'A'){
        if(data.at(i).at(j+1) == 'B'){
          count++;
        }
      }
    }
  }
  
  long sum;
  
  if((doublecount>0)&&(doublecount == countA) && (doublecount == countB)){
    sum = count + doublecount - 1;
  }else{
    sum = count + min(countA,countB);
  }
  
  cout << sum << endl;
}

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

typedef long long ll;

int main(){
    int n;
    ll sum = 0;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0) sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3612
# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。

if __name__ == "__main__":

	N,K = map(int,input().split())
	P = [ int(p)-1 for p in input().split() ]
	C = list(map(int,input().split()))

	# print(P)

	ans = -1e10

	for n in range(N):

		v = n
		currentCycleItemCnt = 0
		currentCycleTotal = 0

		while True:
			# 全頂点について、属するサイクルを計算する
			currentCycleItemCnt += 1
			currentCycleTotal += C[v]

			v = P[v]
			if v == n:
				# サイクル発見
				break

		procCnt = 0
		currentCycleSumTmp = 0

		while True:

			# 頂点vにコマが置かれた時の最高スコアを計算し、
			# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
			procCnt += 1
			currentCycleSumTmp += C[v]
			if K < procCnt:
				break

			cycleLoopCnt = 0
			if procCnt < K and 0 < currentCycleTotal:
				cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt

			# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt)
			tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal
			ans = max( ans, tmp )

			v = P[v]
			if v == n:
				# サイクル終了
				break

	print(ans)


Measured memory_bytes: 74212
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X;
ll A,B,C;
string S;
ll ans;
int main(){

    cin>>N>>A>>B;
    EREP(i,N){
        ll a=i,su=0;
        while(a>0){
            su+=a%10;
            a/=10;
        }
        if(A<=su&&su<=B){
            ans+=i;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
#include<algorithm>
#include<numeric>
#define LONG long long int
using namespace std;

int main() {
	int a;
	int b;
	cin >> a >> b;
	if (a > 12)cout << b << endl;
	else if (a > 5)cout << b / 2 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll n, x, a[2000], memo[2000];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x;
  FOR(i, 0, n) cin >> a[i];
  Fill(memo, linf);
  ll ans = linf;
  FOR(i, 0, n){
    ll cost = x * i;
    FOR(j, 0, n){
      mins(memo[j], a[(j-i+n)%n]);
      cost += memo[j];
    }
    mins(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int m,n,p;
	while(cin >> m >> n, (m||n)) {
		int p[10000];
		rep(i,m) {
			cin >> p[i];
		}
		sort(p,p+m,greater<int>());
		int sum = 0;
		rep(i,m) {
			if(i%n!=n-1) sum += p[i];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1188
<?php

$stdin = fopen('php://stdin', "r");
fscanf($stdin, "%d", $n);
$arr = array_map('intval', explode(' ', fgets($stdin)));

$c = 0;
for ($i=1; $i<$n-1; $i++) {
    $a = [];
    $a [] = $arr[$i-1];
    $a [] = $arr[$i];
    $a [] = $arr[$i+1];
    sort($a);

    if ($a[1] == $arr[$i]) {
        $c++;
    }
}

echo "$c\n";


Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
const int ab(int x){return x>0?x:-x;} 
int a[222222],b[222222];
long long f[222222],g[222222],h[222222],sum[222222];
long long ans;
int n;
long long wk()
{
	for(register int i=1;i<=n;++i)sum[i]=sum[i-1]+a[i]+b[i];
	for(register int i=1;i<=n;++i)
		f[i]=f[i-1]+2-a[i],
		cmin(f[i],sum[i]);
	for(register int i=n;i;--i)
		g[i]=g[i+1]+2-a[i],
		cmin(g[i],sum[n]-sum[i-1]);
	for(register int i=1;i<=n;++i)
		h[i]=h[i-1]+ab(a[i]-1),
		cmin(h[i],f[i]);
	long long min=0x3f3f3f3f;
	for(register int i=0;i<=n;++i)
		cmin(min,h[i]+g[i+1]);
	return min;
} 
int main()
{
	n=io::F();
	for(register int i=1;i<=n;++i)
	{
		int x=io::F();
		if(x<=2)a[i]=x;
			else if(x&1)a[i]=1,b[i]=x-1;
			else a[i]=2,b[i]=x-2;
	}
	ans=wk();
	std::reverse(a+1,a+n+1);
	std::reverse(b+1,b+n+1); 
	long long tmp=wk();
	cmin(ans,tmp);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 8704
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b;
	cin >> a >> b;

	cout << (b % a == 0 ? a + b : b - a) << endl;
	return 0;
}


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


int main() 
{
    long long int n,p,w;
    cin>>n;
    p=ceil(n/float(1000));
    w=(p*1000)-n;
    cout<<w;
    
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
int inv(int n){
    return p(n, MOD-2);
}
vector<int> fact;
int nCr(int n, int r){
    // if(r == 0)  return 1;
    return m(m(m(fact[n])*m(inv(fact[r])))*m(inv(fact[n-r])));
}
signed main(){
    fast();
    string s;
    int k;
    cin >> k;
    cin >> s;
    int n = k+s.length();
    fact.resize(n+1);
    fact[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = m(m(fact[i-1])*m(i));
    }
    int z = 26;
    int ans = p(z,n), f = 0;
    for(int i=0; i<s.length(); i++){
        f = m(m(nCr(n, i))*m(p(z-1, n-i)));
        ans = m(m(ans)-m(f));
    }
    // cout << f << endl;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 19844
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, D = in_nn()

    cnt = 0
    for i in range(N):
        x, y = in_nn()
        d = x**2 + y**2
        if d <= D**2:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	double times = n / 1000.0;
	if (floor (times) == ceil(times)) {
	    cout << 0 << endl;
	    
	}
	else {
	   cout << ceil(times) * 1000 - n << endl;  
	}
	return 0;
}


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

using namespace std;

struct point{
    int x, y;
    bool operator < (const point &a)const{
        if(x == a.x)
            return y < a.y;
        return x < a.x;
    }
};

struct data1{
    int ind, val;
    bool operator < (const data1 &a)const{
        return val > a.val;
    }
};

set <point>points;

const int NMAX = 300000;
int l[NMAX+5], c[NMAX+5];
vector<data1> linie;
vector<data1> coloana;


int main()
{
    int h, w, m, i, j, x, y;
    cin>>h>>w>>m;
    int solcol = 0;
    int sollin = 0;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        point aux;
        aux.x = x;
        aux.y = y;
        l[x]++;
        c[y]++;
        points.insert(aux);
    }
    for(i=1;i<=h;i++)
    {
        if(l[i]!=0)
        {
            data1 a;
            a.ind = i;
            a.val = l[i];
            linie.push_back(a);
        }
    }
    for(i=1;i<=w;i++)
    {
        if(c[i]!=0)
        {
            data1 a;
            a.ind = i;
            a.val = c[i];
            coloana.push_back(a);
        }
    }
    sort(linie.begin(), linie.end());
    sort(coloana.begin(), coloana.end());
    int sol = linie[0].val + coloana[0].val;
    point aux;
    aux.x = linie[0].ind;
    aux.y = coloana[0].ind;

    solcol = coloana[0].val;
    sollin = linie[0].val;
    bool ok = true;
    if(points.find(aux) != points.end()) {
        sol--;
        ok = false;
    }
    if(ok == true)
    {
        cout<<sol<<"\n";
        return 0;
    }
   for(i=0; i<linie.size();i++)
   {
       if(linie[i].val != sollin)
           break;

       for(j=0; j < coloana.size(); j++)
       {
           if(coloana[j].val != solcol)
               break;
           int csol = linie[i].val + coloana[j].val;
           if(csol == sol)
               continue;
           point aux;
           aux.x = linie[i].ind;
           aux.y = coloana[j].ind;
           bool ok1 = true;
           if(points.find(aux) != points.end()) {
               csol--;
               ok1 = false;
           }
           if(ok1 == true)
           {
               cout<<csol<<"\n";
               return 0;
           }
           sol = max(sol, csol);
       }
   }

    cout<<sol;



}

Measured memory_bytes: 28032
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    int ans = 0;
    if(s.size() == 0){
        ANS;
        return 0;
    }
    rep(i,s.size() - 1){
        if(s[i] == s[i+1]){
            ans++;
            if(s[i] == '0') s[i+1] = '1';
            else s[i+1] = '0';

        }
    }
    ANS;
    
    
    return 0;
}

Measured memory_bytes: 512
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]

lst=[-1]*n
for i in range(m):
    a,b=ab[i]
    a-=1
    b-=1
    if h[a]<h[b]:
        lst[a]=0
    elif h[a]>h[b]:
        lst[b]=0
    else:
        lst[a]=0
        lst[b]=0

ans=0
for i in range(n):
    if lst[i]==-1:
        ans+=1
print(ans)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N, ans=0;
	vector<int> child[100005];
	int a[100005]={};

	cin >> N;
	rep(i,N-1){
		cin >> a[i+2];
		child[a[i+2]].push_back(i+2);
	}

	queue<int> que;
	rep(i,N-1) if( child[i+2].empty() ) que.push(i+2);

	vector<int> v[100005];
	while( !que.empty() ){
		int i = que.front(); que.pop();
		int p = a[i];
		int depth = 0;
		if( v[i].empty() ) depth = 1;
		else{
			int s = v[i].size();
			sort( all(v[i]) );
			rep(j,s){
				chmax( depth, s-j + v[i][j] );
			}
		}
		v[p].push_back( depth );
		if( v[p].size() == child[p].size() ){
			que.push( p );
		}
	}

	ans = v[0][0] - 1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m, 0));
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int x;
            cin >> x;
            a[i][--x]++;
        }
    }
    int ans = 0;
    rep(i, m){
        int tmp = 0;
        rep(j, n) if(a[j][i]) tmp++;
        if(tmp == n) ans++;

    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll r,D,x;
    cin>>r>>D>>x;
    for (int i = 0; i <10; ++i)
    {
    	x=r*x-D;
    	cout<<x<<'\n';
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Job{
  int date, award;
  Job(int d,int a){
    date=d;
    award=a;
  }
  bool operator<(const Job& another)const{
    return award<another.award;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  std::priority_queue<int> pq_date[100001];
  std::priority_queue<Job> pq_main;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    pq_date[a].push(b);
  }
  int result=0;
  for(int i=1;i<=m;i++){
    if(!pq_date[i].empty()){
      pq_main.push(Job(i,pq_date[i].top()));
      pq_date[i].pop();
    }
    if(!pq_main.empty()){
      result+=pq_main.top().award;
      int push_date=pq_main.top().date;
      if(!pq_date[push_date].empty()){
        pq_main.push(Job(push_date,pq_date[push_date].top()));
        pq_date[push_date].pop();
      }
      pq_main.pop();
    }
  }
  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 6528
c=str(input())
if c == 'a' :
    print("b")
elif c == 'b' :
    print("c")
elif c == 'c' :
    print("d")
elif c == 'd' :
    print("e")
elif c == 'e' :
    print ("f")
elif c == 'f' :
    print("g")
elif c == 'g' :
    print("h")
elif c == 'h' :
    print("i")
elif c == 'i' :
    print("j")
elif c == 'j' :
    print("k")
elif c == 'k' :
    print("l")
elif c == 'l' :
    print("m")
elif c == 'm' :
    print("n")
elif c == 'n' :
    print("o")
elif c == 'o' :
    print("p")
elif c == 'p' :
    print("q")
elif c == 'q' :
    print("r")
elif c == 'r' :
    print("s")
elif c == 's' :
    print("t")
elif c == 't' :
    print("u")
elif c == 'u' :
    print("v")
elif c == 'v' :
    print("w")
elif c == 'w' :
    print("x")
elif c == 'x' :
    print("y")
elif c == 'y' :
    print("z")


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    string a;
    cin>>a;
    if(a=="SUN")
        cout<<"7"<<endl;
    else if(a=="SAT")
        cout<<"1"<<endl;
    else if(a=="FRI")
        cout<<"2"<<endl;
else if(a=="THU")
        cout<<"3"<<endl;
else if(a=="WED")
        cout<<"4"<<endl;
else if(a=="TUE")
        cout<<"5"<<endl;
else
    cout<<6<<endl;
    return 0;
}




Measured memory_bytes: 768
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{

      int n,k;
        scanf("%d%d",&n,&k);
        if(k==1)
        {
            printf("0");
            return 0;
        }

        int sum = n, c=1;
        while(sum < k)
        {
            sum += n-1;
            c++;
        }
        printf("%d",c);
    return 0;
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

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

    vector<int> l(n);
    rep(i,n) l[i] = INF;   

    int length = 1;
    l[0] = a[0];
    for(int i=1; i<n; i++){
        if(a[i] > l[length-1]){
            length++;
            l[length-1] = a[i];
        }else{
            *lower_bound(l.begin(), l.end(), a[i]) = a[i];
        }
    }

    cout << length << endl;
}


Measured memory_bytes: 3612
fun main(args: Array<String>) {
    val s = readLine()!!
    val dp = intArrayOf(1,0,0,0)
    s.forEach { when(it){
        'A' -> dp[1] = dp[1].mAdd(dp[0])
        'B' -> dp[2] = dp[2].mAdd(dp[1])
        'C' -> dp[3] = dp[3].mAdd(dp[2])
        '?' ->{
            dp[3] = dp[3].mMul(3).mAdd(dp[2])
            dp[2] = dp[2].mMul(3).mAdd(dp[1])
            dp[1] = dp[1].mMul(3).mAdd(dp[0])
            dp[0] = dp[0].mMul(3)
        }
    } }
    println(dp[3])
}

const val mod = 1000000007
fun Int.mAdd(a : Int) = if(this+a<mod) this+a else this+a-mod
fun Int.mSub(a : Int) = if(this-a>=0 ) this-a else this-a+mod
fun Int.mMul(a : Int) = (this*a.toLong()%mod).toInt()

Measured memory_bytes: 34272
def main():
	from collections import deque
	H, W = map(int, input().split())
	S = []
	for i in range(H):
		tmp = list(input())
		S.append(tmp[:])

	max_step = 0	 
	for i in range(H * W):
		#yはWで割り切れる位置、xはWのあまりの位置になる
		sy, sx = i // W, i % W
		#壁なら以降全部飛ばす
		if S[sy][sx] == "#":
			continue
		
		#-1で未訪問を表す
		steps = [[-1] * W for _ in range(H)]

		#sx,syを0で初期訪問位置とする
		steps[sy][sx] = 0
		#queueで発見済みだが未訪問の頂点を格納
		queue = [(sy, sx)]
		#発見済み+未訪問の点がなくなるまで続ける
		while len(queue) >= 1:
			#初手は初期位置がpopする
            #発見済み+未訪問の地点をcy,cxに格納してqueueからはpopする
			cy, cx = queue.pop(0)
			#上下左右の点をdy,dxに代入
			for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0)):
				ny, nx = cy + dy, cx + dx
				#迷路の範囲外でないか確認
				if not (0 <= ny <= H - 1 and 0 <= nx <= W - 1):
					continue
				#壁か訪問済みでないか確認
				if S[ny][nx] == "#" or steps[ny][nx] >= 0:
					continue
				#ここまで来たら移動可能であることがわかるので発見済み+未訪問にny,nxを追加
				queue.append((ny, nx))
				#移動前(cy,cx)から距離+1であることを記録
				steps[ny][nx] = steps[cy][cx] + 1
		# print("steps = {} after while".format(steps))
	 
		#i = H*Wの時のmaxを算出
		ms = max(max(r) for r in steps)
		#これまでのmaxと比較
		max_step = max(ms, max_step)
	print(max_step)

if __name__ == '__main__':
	main()

Measured memory_bytes: 43996
from sys import exit, stdin

input = stdin.readline
import copy
from scipy.special import comb


# from collections import deque,Counter
# import numpy as np

(S,) = list(map(int, input().split()))
i = 0
s = S - 3
ans = 0
while s >= 0:
    ans = (ans + comb(s + i, i, exact=True)) % (10 ** 9 + 7)
    i += 1
    s -= 3


print(int(ans % (10 ** 9 + 7)))


Measured memory_bytes: 42184
/* ***********************************************
Author        :yang12138
Created Time  :2017/11/12 19:11:02
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;



int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	int n,m;
	scanf("%d%d",&n,&m);
	printf("%d\n",(1<<m)*(m*1900+(n-m)*100));
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.append(0)

r = 0
ans = 0
su = 0

for l in range(N):
  while (l == r or su+A[r]==su^A[r]) and r<N:
    su += A[r]
    r+=1
  ans += r - l
  su -= A[l]
print(ans)

Measured memory_bytes: 32296
package main

import "fmt"

func main() {
	var n int
	var h []int
	var hi int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&hi)
		h = append(h, hi)
	}
	result := make([]int, n)
	for index, num := range h {
		result[num-1] = index + 1
	}
	// fmt.Printf("%v", result)
	for _, r := range result {
		fmt.Print(r)
		fmt.Print(" ")
	}
	fmt.Println("")
}


Measured memory_bytes: 6016
using System;

namespace D
{
    class Program
    {
        private const long MOD = 1000000000L + 7L;

        private static readonly long[,] Pascal = new long[2005, 2005];

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int N = Convert.ToInt32(input[0]);
            int K = Convert.ToInt32(input[1]);
            CreatePascal();
            for (var i = 1; i <= K; i++)
            {
                long ans = Pascal[N - K + 2, i + 1] * Pascal[K, i] % MOD;
                Console.WriteLine(ans);
            }
        }


        /// <summary>
        /// Overflowとか不正な値は考慮していない
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        static long Conbination(long left, long right)
        {
            long denominator = 1L;
            long numerator = 1L;
            while (right >= 1)
            {
                denominator *= right;
                numerator *= left;
                left--;
                right--;
            }
            return numerator / denominator;
        }


        static void CreatePascal()
        {
            Pascal[1, 1] = 1L;
            Pascal[2, 1] = 1L;
            Pascal[2, 2] = 1L;
            for (var i = 3; i < 2005; i++)
            {
                for (var j = 1; j <= i; j++)
                {
                    Pascal[i, j] = (Pascal[i - 1, j - 1] + Pascal[i - 1, j]) % MOD;
                }
            }
        }
    }
}


Measured memory_bytes: 42324
#include <iostream>
#include <string>
using namespace std;
int main(void){
int a,b[1000],min,max;
max=0;
min=1000;
    cin>>a;
    for(int i=0;i<a;i++){
        cin>>b[i];
    }
    for(int i=0;i<a;i++){
        if(max<b[i]){
            max=b[i];
        }
    }
    for(int i=0;i<a;i++){
        if(min>b[i]){
            min=b[i];
        }
    }
    cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;
const int M=210;
typedef long long ll;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,st[M][N],tp[M],v[N][M];
ll s[N],a[N],b[N];

int main() {
	cin>>n>>m;
	for(int i=2;i<=n;i++) s[i]=s[i-1]+gi();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) v[i][j]=gi();
	ll ans=0;
	for(int i=1;i<=n;i++) {
		memset(b,0,sizeof(b));
		for(int j=1;j<=m;j++) {
			b[i]+=v[i][j];
			ll diff;
			while(tp[j]&&(diff=v[i][j]-v[st[j][tp[j]]][j])>=0) {
				b[st[j][tp[j]-1]+1]+=diff;
				b[st[j][tp[j]]+1]-=diff;
				--tp[j];
			}
			st[j][++tp[j]]=i;
		}
		for(int j=1;j<=i;j++) {
			b[j]+=b[j-1];a[j]+=b[j];
			ans=max(ans,a[j]-s[i]+s[j]);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 8448
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
while(a!=0 and b!=0){
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
if((i+j)%2==0)cout<<'#';
else cout<<'.';
}
cout<<endl;
}
cout<<endl;
cin>>a>>b;
}
return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(x <= y) {
        ans++;
        x *= 2;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(2*m);
   vector<int> r(n);
   for (int i=0;i<2*m;i++){
      cin >> a.at(i);
      r.at(a.at(i)-1)++;
   }
   for (int i=0;i<n;i++){
      cout << r.at(i) << endl;
   }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int n,x;
cin>>n;
for(int i=1;i<=n;i++)
{
x=i;
if(x%3==0)cout<<" "<<i;
else
{
while(x)
{
if(x%10==3)
{
cout<<" "<<i;
break;
}
x/=10;
}
}
}
cout<<endl;
return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> factorial(n + 1);
  factorial[0] = 1;
  for(int i = 1;i <= n;i++)factorial[i] = (factorial[i - 1] * i) % mod;
  ll res = 0;
  for(int i = 0;i <= min(n - 1,k);i++){
    ll now = 0;
    now = 1;
    now *= factorial[n],now %= mod;
    now *= power(factorial[i],mod - 2),now %= mod;
    now *= power(factorial[n - i],mod - 2),now %= mod;
    
    now *= factorial[n - 1],now %= mod;
    now *= power(factorial[n - i - 1],mod - 2),now %= mod;
    now *= power(factorial[i],mod - 2),now %= mod;
    res += now,res %= mod;
  }
  cout  << res  << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    int k = 10010;
    vector<int> bs(n), cs(k);

    rep(i, n) cs[as[i]]++;
    rep(i, k - 1) cs[i + 1] += cs[i];
    rep(i, n) {
        cs[as[i]]--;
        bs[cs[as[i]]] = as[i];
    }

    rep(i, n - 1) cout<<bs[i]<<" ";
    cout<<bs[n - 1]<<endl;
}


Measured memory_bytes: 18664
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  vector<string> S(N);
  for(int i = 0;i < N;i++) cin >> S.at(i);

  sort(S.begin(),S.end());
  vector<pair<int,string>> c(0);
  int num = 1;
  for(int i = 0;i < S.size()-1;i++) {
    if(S.at(i) == S.at(i+1)) num++;
    else {
      c.push_back(make_pair(num,S.at(i)));
      num = 1;
    }
  }

  c.push_back(make_pair(num,S.at(S.size()-1)));

  sort(c.begin(),c.end());
  int M = c.at(c.size()-1).first;
   vector<string> ans(0);
  for(int i = c.size()-1;i >= 0;i--) {
    if(c.at(i).first == M) ans.push_back(c.at(i).second);
  }

  sort(ans.begin(),ans.end());
  for(int i = 0;i < ans.size();i++) cout << ans.at(i) << endl;

 



}


Measured memory_bytes: 21616
using System;
using System.Collections.Generic;
using System.Text;

namespace SwitchingRailRoad
{
    class Program
    {
        static void Main(string[] args)
        {
            var sb = new StringBuilder();
            var stk = new Stack<int>();

            while (true)
            {
                var str = Console.ReadLine();
                try
                {
                    var input = int.Parse(str);
                    if (input == 0)
                    {
                        int temp = stk.Pop();
                        sb.AppendLine(temp.ToString());
                    }
                    else
                    {
                        stk.Push(input);
                    }
                }
                catch
                {
                    Console.Write(sb);
                    break;
                }
             }

        }
    }
}



Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  int ans=1;
  while(ans*2<=n) {
    ans*=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

k = int(input())
sum = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd_ij = gcd(i, j)
        for k in range(1, k + 1):
            sum += gcd(gcd_ij, k)
print(sum)

Measured memory_bytes: 9108
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>

using namespace std;

int main() {
	int n;
	long long int l, h;
	int ans = 0;


	cin >> n;
	cin >> l;
	int count = 0;

	for (int i = 0; i < n-1; i++) {
		cin >> h;
		if (l >= h) {
			count++;
		}
		else {
			count = 0;
		}
		if (ans < count) {
			ans = count;
		}
		l = h;
	}


	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int N;

    cin >> N;

    long long L2 = 2;
    long long L1 = 1;
    long long L;

    for(int i = 2; i <= N; i++){
        L = L1+L2;
        L2 = L1;
        L1 = L;
    }

    if(N == 1){
        cout << 1 << endl;
    }else{
        cout << L << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

vector<mint> kai(100009),ikai(100009);

mint ncr(int n, int k){
    if (k < 0 || k > n) return 0;
    return kai[n]*ikai[k]*ikai[n-k];
  }





 




int main(){
  int n,k;cin>>n>>k;
  assert(n < mod);
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  
  kai[0]=1;
  rep(i,n){
    kai[i+1]=kai[i]*(mint)(i+1);
  }
  ikai[n]=kai[n].inv();
  rep(i,n){
    int o=n-1-i;
    ikai[o]=ikai[o+1]*(mint)(o+1);
  }
  
  sort(all(a));
  if(k==1) cout<<0<<endl;
  else{
  mint ans=0;
  
    rep(i,n){
      int l=n-1-i;
      
      ans+=((mint)a[l]-(mint)a[i])*ncr(n-1-i,k-1);
    }
    
    cout<<ans.x<<endl;
  }
  
}
  
  

Measured memory_bytes: 2560
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false 
using namespace std;


ll kmm(ll a, ll b) {
	return(a*b) / __gcd(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 2e5+5;
ll modpower(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modpower((x*x)%mod,n/2);
    else
        return (x*modpower((x*x)%mod,(n-1)/2))%mod;

}

void solve(){
	ll n,sum=0,a[MAXN];
	cin >> n;
	rep(i,0,n){
		cin >> a[i];
		sum+=a[i];
	}
	cout << sum-n;
}

int main() {
	isc;
	solve();
	return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b;
  bool bb = false;
  if(b >= 100) {
    c = 1000 * a + b;
  }
  else if(b >= 10) {
    c = 100*a + b;
  }
  else {
    c = 10* a + b;
  }
  for(int i = 0; i < 10000000; i++) {
    if(i*i ==c) {
      bb = true;
      break;
    }
  }
  if(bb) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)

int main(){
	int N;
	cin>>N;
	int cnt[N]={};
	
	for(int i=0;i<N;i++){
		int a;cin>>a;
		cnt[a]++;
		
		int x = abs((N-i-1)-i);
		cnt[x]--;
	}
	
	for(int i=0;i<N;i++){
		if(cnt[i]!=0){
			cout<<0<<endl;
			return 0;
		}
	}
	int x = 1;
	
	for(int i=0;i<N/2;i++){
		x=mod(x*2);
	}
	
	cout<<x<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
   long int a,b;
    cin>>a>>b;
    if((a+b)%2==0)
      cout<<(a+b)/2;
    else cout<<"IMPOSSIBLE";
  
    return 0; 
} 

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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,k;
    cin >> n >> k;
    vi a(n);
    ffor(i,n) cin >> a[i];
    sort(all(a));
    int ans = 1e10;
    int start = 0,end = start + k - 1;
    while(end < n){
        ans = min({ans,abs(a[start]) + abs(a[start] - a[end]),abs(a[end]) + abs(a[start] - a[end])});
        ++end;
        ++start;
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int c[300006];
	char tmp;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp == 'W')c[i] = ++cnt;
		else c[i] = cnt;
	}
	int mini = 9999999;
	for (int i = 0; i < n; i++) {
		int now;
		if (i == 0)now = (n - c[n - 1]) - (i + 1 - c[i]);
		if(i!=0) now=c[i - 1]+(n-c[n-1])-(i+1-c[i]);
		if (now < mini)mini = now;
	}
	cout << mini;
}

Measured memory_bytes: 1408