akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    vector<vector<int>> cnt(N,vector<int>(22));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < 22;j++) {
            cnt.at(i).at(j) = vec.at(i) % 2;
            vec.at(i) /= 2;
        }
    }
    ll ret = 0;
    int right = 0;
    vector<int> count(22);
    for(int left = 0;left < N;left++) {
        bool ret2 = true;
        while(right < N && ret2 == true) {
            for(int i = 0;i < 22;i++) {
                if(cnt.at(right).at(i) == 1) {
                    if(count.at(i) == 1) {
                        ret2 = false;
                    }
                    count.at(i)++;
                }
            }
            if(ret2 == false) {
                break;
            }
            right++;
        }
        ret += (right - left);
        for(int i = 0;i < 22;i++) {
            if(right != N) {
                count.at(i) -= cnt.at(right).at(i);
            }
            count.at(i) -= cnt.at(left).at(i);
        }
        if(right == left) {
            right++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 24448
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
thx
https://beta.atcoder.jp/contests/arc087/submissions/1876515
*/
struct Trie{
	Trie *son[2];
	Trie(){
		son[0]=son[1] = NULL;
	}
};

Trie* root;

void Insert(string str){
	int size = str.size();//文字サイズ
	Trie* node = root;//初期ノード
	for(int i=0;i<size;++i){
		int index = str[i]-'0';
		if( node->son[index] == NULL ){
			node->son[index] = new Trie();
		}
		//次のノードへ
		node = node->son[index];
	}
}

LL getGrundy(LL x){
	return x & -x;
}
LL L;
LL dfs(Trie* node,LL depth){
	LL ret = 0;
	for(int i=0;i<2;++i){
		if(node->son[i] == NULL ){
			ret ^= getGrundy(depth-1);
		}else{
			ret ^= dfs(node->son[i],depth-1);
		}
	}
	return ret;
}
void solve(){
	int N;
	
	cin>> N >> L;
	root = new Trie();
	for(int i=0;i<N;++i){
		string str;
		cin>> str;
		Insert( str );
	}
	LL ret = dfs(root,L+1);
	cerr << ret << endl;
	if( ret ){
		cout<< "Alice" << endl;
	}else{
		cout << "Bob" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 8172
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

using State = tuple<int, int, int>;
using D = long double;
using P = pair<D, State>;

const D INF = 1e8;
const D eps = 1e-8;

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

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

    int h, w, k;
    cin >> h >> w >> k;

    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    --sy;
    --sx;
    --gy;
    --gx;

    vector<string> c(h);
    rep(i, h) cin >> c[i];

    auto OK = [&](int y, int x) {
        return 0 <= y && y < h && 0 <= x && x < w && c[y][x] == '.';
    };

    vector<vector<vector<D>>> dp(h, vector<vector<D>>(w, vector<D>(4, INF)));
    priority_queue<P, vector<P>, greater<P>> pq;
    rep(i, 4) {
        dp[sy][sx][i] = 0;
        pq.push({0, {sy, sx, i}});
    }

    while (!pq.empty()) {
        P now = pq.top();
        pq.pop();

        State s = now.se;
        int y = get<0>(s), x = get<1>(s), d = get<2>(s);
        D val = dp[y][x][d];
        if (now.fi - eps > val) continue;

        int ny = y + dy[d], nx = x + dx[d];
        if (OK(ny, nx)) {
            D ndp = val + 1.0 / k;
            if (dp[ny][nx][d] - eps > ndp) {
                dp[ny][nx][d] = ndp;
                pq.push({ndp, {ny, nx, d}});
            }
        }

        rep(i, 4) {
            D ndp = ceil(val - eps);
            if (dp[y][x][i] - eps > ndp) {
                dp[y][x][i] = ndp;
                pq.push({ndp, {y, x, i}});
            }
        }
    }

    D mn = INF;
    rep(i, 4) mn = min(mn, dp[gy][gx][i]);

    int ans = (int)(ceil(mn - eps) + eps);
    if (abs(mn - INF) < eps) ans = -1;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 207272
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

N=int(input())

ans=num2alpha(N)
ans=ans.lower()

print(ans)

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

using namespace std;

int main() {
    int n;
    long long a, b;
    cin >> n >> a >> b;

    vector<long long> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }

    long long ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        ans += min((x[i + 1] - x[i]) * a, b);
    }

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


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    c=a+b;
    if(c%2==0){
        c/=2;
        printf("%d\n",c);
    }else{
        printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 128
init_list = list(map(lambda x: int(x) if x.isdigit() else x, input().split()))

num1 = 0
num2 = 0

def calc(n1, n2, a):
    if a == '+':
        return n1 + n2
    elif a == '-':
        return n1 - n2
    elif a == '*':
        return n1 * n2

list = []

for l in init_list:
    if l == '+' or l == '-' or l == '*':
        a = list.pop(-1)
        b = list.pop(-1)
        list.append(calc(b, a, l))

    else:
        list.append(l)

print(list[0])


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

 int main(){
 	int N,A;
 	cin >> N >> A;
 	if( N%500 <= A ){
 		cout << "Yes"<< endl;
 		}
 		else{
 			cout << "No" << endl;
 			
 		}
 }

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i;
	char s[4],d[8][3]={"a","SA","FR","TH","WE","TU","MO","SU"};
	scanf("%s", s);
	for(i=1; i<8; i++)
	{
		if(s[0]==d[i][0]&&s[1]==d[i][1])
		printf("%d\n", i);
	}
	
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
nums = []
for i in range(1, N + 1):
    nums.append(i)
Per = list(itertools.permutations(nums, N))
a = Per.index(P)
b = Per.index(Q)
print(abs(a - b))

Measured memory_bytes: 8052
# https://atcoder.jp/contests/abc046/tasks/arc062_a

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def div(a, b):
    if a % b == 0:
        return a // b
    else:
        return (a // b) + 1

def main():
    n = int(input())
    t, a = 1, 1
    for _ in range(n):
        tt, at = map(int, input().split())

        temp_t = div(t, tt)
        temp_a = div(a, at)
        co = max(temp_t, temp_a)

        t = co * tt
        a = co * at

    print(t + a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 998244353;

ll exp(ll x, ll a);  // x^a (mod MOD)
ll comb(ll n, ll r); // nCr (mod MOD)

vector<ll> fac(200005);  // n! (mod MOD)
vector<ll> ifac(200005); // (k!)^(MOD-2) (mod MOD) = (k!)^(-1) (mod MOD)

int main()
{
    ll N, M, K;
    cin >> N >> M >> K;

    // fac,ifacの値をあらかじめ用意しておく
    fac.at(0) = 1;
    ifac.at(0) = 1;
    rep(0, i, 200000)
    {
        fac.at(i + 1) = (fac.at(i) * (i + 1)) % MOD;
        ifac.at(i + 1) = (ifac.at(i) * exp(i + 1, MOD - 2)) % MOD;
    }

    ll ans = 0;
    ll tmp = exp(M - 1, N - K - 1);
    for (ll i = K; i >= 0; i--)
    {
        ans += ((M * tmp) % MOD * comb(N - 1, i)) % MOD;
        ans %= MOD;
        tmp *= (M - 1);
        tmp %= MOD;
    }

    cout << ans << endl;
}

ll exp(ll x, ll a)
{
    if (a == 0)
    {
        return 1;
    }
    if (a % 2 == 0)
    {
        ll xx = (x * x) % MOD;
        return exp(xx, a / 2) % MOD;
    }
    else
    {
        return (x * exp(x, a - 1)) % MOD;
    }
}

ll comb(ll n, ll r)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0)
    {
        return 0;
    }
    ll tmp = (ifac.at(n - r) * ifac.at(r)) % MOD;
    return (tmp * fac.at(n)) % MOD;
}

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

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

Measured memory_bytes: 256
#include<stdio.h>  
    main(){  
      int a,c,d=0,e=0,f=0,g=0;  
      int b[10000];  
      while(1){  
        scanf("%d",&a);  
        if(a==0)break;  
        for(c=0;c<a;c++){  
          scanf("%d",&b[c]);  
          if(b[c]>=2){  
        d=1;  
          }  
          else if(b[c]==0){  
        f=f+1;  
          }   
          else{  
        e=e+1;  
          }  
        }  
        if(d!=1){  
          printf("NA\n");  
        }  
        else{  
          g=a-f+1;  
          printf("%d\n",g);  
        }  
        d=0;  
        e=0;  
        f=0;  
        g=0;  
      }  
      return 0;  
    }  

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

int main(){
	int a[10000],b[10000],c=0;
	cin>>a[0]>>b[0];
	while(a[c]!=0||
		b[c]!=0){
		cin>>a[c+1]>>b[c+1];
		c++;
	}
	for(int d=0;d<c;d++){
		for(int e=0;e<b[d];e++) cout<<'#';
		cout<<endl;
		for(int i=2;i<a[d];i++){
			cout<<'#';
			for(int j=2;j<b[d];j++){
				cout<<'.';
			}
			cout<<'#'<<endl;
		}
		for(int f=0;f<b[d];f++) cout<<'#';
		cout<<endl<<endl;;
	}
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int a, b, c, k, maks, n;
int main()
{
    cin >> a >> b >> c;
	cin >> k;
    for (int i = 1; i <= k; i++)
    {
        if (a > b && a > c)
        {
            a *= 2;
            maks = a + b + c;
        }
        else if (b > a && b > c)
        {
            b *= 2;
            maks = a + b + c;
        }
        else
        {
            c *= 2;
            maks = a + b + c;
        }
        
    }
    cout << maks << endl;
}

Measured memory_bytes: 256
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	rep(i, N){
		S[i]=='R'? r++: S[i]=='G'? g++: b++;
		rep(d, N){
			int j = i + d, k = j + d;
			if(k >= N) break;
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ng++;
		}
	}
	cout<< r*g*b - ng <<endl;
}

Measured memory_bytes: 3580
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e3 + 5;
int dp[N][N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    string ans;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    int i = n, j = m;
    while(i > 0 && j > 0){
        if(s[i - 1] == t[j - 1]){
            ans += s[i - 1];
            i--, j--;
        }
        else if(dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    for(auto i : ans) cout << i;
return 0;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

ll ans = 0;
bool check = 0;
bool boo = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n, m = 1000000;
int x = 0, y = 0;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    // 47
    cin >> n >> x;

    rep(i, n)
    {
        cin >> a;
        sum += a;
        m = min(a, m);
    }

    x -= sum;
    ans = x / m + n;
    pr(ans);
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    int AliceScore = 0;
    int BobScore = 0;
    cin >> n;


    vector<int> a(n);
    for (int i = 0; i < a.size(); i++) {
        cin >> a.at(i);
    }

    sort(a.rbegin(), a.rend());

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            AliceScore += a.at(i); 
        }
        else {
            BobScore += a.at(i);     
        }
    }

    cout << AliceScore - BobScore << endl;

}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, K, Q; cin >> N >> K >> Q;
  ll A[N]; rep(i,N) cin >> A[i];

  if (Q==1) { cout << 0 << endl; return 0; }
  ll result = INF;
  rep(i,N) {
    vector<ll> num, now;
    rep(j,N+1) {
      if (j!=i&&j!=N&&A[j]>=A[i]) now.push_back(A[j]);
      else if (j!=i) {
        sort(all(now));
        rep(i,now.size()-K+1) num.push_back(now[i]);
        now.clear();
      }
    }
    sort(all(num));
    // debug(all(num));
    if (num.size()>=Q-1) result = min(result, num[Q-2]-A[i]);
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

	int N;
	cin >> N;

	Vi L(N);
	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}

	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 0; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int s = abs(L[i] - L[j]);
			int t = L[i] + L[j];

			int idx1 = upper_bound(L.begin(), L.end(), s) - L.begin();
			int idx2 = lower_bound(L.begin(), L.end(), t) - L.begin();

			idx1 = max(idx1, j);
			idx2 = max(idx2, j);
			

			int diff = idx2 - idx1;

			if (idx1 <= i && i < idx2) --diff;
			if (idx1 <= j && j < idx2) --diff;
			ans += max(0, diff);
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++) 
#define Rep(i, n) for (int i = 1; i < n; i++)
#define pb emplace_back
#define vi vector<int>
#define in(a, b, c) a <= b && b < c


signed main()
{
    int n; cin >> n;
    vi data(n);
    vi funami(n);
    rep(i, n) cin >> data[i];
    rep(i, n-1) {
        funami[i] = data[i+1] - data[i];
    }

 /*   rep(i, n) {
    cout << funami[i] << " ";
    }
    cout << endl;*/

    int ans = 0;
    rep(i, n-1) {
        if (i % 2) {
            if (funami[i] > 0) {
                if (i + 1 < n-1 && funami[i] < -funami[i+1]) {
                    funami[i+2] += funami[i+1];
                    funami[i+1] *= -1;
                } else {
                    funami[i+1] += funami[i];
                    funami[i] *= -1;
                }
                ans++;
            }
        } else {
            if (funami[i] < 0) {
                if (i + 1 < n-1 && funami[i] > -funami[i+1]) {
                    funami[i+2] += funami[i+1];
                    funami[i+1] *= -1;
                } else {
                    funami[i+1] += funami[i];
                    funami[i] *= -1;
                }
                ans++;
            }
        }
    }

    //cout << ans << endl;

    rep(i, n-1) {
        funami[i] = data[i+1] - data[i];
    }
    int cnt = 0;
    rep(i, n-1) {
        if (i % 2) {
            if (funami[i] < 0) {
                funami[i+1] += funami[i];
                funami[i] *= funami[i]-1;
                cnt++;
            }
        } else {
            if (funami[i] > 0) {
                funami[i+1] += funami[i];
                funami[i] *= funami[i]-1;
                cnt++;
            }
        }
    }

//    cout << cnt << endl;

    cout << min(ans, cnt) << endl;

    return 0;
}




Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, p;
	while (cin >> n >> p, n) {
		int x = p;
		vi a(n, 0);
		rep(i, 0, 1000000) {
			if (x == 0) {
				x += a[i%n];
				a[i%n] = 0;
			}
			else {
				a[i%n]++;
				x--;
				if (x == 0 && a[i%n] == p) {
					cout << i % n << endl;
					break;
				}
			}
		}
	}
}



Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main(){
int N, K;
cin >> N >> K;
if( N % 2 ==0){
	if(N-K >=K){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
}
		}else{
if(N-K >=K-1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
		}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char n[3];
  scanf("%s",n);
  
  for(int i=0;i<3;i++){
    if(n[i]=='1'){
      n[i]='9';
    }else if(n[i]=='9'){
      n[i]='1';
    }
  }
  printf("%s",n);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d[200]={},t,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){ cin>>t; d[t]++; }
  for(int i=0;i<=100;i++){
    if(0<d[i]) cnt++;
  }
  cout<<cnt;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string s; cin >> s;
	vector<int> v(2019);
	int now = 0;
	int d = 1;
	rrep(i, s.size())
	{
		now += (s[i] - '0')*d;
		now %= 2019;
		++v[now];
		d *= 10;
		d %= 2019;
	}
	int res = v[0];
	rep(i, 2019)res += v[i] * (v[i] - 1) / 2;
	cout << res << endl;
}


Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int a;
	cin >> a;

	cout << a + a * a + a * a * a << endl;

	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef struct {
  uint32_t R;
  uint32_t L;
  uint32_t RL;
} RLType;

int main() {
  string S;
  cin >> S;
  uint32_t *Res;
  Res = new uint32_t[S.size()];

  for (uint32_t i = 0; i < S.size(); ++i) Res[i] = 0;

  vector<RLType> RLPos;
  RLType RL;
  RL.L = 0;
  char Current = 'R';

  for (uint32_t i = 0; i < S.size(); ++i) {
    if (S[i] != Current) {
      if (Current == 'R') {
        RL.RL = i;
        Current = 'L';
      } else {
        RL.R = i - 1;
        Current = 'R';
        RLPos.push_back(RL);
        RL.L = i;
      }
    }
  }
  RL.R = S.size() - 1;
  RLPos.push_back(RL);

  for (uint32_t i = 0; i < RLPos.size(); i++) {
    uint32_t tmp = RLPos[i].R - RLPos[i].L;
    if (tmp & 0x01) {
      Res[RLPos[i].RL - 1] = (tmp + 1) / 2;
      Res[RLPos[i].RL] = (tmp + 1) / 2;
    } else {
      Res[RLPos[i].RL - 1] = (tmp + 1) / 2;
      Res[RLPos[i].RL] = (tmp + 1) / 2;
      if ((RLPos[i].RL - RLPos[i].L) & 0x01)
        Res[RLPos[i].RL - 1]++;
      else
        Res[RLPos[i].RL]++;
    }
  }

  for (uint32_t i = 0; i < S.size(); i++) {
    cout << Res[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1724
import sys
input = sys.stdin.readline
from collections import *

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N = int(input())
xy = [(i,)+tuple(map(int, input().split())) for i in range(N)]
xy.sort(key=lambda t: t[1])
edges = []

for i in range(N-1):
    edges.append((xy[i][0], xy[i+1][0], xy[i+1][1]-xy[i][1]))

xy.sort(key=lambda t: t[2])

for i in range(N-1):
    edges.append((xy[i][0], xy[i+1][0], xy[i+1][2]-xy[i][2]))

edges.sort(key=lambda t: t[2])
uf = Unionfind(N)
ans = 0

for s, t, w in edges:
    if not uf.is_same(s, t):
        uf.unite(s, t)
        ans += w

print(ans)


Measured memory_bytes: 98400
import java.util.*;
import java.io.*;
import java.math.BigInteger;

 
public class Main implements Runnable {
  static Scanner in;
  // static FastReader in;
  static PrintWriter out;
  static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
  static int[][] dirs = {{0, -1}, {1, 0}, {0, +1}, {-1, 0}};
 
  static int[][] E;
  // static List<int[]>[] adj;
  static List<Integer>[] adj;
  static int[] vis;
 
  static long INFL = (long) 1e15 + 7;
  static int INF = (int) 1e7 + 9;
 
  static int T, n, m, k, count;
  static boolean flag;
  static int[] a, b;
  static int[][] map;

  static int mod = 998244353;
 
  static void solve() throws Exception {
    out.println(6 - in.nextInt() - in.nextInt());
  }


  public static void main(String[] args) throws Exception {
 
    in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    // in = new FastReader();
    out = new PrintWriter(System.out);
 
    // int T = in.nextInt();
    // for (int tt = 1; tt <= T; tt++) {
    //   // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    //   // t.start();
    //   // t.join();
    //   solve();
    // }
 
    // // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    // // t.start();
    // // t.join();
    solve();
 
    out.flush();
    out.close();
  }
 
  @Override
  public void run() {
    try {
      solve();
    } catch (Exception e) {
      e.printStackTrace(); 
    }
  }
 
  static class FastReader {
    public BufferedReader br; 
    StringTokenizer st; 
    public FastReader() {br = new BufferedReader(new InputStreamReader(System.in));} 
    String next() { 
      while (st == null || !st.hasMoreElements()) { 
          try {st = new StringTokenizer(br.readLine());} 
          catch (IOException e) {e.printStackTrace();} 
      } 
      return st.nextToken(); 
    } 
    int nextInt() {return Integer.parseInt(next());} 
    long nextLong() {return Long.parseLong(next());} 
    double nextDouble() {return Double.parseDouble(next());} 
    String nextLine() {
      String str = ""; 
        try {str = br.readLine();} 
        catch (IOException e) {e.printStackTrace();} 
        return str; 
    }
  }

  static void as(boolean result) throws Exception {
    if (!result) {
      throw new Exception();
    }
  }

  static int modInverse(int a, int m) { 
    int m0 = m; 
    int y = 0, x = 1; 
    if (m == 1) {return 0;} 
    while (a > 1) { 
      // q is quotient 
      int q = a / m; 
      int t = m; 
      // m is remainder now, process 
      // same as Euclid's algo 
      m = a % m; 
      a = t; 
      t = y; 
      // Update x and y 
      y = x - q * y; 
      x = t; 
    } 
    // Make x positive 
    if (x < 0) 
      x += m0; 
    return x; 
  } 
} 

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);
  
  
  
  int A,B,C,K;
vector<ll> vec(3);
  for(int i=0;i<3;i++){
    cin>>vec[i];
  }
  cin>>K;
  vsort(vec);
  vec[2]*=pow(2,K);
  cout<<vec[0]+vec[1]+vec[2]<<endl;
  
}


Measured memory_bytes: 512
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
for i in range(n-m+1):
    for j in range(n-m+1):
        flg=True
        for k in range(m):
            for kk in range(m):
                if b[k][kk]!=a[i+k][j+kk]:
                    flg=False
        if flg:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9148
n = int(input())
cand = [1]
for i in range(1,7):
    cand.append(6**i)
for j in range(1,6):
  cand.append(9**j)
cand.sort()
dp = []
for c in cand:
  hoge = []
  for i in range(n+1):
    if i % c == 0:
      hoge.append(i//c)
    else:
      hoge.append(i)
  dp.append(hoge)
for a in range(1,12):
  for b in range(1,n+1):
    if b >= cand[a]:
    	dp[a][b] = min(dp[a-1][b],dp[a][b - cand[a]] + 1)
    else:
      dp[a][b]  = dp[a-1][b]
      
print(dp[-1][n])
      

      

     
    

  

Measured memory_bytes: 50408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

int hb[51];
int pn[51];


int sol(int l,int v){
    if(v==0) return 0;
    if(l==0) return 1;
    if(v==1) return 0;
    if(v<=1+hb[l-1]){
        return sol(l-1,v-1);
    }else{
        return pn[l-1]+1+sol(l-1,v-2-hb[l-1]);
    }


}



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,X;
    cin>>N>>X;
    hb[0]=1;
    pn[0]=1;
    for(int i=1;i<=50;i++){
        hb[i]=2*hb[i-1]+3;
        pn[i]=2*pn[i-1]+1;
    }
    int ans=sol(N,X);
    cout << ans << endl;





}


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

#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007

using namespace std;

int main() {
    ios
    ll n; cin>>n;
	ll a[n], c[n], ans=0;
	repi(i,n) cin>>a[i];
	repi(i,n){
		ll b; cin>>b;
		ans += b;
	}
	repi(i,n-1) cin>>c[i];
	repi(i, n-1){
		if(a[i]+1 == a[i+1]) ans += c[a[i]-1];
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
def keta(N):
    bit_s = bin(N)[2:]#Nの2ビット変換
    bit_s = (bit_s.zfill(S_n))[::-1]#ゼロ埋/反転 
    
    res =[1]
    temp = 1
                               
    for i in range(len(bit_s)-1):
        if int(bit_s[i]):#1
            temp = 1
            res.insert(0, temp)
        else:#0
            temp *= 10
            res.insert(0, temp)
    
    return res


def solve():
    S_l = list(map(int, list(S)))#分割
    res = 0
    
    for n in range(2**(S_n-1)):
        K_l = keta(n)
        for i in range(S_n):
            res += K_l[i] * S_l[i]
    
    return res
        

if __name__ == '__main__':
    S = input()
    S_n = len(S)
    
    print(solve())

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

using namespace std;

int const NMAX = 1e5;
int v[1 + NMAX];

int main() {

  int n, pos = 1, p, ans = 1;
  cin >> n;
  while(n > 1){
    n = n >> 1;
    ans = ans << 1;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3532
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    int A, B, K;
    cin >> A >> B >> K;

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

    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
c1=0
c2=0
p=10**100
q=10**100
for i in s:
    if i=="(":
        c1+=1
    else:
        c1-=1
    p=min(p,c1)
if p<0:
    s="("*abs(p)+s

for i in range(1,len(s)+1):
    if s[-i]==")":
        c2+=1
    else:
        c2-=1
    q=min(q,c2)
if q<0:
    s=s+")"*abs(q)
print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, w, w1, bufw, wv[4][100], c[4];

int main() {
	cin >> n >> w;
	for(ll i = 0; i < 4; i++){wv[i][0] = 0; c[i] = 0;}
	cin >> w1 >> wv[0][1];
	c[0]++;
	
	for(ll i = 1; i < n; i++){
		cin >> bufw;
		cin >> wv[bufw-w1][++c[bufw-w1]];
	}
	
	for(ll i = 0; i < 4; i++){sort(wv[i]+1, wv[i]+c[i]+1, greater<>());}
	for(ll i = 0; i < 4; i++){for(ll j = 1; j <= c[i]; j++){wv[i][j] += wv[i][j-1];}}
	
	ll vmax = 0;
	for(ll i = 0; i <= c[0] && i*w1 <= w; i++){
		for(ll j = 0; j <= c[1] && i*w1 + j*(w1+1) <= w; j++){
			for(ll k = 0; k <= c[2] && i*w1 + j*(w1+1) + k*(w1+2) <= w; k++){
				for(ll l = 0; l <= c[3] && i*w1 + j*(w1+1) + k*(w1+2) + l*(w1+3) <= w; l++){
					vmax = max(wv[0][i]+wv[1][j]+wv[2][k]+wv[3][l], vmax);
				}	
			}	
		}
	}
	//for(ll i = 0; i < 4; i++){for(ll j = 0; j <= c[i]; j++){cout << wv[i][j];}cout << endl;}
	cout << vmax;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n;
	long f[45];
	f[0] = f[1] = 1;
	cin >> n;
	for (int i = 2; i <= n; i++){
		f[i] = f[i - 1] + f[i - 2];
	}
	cout << f[n] << endl;;
	return 0;
}

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

int main() {
  const int base = 1000000007;
  int a, b;
  cin >> a >> b;
  long ans, fa = 1, fb = 1;
  if (abs(a-b) >= 2) {
    ans = 0;
    cout << ans << endl;
    return 0;
  }
  for (int i = 1; i <= a; i++) fa = fa*i%base;
  for (int i = 1; i <= b; i++) fb = fb*i%base;
  if (a == b) {
    ans = 2*fa*fb % base;
  }
  else {
    ans = fa*fb % base;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}
const int N = 3e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	#define int ll
	int n; cin>>n;
	vector<int> ar[2];
	/*
		0 -> /
		1 -> \
	*/
	vector<pii> vec(n);
	for(int i = 0; i < n; i++){
		int x, y; cin>>x>>y;
		ar[0].pb(y-x);
		ar[1].pb(y+x);
		vec[i] = {x, y};
	}
	SORT(ar[0]);
	SORT(ar[1]);
	int ans = 0;
	for(int i = 0; i < n; i++){
		int zero = vec[i].second - vec[i].first;
		int one = vec[i].second + vec[i].first;
		ans = max({ans, abs(zero - *ar[0].begin()), abs(zero - ar[0].back())});
		ans = max({ans, abs(one - *ar[1].begin()), abs(one - ar[1].back())});
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 8236
#include <stdio.h>

int main() {
    int H, W, i, j;
    while (scanf("%d%d", &H, &W) == 2 && (H || W)) {
        for (i = 0; i < H; i++) {
            for (j=0;j<W;j++) {
                if ((i+j)%2) {
                    printf(".");
                } else {
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=405;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Edge{
    int to,nex;
}edge[N*N];
int n,m,head[N],tot,res[N],vist[N];
int a[N],b[N],c[N],d[N];
inline void Add(int u,int v)
{
    edge[++tot].to=v;
    edge[tot].nex=head[u];
    head[u]=tot;
}
bool dfs(int u)
{
    for(int i=head[u];i;i=edge[i].nex)
    {
        int v=edge[i].to;
        if(!vist[v])
        {
            vist[v]=1;
            if(!res[v]||dfs(res[v])){
                res[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int tmp;
    n=read();
    for(int i=1;i<=n;i++) a[i]=read(),b[i]=read();
    for(int i=1;i<=n;i++) c[i]=read(),d[i]=read();
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
        if(a[i]<c[j]&&b[i]<d[j])
          Add(i,j);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        clr(vist,0);
        if(dfs(i))
          ans++;
    }
    printf("%d\n",ans);
    return 0;
}

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

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

    int count = 0;
    // B > A
    while (count < K) {
        if (B > A)
            break;
        B *= 2;
        count++;
    }

    while (count < K) {
        if (C > B)
            break;
        C *= 2;
        count++;
    }

    if (A < B && B < C)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

}

Measured memory_bytes: 3576
fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList().sorted().reversed()
    val bob = (1 until n step 2).sumBy { a[it] }
    val alice = (0 until n step 2).sumBy { a[it] }
    println(alice - bob)
}

fun readIntList(): List<Int> = readLine()!!.split(' ').map { it.toInt() }

fun readInt(): Int = readLine()!!.toInt()

fun err(print: Any) {
    System.err.println(print)
}

Measured memory_bytes: 37872
#include <iostream>
#include<utility>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n,x,y;
    cin >> n;
    vector< pair<int, int> > vec(n);
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        vec[i].first = x;
        vec[i].second = y;
    }
    sort(begin(vec), end(vec));
    for (int i = 0; i < n; i++) {
        cout << vec[i].first << " ";
        cout << vec[i].second << endl;
    }
}



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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i=2; i*i<=n; i++) {
    while (n%i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

void solve()
{
  ll n;cin>>n;
  vector<ll> t(n+1, 1);
  for (int i=1; i<=n; i++) {
    map<int, int> mp = prime_factor(i);
    for (auto p:mp) {
      t[p.first] = (t[p.first]+p.second)%mod;
    }
  }
  ll ans=1;
  for (int i=0; i<=n; i++) {
    ans = (ans*t[i])%mod;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    N,M = LMIIS()
    A =  list(set(map(lambda x: int(x)//2 ,input().split())))
    # print(A)
    from fractions import gcd
    a = A[0]
    lcm = a
    x = len(bin(a))-len(bin(a).rstrip('0'))
    for a in A:
        # print(bin(a),len(bin(a))-len(bin(a).rstrip('0')))
        if x != len(bin(a))-len(bin(a).rstrip('0')):
            print(0)
            return
        lcm = lcm * a // gcd(lcm,a)


    print(((M+lcm)//lcm)//2)
    

    

    



if __name__ == '__main__':
    main()

Measured memory_bytes: 77972
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

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

int R, C, M;
string field[50];
bool visited[50][50];

bool dfs(int px, int py, int gx, int gy, vector<int>& res)
{
	
	if(visited[px][py]) return false;
	visited[px][py] = true;


	if(px == gx && py == gy){
		return true;
	}

	for(int i=0; i<4; i++)
	{
		int tx = px + dx[i];
		int ty = py + dy[i];

		if(tx < 0 || ty < 0 || tx >= C || ty >= R) continue;
		if(field[ty][tx] == '#') continue; 

		if(dfs(tx,ty,gx,gy,res)) {
			res.push_back(ty*50+tx);
			return true;
		}

	}

	return false;
	
}

int main()
{
	cin >> R >> C >> M;

	for(int i=0; i<R; i++)
		cin >> field[i];

	int upkeep[50][50], oncost[50][50], offcost[50][50];
	int objx[1000], objy[1000];

	for(int i=0; i<R; i++)
	for(int j=0; j<C; j++)
		cin >> upkeep[j][i];

	for(int i=0; i<R; i++)
	for(int j=0; j<C; j++)
		cin >> oncost[j][i];

	for(int i=0; i<R; i++)
	for(int j=0; j<C; j++)
		cin >> offcost[j][i];

	for(int i=0; i<M; i++)
		cin >> objy[i] >> objx[i];

	int cost=0;
	vector<vector<int> > route(50*50);
	route[objy[0]*50+objx[0]].push_back(cost++);

	for(int i=0; i<M-1; i++) {
		vector<int> r; 

		memset(visited, 0, sizeof(visited));
		dfs(objx[i], objy[i], objx[i+1], objy[i+1], r);

		reverse(r.begin(), r.end());

		for(int j=0; j<r.size(); j++) {
			int a = r[j];

			route[a].push_back(cost++);
		}
	}

	int res = 0;
	for(int i=0; i<2500; i++) {
		int x = (i % 50);
		int y = (i / 50);

		for(int j=0; j<route[i].size(); j++) {
			if(j+1 == route[i].size()) {

				res += offcost[x][y];
				if(route[i].size() == 1) res += oncost[x][y];
			}
			else {
				if(j==0) res += oncost[x][y];

				int diff = route[i][j+1] - route[i][j];	
				res += min(diff*upkeep[x][y], offcost[x][y] + oncost[x][y]);
			}
		}
	}

	cout << res << endl;

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main(){
int N;
cin>>N;
vi a(N);
for(int &x:a)cin>>x;
vi A=a;
sort(a.begin(),a.end());
int cnt=0;
for(int i=0;i<N;i++){
    if(A[i]!=a[i])cnt++;
}
if(cnt<=2)cout<<"YES";
else cout<<"NO";

return 0;
}


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

#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

using namespace atcoder;

int main() {
    lint n;
    scanf("%lld", &n);
    lint ans = LLONG_MAX;
    for (lint a = 1; a * a <= 2 * n; ++a) {
        if (2 * n % a == 0) {
            lint b = 2 * n / a;
            auto f = [&](lint x, lint y) {
                vector<lint> r = {x - 1, 0}, m = {x, y};
                auto [s, t] = crt(r, m);
                if (s == 0) return t == 0 ? LLONG_MAX : s + t;
                return s;
            };
            chmin(ans, f(a, b));
            chmin(ans, f(b, a));
        }
    }
    printf("%lld\n", ans);
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

ll arr[200005];

void dfs(int n,vll neigh[],int k,int p){
	arr[n] = k + arr[n];
	for(int i=0;i<neigh[n].size();i++){
		if(neigh[n][i]!=p){
			dfs(neigh[n][i],neigh,arr[n],n);
		}
	}
}

int main(){
	boost;
	int n,q;
	cin>>n>>q;
	vll neigh[n+1];

	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		neigh[a].pb(b);
		neigh[b].pb(a);
	}

	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		arr[a] = arr[a] + b;
	}

	dfs(1,neigh,0,-1);

	for(int i=1;i<=n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 27392