akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

vector<vi> G(1000);

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    REP(i, M) {
        int a, b; cin >> a >> b;
        --a; --b;
        G[a].pb(b);
    }

    // find loop
    vi loop;
    {
        REP(i, N){
            vector<bool> used(N, false);
            vector<int> prev(N);
            queue<int> q;
            q.push(i);
            while (!q.empty()) {
                int cur = q.front();
                q.pop();

                for (auto to: G[cur]) {
                    if (to == i) {
                        vi a;
                        while (cur != i) {
                            loop.pb(cur);
                            cur = prev[cur];
                        }
                        loop.pb(i);

                        reverse(ALL(loop));
                        q = queue<int>();
                        break;
                    }

                    if (used[to]) continue;
                    q.push(to);
                    used[to] = true;
                    prev[to] = cur;
                }
            }

            if (loop.size() > 0) break;
        }
    }

    if (loop.size() == 0) {
        print(-1);
        return 0;
    }

    while(true) {
        // validate
        vector<bool> used(N, false);

        bool f = true;
        int s, t;
        for(auto e: loop) {
            for(auto to: G[e]) {
                if (used[to]) {
                    s = e;
                    t = to;
                    if (s == loop.back() && t == loop.front()) continue;
                    f = false;
                    break;
                }
            }
            if (!f) break;
            used[e] = true;
        }

        if (f) break;

        vector<int> loop_new;

        auto it = find(ALL(loop), t);
        while(*it !=s) loop_new.pb(*it++);
        loop_new.pb(s);
        loop = loop_new;

    }

    print(loop.size());
    for(auto e: loop) {
        print(e + 1);
    }

}


Measured memory_bytes: 3652
#include <stdio.h>

#define MAX 100000
#define NIL -1

typedef struct{
  int parent;
  int leaf;
  int ree;
}tree;

tree T[MAX];

int main(){

  int n,i,j,node,zisu,child,left,count,Npare,Nani;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent=NIL;
    T[i].leaf=NIL;
    T[i].ree=NIL;
  }

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

    scanf("%d%d",&node,&zisu);
    for(j=0;j<zisu;j++){
      if(j==0){
    scanf("%d",&child);
    T[node].leaf=child;
    T[child].parent=node;
    }
      else {
    scanf("%d",&child);
    T[left].ree=child;
    T[child].parent=node;
}
      left=child;

    }
  }

  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    count=0;
    Npare=i;
    while(1){
      if(T[Npare].parent==NIL) break;
      Npare=T[Npare].parent;
      count++;
    }
    printf("depth = %d, ",count);
    if(T[i].parent == NIL){
      printf("root, ");
    }
    else if(T[i].leaf == NIL && T[i].parent != NIL){
      printf("leaf, ");
    }
    else{
      printf("internal node, ");
    }
    printf("[");
    if(T[i].leaf !=-1){
      printf("%d",T[i].leaf);
      Nani= T[i].leaf;
      while(1){
    if(T[Nani].ree == -1)break;
    printf(", %d",T[Nani].ree);
    Nani=T[Nani].ree;
      }
    }
    printf("]\n");
  }

  return 0;
}

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

int main(){
    int H, W;
    cin >> H >> W;

    char a[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }

    /* for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << a[i][j];
        }
        cout << endl;
    }*/

    int cou = 0;
    int frag_y[H];
    for(int i = 0; i < H; i++){
        frag_y[i] = 0;
    }
    int frag_x[W];
    for(int i = 0; i < W; i++){
        frag_x[i] = 0;
    }

    for(int i = 0; i < H; i++){
        cou = 0;
        for(int j = 0; j < W; j++){
            if(a[i][j] == '.'){
                cou++;
            }
        }
        if(cou == W){
            frag_y[i] = 1;
        }
    }

    for(int i = 0; i < W; i++){
        cou = 0;
        for(int j = 0; j < H; j++){
            if(a[j][i] == '.'){
                cou++;
            }
        }
        if(cou == H){
            frag_x[i] = 1;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(frag_y[i] == 0 && frag_x[j] == 0){
                cout << a[i][j];
            }else{
                continue;
            }
        }

        if(frag_y[i] == 0){
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
import sys

line = sys.stdin.readlines()[0]
X, Y = map(int,line.split(' '))

ret = 0

if X == Y == 1:
    ret += 400000

for p in [X,Y]:
    if p == 1:
        ret += 300000
    if p == 2:
        ret += 200000
    if p == 3:
        ret += 100000

print(ret)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e6+5;
bool exists,a[N],b[N];
int n;

bool C(int n,int m){
	if(n<m) return 0;
	if(n<=1) return 1;
	return C(n&1,m&1)&C(n>>1,m>>1);
}

bool calc(bool *a){
	bool ans=0;
	for(int i=1;i<=n;i++) if(a[i]) ans^=C(n-1,i-1);
	return ans;
}

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++){
		scanf("%1d",&x);x--;
		exists|=x==1;
		a[i]=x&1;
		b[i]=x>>1;
	}
	if(exists) write(calc(a));
	else write(calc(b)<<1);
}

Measured memory_bytes: 5628
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	String[] list = s.split("");
      	int count0 = 0;
      	int count1 = 0;
      	for(int i=0; i<s.length(); i++){
          if(list[i].equals("0")) count0++;
          if(list[i].equals("1")) count1++;
        }
      	if(count0>=count1) System.out.println(count1*2);
      	if(count0<count1) System.out.println(count0*2);
	}
}


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

long long dp[200000];
long long sum[200000];
map<long long, long long> m;
void solve(long long N, vector<long long> C){
	dp[0] = 1;
	sum[0] = 1;
	for(int i = 1 ; i < N ; i++) m[C[i]] = -1;
	m[C[0]] = 0;
	for(int i = 1 ; i < N ; i++){
		if (-1 != m[C[i]] && i-1 != m[C[i]]) {
			dp[i] = sum[m[C[i]]]*2%MOD;
			sum[i] = (sum[i-1]+sum[m[C[i]]])%MOD;

			// cout << i << " " << m[C[i]]-1 << " " << res << "\n";
		} else {
			dp[i] = dp[i-1];
			sum[i] = sum[i-1];
		}
		m[C[i]] = i;
	}
	// long long res = 0;
	// map<long long, long long> m2;
	// for(int i = 0 ; i < N ; i++) {
	// 	if (m2[C[i]] == 0) {
	// 		res += dp[m[C[i]]];
	// 		m2[C[i]]++;
	// 	}
	// }
	// cout << res << "\n";
	cout << sum[N-1] << "\n";
}

int main(){
	long long N;
	scanf("%lld",&N);
	vector<long long> C(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&C[i]);
	}
	solve(N, C);
	return 0;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    vector<vector<set<uint_fast64_t>>> st(51);
    Fr(i,50){
        st[i].resize((i+1)/2);
        Fr(j,i){
            int k=i%j;
            st[i][k].insert(1ul<<j);
            fr(l,(k+1)/2) for(auto m:st[k][l]) st[i][l].insert(m|(1ul<<j));
        }
    }
    int n;
    in>>n;
    uint_fast64_t ans=0;
    vector<int> a(n),b(n),A,B;
    for(auto&i:a) in>>i;
    for(auto&i:b) in>>i;
    fr(i,n){
        if(a[i]!=b[i]&&b[i]>(a[i]-1)/2){
            cout<<-1<<endl;
            return 0;
        }
        if(a[i]!=b[i]) A.emplace_back(a[i]),B.emplace_back(b[i]);
    }
    n=A.size();
    a.swap(A);
    b.swap(B);
    while(true){
        fr(i,n){
            set<uint_fast64_t> s;
            for(auto k:st[a[i]][b[i]]) s.insert(k&(~ans));
            st[a[i]][b[i]].swap(s);
        }
        uint_fast64_t t{};
        fr(i,n) t=max(t,*st[a[i]][b[i]].begin());
        if(t==0) break;
        int T=63-__builtin_clzll(t);
        ans|=(1ll<<T);
    }
    cout<<ans<<endl;
}

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

int main(){

    int N; cin >> N;
    ll ans = 0;
    int data[N];
    map<int,ll> mp{};
    
    for(int i=0;i<N;i++) cin >> data[i];
    sort(data,data+N);

    for(int i=0;i<N;i++){ mp[data[i]]++; }
    
    for(int i=data[0];i<=data[N-1];i++){
        ll sum;
        sum = mp[i-1] + mp[i] + mp[i+1];
        if(sum > ans) ans = sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10276
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  auto v = readln.chomp.split.map!(to!int);
  int x = v[0];
  int a = v[1];
  int b = v[2];
  if (abs(x - a) < abs(x - b)) {
    "A".writeln;
  } else {
    "B".writeln;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, X;
    cin >> N >> X;
    int sum = 0, ans = 1;
    for(int i = 0; i < N; i++){
        int L;
        cin >> L;
        sum += L;
        if(sum > X){
            break;
        }
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, z = 0;
    ll d, x, y;
    cin >> n >> d;
    while (n--) {
        cin >> x >> y;
        if (x * x + y * y <= d * d) z++;
    }
    cout << z;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int main(void) {
    int n;
    cin>>n;
    unordered_map<string,int> mp;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto p : mp){
        int s=p.second;
        ans+=(ll)s*(s-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
typedef		vector<int>				 vi;
typedef 	vector<vi>				vii;
typedef		pair<int,int>			pii;
typedef		unsigned long long		ull;
typedef		long long				ll ;
#define MOD (int)(1e9+7)
#define INF (int)(1<<29) 
#define fori(i,a,b)		for(int i=a ; i <= b ; i++) 			
#define ford(i,a,b)  	for(int i=a ; i >= b ; i-- ) 
#define rep(i,n)   		for(int i=0; i < n ; i++ ) 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;


int main()
{
	ios_base::sync_with_stdio(0);	
	string s ;
	cin >> s; 
	int has[26] ;
	rep(i,26) has[i] = 0 ;
	for(int i = 0 ; i < s.length() ; ++i ) 
	{
		has[s[i]-'a']++;
	}
	for(int i = 0 ; i < 26 ; ++i ) 
	{
		if ( !has[i] )
		{
			cout << (char) ( 'a' + i ) ;
			return 0 ; 
		}
	}
	cout << "None\n";
	return 0 ;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

const int mod = 1000000007;

int main() {
  string s; cin >> s;
  // dp[x][mod] := x文字目までみたとき, 13で割ってmod余るようなものの場合の数
  vector<vector<long long>> dp(s.length()+10, vector<long long>(13, 0));
  dp[0][0] = 1;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    int num = (s[i] == '?' ? -1 : s[i]-'0');
    for (int j = 0; j < 10; j++) {
      if (num != -1 && num != j) { continue; }
      for (int k = 0; k < 13; k++) {
        dp[i+1][(k*10+j)%13] += dp[i][k];
      }
    }
    for (int j = 0; j < 13; j++) {
      dp[i+1][j] %= mod;
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    double ans = 0;
    int max_omote = 0;
    int a = 1;
    while(a < K)
    {
        a *= 2;
        max_omote++;
    }

    for(int i = 1; i < N + 1;i++)
    {
        if(i * a / 2 >= K) a /= 2;
        if(a == 0) a = 1;
        ans += (double) 1 / (a * N );
    }
    cout << setprecision(16) << ans << endl;
    return 0;  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int n=stoi(s);
   int sz=s.size();
   if(sz==1)cout<<n<<endl; 
   else if (sz==2)cout<<9<<endl; 
   else if(sz==3)cout<<(n-100+1)+9<<endl;  
   else if(sz==4)cout<<900+9<<endl; 
   else if(sz==5)cout<<900+9+(n-10000+1)<<endl; 
   else if(sz==6)cout<<9+900+90000<<endl; 
   
        
       
           
  
  
  
    return 0;
}


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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int solve(vector<int> v, int cnt){
    if(v[0] == v[1] && v[1] == v[2]){
        return cnt;
    }
    SORT(v);
    if(v[2] - v[0] == 1){
        v[0]++;
        v[1]++;
    }else{
        v[0] += 2;
    }
    return solve(v, cnt + 1);
}

int main(){
    vector<int> v(3);
    rep(i, 3){
        cin >> v[i];
    }
    int ans = solve(v, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a;
	for (int h = 0; h < 100; h++) {
		cin >> n; int sum = 0;
		int test[11] = { 0 };
		if (n == 0) {
			cin >> n; return 0;
		}
		string s; cin >> s;
		for (int h = 0; h < s.size(); h++) {
			if ((h + 1) % n == 0) {
				if (s[h] == 'M') { test[n]++; }
				if (s[h] == 'S') { sum += test[n] + 1; test[n] = 0; }
				if (s[h] == 'L') { test[n] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 1) {
				if (s[h] == 'M') { test[1]++; }
				if (s[h] == 'S') { sum += test[1] + 1; test[1] = 0; }
				if (s[h] == 'L') { test[1] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 2) {
				if (s[h] == 'M') { test[2]++; }
				if (s[h] == 'S') { sum += test[2] + 1; test[2] = 0; }
				if (s[h] == 'L') { test[2] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 3) {
				if (s[h] == 'M') { test[3]++; }
				if (s[h] == 'S') { sum += test[3] + 1; test[3] = 0; }
				if (s[h] == 'L') { test[3] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 4) {
				if (s[h] == 'M') { test[4]++; }
				if (s[h] == 'S') { sum += test[4] + 1; test[4] = 0; }
				if (s[h] == 'L') { test[4] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 5) {
				if (s[h] == 'M') { test[5]++; }
				if (s[h] == 'S') { sum += test[5] + 1; test[5] = 0; }
				if (s[h] == 'L') { test[5] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 6) {
				if (s[h] == 'M') { test[6]++; }
				if (s[h] == 'S') { sum += test[6] + 1; test[6] = 0; }
				if (s[h] == 'L') { test[6] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 7) {
				if (s[h] == 'M') { test[7]++; }
				if (s[h] == 'S') { sum += test[7] + 1; test[7] = 0; }
				if (s[h] == 'L') { test[7] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 8) {
				if (s[h] == 'M') { test[8]++; }
				if (s[h] == 'S') { sum += test[8] + 1; test[8] = 0; }
				if (s[h] == 'L') { test[8] += 1 + sum; sum = 0; }
			}
			else if ((h + 1) % n == 9) {
				if (s[h] == 'M') { test[9]++; }
				if (s[h] == 'S') { sum += test[9] + 1; test[9] = 0; }
				if (s[h] == 'L') { test[9] += 1 + sum; sum = 0; }
			}
		}
		for (int s = 1; s < n; s++) {
			for (int t = s + 1; t <= n; t++) {
				if (test[s] > test[t]) {
					int uio = test[s];
					test[s] = test[t];
					test[t] = uio;
				}
			}
		}
		for (int s = 1; s <= n; s++) {
			cout << test[s] << ' ';
		}
		cout << sum << endl;
	}
	cin >> n;
}


Measured memory_bytes: 3204
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int x, a;
        cin >> x >> a;
        if (x < a) {
            cout << 0 << endl;
        } else {
            cout << 10 << endl;
        }

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
import os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit
from copy import deepcopy
setrecursionlimit(10**6)

n=int(input())
h=list(map(int,input().split()))
h[0]-=1
for i in range(1,n):
    if h[i]==h[i-1]:
        continue
    if h[i]-1<h[i-1]:
        print("No")
        exit()
    h[i]-=1
print("Yes")

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

int main(){
    int D;
  	cin >> D;
  	switch(25-D){
      case 0:
        cout << "Christmas";
        break;
      case 1:
        cout << "Christmas Eve";
        break;
      case 2:
        cout << "Christmas Eve Eve";
        break;
      case 3:
        cout << "Christmas Eve Eve Eve";
        break;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){

	int a[3],j,k,w;

	scanf("%d %d %d",&a[0],&a[1],&a[2]);

	for(j=0;j<2;j++){

		for(k=j+1;k<3;k++){

			if(a[j]>a[k]){

				w=a[j];
				a[j]=a[k];
				a[k]=w;
			}
		}
	}

		printf("%d %d %d\n",a[0],a[1],a[2]);

	return 0;

}

Measured memory_bytes: 596
#include <cstdio>
#include <cstring>
int main(){
  char s[101],t[101],p[101];
  scanf("%s %s",s,p); 
  strcpy(t,s);
  strcat(s,t);
  if(strstr(s,p)==NULL){
    printf("No\n");
  }
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <algorithm>

using namespace std;

int h, w, n;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> h >> w >> n;
	
	int ma = max(h, w);
	int ans = n / ma;
	if (n % ma) ans ++;
	
	cout << ans << '\n';
	
	return 0;
}

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

using namespace std;
using ll = long long;

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

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
    int n,t;

	V<int> v;
	V<int> v2;

    cin >> n;
    REP(i,n) {
		cin >> t;
		v.push_back(t);
		v2.push_back(t);
    }

	sort(ALL(v));


	int cnt = 0;

	REP(i,n) {
		if(v[i] != v2[i]) {
			cnt++;
		}
	}
	if(cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;

}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())

import math

ALPHABET = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
result = []

def alphabet_decimal(v):
    quotient = math.floor(v / len(ALPHABET))
    surplus = v % len(ALPHABET)
    quotient -= 1 if surplus == 0 else 0
    surplus = len(ALPHABET) if surplus == 0 else surplus
    result.append(surplus)
    if len(ALPHABET) < quotient:
        alphabet_decimal(quotient)
    elif len(ALPHABET) < v:
        result.append(quotient)
    return "".join([ALPHABET[i - 1] for i in reversed(result)])
print((alphabet_decimal(n)).lower())

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

ll n;

ll solve(ll now, bool used3, bool used5, bool used7) {
    //cout << now << endl;
    if(now > n) return 0;
    ll ans = 0;
    if(used3 && used5 && used7) ans++;
    ans += solve(now*10+3, true, used5, used7);
    ans += solve(now*10+5, used3, true, used7);
    ans += solve(now*10+7, used3, used5, true);
    return ans;
}

int main() {
    cin >> n;
    ll ans = solve(0, false, false, false);

    cout << ans << endl;

    return 0;
}

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

using ll = long long;
#define rep(n, i) for(ll i = 0; i < n; ++i)

void solve(void){
  ll a, b, c, d, e; cin >> a >> b >> c >> d >> e;

  if (a == 0) {
    cout << 1 << endl;
  } else if (b == 0){
    cout << 2 << endl;
  } else if (c == 0) {
    cout << 3 << endl;
  } else if (d == 0) {
    cout << 4 << endl;
  } else {
    cout << 5 << endl;
  }
}

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

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, a, b; cin >> n >> a >> b;
	if(n * a >= b) cout << b << endl;
	else cout << n * a << endl;
} 

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  s = "E" + s + "E";
  ll l_cnt = 0;
  ll r_cnt = 0;
  ll base = 0;
  for (int i = 1; i < n + 1; i++) {
    if (s[i] == 'L' && s[i - 1] == 'L') {
      base++;
    } else if (s[i] == 'R' && s[i + 1] == 'R') {
      base++;
    }
  }
  // cout << base << endl;
  cout << min(n - 1, base + 2 * k) << endl;
  return 0;
}


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




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    vector<int> ma(n+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j*i<=n;j++)
            ma[i*j]++;
    }
    int ans = 0;
    for(int i=1;i<n;i++)
    {
        ans+=ma[n-i];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 7140
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    string s;
    cin>>s;
    if(s=="Sunny"){cout<<"Cloudy";}
    else if(s=="Cloudy"){cout<<"Rainy";}
    else{cout<<"Sunny";}
    cout<<endl;
    return 0;
}

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

using namespace std;

int main(void){
    
    int n, t, a;
    cin >> n >> t >> a;
    
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    
    double min_abs = 100000;
    int index = 0;
    for(int i=0; i<n; i++) {
        double temp = (double)t - (double)h[i]*0.006;
        temp = abs((double)a - temp);
//        cout << temp << endl;
        if(min_abs > temp) {
            min_abs = temp;
            index = i;
        }
    }
    
    cout << index+1 << endl;

    return 0;
    
}


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



int main() {
	int n;
	cin >> n;
	int ans = min(n, 9);
	ans += min(max(n - 99, 0), 900);
	ans += min(max(n - 9999, 0), 90000);
	ans += min(max(n - 999999, 0), 9000000);

	cout << ans << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
int a,b,c,i,count=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(c%i==0){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

#define read(a) cin >> a
#define out(a)  cout << a
#define ull unsigned long long
#define ll long long
#define FOR(i, l, r) for (ll i = l; i <= r; i++)
#define FOD(i, l, r) for (ll i = l; i >= r; i--)
#define fast ios_base::sync_with_stdio(false);
#define mod 1000000007
#define ll long long

int main()
{
  string s;
  ll t = 0;
  cin >> s;
  FOR(i, 0, s.size()-1)
  {
      t += s[i] - 48;
  }
  if (t % 9 == 0) cout << "Yes";
  else cout << "No";
}


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

int main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
bool direct=false;
bool kansetu=false;
if (abs(a-b)<=d&&abs(b-c)<=d)
{
    /* code */
    kansetu=true;
}

if (abs(a-c)<=d)
{
    /* code */
    direct=true;
}

if (direct||kansetu)
{
    /* code */
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}

}

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

const int N = 2e5 + 10;
int n, par[N], x[N], y[N]; 
long long total;
vector<int> vx[N], vy[N], tmpx[N], tmpy[N];

int getpar(int v){
	if(par[v] == v)
		return v;
	par[v] = getpar(par[v]);
	return par[v];
}
int unq(vector<int> &v){
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	return v.size();
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < N; i++)
		par[i] = i;
	
	for (int i = 1; i <= n; i++){
		cin >> x[i] >> y[i];
		
		vx[x[i]].push_back(i);
		vy[y[i]].push_back(i);
	}
	
//	for (int i = 0; i < N; i++){
//		for (int j : vx[i])
//			cout << j << ' ';
//		if(!vx[i].empty())
//			cout << endl;
//	}
//	cout << endl;
//	for (int i = 0; i < N; i++){
//		for (int j : vy[i])
//			cout << j << ' ';
//		if(!vy[i].empty())
//			cout << endl;
//	}

	for (int i = 0; i < N; i++){
		if(vx[i].size() < 2)
			continue;
		for (int j = 1; j < vx[i].size(); j++)
			//cout << "change par " << vx[i][j] << endl, 
			par[getpar(vx[i][j])] = getpar(vx[i][j - 1]); 
	}
	for (int i = 0; i < N; i++){
		if(vy[i].size() < 2)
			continue;
		for (int j = 1; j < vy[i].size(); j++)
			//cout << "change par " << vy[i][j] << endl, 
			par[getpar(vy[i][j])] = getpar(vy[i][j - 1]); 
	}
	
	for (int i = 1; i <= n; i++){
		int t = getpar(i);
		tmpx[t].push_back(x[i]);
		tmpy[t].push_back(y[i]);
	}
	
	for (int i = 0; i < N; i++){
		if(tmpx[i].size() == 0)
			continue;

		total += (1LL * unq(tmpx[i]) * unq(tmpy[i]));
	}
	
	cout << total - n;
}

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

int main(void){
    int w,a,b;
    cin >> w >> a >> b;

    if(b-a-w>0) cout << b-a-w << endl;
    else if(a-b-w>0) cout << a-b-w << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int UF[110000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);p--;q--;
		UNION(p,q);
	}

	int ret=0;
	for(int i=0;i<a;i++)if(UF[i]<0)ret++;
	printf("%d\n",ret);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <sstream>

void CountingSort(std::vector<int>& A, std::vector<int>& B, int k)
{
    std::vector<int> C(k+1);
    int n = A.size();
    
    for(int i = 0; i < k+1; i++){
	C[i] = 0;
    }

    /* C[i] に i の出現数を記録する */
    for(int j = 0; j < n; j++){
	C[A[j]]++;
    }

    /* C[i] に i 以下の数の出現数を記録する*/
    for(int i = 1; i < k+1; i++){
	C[i] = C[i] + C[i-1];
    }

    for(int j = n-1; j >= 0; j--){
        B[C[A[j]]-1] = A[j];
        C[A[j]]--;
    }
}

int main(int argc, char **argv){
    int n;
    std::cin >> n;

    std::vector<int> A(n), B(n);
    int max = 0;
    
    for(int i = 0; i < n; i++){
	std::cin >> A[i];
	max = A[i] > max ? A[i] : max;
    }

    CountingSort(A, B, max);
    
    std::stringstream ss;
    std::string sep = "";
    for(int i = 0; i < n; i++){
	ss << sep << B[i];
	sep = " ";
    }
    std::cout << ss.str() << std::endl;
    
}



Measured memory_bytes: 37520
n=int(input())
m=n
a=list(map(int,input().split()))
if(m%2==0):
  while(n>=4):
    print(str(a[n-1])+' ',end="")
    n-=2
  print(str(a[1])+' ',end="")
  n=1
  while(n!=m-1):
    print(str(a[n-1])+' ',end="")
    n+=2
  print(a[m-2])
else:
  if(m==1):
    print(a[0])
  else:
    while(n>=3):
      print(str(a[n-1])+' ',end="")
      n-=2
    print(str(a[0])+' ',end="")
    n=2
    while(n!=m-1):
      print(str(a[n-1])+' ',end="")
      n+=2
    print(a[m-2])

Measured memory_bytes: 25744
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)


Measured memory_bytes: 97236
import heapq
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    ta,tb,tc = map(int, input().split())
    E[ta].append([tc,tb])
    E[tb].append([tc,ta])

Q, K = map(int, input().split())
inf = float('inf')
D = [inf] * (N+1)

q = []
heapq.heappush(q,[0,K])
cnt = 0
while True:
    d, cp = heapq.heappop(q)
    if D[cp] != inf:
        continue
    else:
        D[cp] = d
        cnt += 1
        if cnt == N:
            break

        for nd,np in E[cp]:
            heapq.heappush(q,[D[cp]+nd, np])

ans = []
for _ in range(Q):
    ts,tg = map(int, input().split())
    ans.append(D[ts]+D[tg])

for a in ans:
    print(a)

Measured memory_bytes: 62676
my ($X,$K,$D) = split(/ /,<>);

my $AX = abs($X);

my $ans=0;
if($AX > $K*$D){
    if($X>0){
        $ans = $X - $K * $D; 
    }else{
        $ans = $X + $K * $D;
    }
}else{
#print "TT\n";
    my $mod = $X % $D; 
    my $C = ($X -$mod)/$D;
#print "mod$mod c$C\n";
    $K = $K -$C;
#print "K$K\n";
    if(($K%2)==0){
        if($X>0){ 
            $ans = $mod;
        }else{
            $ans = -$mod;
        }
    }else{
        if($X>0){ 
            $ans = ($mod-$D);
        }else{
            $ans = (-$mod+$D);
        }        
    }
}
$ans = abs($ans);
print "$ans";

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int a;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int k[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  	cin >> a;
  	print1(k[a-1]);
	return 0;
}


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

#define x first
#define y second

#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cerr << #x << ": " << x << endl;
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}
/*
template<class T>
struct SegmentTree {
	T I,t[4]; int N;
	vector<T> A;

	SegmentTree(int N, T I=T()): I(I), N(N), A(2*N,I) {}
	SegmentTree(const vector<T>& data, T I=T()): I(I), N(data.size()), A(2*N,I)
	{
		copy(data.begin(),data.end(),A.begin()+N);
		for (int i=N-1;i;i--) A[i].op(A[2*i],A[2*i+1]);
	}

	void update(int i,T v) {
		for (A[i+=N]=v;i/=2;) A[i].op(A[2*i],A[2*i+1]);
	}

	T query(int l,int r) {
		t[0]=t[2]=I;
		int i=0,j=2;
		for (l+=N,r+=N;l<r;l/=2,r/=2) {
			if (l&1) t[i^1].op(t[i],A[l++]), i^=1;
			if (r&1) t[j^1].op(A[--r],t[j]), j^=1;
		}
		t[i^1].op(t[i],t[j]);
		return t[i^1];
	}

	template<class...Ts>
	pair<int,T> queryRight(int l,Ts...args) {
		int r=l,w=1,p=0;
		t[0]=I;

		for (l+=N;r+2*w<=N && (t[1-p].op(t[p],A[l]),t[1-p].b(args...));)
			if (l&1) l++,r+=w,p^=1;
			else l/=2,w*=2;
		for (;w;l*=2,w/=2) if (r+w<=N && (t[1-p].op(t[p],A[l]),t[1-p].b(args...)))
			l++,r+=w,p^=1;

		return {r,t[p]};
	}

	template<class...Ts>
	pair<int,T> queryLeft(int r,Ts...args) {
		int l=r,w=1,p=0;
		t[0]=I;

		for (r+=N;l>=2*w && (t[1-p].op(A[r-1],t[p]),t[1-p].b(args...));)
			if (r&1) r--,l-=w,p^=1;
			else r/=2,w*=2;
		for (;w;r*=2,w/=2) if (l>=w && (t[1-p].op(A[r-1],t[p]),t[1-p].b(args...)))
			r--,l-=w,p^=1;

		return {l,t[p]};
	}
};


struct RangeMax {
		int a=0;
		void op(RangeMax& b,RangeMax& c) {a=max(b.a,c.a);}
		//bool b(int v) {return a>=v;}
	};
*/

int b[2000],f[2000];
int n;

int solve(string A,string B) {
	for (int i=0,l=INT_MIN/2;i<2*n;i++) {
		int j=i%n;
		if (B[j]=='1') l=i;
		b[j]=i-l;
	}

	for (int i=2*n-1,l=INT_MAX/2;i>=0;i--) {
		int j=i%n;
		if (B[j]=='1') l=i;
		f[j]=l-i;
	}

	int bans=INT_MAX;

	for (int shift=0;shift<n;shift++) {
		vector<ii> chngs;
		bool fail=0;
		for (int i=0;i<n;i++) if (A[i]!=B[(i+shift)%n]) {
			chngs.emplace_back(b[i],f[i]);
			if (b[i]>INT_MAX/3) {
				fail = 1;
				break;
			}

		}

		if (fail) continue;

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

		//SegmentTree<RangeMax> st(n);
		int fw=0;

		for (int bk=n-1,i=0;bk>=0;bk--) {
			//int fw = st.query(0,n).a;
			bans=min(bans,2*bk+shift+2*max(0,fw-shift)+(int)chngs.size());

			while (i<chngs.size() && chngs[i].x>=bk) {
				fw = max(fw,chngs[i++].y);
			}
		}
	}

	return bans;

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

	string A,B;
	cin >> A >> B;n=A.size();

	int an1=solve(A,B);
	reverse(A.begin(),A.end());
	reverse(B.begin(),B.end());
	int an2=solve(A,B);

	int ans=min(an1,an2);

	if (ans == INT_MAX) cout << -1 << endl;
	else cout << ans << endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>

typedef long long ll;
#define fi first
#define se second


using namespace std;

int main(){
  
  int K;
  int T;
  int a[112];
  
  cin>>K>>T;
  
  int i;
  int big = 0;
  
  for( i = 0; i < T; i++ ){
    scanf("%d", a+i );
    big = max( big, a[i] );
  }
  
  
  
  int ans = 0;
  
  if( (K+1)/2 < big ){
    ans = (big - (K+1)/2) * 2;
    if( !(K%2) ) ans--;
  }
    
  printf("%d\n", ans);
  
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
    unordered_set<int> x;
    for (int i = 0; i < n; i += 2) x.insert(a[i]);
    whole(sort, a);
    int ans = 0;
    for (int i = 1; i < n; i += 2) ans += x.count(a[i]);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2700
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
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;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, 0, N) { cin >> p[i]; }
    sort(p.begin(), p.end());
    int sum = 0;
    rep(i, 0, K) { sum += p[i]; }
    cout << sum << endl;
}

Measured memory_bytes: 3664
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long
#define mo 1000000007

int main()
{
  int i,j,k,s;
  _int64 sum,ans,tmp,tmp1,tmp2,tmp3,tmp4;
  vector<pair<int,int> > a;
  vector<pair<int,int> > now;
  scanf("%d",&s);
  a.clear();
  a.push_back(make_pair(1,9));
  a.push_back(make_pair(2,90));
  a.push_back(make_pair(3,900));
  a.push_back(make_pair(4,9000));
  a.push_back(make_pair(5,90000));
  a.push_back(make_pair(6,900000));
  a.push_back(make_pair(7,9000000));
  a.push_back(make_pair(8,90000000));
  now.clear();
  sum=0;
  ans=0;
  while (1)
  {
    if (sum<=s)
    {
      if (sum==s) ans++;
      if (a.size()==0) break;
      /*
      if ((now.size()==1)&&(now[0].first==a[0].first)&&(sum+a[0].first>s))
      {
        if (sum==s) ans+=a[0].second;
        a.erase(a.begin());
        continue;
      }
      */
      if ((now.size()>0)&&(now[now.size()-1].first==a[0].first))
      {
        now[now.size()-1].second++;
        sum+=a[0].first;
        a[0].second--;
        if (a[0].second==0) a.erase(a.begin());
      }
      else
      {
        now.push_back(make_pair(a[0].first,1));
        sum+=a[0].first;
        a[0].second--;
        if (a[0].second==0) a.erase(a.begin());
      }
    }
    else if (sum>s)
    {
      now[0].second--;
      sum-=now[0].first;
      if (now[0].second==0) now.erase(now.begin());
    }
  }
  
  for (i=8;i<s;i++)
  {
    tmp1=s%i;
    if (tmp1==0) tmp1+=i;
    if (s<=tmp1*(i+1)) continue;
    //tmp2=(s-(tmp1*(i+1)))/i;
    //if (tmp2<=0) continue;

    tmp4=i+1-s%(i+1);
    tmp3=(s-tmp4*i)/(i+1);
    if (tmp3<=0) continue;
    if (tmp1>tmp3) continue;
    ans+=(tmp3-tmp1)/i+1;
    if (ans>=mo) ans-=mo;
  }

  tmp=900000000;
  for (i=9;i<=s;i++)
  {
    if (s%i==0)
    {
      ans+=(tmp-s/i+1);
      if (ans<mo) ans+=mo;
      if (ans<mo) ans+=mo;
      if (ans>=mo) ans-=mo;
      if (ans>=mo) ans-=mo;
    }
    tmp*=10;
    tmp%=mo;
  }
  
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 384
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque
#from functools import reduce


def main():
    A = []
    for i in range(3):
        ary = [int(v) for v in input().split()]
        A.append(ary)
    N = int(input())

    B = []
    for _ in range(N):
        b = int(input())

        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    A[i][j] = 0

    for i in range(3):
        cnt1 = 0
        cnt2 = 0
        for j in range(3):
            if A[i][j] == 0:
                cnt1 += 1
            if A[j][i] == 0:
                cnt2 += 1
        if cnt1 == 3 or cnt2 == 3:
            print("Yes")
            exit()

    if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
        print("Yes")
        exit()
    if A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0:
        print("Yes")
        exit()

    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064