akhauriyash/Code-Regression huggingface dataset:
/**
*   author:  akifpathan
*   created: Sunday 13.09.2020 03:56:48 PM
**/

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const ll base=31;
const ll mod=1e9+7;

ll ara[6000],power[6000];

void solve()
{
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	
	s='.'+s;
	
	power[0]=1LL;
	for(int i=1;i<=n;i++) power[i]=(power[i-1]*base)%mod;
	
	for(int i=1,j=n-1;i<=n;i++,j--)
	{
		ara[i]=ara[i-1]+(power[j]*s[i])%mod;
		ara[i]%=mod;
	}
	
	int hi=n/2;
	int lo=1;
	int ans=0;
	
	while(hi>=lo)
	{
		int mid=(hi+lo)/2;
		
		map<ll,vector<int>>indx;
		
		for(int i=1;i+mid-1<=n;i++)
		{
			ll temp=ara[i+mid-1]-ara[i-1];
			temp%=mod;
			if(temp<0) temp+=mod;
			
			temp*=power[i-1];
			temp%=mod;
			
			indx[temp].push_back(i);
		}
		
		bool flag=false;
		
		for(auto it: indx)
		{
			if(it.second.size()>=2)
			{
				flag|=(it.second[0]+mid<=it.second.back());
			}
		}
		
		if(flag)
		{
			ans=mid;
			lo=mid+1;
		}
		else hi=mid-1;
	}
	
	
	cout<<ans;
	
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}



Measured memory_bytes: 4268
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  int d[10]={};
  for(int i=1;i<=k;i++) cin>>d[i];

  for(int i=n;;i++){
    int flag=1;
    for(int j=i;j>0;j/=10){
      int tmp=j%10;
      for(int l=1;l<=k;l++){
        if(tmp==d[l]) flag=0;
      }
    }
    if(flag){
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int main()
{
    string s,t,ans="Yes";
    in s>>t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])ans="No";
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3632
import math

def check(a, b, x, deg):
    theta = math.radians(deg)
    if b * math.cos(theta) >= a * math.sin(theta):
        return (a * a) * (b - a * math.tan(theta) / 2.0) >= x
    else:
        return (b * b * a) / (2.0 * math.tan(theta)) >= x


a, b, x = map(float, input().split(" "))
high, low = 90, 0   # [low, high)
while (high - low) > 1e-10:
    mid = (high + low) / 2
    if check(a, b, x, mid):
        low = mid
    else:
        high = mid
print(low)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		PriorityQueue<Double> q = new PriorityQueue<>();
		for (int i = 0; i < N; i++) {
			q.add((double) sc.nextInt());
		}
		while (q.size() > 1) {
			double x = q.poll();
			double y = q.poll();
			q.add((x + y) / 2);
		}
		System.out.println(q.poll());
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <atcoder/modint>
#include <atcoder/lazysegtree>

namespace ac = atcoder;

using mint = ac::modint998244353;
const mint inv9 = mint(9).inv();

// ノードに持たせる値
struct S {
    mint val;
    int len;

    S(mint _val, int _len) : val(_val), len(_len) {}

    static S op(S a, S b) {
        return S(a.val * mint(10).pow(b.len) + b.val,
                 a.len + b.len);
    }
    static S id() { return S(0, 0); }
};

// 作用素(更新する値)
using F = int;
// fが新しい方、0が単位元であることに注意
F f_op(F f, F g) { return f == 0 ? g : f; }
F f_id() { return 0; }

// 作用素の適用
S mapping(F f, S a) {
    if (f == 0) return a;
    return S((mint(10).pow(a.len) - 1) * inv9 * f, a.len);
}

void solve() {
    int n;
    std::cin >> n;

    // 初期配列
    std::vector<S> init(n, S(1, 1));

    ac::lazy_segtree<S, S::op, S::id, F, mapping, f_op, f_id> seg(init);

    int q;
    std::cin >> q;
    while (q--) {
        int l, r, d;
        std::cin >> l >> r >> d;
        --l;  // [l, r)

        seg.apply(l, r, d);
        std::cout << seg.all_prod().val.val() << "\n";
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 9772
from collections import deque
s = input()
tmp = s.replace('x','')
if tmp == tmp[::-1]:
  left = 0
  right = len(s)-1
  result = deque()
  while 1:
    if right == left:
      result.append(s[left])
      break
    if s[left] == s[right]:
      result.appendleft(s[left])
      result.append(s[right])
      left += 1
      right -= 1
    else:
      result.appendleft('x')
      result.append('x')
      if s[left] == 'x':
        left += 1
      else:
        right -= 1
    if right < left:
      break
  print(len(result)-len(s))
else:
  print(-1)

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
template< typename T > using Vec = vector< T >;
typedef long long lint;
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }

struct Edge {
	int v;
	lint d;
	bool operator > (const Edge& e) const { return d > e.d; }
};

int N, M, S, T, U[200005], V[200005];
lint D[200005];
Vec< Vec< Edge > > edge;

lint dst[2][100005];
lint numpath[2][100010];
const lint MOD = (lint)1e9 + 7;

void calcDist(int piv, int start) {
	priority_queue< Edge, Vec< Edge >, greater< Edge > > que;
	que.push(Edge{start, 0});
	dst[piv][start] = 0;
	numpath[piv][start] = 1;
	while (!que.empty()) {
		Edge e = que.top(); que.pop();
		if (dst[piv][e.v] < e.d) continue;
		for (const Edge& ei : edge[e.v]) {
			if (dst[piv][ei.v] == -1 || dst[piv][ei.v] > e.d + ei.d) {
				dst[piv][ei.v] = e.d + ei.d;
				numpath[piv][ei.v] = numpath[piv][e.v];
				que.push(Edge{ei.v, dst[piv][ei.v]});
			} else if (dst[piv][ei.v] == e.d + ei.d) {
				modAdd(numpath[piv][ei.v], numpath[piv][e.v], MOD);
			}
		}
	}
}

void solve() {
	memset(dst, -1, sizeof(dst));
	calcDist(0, S);
	calcDist(1, T);
	
	lint collision = 0;	
	
	for_(v,0,N) {
		if (dst[0][v] == dst[1][v] && dst[0][v] + dst[1][v] == dst[0][T]) {
			lint num = (numpath[0][v] * numpath[1][v]) % MOD;
			modAdd(collision, num * num, MOD);
		}
	}
	
	double thr = (double)dst[0][T] / 2.;
	for_(i,0,M) {
		int u = U[i], v = V[i], d = D[i];
		if (abs(dst[0][v] - dst[0][u]) == d) {
			if (dst[0][v] + d == dst[0][u]) swap(u, v);
			if (dst[0][u] + dst[1][v] + d == dst[0][T] && (double)dst[0][u] < thr && (double)(dst[0][u] + d) > thr) {
				lint num = (numpath[0][u] * numpath[1][v]) % MOD;
				modAdd(collision, num * num, MOD);
			}
		}
	}
	
	cout << ((numpath[0][T] * numpath[1][S] - collision + MOD) % MOD) << endl;
}

int main() {
	cin >> N >> M;
	cin >> S >> T;
	--S; --T;
	
	edge.assign(N, Vec< Edge >());
	for_(i,0,M) {
		cin >> U[i] >> V[i] >> D[i];
		--U[i]; --V[i];
		edge[U[i]].push_back(Edge{V[i], D[i]});
		edge[V[i]].push_back(Edge{U[i], D[i]});
	}
	
	solve();
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll A,B,Q;
int main(){
    cin >> A >> B >> Q;
    ll s[100100], t[100100], x;
    ll d[8];
    s[0] = -INF; s[A+1] = INF;
    t[0] = -INF; t[B+1] = INF;
    for(ll i = 1; i <= A; i++) cin >> s[i];
    for(ll i = 1; i <= B; i++) cin >> t[i];
    for(ll i = 0; i < Q; i++){
        cin >> x;
        ll* u = lower_bound(s,s+A+2,x);
        ll* v = lower_bound(t,t+B+2,x);

        d[0] = x - min(*(u-1), *(v-1));
        d[1] = x - *(u-1) + *v - *(u-1);
        d[2] = x - *(v-1) + *u - *(v-1);
        d[3] = max(*v,*u)-x;
        d[4] = *v - x + *v - *(u-1);
        d[5] = *u - x + *u - *(v-1);

        ll mini = d[0];
        for(ll j = 1; j <= 5; j++){
            mini = min(d[j], mini);
        }
        cout << mini << endl;
    }
    return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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;}

using namespace std;

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

string yaml[50010];

int main(void){
	string s;
	cin >> s;
	vector<string> keys;

	while(s!=""){
		int cur=1;
		while(cur<s.size()&&s[cur]!='.') cur++;
		keys.push_back(s.substr(1,cur-1));
		s=s.substr(cur);
	}

	cin.ignore();
	
	int n=0;
	while(1){
		getline(cin,yaml[n++]);
		if(cin.eof()) break;
	}

	//cout << n << endl;
	bool not_found=false;

	int cur=0,idx=0,pos=0;
	while(1){
		const int len=keys[idx].size();
		while(cur<n){
			if(pos+len<=yaml[cur].size()&&keys[idx]==yaml[cur].substr(pos,len))
				break;
			cur++;
		}
		
		//cout << cur << " " << idx << " " << pos << endl;

		if(cur==n){
			not_found=true;
			break;
		}

		if(idx+1==keys.size()) break;
		cur++,idx++;

		if(cur==n || yaml[cur][pos]!=' '){
			not_found=true;
			break;
		}

		while(pos<yaml[cur].size() && yaml[cur][pos]==' ') pos++;
	}

	if(not_found){
		cout << "no such property" << endl;
		return 0;
	}

	string elem=yaml[cur].substr(pos+1+keys[keys.size()-1].size());
	if(elem=="")
		cout << "object" << endl;
	else{
		elem=elem.substr(1,elem.size()-1);
		cout << "string \""  << elem << "\"" << endl;
	}
	return 0;
}

Measured memory_bytes: 3700
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int n;
vector<string> s(100005);
queue<int> num;
ll cntm=0,cnta=0,cntr=0,cntc=0,cnth=0,ans=0;
vi a(105,0);
vi b(105,0);
int main(int argc,char const* argv[])
{
  cin >> n;
  for(int i=0;i<n;i++)
    {
      cin >> s[i];
      if(s[i][0]=='M') cntm++;
      if(s[i][0]=='A') cnta++;
      if(s[i][0]=='R') cntr++;
      if(s[i][0]=='C') cntc++;
      if(s[i][0]=='H') cnth++;
    }
  ans+=(cntm*cnta*cntr);
  ans+=(cntm*cnta*cntc);
  ans+=(cntm*cnta*cnth);
  ans+=(cntm*cntr*cntc);
  ans+=(cntm*cntr*cnth);
  ans+=(cntm*cntc*cnth);
  ans+=(cnta*cntr*cntc);
  ans+=(cnta*cntr*cnth);
  ans+=(cnta*cntc*cnth);
  ans+=(cntr*cntc*cnth);
  
  
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <limits.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n, f[105][10], p[105][11];
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) cin >> p[i][j];
    }
    
    int mx = -1e9, trl;
    for (int at = 1; at < 1024; at++) {
        int atc = at, same[105];
        trl = 0;
        for (int i = 0; i < n; i++) same[i] = 0;
        for (int bn = 0; bn < 10; bn++) {
            if (atc % 2 == 1) {
                for (int i = 0; i < n; i++) {
                    if (f[i][bn] == 1) same[i]++;
                }
            }
            atc /= 2;
        }
        for (int i = 0; i < n; i++) trl += p[i][same[i]];
        mx = max(mx, trl);
    }
    
    cout << mx << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int H, W;
char sky[112][112];
int nearly_c = -1;
int ans[112][112];

int main(void) {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) { scanf("%s", &sky[i]); }

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (sky[i][j] == 'c') {
				ans[i][j] = 0;
				if (nearly_c < j) { nearly_c = j; }
			}
			if (sky[i][j] == '.') {
				if (nearly_c == -1) { ans[i][j] = -1; }
				else { ans[i][j] = j - nearly_c; }
			}
		}
		nearly_c = -1;
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (j < W - 1) { printf("%d ", ans[i][j]); }
			else { printf("%d\n", ans[i][j]); }
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int value[n];
    int cost[n];
    int vsum = 0, csum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> value[i];
    }
    for(int i = 0; i < n; i++){
        cin >> cost[i];
    }
    
    for(int i = 0; i < n; i++){
        if(value[i] > cost[i]){
            vsum+=value[i];
            csum+=cost[i];
        }else{
            
        }
    }
    
    cout << vsum-csum;
    
    
}

Measured memory_bytes: 384
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == "?":
        break
    else:
        ans = 0
        if op == "+":
            ans = a + b
        elif op == "-":
            ans = a - b
        elif op == "*":
            ans = a * b
        else:
            ans = a // b
        print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

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

  set<pair<int,pair<int,int>>> removed;

  long ans = 2L*(a*b+b*c+c*a);
  rep(i,n){
    int x,y,z;
    cin>>x>>y>>z;
    ans += 6;
    if(x==0) ans-=2;
    if(x==a-1) ans -=2;
    if(y==0) ans -=2;
    if(y==b-1) ans -=2;
    if(z==0) ans-=2;
    if(z==c-1) ans -=2;
    const int d[] = {0,0,0,0,1,-1,0,0,0,0};
    rep(k,6){
      auto p = mp(x+d[k], mp(y+d[k+2], z+d[k+4]));
      if(removed.count(p)==1) ans -= 2;
    }
    removed.insert(mp(x,mp(y,z)));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll x;
  cin >> x;
  ll ans = x/11;
  x -= ans*11;
  ans *= 2;
  if(x>=1 && x<=6) ans++;
  if(x>=7) ans += 2;
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;
 
 
int32_t main()
{
    fast_io;
    int n;
    cin>>n;
    vi a(n);
    c(a,n);
    vii dp(n,vi(n,LLONG_MAX));
    vi pre(n+1,0);
    for(int i=1;i<=n;i++)pre[i]=a[i-1]+pre[i-1];
    for(int i=0;i<n;i++)dp[i][i]=0;
    for(int i=0;i<n-1;i++)
    dp[i][i+1]=a[i]+a[i+1];

    for(int size=3;size<=n;size++)
    {
        for(int i=0;i<=n-size;i++)
        {
            for(int l=i;l<i+size-1;l++)
            dp[i][i+size-1]=min(dp[i][i+size-1],pre[i+size]-pre[i]+dp[i][l]+dp[l+1][i+size-1]);
        }
    }
    cout<<dp[0][n-1];
    return 0;
}

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        // freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

LL n , x , Ans;

int main()
{
    read(n) , read(x);
    Ans = n;
    LL L = x , R = n - x;
    if(L < R) swap(L , R);
    while(true)
    {
        if(L % R == 0) {
            Ans += R * (2 * (L / R) - 1);
            break;
        }
        else
        {
            Ans += R * (2 * (L / R));
            L %= R;
            if(L < R) swap(L , R);
        }
    }
    printf("%lld\n" , Ans);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101

int A[MAX][MAX], s[MAX], h[MAX];

void serch(int x, int y){
  int i;
  h[x] = y;
  for(i=1; i<=s[x]; i++){
    if(h[A[x][i]] > y)
      serch(A[x][i], y+1);
  }
}

int main(){
  int i, j, k, n;
  
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    h[i] = 10000;
    for(j=1; j<=n; j++)
      A[i][j] = 0;
  }
  
  for(i=1; i<=n; i++){
    scanf("%d", &k);
    scanf("%d", &s[k]);
    for(j=1; j<=s[k]; j++)
      scanf("%d", &A[k][j]);
  }
  
  serch(1,0);
  
  for(i=1; i<=n; i++){
    if(h[i] == 10000)
      h[i] = -1;
    printf("%d %d\n", i, h[i]);
  }
  return 0;
}
  

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

int main(){
	int N;
	int max_L = 0;
	int sum_L = 0;

	std::cin >> N;

	for(int i=0;i<N;i++){
		int L;
		std::cin >> L;
		if(L > max_L) max_L = L;
		sum_L += L;
	}

	sum_L -= max_L;

	if(sum_L > max_L) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

const val MOD = 1000000007L

fun main() {
    val pow = Array(401) { LongArray(401) }
    for (k in 0..400) {
        pow[k][0] = 1L
        for (e in 1..400) {
            pow[k][e] = (pow[k][e - 1] * k.toLong()) % MOD
        }
    }
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val (n, c) = jin.readLine().split(" ").map { it.toInt() }
    val dp = Array(n + 1) { LongArray(c + 1) }
    dp[0][0] = 1L
    val tokenizerA = StringTokenizer(jin.readLine())
    val tokenizerB = StringTokenizer(jin.readLine())
    for (j in 1..n) {
        val a = tokenizerA.nextToken().toLong()
        val b = tokenizerB.nextToken().toLong()
        for (e in 0..c) {
            var factor = 0L
            for (k in a..b) {
                factor += pow[k.toInt()][e]
            }
            factor %= MOD
            for (j2 in e..c) {
                dp[j][j2] += factor * dp[j - 1][j2 - e]
                dp[j][j2] %= MOD
            }
        }
    }
    println(dp[n][c])
}

Measured memory_bytes: 40828
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long dp[110000][4], n; string T; char F[5] = "JOI!";
long long solve(string S) {
	for (int i = 0; i < 440000; i++)dp[i / 4][i % 4] = 0; dp[0][0] = 1;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < 4; j++) {
			if (F[j] == S[i])dp[i + 1][j + 1] += dp[i][j];
			dp[i + 1][j] += dp[i][j];
		}
	}
	return dp[S.size()][3];
}
int main() {
	cin >> n >> T;
	long long J = 0, I = 0; for (int i = 0; i < T.size(); i++)if (T[i] == 'I')I++;
	int maxn = 0, maxid = 0;
	for (int j = 0; j < T.size(); j++) {
		if (T[j] == 'J')J++; if (T[j] == 'I')I--;
		if (J*I > maxn) { maxn = J*I; maxid = j + 1; }
	}
	string T1 = 'J' + T, T2 = T + 'I', T3 = T.substr(0, maxid) + 'O' + T.substr(maxid, T.size() - maxid);
	cout << max(solve(T1), max(solve(T2), solve(T3))) << endl;
	return 0;
}

Measured memory_bytes: 7216
#include <bits/stdc++.h>
using namespace std;
// typedef __uint128_t u128;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> ii;
typedef vector<pair<ll, ll>> vii;
typedef vector<vector<pair<ll, ll>>> vvii;
typedef long double ld;
typedef vector<long double> vld;
typedef vector<vector<long double>> vvld;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;
#define ff first
#define ss second
#define pb push_back
#define all(c) (c).begin(), (c).end()
const long long MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int s, w;
    cin >> s >> w;
    if (s <= w)
        cout << "unsafe\n";
    else
    {
        cout << "safe\n";
    }
    return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
struct N{int p,l,r;};
N T[100000];
int n,d,k,c,r,i,j,m,o,D[100000];
void R(int r,int d){
  D[r]=d;
  if(T[r].r+1)R(T[r].r,d);
  if(T[r].l+1)R(T[r].l,d+1);
}
main(){
  for(scanf("%d",&n);j<n;++j)T[j].p=T[j].l=T[j].r=-1;
  for(;i++<n;)
    for(scanf("%d%d",&d,&k),j=0;j<k;r=c){
      scanf("%d",&c);
      T[c].p=d;
      j++?T[r].r=c:T[d].l=c;
    }
  for(;m<n;++m)r=T[m].p+1?r:m;
  for(R(r,0);o<n;++o){
    printf("node %d: parent = %d, depth = %d, ",o,T[o].p,D[o]);
    printf(T[o].p+1?T[o].l+1?"internal node, [":"leaf, [":"root, [");
    for(i=0,j=T[o].l;j+1;)printf(i++?", %d":"%d",j),j=T[j].r;
    printf("]\n");
  }
}

Measured memory_bytes: 7340
// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    // var... 変数の識別子, $t...型を一つよむ
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        //ここで繰り返し
        input_inner!{$iter $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    //
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    // 配列の最後のNestではここで型が指定されてparseされる
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// =========

fn main() {
    input! {
        n: usize,
        a: [usize;n]
    }
    let mut a = a;
    a.sort();
    let mut prev = 0;
    for e in a {
        if prev == e {
            println!("NO");
            exit(0);
        }
        prev = e;
    }
    println!("YES",);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

ll a, b, c, d;
unordered_map<ll, ll> cache;
ll f(ll n){
    if(n == 0){ return 0; }
    if(n == 1){ return d; }
    if(cache.count(n)){ return cache[n]; }

    ll ret = numeric_limits<ll>::max();

    // div 2
    ret = min(
        ret,
        min(
            f((n + 1) / 2) + a + d * (n % 2),
            f(n / 2) + a + d * (n % 2)
        )
    );

    // div 3
    ret = min(
        ret,
        min(
            f((n + 2) / 3) + b + d * (3 - n % 3),
            f(n / 3) + b + d * (n % 3)
        )
    );

    // div 5
    ret = min(
        ret,
        min(
            f((n + 4) / 5) + c + d * (5 - n % 5),
            f(n / 5) + c + d * (n % 5)
        )
    );

    if(ret / d > n){
        ret = min(ret, n * d);
    }
    cache[n] = ret;
    return ret;
}

int main(){
    ll t;
    cin >> t;
    REP(i, t){
        ll n;
        cin >> n >> a >> b >> c >> d;
        cache.clear();
        cout << f(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 4040
#include <cstdio>
#include <cstring>
#include <algorithm>

const int maxn = 110;

int a[maxn][maxn], x, y, n, m, dp[maxn][maxn][maxn], pd[maxn][maxn][maxn], ans, x1, Y1, x2, y2;

inline void upd(int &x, int y) {
	x = x < y ? y : x;
}

inline int qry(int x1, int Y1, int x2, int y2) {
	x1 = std::max(x1, ::x1);
	Y1 = std::max(Y1, ::Y1);
	x2 = std::min(x2, ::x2);
	y2 = std::min(y2, ::y2);
	if(x1 > x2 || Y1 > y2) {
		return 0;
	}
	return a[x2][y2] - a[x1 - 1][y2] - a[x2][Y1 - 1] + a[x1 - 1][Y1 - 1];
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			char c = getchar();
			while(c != '.' && c != 'o' && c != 'E') {
				c = getchar();
			}
			if(c == 'o') {
				a[i][j] = 1;
			}
			if(c == 'E') {
				x = i;
				y = j;
			}
			a[i][j] -= a[i - 1][j - 1] - a[i - 1][j] - a[i][j - 1];
		}
	}
	memset(dp, -1, sizeof dp);
	dp[0][0][0] = 0;
	for (int l = 0; l <= m; ++l) {
		memset(pd, -1, sizeof pd);
		for (int u = 0; u <= n; ++u) {
			for (int r = 0; r + l <= m; ++r) {
				for (int t, d = 0; d + u <= n; ++d) {
					if(~(t = dp[u][r][d])) {
						ans = std::max(ans, t);
						x1 = u + 1, Y1 = l + 1, x2 = n - d, y2 = m - r;
						upd(pd[u][r][d], t + qry(x - d, y + l + 1, x + u, y + l + 1));
						upd(dp[u + 1][r][d], t + qry(x + u + 1, y - r, x + u + 1, y + l));
						upd(dp[u][r + 1][d], t + qry(x - d, y - r - 1, x + u, y - r - 1));
						upd(dp[u][r][d + 1], t + qry(x - d - 1, y - r, x - d - 1, y + l));
					}
				}
			}
		}
		memcpy(dp, pd, sizeof dp);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 10624
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_a = [0]
sum_b = [0]
ans = 0
for i in range(1,len(A)+1):
    sum_a.append(sum_a[i - 1] + A[i - 1])
for i in range(1,len(B)+1):
    sum_b.append(sum_b[i - 1] + B[i - 1])


j = len(sum_b)-1
for i in range(len(sum_a)):
    if sum_a[i] > K: break
    while (sum_b[j] + sum_a[i] > K):
        j -= 1
    ans = max(ans, i + j)

    
print(ans)

Measured memory_bytes: 47492
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        BigInteger a=BigInteger.valueOf(100);
        BigInteger x=sc.nextBigInteger();
        int count=0;
        while (a.compareTo(x)<0){
            a= a.add(a.divide(BigInteger.valueOf(100)));
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 28456
#include<iostream>
using namespace std;
int main (){
	while(true) {
		int N;
		cin >> N;
		if ( N == 0)break;
		int count = 0;
		bool na = true;
		for (int i = 0; i < N; i++){
			int k;
			cin >> k;
			if (k > 1)
				na = false;
			if (k > 0)
				count++;
		}
		if (na == true)
			cout << "NA" << endl;
		else
			cout << count + 1 << endl;
	}
	
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

string to(int n,int digit){
	string ans;
	while( max(0,digit--) || n)
		ans += n%2 + '0', n /= 2;
	reverse(ans.begin(),ans.end());
	return ans;
}
int main(){
	double num;
	while(cin >> num , num >= 0){
		double a = (int)num , b = (num - a)*16;
		if( a < 256 && b < 16 && b == (int)b){
			cout << to(a,8) << "." << to(b,4) << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    for (auto & a : A) cin >> a;
    int temp = accumulate(A.begin(), A.end(), 0);
    puts((temp >= H) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 640
#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 n,q; cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s.at(i);
    cin >> q;
    vector<int> t(q);
    rep(i, q) cin >> t.at(i);
    int ans = 0;
    for (auto i : t) {
        for (auto j : s)
            if (i == j) {
                ans++;
                break;
            }
    }
    cout << ans << endl;
}


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

typedef long long ll;


int main(){
    vector<string> v = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string S;
    cin >> S;
    auto itr = find(v.begin(), v.end(), S);
    int dist = distance(v.begin(), itr); 
    cout << 7 - dist << endl;
}


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

int main(){
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  if(abs(a-c) <= d){
    cout << "Yes" << endl;
  }
  else if(abs(a-b) <= d && abs(b-c) <= d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int dp[5][32769];

int main(){
	dp[0][0] = dp[1][0] = dp[2][0] = dp[3][0] = 1;

	for(int i = 1; i < 200; ++i){
		int t = i * i;

		for(int k = 1; k <= 4; ++k)
		for(int j = t; j <= 32768; ++j){
			dp[k][j] += dp[k-1][j-t];
		}
	}

	int n;
	for(; scanf("%d", &n), n != 0;){
		printf("%d\n", dp[4][n]);
	}
}

Measured memory_bytes: 1544
var s = require("fs").readFileSync("/dev/stdin", "utf8");
var s = s.split("\n");
var n = Number(s[0]);
var a = s[1].split(" ").map(e => Number(e));
var up = false, down = false;
var ans = 1;
for (var i = 1; i < n; i++) {
  if (a[i - 1] < a[i]) up = true;
  if (a[i - 1] > a[i]) down = true;
  if (up && down) {
    ans++;
    up = down = false;
  }
}
console.log(ans)

Measured memory_bytes: 17484
// *
// *
// *  Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu" 
// *------------------------------------
// *  OS : Ubuntu 16.04
// *  Language : CPP14
// *  Editor : Sublime Text 3
// *  C++ compiler : g++
// *https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/
// *https://www.geeksforgeeks.org/binomial-coefficient-dp-9/
//https://www.geeksforgeeks.org/compute-ncr-p-set-2-lucas-theorem/
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
vector<ll>v[100005];
ll vis[100005];
void dfs(ll x)
{
    vis[x]=1;
    for(auto it:v[x])
    {
        if(!vis[it])
        {
            vis[it]++;
            dfs(it);
        }
    }
}


void solve()
{
//comb(2001,2001);
std::ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
ll t;
//cin>>t;
//buildPrefix();
 t=1;
while(t--)
{
  ll n,m;
  cin>>n>>m;
  ll ans=0;
  while(m--)
  {
      ll x,y;
      cin>>x>>y;
      v[x].pb(y);
      v[y].pb(x);
  }
  FOR(i,1,n+1)
  {
      if(!vis[i])
      {
         // cout<<i<<endl;
          ans++;
          dfs(i);
      }
  }
  cout<<ans-1;
}
}
 
 
 
int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    solve();
    
}
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 11124
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define INF_LL 1000000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

int main() {
    int n, m;
    cin >> n >> m;
    mf_graph<int> g(n * m + 2);
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    rep(i, n) rep(j, m) {
        if(s[i][j] == '.') {
            if((i + j) % 2) {
                g.add_edge(n * m, i * m + j, 1);
            } else {
                g.add_edge(i * m + j, n * m + 1, 1);
            }
        }
    }
    rep(i, n) {
        rep(j, m) {
            if((i + j) % 2) {
                if(j > 0)
                    g.add_edge(i * m + j, i * m + j - 1, 1);
                if(j < m - 1)
                    g.add_edge(i * m + j, i * m + j + 1, 1);
            }
        }
    }
    rep(j, m) {
        rep(i, n) {
            if((i + j) % 2) {
                if(i > 0)
                    g.add_edge(i * m + j, (i - 1) * m + j, 1);
                if(i < n - 1)
                    g.add_edge(i * m + j, (i + 1) * m + j, 1);
            }
        }
    }
    cout << g.flow(n * m, n * m + 1) << endl;
    for(auto e : g.edges()) {
        if(e.from != n * m && e.to != n * m + 1 && e.flow == 1) {
            int p = min(e.from, e.to), q = max(e.from, e.to);
            if(n != 1 && q - p == m) {
                s[p / m][p % m] = 'v';
                s[q / m][q % m] = '^';
            } else {
                s[p / m][p % m] = '>';
                s[q / m][q % m] = '<';
            }
        }
    }
    rep(i, n) cout << s[i] << endl;
    return 0;
}


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

int main(){
  ll N, M;
  ll result = 1;
  cin >> N >> M;
  for (int i = M/N; i >= 1; i--) {
    if (M % i == 0) {
      result = i;
      break;
    }
  }
  if (N != 1) {
    cout << result << endl;
  }else{
    cout << M << endl;
  }
}


Measured memory_bytes: 384
'use strict'
function Main(input) {
  input = input.split(" ");
  const A = input[0];
  const B = input[1];
  let result = B;
  
  if(6 <= A && A <= 12) result = B / 2;
  else if (A <= 5) result = 0
  
  console.log(result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

std::vector<int> a, b, c, d;

using namespace std;
template<typename T>
struct Dinic{
	struct edge{
		int to;
		T cap;
		int rev;
	};
	
	const T INF;
	vector<vector<edge>> g;
	vector<T> min_cost;
	vector<int> itr;
	
	Dinic(int n) : INF(numeric_limits<T>::max()){
		g.resize(n);
	}
	
	void add_edge(int from, int to, T cap){
		g[from].push_back(edge{to, cap, (int)g[to].size()});
		g[to].push_back(edge{from, 0, (int)g[from].size() - 1});
	}
	
	bool bfs(int s, int t){
		min_cost.assign(g.size(), -1);
		queue<int> qu; qu.push(s); min_cost[s] = 0;
		
		while(!qu.empty()){
			auto p = qu.front(); qu.pop();
			
			for(auto e:g[p]){
				if(e.cap <= 0 or min_cost[e.to] != -1) continue;
				min_cost[e.to] = min_cost[p] + 1;
				qu.push(e.to);
			}
		}
		
		return min_cost[t] != -1;
	}
	
	T dfs(int idx, const int t, T flow){
		if(idx == t) return flow;
		for(int &i = itr[idx]; i < g[idx].size(); i++){
			edge &e = g[idx][i];
			
			if(e.cap <= 0 or min_cost[idx] >= min_cost[e.to]) continue;
			T d = dfs(e.to, t, min(flow, e.cap));
			if(d > 0){
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
			
		}
		
		return 0;
	}
	
	T max_flow(int s, int t){
		T flow = 0;
		while(bfs(s, t)){
			itr.assign(g.size(), 0);
			T f = 0;
			while((f = dfs(s, t, INF)) > 0) flow += f;
		}

		return flow;
	}
};

int main(){
	int n; cin >> n; a.resize(n); b.resize(n); c.resize(n); d.resize(n);
	Dinic<int> flow(2 * n + 2);
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = 0; i < n; i++) cin >> c[i] >> d[i];
	
	
	for(int i = 0; i < n; i++) flow.add_edge(n + n, i, 1);
	for(int i = 0; i < n; i++) flow.add_edge(i + n, n + n + 1, 1);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(a[i] < c[j] and b[i] < d[j]){
				flow.add_edge(i, n + j, 1);
			}
		}
	}
	
	cout << flow.max_flow(n + n, n + n + 1) << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,cnt;
string s;
int main()
{
	ans=-4;
	cin>>s;
	for(int i=0;i<s.size();i++)
	if(s[i]=='+')
	ans+=2;
	cout<<ans<<endl;
    return 0;
	} 

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,l;
  cin >> n >> l;
  vector<ll> v(n,0),v2(n+1,0);
  rep(i,n){
    cin >> v[i];
  }
  ll suf = -1;
  rep(i,n-1){
    if(v[i] + v[i+1] >= l){
      suf = i;
      break;
    }
  }
  if(suf == -1){
   cout << "Impossible" << endl;
   return 0;
  }
  cout << "Possible" << endl;
  rep(i,suf){
    cout << i+1 << endl;
  }
  for(int i = n-1; i > suf; --i){
    cout << i << endl;
  }
  return 0 ;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[n];
  vector<int> o,e;
  REP(i,n) {
    cin >> a[i];
    if (i%2) o.push_back(a[i]);
    else e.push_back(a[i]);
  }

  M mo,me;
  REP(i,o.size()) mo[o[i]]++;
  REP(i,e.size()) me[e[i]]++;

  int o1=0,o1k;
  REP(i,o.size()) {
    if (o1 < mo[o[i]]) {
      o1 = mo[o[i]];
      o1k = o[i];
    }
  }
  mo[o1k] = 0;
  int o2=0;
  REP(i,o.size()) {
    o2 = max(o2,mo[o[i]]);
  }

  int e1=0,e1k;
  REP(i,e.size()) {
    if (e1 < me[e[i]]) {
      e1 = me[e[i]];
      e1k = e[i];
    }
  }
  me[e1k] = 0;
  int e2=0;
  REP(i,e.size()) {
    e2 = max(e2,me[e[i]]);
  }

  int ans = INF;
  int tot = o.size()+e.size();
  if (o1k==e1k) {
    if (e2==0) ans = tot - o1;
    else ans = tot - o1 - e2;

    if (o2==0) ans = min(ans, tot - e1);
    else ans = min(ans, tot -o2 - e1);

  } else ans = tot - (e1+o1);
  COUT(ans);
  return 0;
}

Measured memory_bytes: 5756
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, x, sum, ans;

int main()
{
	in >> N >> x;
	std::vector<LL>a(N);
	rep(i, N) in >> a[i];
	rep(i, N) sum += a[i];
	if (sum >= x)
	{
		std::sort(a.begin(), a.end());
		rep(i, N)
		{
			if (x < a[i]) break;
			x -= a[i];
			++ans;
		}
	}
	else ans = N - 1;
	out << ans << std::endl;
	return 0;
}


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

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, m, q;
lint table[1010];

int main(){
    string s[1010], a[1010], b[1010];
    while(scanf("%d%d%d", &n, &m, &q) && n){
        rep(i, q) cin >> s[i] >> a[i];
        b[0] = a[0];
        rep(i, q)if(i >= 1){
            b[i] = a[i];
            rep(j, m) b[i][j] = '0' + (a[i][j] != a[i-1][j]);
        }

        rep(i, m) table[i] = (1LL<<n) - 1;
        rep(i, q){
            rep(j, m){
                lint tmp = (1LL<<n) - 1;
                rep(k, n)if(s[i][k] != b[i][j]) tmp ^= 1LL<<k;
                table[j] &= tmp;
            }
        }
        string ans;
        rep(i, m){
            if(__builtin_popcountll(table[i]) > 1) ans += '?';
            else {
                rep(j, n){
                    if(table[i]>>j & 1){
                        ans += (j<=9 ? '0'+j : 'A'+(j-10));
                    }
                }
            }
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 3;

int main()
{
ll n;
cin >> n;
string s1,s2;
cin >> s1;
cin >> s2;
ll see=0,past=0;
if(s1[see]==s2[see]){see=1;past=1;}
else{see=2;past=0;ans=6;}
while(see<n){
    if(s1[see]==s2[see]){
        see+=1;
        ans=ans*(past+1);
        ans%=mo;
        past=1;
    }
    else{
        see+=2;
        ans=ans*(past*(-1)+3);
        ans%=mo;
        past=0;
    }
}

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

Measured memory_bytes: 256
n,a,b=map(int,input().split())
h=[int(input())for _ in range(n)]
ok=10**9
ng=0
while ng+1!=ok:
  mid=(ok+ng)//2
  s=0
  for i in h:
    j=max(i-mid*b,0)
    s+=0--j//(a-b)
  if s>mid:ng=mid
  else:ok=mid
print(ok)

Measured memory_bytes: 7072
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(8);
  int n,m;
  string s,t,s1="",t1="";
  cin >> n >> m >> s >> t;
  int ans = lcm(n,m);
  int g = gcd(n,m);
  
  rep(i,0,g){
    s1 += s[i*(n/g)];
  }
  rep(i,0,g){
    t1 += t[i*(m/g)];
  }
  //cout << s1 <<' '<<t1<<endl;
  if(s1==t1) cout << ans << endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 512