akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000009

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
   int a,b,c;
   cin >> a >> b >> c;
   if((a < c && b < c) || (a > c && b > c)) ns();
   else ys();

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

int main() {
    int A, B, K;
    cin >> K;
    cin >> A >> B;
    REP(i, A, B+1) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3636
# import math
# import statistics
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#    c.append(i)
#e1,e2,e3 = map(int,input().split())
#K = input()
f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
now=1000
buy=0
sell=0
kabu=0
for i in range(a-1):
    if f[i]<f[i+1]:
        if now>=f[i]:
            buy=now//f[i]
            now=now-buy*f[i]
            kabu=buy
            buy=0
    if f[i]>f[i+1] :
        if kabu>=1:
            sell=kabu
            now=now+sell*f[i]
            kabu=0
            sell=0
    if f[i]==f[i+1]:
        continue
now = now+f[-1]*kabu
print(now)
        
        



Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
void solve(){
    int n;
    cin>>n;
    cout<<1-n<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

int main() {
  int N, Q; cin >> N >> Q;
  UnionFindTree tree(N + 1);
  for (int i = 0; i < Q; ++i) {
    int t, u, v; cin >> t >> u >> v;
    if (t == 0) {
      tree.Unite(u, v);
    } else {
      cout << tree.IsSameRoot(u, v) << endl;
    }
  }
}


Measured memory_bytes: 3988
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	    int x;
	    cin >> x;
		if (x < 1200)cout << "ABC" << endl;
		else cout << "ARC" << 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>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

// ref: http://prd-xxx.hateblo.jp/entry/2017/10/13/004256
struct BipartileGraph {
    vi colors;
    vvi edges;
    int n;
    BipartileGraph(int n) : colors(n, -1), edges(n), n(n) {}
    void addEdge(int f, int t) {
        edges[f].emplace_back(t);
        edges[t].emplace_back(f);
    }
    void clear() { colors.resize(n, -1); }
    // true = bipartile
    bool build(int s, int color = 0) {
        colors[s] = color;
        for (auto &e : edges[s]) {
            if (colors[e] == color)
                return false;
            if (colors[e] == -1 && !build(e, color ^ 1))
                return false;
        }
        return true;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    BipartileGraph g(n);
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g.addEdge(a, b);
        uf.unite(a, b);
    }
    vector<bool> used(100001, false);
    ll twoes  = 0;
    ll num    = 0;
    ll single = n;
    for (int i = 0; i < n; ++i) {
        int r = uf.root(i);
        if (used[r])
            continue;
        int s   = uf.getSize(r);
        used[r] = true;
        if (s != 1) {
            num++;
            single -= s;
            g.clear();
            if (g.build(r)) {
                twoes++;
            }
        }
    }
    ll ret = num * num;
    ret += twoes * twoes;
    ret += 2 * n * single - single * single;
    cout << ret << "\n";
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x3 - dx;
  int y4 = y3 - dy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
let solve i = 
  if i <= 599 then
    8
  else if i <= 799 then
    7
  else if i <= 999 then
    6
  else if i <= 1199 then
    5
  else if i <= 1399 then
    4
  else if i <= 1599 then
    3
  else if i <= 1799 then
    2
  else
    1

stdin.ReadLine() 
|> int 
|> solve
|> printfn "%d" 

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll L,T;
ll X[101010],W[101010];
ll ret[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L>>T;
	int id=-1;
	L*=2;
	T*=2;
	FOR(i,N) {
		cin>>X[i]>>W[i];
		X[i]*=2;
		if(W[i]==1 && id==-1) id=i;
	}
	if(id==-1) {
		FOR(i,N) {
			X[i]=((X[i]-T)%L+L)%L;
			_P("%d\n",X[i]/2);
		}
		return;
	}
	ll hit=0;
	vector<ll> V;
	FOR(i,N) {
		if(W[i]==1) V.push_back((X[i]+T)%L);
		else V.push_back(((X[i]-T)%L+L)%L);
	}
	sort(ALL(V));
	
	FOR(i,N) if(W[i]==2) {
		ll dif=(i>id)?(X[i]-X[id]):(L+X[i]-X[id]);
		ll TT=T;
		if(dif/2<=TT) {
			hit++;
			TT-=dif/2;
		}
		hit+=TT/(L/2);
	}
	ll tid=(id+hit)%N;
	ll TX=(X[id]+T)%L;
	
	for(i=N-1;i>=0;i--) if(V[i]==TX) {
		FOR(j,N) {
			ret[(tid+j)%N]=V[(i+j)%N]/2;
		}
		break;
	}
	
	FOR(i,N) _P("%lld\n",ret[i]);
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 4468
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(a*n, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() 
{
    ll n;
    cin>>n;
    if(n%2==0)
    {
        cout<<n/2;
    }
    else
    {
        cout<<n/2+1;
    }
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 4e5+10;
const int inf = 0x3f3f3f3f;
char str[maxn];
int pre[maxn],nex[maxn];
int cnt[maxn];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0); 
	int n,k,c;
	cin>>n>>k>>c;
	cin>>(str+1);
	rep(i,1,n) {
		int xx;
		if(i>c) xx=pre[i-c-1];
		else xx=0;
		if(str[i]=='o') xx++;
		pre[i]=max(pre[i-1],xx);
	}
	per(i,n,1) {
		int xx;
		if(n-i+1>c) xx=nex[c+i+1];
		else xx=0;
		if(str[i]=='o') xx++;
		nex[i]=max(nex[i+1],xx);
	}
	rep(i,1,n) {
		if(str[i]=='x')continue;
		if(pre[i]+nex[i+c+1]==k) cnt[pre[i]]++;
	}
	rep(i,1,n) {
		if(str[i]=='x')continue;
		if(pre[i]+nex[i+c+1]==k) {
			if(cnt[pre[i]]==1) cout<<i<<'\n';
		}
	}
	return 0;
}


Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int l = Integer.parseInt(sa[2]);
		long[][] d = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(d[i], 100000000000000L);
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			int c = Integer.parseInt(sa[2]);
			if (c <= l) {
				d[a][b] = c;
				d[b][a] = c;
			}
		}
		int q = Integer.parseInt(br.readLine());
		int[] s = new int[q];
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			s[i] = Integer.parseInt(sa[0]) - 1;
			t[i] = Integer.parseInt(sa[1]) - 1;
		}
		br.close();

		int[][] ans = new int[n][n];
		long[][] ansd = new long[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(ans[i], 1000000000);
		}
		for (int i = 0; i < n; i++) {
			boolean[] fix = new boolean[n];
			PriorityQueue<Node> que = new PriorityQueue<>();
			que.add(new Node(i, 0, 0));
			ans[i][i] = 0;
			while (!que.isEmpty()) {
				Node cur = que.poll();
				if (fix[cur.v]) {
					continue;
				}
				fix[cur.v] = true;
				for (int j = 0; j < n; j++) {
					if (fix[j]) {
						continue;
					}
					int alta = ans[i][cur.v];
					long c = d[cur.v][j];
					long altd = cur.d + c;
					if (altd >= 100000000000000L) {
						continue;
					}
					if (altd > l) {
						alta++;
						altd = c;
					}
					if (alta < ans[i][j]
							|| alta == ans[i][j] && altd < ansd[i][j]) {
						ans[i][j] = alta;
						ansd[i][j] = altd;
						Node next = new Node(j, alta, altd);
						que.add(next);
					}
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int o = ans[s[i]][t[i]];
			if (o == 1000000000) {
				pw.println(-1);
			} else {
				pw.println(o);
			}
		}
		pw.flush();
	}

	static class Hen {
		int v, c;

		public Hen(int v, int c) {
			this.v = v;
			this.c = c;
		}
	}

	static class Node implements Comparable<Node> {
		int v;
		int a;
		long d;

		public Node(int v, int a, long d) {
			this.v = v;
			this.a = a;
			this.d = d;
		}

		public int compareTo(Node o) {
			if (a != o.a) {
				return a - o.a;
			}
			return Long.compare(d, o.d);
		}
	}
}


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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  ll cnt=0;
  int mod=1e9+7;
  rep(i,n){
    cin>>a[i];
    cnt+=a[i]%mod;
    cnt%=mod;
  }
  ll ans=0;
  rep(i,n){
    cnt-=a[i];
    if(cnt<0)cnt+=mod;
    ans+=a[i]*cnt%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4052
#include <stdio.h>

int main()
{
   int a, b;
   scanf("%d %d", &a, &b);
   
   if(a > b)
     printf("a > b\n");
   else if(a == b)
     printf("a == b\n");
   else 
     printf("a < b\n");

return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, x, t;
	cin >> n >> x >> t;
	cout << t * ((n + x - 1) / x) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3648
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;

int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>a>>b>>c>>k;
    ll ans = min(a,k);
    k-=ans;
    ans = ans+ min(k,b)*0;
    k-=min(k,b);
    ans = ans+ min(k,c)*(-1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
using ll = long long;

int n,m,x,sum,ans=1e9;
string s,t;
int a[100][100],c[100];

int main() {
  cin >> n >> m >> x;
  rep(i,n){
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
  rep(b,1<<n){
    vector<int> r(m); sum=0;
    rep(i,n)if(b&1<<i){
      sum+=c[i];
      rep(j,m) r[j]+=a[i][j];
    }
    bool ok=true;
    rep(k,m)if(r[k]<x) ok=false;
    if(ok) chmin(ans,sum);
  }
  cout << (ans!=1e9 ? ans : -1) << endl;
}

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

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

int main(void) {
    int n, a, b, tmp, sum, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> a >> b;
    REP(i, n + 1) {
        tmp = i;
        sum = 0;
        while (tmp >= 1) {
            sum += tmp % 10;
            tmp /= 10;
        }

        if (a <= sum && sum <= b) {
            ans += i;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
  inl(N, K);

  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    que.push(make_pair(a, b));
  }

  ll count = 0;
  rep(i, N) {
    auto p = que.top();
    que.pop();
    count += p.second;
    if (count >= K) {
      out(p.first);
      break;
    }
  }
}


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

int main(){
  int h,w,x,y,n,m;
  cin>>h>>w>>x>>y;
  if((h*w)%2==1 && (x+y)%2==1){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}



Measured memory_bytes: 3100
A, B = map(int,input().split())

def make_base_list(N):
    base_list = [0]*40
    for i in range(40):
        if abs(N) % 2 == 0:
            base_list[i] = 0
        else:
            base_list[i] = 1
            N -= 1
        N = int(N)
        N = N // 2
    return base_list

if A % 2 == 0:
    A_base_list = [0]*40
else:
    A_base_list = make_base_list(A)

if B % 2 == 1:
    B_base_list = [0]*40
else:
    B_base_list = make_base_list(B)

xor_world = [1 if A_base_list[i]+B_base_list[i]==1 else 0 for i in range(40)]
xor_world[0] = 0

ans = 0
for i in range(40):
    ans += (2**i)*xor_world[i]

if A % 4 == 0 or A % 4 == 1:
    zero_a = 0
else:
    zero_a = 1

if B % 4 == 0 or B % 4 == 3:
    zero_b = 0
else:
    zero_b = 1
if zero_a != zero_b:
    ans += 1
print(ans)


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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            int now = a[i];
            while(now%2==0){
                ans++;
                now /= 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long N = lread();
    long T, A;
    scan(T, A);
    auto H = aryread();

    long result;
    double diff_min = double.infinity;

    foreach (i, h; H)
    {
        double t = T - (h * 0.006);
        double diff = abs(t - A);
        if (diff < diff_min)
        {
            diff_min = diff;
            result = i;
        }
    }
    writeln(result + 1);
}


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

using namespace std;


int N, M;
int **d_edge; //1-indexed
int *start;
int DP[100010]; //DP[i] :=iを始点としたときの最長パス

int path(int a) {
	if (start[a] == -1) return 0;
	else if (DP[a] != -1) return DP[a];
	else {
		int i = 1, longest = path(d_edge[start[a]][1]);
		while (start[a] + i < M && d_edge[start[a] + i][0] == a) {
			if (longest < path(d_edge[start[a] + i][1]))
				longest = path(d_edge[start[a] + i][1]);
			i++;
		}
		return DP[a] = longest + 1;
	}
}

int main() {
	int i, j;

	cin >> N >> M;

	d_edge = new int*[M];

	for (i = 0; i < M; i++) {
		d_edge[i] = new int[2];
		cin >> d_edge[i][0] >> d_edge[i][1];

		d_edge[i][0]--;
		d_edge[i][1]--;
	}

	sort(&d_edge[0], &d_edge[0] + M,
		[](const int *a, const int *b) {return a[0] < b[0]; });

	start = new int[N];

	for (i = 0; i < N; i++)
		start[i] = -1;

	i = 0;
	j = -1;
	while (i < M) {
		if (d_edge[i][0] > j) {
			start[d_edge[i][0]] = i;
			j = d_edge[i][0];
		}
		i++;
	}

	for (i = 0; i < N; i++)
		DP[i] = -1;

	int longest = path(0);
	for (i = 1; i < N; i++)
		if (longest < path(i))
			longest = path(i);

	cout << longest << endl;

	for (i = 0; i < M; i++)
		delete[] d_edge[i];
	delete[] d_edge;
	delete[] start;

	return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int N;
    cin >> N;

    if(N < 10){
      cout << N;
    }else if(N < 100){
      cout << 9;
    }else if(N < 1000){
      cout << N - 90;
    }else if(N < 10000){
      cout << 909;
    }else if(N < 100000){
      cout << N - 9090;
    }else{
      cout << 90909;
    }
}

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

int main()
{
    string n;
    cin >> n;
    if(n.size() == 1) {
        cout << n[0] - '0' << endl;
        return 0;
    }
    bool t = true;
    repl(i, 1, n.size()) {
        if(n[i] != '9') t = false;
    }
    if(t) cout << 9 * (n.size() - 1) + (n[0] - '0') << endl;
    else {
        cout << (n[0] - '0' - 1) + 9 * (n.size() - 1) << endl;
    }
    return 0;
}


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

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int x = sc.nextInt();
    if (x == 3 || x == 5 || x == 7) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21204
n = int(input())
l = []
e = "abcdefghijklmnopqrstuvwxyz"
ans = "Yes"
for i in range(n):
  w = input()
  if w[0] not in e or w in l : ans = "No" 
  l.append(w)
  e = w[-1]
print(ans)

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

typedef long long ll;
const ll MOD = 1000000007;

int main() {
    ll N, x;
    cin >> N;
    set<ll>s;
    for (int i = 0; i < N; i++) {
        cin >> x;
        s.insert(x);
    }
    if (s.size() % 2 == 0) {
        cout << s.size() - 1 << endl;
    } else {
        cout << s.size() << endl;
    }
}


Measured memory_bytes: 4992
// 以下と同じ内容を提出.
// https://atcoder.jp/contests/caddi2018b/submissions/9359911
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second

// Efficient program to print all prime factors of a given number
// https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/
// 与えられた正整数についての素因数分解を計算.
// @param X: 素因数分解を行う整数.
// @return ret: 素因数分解 の 結果 を 返却.
map<LL, LL> div(LL X){
    
    // 1. X を 2で割り切れなくなるまで割っていく.
    map<LL, LL> ret;
    while(X % 2 == 0) ret[2]++, X >>= 1;
    
    // 2. X を 3以上の奇数で, 割り切れなくなるまで順次割っていく.
    repex(i, 3, sqrt(X) + 1, 2){
        while(X % i == 0){
            ret[i]++;
            X /= i;
        }
    }
    
    // 3. X が 2 より 大きな素数であれば, 追加.
    if(X > 2) ret[X]++;
    
    // 4. 出力.
    return ret;
}

int main(){
    
    // 1. 入力情報.
    LL N, P;
    scanf("%lld %lld", &N, &P);
    
    // 2. 素因数分解.
    map<LL, LL> m = div(P);
    // for(auto &p : m) printf("%lld %lld\n", p.a, p.b);
    
    // 3. 最大公約数は？
    LL ans = 1;
    for(auto &p : m){
        int l = p.b / N;
        rep(i, l) ans *= p.a;
    }
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		long a = Integer.parseInt(scan.next());
		long b = Integer.parseInt(scan.next());
		long mult = a * b;
		
		if(a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}
		
		long r = a % b;
		while(r > 0) {
			a = b;
			b = r;
			r = a % b;
		}
		
		System.out.println(mult / b);
		scan.close();
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll B[N]{};
    ll C[N]{};
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (i + A[i] < N) {
            B[i + A[i]]++;
        }
        if (i - A[i] > 0) {
            C[i - A[i]]++;
        }
    }
    for (int i = 1; i < N; i++) {
        ans += B[i] * C[i];
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
    string str;
    cin >> str;
    if(str.at(0) == str.at(2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    int x,y,z,a,b,c;
    std::cin >> x >> y >> z;
   a=z;
   b=x;
   c=y;
   
    std::cout << a << " " << b << " " << c << std::endl;
    
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

N,M=map(int,input().split())

def main():
  H=[int(x) for x in input().split()]
  G=[1]*N

  for i in range(M):
    a,b=map(int,input().split())
    G[~-a]*=1 if H[~-a]>H[~-b] else 0
    G[~-b]*=1 if H[~-b]>H[~-a] else 0

  print(sum(G))

main()


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

using namespace std;

#define int long long

int dp[3010][3010];
int mod;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        dp[i][i] = a[i];
    }
    for (int len = 2; len <= n; len++) {
        for (int l = 0; l + len <= n; l++) {
            int r = l + len - 1;
            dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}


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

using namespace std;

int gcd(int x,int y){
    if(y==0)return x;
    return gcd(y,x%y);
}

int main()
{
    int n;
    cin >>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<int >l(n,0),r(n,0);
    for(int i=0;i<n-1;i++){
        l[i+1]=gcd(l[i],a[i]);
    }
    for(int i=n-1;i>0;--i){
        r[i-1]=gcd(r[i],a[i]);
    }
    int ans=1;
    for (int i=0;i<n;i++){
        ans=max(ans,gcd(l[i],r[i]));
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 2001;

int n, m, dp[3 * N][5 * N];

int solve(int s, int t){
    if(s == 0) return t <= 0;
    int &ret = dp[s][t + 3 * N];
    if(ret != -1) return ret;
    ret = 0;
    ret = (ret + solve(s - 1, t - 1)) % m;
    if(s >= 2 && t < n) ret = (ret + 1LL * solve(s - 2, t + 1) * (s - 1)) % m;
    if(s >= 3) ret = (ret + 1LL * solve(s - 3, t) * (s - 1) % m * (s - 2)) % m;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    cout << solve(3 * n, 0) << endl;
}


Measured memory_bytes: 235392
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++)
        cin >> H[i];
    
    int height = 0;
    int res = 0;
    for(int i = 0; i < N; i++)
    {
        if(H[i] >= height)
        {
            res++;
            height = H[i];
        }
    }
    cout << res <<endl;

    return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
const int N = 1e4+5;

int a[] = {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};

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
	int n;
	cin >> n;
	cout << a[n-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n;
string s;
string res;

int main(void)
{
	cin>>s; int i;
	for(i=0 ; i<s.length() ; i++)
	{
		if(s[i]=='0') res.push_back('0');
		if(s[i]=='1') res.push_back('1');
		if(s[i]=='B' && res.length()>=1) res.pop_back();
	}
	cout<<res; return 0;
	return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main() {
  double rad, c;
  int a, b, C;
  double S, L, h;
  scanf("%d %d %d", &a, &b, &C);

  rad = M_PI * C / 180;
  c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad));
  L = a + b + c;
  h = fabs(sqrt(pow(b, 2) - pow(b * cos(rad), 2)));
  S = a * h / 2;

  printf("%lf\n%lf\n%lf\n", S, L, h);

  return 0;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(int x,const vi& ms,unordered_map<int,int>& memo)
{
	auto i=memo.find(x);
	if(i!=end(memo)) return i->second;
	
	if(x==0) return memo[x]=0;
	int res=INF;
	for(int m:ms) if(__builtin_ctz(x)==__builtin_ctz(m))
		res=min(res,solve(x^m,ms,memo));
	return memo[x]=res+1;
}

int main()
{
	vi ms;
	rep(t,5) repi(b,t,5) rep(l,5) repi(r,l,5){
		int m=0;
		repi(i,t,b+1) repi(j,l,r+1) m|=1<<(i*5+j);
		ms.push_back(m);
	}
	unordered_map<int,int> memo;
	
	for(int n;cin>>n && n;){
		int x=0;
		rep(i,n) rep(j,n){
			int b; cin>>b;
			x|=b<<(i*5+j);
		}
		
		int res=solve(x,ms,memo);
		rep(i,res) cout<<string("myon"); cout<<endl;
	}
}

Measured memory_bytes: 42364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
set<int> pathes[100050];
bool deleted[100050];
string S;
int N;
bool needed[100050];
int dp[100050];
int maxi = 0;
void dfs(int now, int from) {
    vector<int> v;
    for(auto to: pathes[now]) {
        if(to == from) continue;
        dfs(to, now);
        v.push_back(dp[to]);
    }
    if(v.empty()) {
        if(needed[now]) dp[now]++;
        chmax(maxi, dp[now]);
        return;
    }
    sort(v.begin(), v.end(), greater<int>());
    if(v.size() >= 2) {
        int nowval = v[0] + v[1];
        if(needed[now]) nowval++;
        chmax(maxi, nowval);
    }
    dp[now] = v[0];
    if(needed[now]) dp[now]++;
    chmax(maxi, dp[now]);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        pathes[x].insert(y);
        pathes[y].insert(x);
    }
    cin >> S;
    S = "#" + S;
    bool AllBlack = true;
    queue<int> que;
    for(int i = 1; i <= N; i++) {
        if(S[i] == 'W') AllBlack = false;
        if(S[i] == 'B' && pathes[i].size() == 1) que.push(i);
    }
    if(AllBlack) {
        cout << 0 << endl;
        return 0;
    }
    int SIZE = N;
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        if(deleted[now]) continue;
        deleted[now] = true;
        SIZE--;
        int to = *(pathes[now].begin());
        pathes[now].erase(pathes[now].begin());
        auto itr = pathes[to].lower_bound(now);
        pathes[to].erase(itr);
        if(S[to] == 'B' && pathes[to].size() == 1) que.push(to);
    }
    if(SIZE == 1) {
        cout << 1 << endl;
        return 0;
    }
    int ans = (SIZE - 1) * 2;
    int root = 0;
    for(int i = 1; i <= N; i++) {
        if(deleted[i]) continue;
        root = i;
        if((pathes[i].size() % 2 == 1) ^ (S[i] == 'W')) {
            needed[i] = true;
            ans++;
        }
    }
    dfs(root, -1);
    cout << ans - maxi * 2 << endl;
    return 0;
}


Measured memory_bytes: 23784
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# 方針
# 1個のやつは何もしないでOK
# 合計個数が奇数の数字は自己解決する（最終的に1になる）
# 偶数になる数字は組を作ると解決する（2,2,5,5 のような場合）
# 偶数になる数字の組から漏れた数字は削られる

def main():
  n=I()
  l=LI()

  l.sort()

  l2=[]

  a=l[0]
  c=1
  ans=0
  aa=0
  for x in l[1:]:
    if x==a:
      c+=1
    else:
      if c==1:
        ans+=1
      else:
        if c%2==0:
          aa+=1
        else:
          ans+=1
      a=x
      c=1
  if c==1:
    ans+=1
  else:
    if c%2==0:
      aa+=1
    else:
      ans+=1

  return ans+aa-aa%2

print(main())


Measured memory_bytes: 16648
import java.util.Scanner;

public class Main{

public static void main (String[] args){
 
  Scanner scan = new Scanner(System.in);
  
 int a = scan.nextInt();
 int b = scan.nextInt();
 int c = scan.nextInt();

 
  if(a==5 && b==7 && c==5){
    System.out.println("YES");
  } else if(a==5 && b==5 && c==7){
    System.out.println("YES");
  } else if(a==7 && b==5 && c==5){
    System.out.println("YES");
  } else {
     System.out.println("NO");
  }
  
}
}

Measured memory_bytes: 35368
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), x(M), y(M), c(M);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];
    int ans = *min_element(a.begin(), a.end())
        + *min_element(b.begin(), b.end());

    int d;
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i] >> c[i];
        d = a[x[i] - 1] + b[y[i] - 1] - c[i];
        ans = min(d, ans); 
    }

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


Measured memory_bytes: 2176
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


N = int(input())
s = input()
s = s + s[0]

def check(SW):
	global N
	global s
	for i in range(1,N+1):
		if SW[i]:
			if s[i] == 'o':
				SW.append(SW[i-1])
			else:
				SW.append(not SW[i-1])
		else:
			if s[i] == 'o':
				SW.append(not SW[i-1])
			else:
				SW.append(SW[i-1])

	if SW[N] == SW[0] and SW[N+1] == SW[1]:
		for i in range(N):
			if SW[i]:
				sys.stdout.write("S")
			else:
				sys.stdout.write("W")
		print()
		sys.exit()

check([True,True])
check([True,False])
check([False,True])
check([False,False])
print(-1)


Measured memory_bytes: 5380
#include<iostream>
#include<cstring>
#include<algorithm> 
#include<string>
#include<string.h>
#include<cstdio>
using namespace std;
int main()
{
	int a[200005];
	memset(a,0,sizeof(a));
	int k,n;
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int max1=a[n-1]-a[0]>k/2?k-(a[n-1]-a[0]):a[n-1]-a[0];
	for(int i=0;i<n-1;i++)
	{
		max1=max(max1,a[i+1]-a[i]>k/2?k-(a[i+1]-a[i]):a[i+1]-a[i]);
	}
	printf("%d",k-max1);
	return 0;
} 

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
char _s[5252];
int s[5252];

ll dp[5252][5252];

int main(){
  scanf("%d",&n);
  scanf("%s",_s);
  m = strlen(_s);
  REP(i,m){
    s[i] = _s[i]-'0';
  }
  dp[0][m] = 1;
  REP(i,n){
    REP(j,n+1){
      // backspace
      if(j==0)dp[i+1][j] += dp[i][j];
      else dp[i+1][j-1] += dp[i][j];
      // step
      dp[i+1][j+1] += dp[i][j]*2;

      if(j==0)dp[i+1][j] %= MOD;
      else dp[i+1][j-1] %= MOD;
      dp[i+1][j+1] %= MOD;
    }
  }
  printf("%lld\n",dp[n][0]);
  return 0;
}


Measured memory_bytes: 205440
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
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 (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
    return 0;
}

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

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

    vector< vector<int64_t> > value(n, vector<int64_t>(3, 0));
    int v[3] = {0};
    cin >> v[0] >> v[1] >> v[2];
    for(int i = 0; i < 3; i++) value[0][i] = v[i];

    for(int i = 1; i < n; i++) {
        cin >> v[0] >> v[1] >> v[2];
        value[i][0] = max(value[i-1][1], value[i-1][2]) + v[0];
        value[i][1] = max(value[i-1][2], value[i-1][0]) + v[1];
        value[i][2] = max(value[i-1][0], value[i-1][1]) + v[2];
    }

    cout << max(value[n-1][0], max(value[n-1][1], value[n-1][2])) << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    string S, T;
    cin >> S >> T;
    bool ans = true;
    int pos = -1;

    for(int i=0;i<S.length() - T.length()+1;i++){
        ans = true;
        for(int j=0;j<T.length();j++){
            if(S[i+j] == T[j] or S[i+j]=='?'){continue;}
            else{
                ans=false;
            }
        }
        if(ans){
            pos = i;
        }
    }
    if(pos < 0 or T.length() > S.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=pos;i<T.length()+pos;i++){
        S[i]= T[i - pos];
    }
    for(int i=0;i<S.length();i++){
        if(S[i]=='?'){
            S[i] = 'a';
        }
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256