akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always



int main() {
    
    
    
    
    int n, a, b, c, x;
    
    while (cin >> n && n) {
        cin >> a >> b >> c >> x;
        int y[n]; rep(i, n) cin >> y[i];
        
        int done = 0;
        int cnt = 0;
        if (x == y[0]) done++;
        
        while (done < n && cnt++ < 10000) {
            x = (a * x + b) % c;
            if (x == y[done]) done++;
        }
        
        if (done == n) out(cnt);
        else out(-1);
        
        
        
    }
    
    
    
    
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple
#define debug(x)     cerr << #x << " : " << x << endl;
#define For(i,a,n)   for(auto i = a; i < n; i++)
#define int          long long

template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;

typedef long long ll;
typedef long double ld;


template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"

// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


const int mod = 1e9+7, N = 1e5+5;
const ll INF = 1e18;



ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}



/*



1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;



*/



// Don't code anything above this //




const int MAX = 305;

ld dp[MAX][MAX][MAX];




int32_t main()
{
    BOOST

    ld n;
    cin >> n;

    int N = n;
    int a[N], f[4] = {};

    for(auto &i : a)
    {
    	cin >> i;
    	f[i]++;
    }

    dp[0][0][0] = 0;

    for(int k = 0; k <= N; k++)
	{	
    	for(int j = 0; j <= N; j++)
    	{	
    		for(int i = 0; i <= N; i++)
    		{
    			if(i + j + k == 0)
    				continue;

                dp[i][j][k] = n / (i+j+k);
                if(i > 0)
                    dp[i][j][k] += (i * dp[i-1][j][k]) / (i+j+k);
                if(j > 0)
                    dp[i][j][k] += (j * dp[i+1][j-1][k]) / (i+j+k);
                if(k > 0)
                    dp[i][j][k] += (k * dp[i][j+1][k-1]) / (i+j+k);
       		}
    	}
	}	
	cout << fixed << setprecision(100) << dp[f[1]][f[2]][f[3]] << "\n";

    return 0;
}

    

Measured memory_bytes: 438528
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        // final int A = sc.nextInt();
        // final int A = sc.nextInt();
        // final int B = sc.nextInt();
        // final int C = sc.nextInt();
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        // System.out.println();
        System.out.println((X - A) % B);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>

using namespace std;
using ll = long long int;

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> wants(n, vector<int>(m, 0));
    vector<int> iter(n, 0);
    unordered_set<int> sports;
    for(int i=0; i<m; i++){
        sports.insert(i);
    }
    int want;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> want; want--; 
            wants[i][j] = want;
        }
    }
    // Debug
    // for(auto& people:wants){
    //     for(auto& v:people){
    //         cout << v << " ";
    //     }
    //     cout << endl;
    // }

    int ans = n;
    for(int j=0; j<m; j++){
        vector<int> participants(m, 0);
        for(int i=0; i<n; i++){
            auto itr1 = sports.find(wants[i][iter[i]]);
            while(itr1 == sports.end()){
                iter[i]++;
                itr1 = sports.find(wants[i][iter[i]]);
            }
            participants[wants[i][iter[i]]]++;
        }
        auto itr2 = max_element(participants.begin(), participants.end());
        // for(auto& v:participants){
        //     cout << v << " ";
        // }
        // cout << "\n";
        // cout << "most famous:" << *itr2 << " " << itr2 - participants.begin() << endl;
        ans = min(ans, *itr2);
        sports.erase(itr2 - participants.begin());
    }
    cout << ans << endl;
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
/*Calculate GCD, LCM =============================*/
long long GCD(long long a, long long b){
    return (b ? GCD(b, a%b) : a);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a,b);
    return (a/g) * (b/g) * g;  // オーバーフローを避ける
}

/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll n; cin >> n;
    ll ans, p; cin >> ans;
    rep(i,n-1) {
        cin >> p;
        ans = LCM(ans, p);
    }
    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long

#define MAX 10000
#define NIL -1

//-----????¨????-----

//?????????????????±
struct Node { int parent, left, right; };


//-----?????°??£?¨?-----

Node tree[MAX];
int n,depth[MAX],hight[MAX];


//-----??¢??°?¨????-----

//??±???????¨????(??±???d???????????????u?????????????????????)
void setDepth(int u, int d) {
	if(u==NIL)return;
	depth[u]=d;
	setDepth(tree[u].left, d + 1);
	setDepth(tree[u].right, d + 1);
}

//??????????¨????(??????u?????????????????????)
//???????????????????????§?????°??§?§??????????
//????????????left??¨right??§?????????????????????????????????????????????
int setHeight(int u) {
	int h1=0,h2=0;
	if(tree[u].left!=NIL)
		h1=setHeight(tree[u].left)+1;
	if(tree[u].right!=NIL)
		h2=setHeight(tree[u].right)+1;

	return hight[u]=(h1>h2 ? h1:h2);
}

//????????????????????????(???????????§????????????????????????????????????????????¨??????????????????)
int getSibling(int u) {
	if(tree[u].parent==NIL)return NIL;
	if(tree[tree[u].parent].left  != u && tree[tree[u].parent].left !=NIL)
		return tree[tree[u].parent].left;
	if(tree[tree[u].parent].right != u && tree[tree[u].parent].right != NIL)
		return tree[tree[u].parent].right;
	return NIL;
}

//????????¨???
void print(int u) {
	cout << "node " << u << ": parent = " << tree[u].parent << ", sibling = " << getSibling(u);
	int deg = 0;
	if (tree[u].left  != NIL)deg++;
	if (tree[u].right != NIL)deg++;
	cout << ", degree = " << deg << ", depth = " << depth[u] << ", height = " << hight[u] << ", ";

	if (tree[u].parent == NIL) cout << "root";
	else if (tree[u].left == NIL && tree[u].right == NIL)cout << "leaf";
	else cout << "internal node";
	cout << endl;
}

//???????????¢??°
int main() {

	//???????¨????
	int v,l,r,root=0;
	cin>>n;
	REP(i,n)tree[i].parent=NIL;

	//??\?????????
	REP(i, n) {
		cin>>v>>l>>r;
		tree[v].left=l;
		tree[v].right=r;
		//????????????????????§???????????¨?????????
		if (l != NIL)tree[l].parent = v;
		if (r != NIL)tree[r].parent = v;
	}

	//???????¢????
	REP(i,n)if(tree[i].parent == NIL)root=i;

	//??±?????¨??????????¢????
	setDepth(root,0);
	setHeight(root);

	//????????¨???
	REP(i,n)print(i);

	//cin >>n;
	return 0;
}

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

const int INF = 1e9;

bool compare(pair<int, int> y1, pair<int, int> y2) {
  return y2.second > y1.second;
}
int main() {
  int n,m;
  cin>>n>>m;
  int p[m];
  pair<int, int> y[m];
  for(int i=0;i<m;i++){
    cin>>p[i];
    int yi;
    cin>>yi;
    y[i]=make_pair(i, yi);
  }
  sort(y, y+m, compare);

  string ans[m];
  int no[n+1];
  for(int i=1;i<n+1;i++){
    no[i]=1;
  }
  int ans_no[m];
  for(pair<int, int> yi: y){
    ans_no[yi.first]=no[p[yi.first]];
    no[p[yi.first]] += 1;
  }
  for(int i=0;i<m;i++){
    printf("%06d%06d\n",p[i],ans_no[i]);
  }
}

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

struct Point {
  double x, y;
  
  Point() = default;
  Point(double x, double y) : x(x), y(y) {}

  Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
  Point operator*(double d) const { return Point(x * d, y * d); }
  Point operator/(double d) const { return Point(x / d, y / d); }
  double operator*(const Point &p) const { return x * p.x + y * p.y; }
  double operator%(const Point &p) const { return x * p.y - y * p.x; }
};

double Dist(const Point &a, const Point &b) {
  return sqrt((a - b) * (a - b));
}

Point Rotate(const Point &a, double ang) {
  return Point(a.x * cos(ang) - a.y * sin(ang), a.x * sin(ang) + a.y * cos(ang));
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n), y(n), c(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> c[i];

  vector<Point> p(n);
  for (int i = 0; i < n; ++i) p[i] = Point(x[i], y[i]);

  double l = 0.0, r = 1e9;
  constexpr int kIter = 200;
  constexpr double kEps = 1e-6;

  for (int it = 0; it < kIter; ++it) {
    double mid = 0.5 * (l + r);
    vector<double> rad(n);
    // mid = 2.40000000;
    for (int i = 0; i < n; ++i) {
      rad[i] = mid / c[i];
      // cout << "rad[" << i << "] = " << rad[i] << endl;
    }
    vector<Point> ints(p.begin(), p.end());
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        double dist = Dist(p[i], p[j]);
        if (dist > rad[i] + rad[j]) continue;
        if (dist < fabs(rad[i] - rad[j])) continue;
        Point vec = p[i] - p[j];
        double ang = acos((rad[j] * rad[j] + dist * dist - rad[i] * rad[i]) / (2 * rad[j] * dist));
        Point v1 = Rotate(vec, ang);
        Point v2 = Rotate(vec, -ang);
        v1 = v1 / sqrt(v1 * v1) * rad[j];
        v2 = v2 / sqrt(v2 * v2) * rad[j];
        // assert(fabs(Dist(p[j] + v1, p[j]) - rad[j]) < kEps);
        // assert(fabs(Dist(p[j] + v2, p[j]) - rad[j]) < kEps);
        // assert(fabs(Dist(p[j] + v1, p[i]) - rad[i]) < kEps);
        // assert(fabs(Dist(p[j] + v2, p[i]) - rad[i]) < kEps);
        ints.push_back(p[j] + v1);
        ints.push_back(p[j] + v2);
        // cout << "ints: " << (p[j] + v1).x << " " << (p[j] + v1).y << endl;
        // cout << "ints: " << (p[j] + v2).x << " " << (p[j] + v2).y << endl;
      }
    }
    bool ok = false;
    for (const auto &e : ints) {
      int cnt = 0;
      for (int i = 0; i < n; ++i) cnt += Dist(e, p[i]) < rad[i] + kEps;
      ok |= cnt >= k;
    }
    // cout << "ok = " << ok << endl;
    // exit(0);
    (ok ? r : l) = mid;
  }
  cout << fixed << setprecision(20) << l << "\n";
  return 0;
}


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

int A, B, C;

int main() {
	cin >> A >> B >> C;
	for (int i = 1; i <= B; i++) {
		if (A*i%B == C) { cout << "YES" << endl; return 0; }
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    for (int i = 0; i < n; i++) {
      String s = sc.next();
      if (s.equals("AC")) {
        ac++;
      } else if (s.equals("WA")) {
        wa++;
      } else if (s.equals("TLE")) {
        tle++;
      } else if (s.equals("RE")) {
        re++;
      }
    }

    System.out.println("AC x " + ac);
    System.out.println("WA x " + wa);
    System.out.println("TLE x " + tle);
    System.out.println("RE x " + re);
  }
}

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

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	bool f = true;
	if (s[0] != 'A') f = false;
	int cnt = 0;
	for (int i = 2; i < s.size() - 1; ++i) {
		if (s[i] == 'C') cnt++;
	}
	if (cnt != 1) f = false;

	rep(i, s.size()) {
		if (s[i] == 'A' || s[i] == 'C') continue;
		if (!('a' <= s[i] && s[i] <= 'z')) f = false;
	}

	printf("%s\n", f ? "AC" : "WA");
	return 0;
}

Measured memory_bytes: 256
def GCD(x, y):
    while (y):
        x, y = y, x % y
    return x


a, b, c, d = map(int, input().split())
e = c * d // GCD(c, d)
f = b // c - (a - 1) // c
g = b // d - (a - 1) // d
h = b // e - (a - 1) // e
ans = b - a + 1 - (f + g - h)
print(ans)

Measured memory_bytes: 3064
N = int(input())
S = list(map(str,input()))
En = S[1:].count("E")
Sn = S[1:].count("W")
res = [En]
cnt = En
for i, s in enumerate(S):
    if i == 0:
        continue
    if s == "E":
        cnt -= 1
    if S[i-1] == "W":
        cnt += 1
    res.append(cnt)
print(min(res))

Measured memory_bytes: 27000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin a(n+1),b(n);
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll sum=0;
    int c;
    int d=0;
    rep(i,n){
        c=min(b[i],a[i]-d);
        sum+=(ll)c;
        d=min(b[i]-c,a[i+1]);
        sum+=(ll)d;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int a[3];
  rep(i, 3)cin >> a[i];
  sort(a, a+3);
  cout << abs(a[1]-a[0])+abs(a[2]-a[1]);
} 

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define li long ll
#define pp pair<ll, ll> 
#define lb lower_bound
#define ub upper_bound
#define mk make_pair
#define pb push_back
#define llp(i, x, n) for (ll i = x; i < n; i++)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr first
#define ss second
using namespace std;
int main()
{
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	priority_queue<ll> pq;
	pq.push(a*c);
	pq.push(a*d);
	pq.push(b*c);
	pq.push(b*d);
	cout<<pq.top()<<endl;
}

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

char C[71][71];
string memo[71][71];
int W, H;
bool isNum(char c) {
    if(c >= '0' && c <= '9') return true;
    else return false;
}
string max_str(string a, string b) {
    if (a.size() > b.size()) return a;
    if (a.size() < b.size()) return b;
    return max(a, b);
}
string dfs(int y, int x) {
    if(memo[y][x] != "") return memo[y][x];
    if((y+1>=H || !isNum(C[y+1][x])) && (x+1>=W || !isNum(C[y][x+1]))) {
        memo[y][x] = C[y][x];
        return memo[y][x];
    }
    string ans = "";
    if(y+1<H && isNum(C[y+1][x])) ans = max_str(ans, C[y][x]+dfs(y+1, x));
    if(x+1<W && isNum(C[y][x+1])) ans = max_str(ans, C[y][x]+dfs(y, x+1));
    memo[y][x] = ans;
    return memo[y][x];
}

int main(void){
    while(cin >> W >> H && W) {
        rep(i, H) rep(j, W) {
            cin >> C[i][j];
            memo[i][j] = "";
        }
        string ans;
        for(int i=H-1; i>=0; --i) {
            for(int j=W-1; j>=0; --j) {
                if(isNum(C[i][j]) && C[i][j]!='0') {
                    ans = max_str(ans, dfs(i, j));
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1388
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int dp[1024][1 << 12];

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(int) KeyMask(M, 0), KeyCost(M);
    FOR(i, 0, M) {
        int k;
        cin >> KeyCost[i] >> k;
        while (k--) {
            int box;
            cin >> box;
            KeyMask[i] |= 1 << (box - 1);
        }
    }

    FOR(i, 0, M + 1)
        FOR(mask, 0, 1 << N)
            dp[i][mask] = 1 << 29;

    dp[0][0] = 0;
    FOR(i, 0, M) {
        FOR(mask, 0, 1 << N) {
            dp[i + 1][mask] = min(dp[i + 1][mask], dp[i][mask]);
            int& v = dp[i + 1][mask | KeyMask[i]];
            v = min(v, dp[i][mask] + KeyCost[i]);
        }
    }

    if (dp[M][(1 << N) - 1] >= 1 << 29)
        cout << -1;
    else
        cout << dp[M][(1 << N) - 1];
    cout << endl;

    return 0;
};

Measured memory_bytes: 16640
N = int(input())

g_list = [[-1 for i in range(N)] for j in range(N)]

for i in range(N):
    m = int(input())
    for j in range(m):
        a_x = list(map(int, input().split()))
        a = a_x[0]
        a -= 1
        x = a_x[1]
        g_list[i][a] = x

ans = 0

for i in range(1 << N):
    d = [0 for l in range(N)]
    for j in range(N):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g_list[j][k] == -1:
                    continue
                if g_list[j][k] != d[k]:
                    ok = False
    if ok:
        total = list(bin(i)[2:].rjust(N, '0'))
        count = 0
        for t in total:
            if t == '1':
                count += 1
        ans = max(ans, count)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100010
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int n,d;
    cin>>n>>d;
    OUT((n+2*d)/(2*d+1));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

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

	std::vector<int> a(n);
	for (auto&& e : a)
		std::cin >> e;

	int ans = 1;

	std::multiset<int> set;
	set.insert(a.back());
	for (int i = n - 2; i >= 0; --i) {
		if (a[i] >= *set.rbegin()) {
			++ans;
			set.insert(set.end(), a[i]);
			continue;
		}

		auto it = set.upper_bound(a[i]);
		set.erase(it);

		set.insert(a[i]);
	}

	std::cout << ans << std::endl;
}

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

typedef long long ll;
#define ten5 100000+10
#define MOD 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define iif(c,t,f) ((c)?(t):(f))
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair

int intcmp(const void *v1,const void *v2){return *(int *)v1-*(int *)v2;}




int main(){
  string s;
  cin>>s;
  int ans=0;
  rep(i,0,4){
    ans+= s[i]=='+'?1:-1;
  }
  cout<<ans<<endl;
  return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    for(int i = 0; i < s.size(); i++){
        if(s[i] + n <= 'Z') cout << char(s[i] + n);
        else cout << char('A' + n - ('Z' - s[i]) - 1);
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-10
#define PI acos(-1)
#define R 6378.1

using namespace std;

struct P
{
	double x,y,z;

	double distance(const P& o)
	{
		return sqrt( (x-o.x)*(x-o.x) + (y-o.y)*(y-o.y) + (z-o.z)*(z-o.z) );
	}
};

double toRad(double a)
{
	return (a/180)*PI;
}

int main()
{
	double a,b,c,d;
	while(cin >> a >> b >> c >> d)
	{
		if(a == -1 && b == -1 && c == -1 && d == -1) break;

		P p[2];

		p[0].x = R*cos(toRad(a))*cos(toRad(b));
		p[0].y = R*cos(toRad(a))*sin(toRad(b));
		p[0].z = R*sin(toRad(a));

		p[1].x = R*cos(toRad(c))*cos(toRad(d));
		p[1].y = R*cos(toRad(c))*sin(toRad(d));;
		p[1].z = R*sin(toRad(c));

		double angle = acos((R*R + R*R - p[0].distance(p[1])*p[0].distance(p[1])) / (2*R*R));
		cout << (int)(PI*R*(angle/PI) + 0.5) << endl;

	}
	return 0;
}

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

int main() {
	string str_taro, str_hanako;
	int st=0,sh=0,n;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> str_taro >> str_hanako;
		if(str_taro>str_hanako) {
			st+=3;
		} else if(str_taro<str_hanako) {
			sh+=3;
		} else {
			++st;
			++sh;
		}
	}
	cout << st << " " << sh << endl;
	return 0;
}

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

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define DINF 1e300
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair

const int N = 1e5 + 10;

int n;
string s, t;

void init() {
  cin >> n >> s >> t;
}
bool compare( int pos ) {
  int ti = 0;
  while ( pos < s.size() ) {
    if ( s[ pos ] != t[ ti ] ) {
      return false;
    }
    ++pos; ++ti;
  }
  return true;
}
void solve() {
  int idx = -1;
  for ( int i = 0 ; i < s.size() ; ++i ) {
    if ( compare( i ) ) {
      idx = i;
      break;
    }
  }
  if ( idx == -1 ) 
    idx = s.size();
  string ans;
  for ( int i = 0 ; i < idx ; ++i ) 
    ans.PB( s[ i ] );
  for ( int i = 0 ; i < t.size() ; ++i )
    ans.PB( t[ i ] );
  cout << ans.size() << endl;
}
int main() {
  IOS;
  int __ = 1;
  //cin >> __;
  while ( __-- ) {
    init();
    solve();
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2000;
const int inf=1e9;
int main(){
	int X,Y,A,B,C;cin>>X>>Y>>A>>B>>C;
	long P[A],Q[B+C];
	rep(i,0,A) cin>>P[i];
    sort(P,P+A,greater<long>());
	rep(i,0,B) cin>>Q[i];
	sort(Q,Q+B,greater<long>());
	rep(i,Y,Y+C) cin>>Q[i];
	sort(Q,Q+Y+C,greater<long>());
	rep(i,1,A) P[i] += P[i-1];
	rep(i,1,Y+C) Q[i] += Q[i-1];
	long sum = 0;
    if(X+Y-1 < Y+C) sum = Q[X+Y-1];
	rep(i,0,X){
        int t = X+Y-i-2;
		if(0 <= t && t < Y+C) sum = max(sum , P[i] + Q[X+Y-i-2]);
	}
	cout<<sum<<endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;

	int n = atoi(s.c_str());
	int ans = 0;
	rep(i, s.size()) ans += (s[i] - '0');

	cout << (n % ans == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pi;
///-------------------------


int main()
{
    Phuong_; /// <3333
    string s;
    cin >> s;
    if (s[1]=='B') cout << "ARC"; else cout << "ABC";
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define f first
#define s second
#define cs 137
#define ll long long
#define mp make_pair
#define N 100025
#define ln 1e16
#define oo 111539786
#define Pa pair < int, int >
#define Pi pair < int, Pa >

using namespace std;

ll ans = ln, SumX[N], SumY[N];
int n, X[N], Y[N], w, h, posX, posY;
Pa a[N];

void Get_ans(int x, int y)
{
    ll Sum = 0, Max = -ln;
    for(int i=1; i<=n; i++)
    {
        Sum += ((ll)abs(x - a[i].f) + abs(y - a[i].s)) * 2;
        Max = max(Max, (ll)abs(x - a[i].f) + abs(y - a[i].s));
    }
    Sum -= Max;
    if(Sum < ans)
    {
        ans = Sum;
        posX = x;
        posY = y;
    }
}

int main()
{
    //filein("SANTA.inp");    fileout("SANTA.out");
    cin >> w >> h >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> X[i] >> Y[i];
        a[i] = mp(X[i], Y[i]);
    }
    sort(X+1, X+n+1);
    sort(Y+1, Y+n+1);
    for(int i=1; i<=n; i++)
    {
        SumX[i] = SumX[i-1] + X[i];
        SumY[i] = SumY[i-1] + Y[i];
    }
    Get_ans(X[(n+1)/2], Y[(n+1)/2]);
    if(n % 2 == 0)
    {
        Get_ans(X[(n+1)/2], Y[n/2+1]);
        Get_ans(X[n/2+1], Y[(n+1)/2]);
        Get_ans(X[n/2+1], Y[n/2+1]);
    }
    cout << ans << endl;
    cout << posX << " " << posY << endl;
}

Measured memory_bytes: 4312
/* Author : bhavye9499 - Bhavye Anand Gupta */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define showArr(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i] << " "; cout << endl;}
#define showPair(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i].fi << " " << A[i].se << endl;}

const ll MOD = 1e9 + 7;

ll n;
double A[3010], dp[3010][3010];

double fun(ll i, ll j);

int main() {
    ios::sync_with_stdio(false);
    for(int i = 0; i < 3010; i++) {
    	for(int j = 0; j < 3010; j++) {
    		dp[i][j] = -1;
    	}
    }

    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> A[i];
    }
    
    double ans = fun(0, 0);

    cout << fixed << setprecision(10);
    cout << ans << endl;
}

double fun(ll i, ll j) {
	if(dp[i][j] != -1)
		return dp[i][j];
	if(i == n && j > n / 2)
		return dp[i][j] = 1;
	if(i == n && j <= n / 2)
		return dp[i][j] = 0;
	return dp[i][j] = A[i] * fun(i + 1, j + 1) + (1 - A[i]) * fun(i + 1, j);
}

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

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

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

int main() {
    int N, K;
    cin >> N >> K;
    int l[55];
    for(int i = 0; i < N; ++i) cin >> l[i];

    sort(l, l + N, greater<int>());

    int sum = 0;
    for(int i = 0; i < K; ++i) {
        sum += l[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
s = str(input())
list_s = list(s)
while len(list_s) > 0:
    if list_s[-5:] == list("dream") or list_s[-5:] == list("erase"):
        for i in range(5):
            list_s.pop()
    elif list_s[-6:] == list("eraser"):
        for i in range(6):
            list_s.pop()
    elif list_s[-7:] == list("dreamer"):
        for i in range(7):
            list_s.pop()
    else:
        ans = "NO"
        break
else:
    ans = "YES"
print(ans)


Measured memory_bytes: 3956
use std::io;


fn main() {
    let n = read_one::<usize>();
    println!("{}", n * (n - 1) / 2);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [0] * (S + 1)
dp[0] = 1

for a in A:
    newDp = [d * 2 % MOD for d in dp]

    for s in range(S + 1):
        if s + a <= S:
            newDp[s + a] += dp[s]

    dp = newDp

print(dp[S] % MOD)


Measured memory_bytes: 71840
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
    char s[11];
    int c = 0, ans = 0;

    scanf("%s", s);

    int l = strlen(s);

    for (int i = 2; i < l - 1; i++) {
        if (s[i] == 'C') {
            c++;
        }
    }

    for (int i = 0; i < l; i++) {
        if (s[i] < 'Z') {
            ans++;
        }
    }
    if (s[0] == 'A' && c == 1 && ans == 2) {
        printf("AC");
    }
    else {
        printf("WA");
    }
}

Measured memory_bytes: 1672
# 整数の入力
n, m = gets.chomp.split(" ").map(&:to_i)


class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end 

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end 
  end 

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end 

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end 

  def count_parent
    rtn = 0 
    @parent.each_with_index do |p, index|
      rtn += 1 if p == index
    end 
    rtn 
  end 
end

union = UnionFind.new n

# クエリの回数だけ、入力受け取りを回す
m.times do
  a, b = gets.split.map{|x| x.to_i - 1}
  union.unite(a, b)
end

puts union.count_parent - 1 

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

int X(int,int);
int ord(int);
int P(int);
int log(int);
int k;
int main(void){
	int i,j;
	int n,q;
	int a[400000];
	bool b[32];
	int c=0;
	const int inf=2147483647;
	int com,x,y;
	scanf("%d%d",&n,&q);
	int n1=n;
	int m[100000];
	int l;
	k=1;
	while(n1!=1){
		n1=(n1+1)/2;
		k++;
	}
//printf("k=%d\n",k);
	for(i=0;i<4*n;i++){
		a[i]=inf;
	}
	
	for(i=0;i<q;i++){
		scanf("%d%d%d",&com,&x,&y);
//printf("done\n");
		if (com==0){

			l=X(x,k-1);	
//printf("%d\n",l);	
			a[l]=y;

			for(j=0;j<k-1;j++){
				l=(l-1)/2;
//printf("l=%d\n",l);
				a[l]=min(a[2*l+1],a[2*l+2]);
			}
//			for(int j1=0;j1<4*n;j1++){
//				if(a[j1]==inf){
//					printf("inf,");
//				} else {
//					printf("%d,",a[j1]);
//				}
//			}
//			printf("\n");
			
		}
		
		if (com==1){
			m[c]=a[X(x,k-1)];
			int z;
			z=x;
			while(z<=y){
				int p=min(ord(z),log(y-z+1));
				m[c]=min(m[c],a[X(z,k-p-1)]);
				z=z+P(p);
				
			}
			c++;
		}
	}	
	for(i=0;i<c;i++){
		printf("%d\n",m[i]);
	}	
	return 0;
}
int X(int x,int a){//xで始まって親からa個目の子,一番下はa=k-1
	int i,j;
	int b[32];
	for(i=0;i<k;i++){
		b[i]=x%2;
		x=x/2;
	}	
	int l=0;			
	for(j=1;j<=a;j++){				
		if(b[k-j-1]==0){
			l=2*l+1;	
		} else {
			l=2*l+2;
		}			
	}
	return l;
}
int ord(int n){
	int i=0;
	if(n==0){
		return 30;
	}
	while(n%2==0){
		n=n/2;
		i++;
	}
	return i;
}
int log(int n){
	int m=0;
	while (n!=1){
		n=n/2;	
		m++;
	}
	return m;
}	
int P(int n){
	int i,p=1;
	for(i=0;i<n;i++){
		p=p*2;
	}
	return p;
}//TLEしたら後で書き直す


Measured memory_bytes: 4440
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    l = list(map(int, readline().split()))
    l.sort()

    if any([x % 2 == 0 for x in l]):
        print(0)
    else:
        s = l[0] * l[1]
        print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61736
#include<cstdio>

int n, m;
double once, rate, rem, ans;

int main() {
	scanf("%d%d", &n, &m);
	once = 1900*m + 100*(n-m);
	rate = 1. - 1./(1<<m);
	rem = 1.;
	for(int i=0;rem > 1e-9;i++) {
		ans += rem * once;
		rem *= rate;
	}
	printf("%d\n", int(ans+0.5));
	
	return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int a[5010];
bool can[5010];
int main(void){
	can[0]=1;
	int n,k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(&a[1],&a[n+1]);
	int l=0,r=n+1;
	while(l+1<r){
		int md=(l+r)>>1;
		memset(can,0,sizeof(can));
		can[0]=1;
		bool f=0;
		for (int i=1;i<=n;i++){
			if (i==md) continue;
			for (int j=k-1;~j;j--){
				if (!can[j]) continue;
				if (j+a[i]<k) can[j+a[i]]=1;
			}
		}
		for (int i=k-1;i>=max(k-a[md],0);i--){
			f|=can[i];
		}
		if (f){
			r=md;
		}
		else{
			l=md;
		}
	}
	printf("%d",r-1);
	return 0;
}

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

using namespace std;

int N, M, a[100009], b[100009], c[100009], d[100009], e[100009], v[100009], ans[100009], aib[100009];
vector < int > g[100009], h[100009];

void refresh (int &x)
{
    x = lower_bound (c + 1, c + N + 3, x) - c;
}

void U (int pos, int val)
{
    while (pos <= N + 1)
        aib[pos] += val, pos += pos - (pos & (pos - 1));
}

int Q (int pos)
{
    int ans = 0;
    while (pos)
        ans += aib[pos], pos &= pos - 1;
    return ans;
}

multiset < pair < int, int > > used, S;
void useSegm (int i, int j)
{
    U (i, +1);
    U (j + 1, -1);
    used.insert ({i, j});
}

void adSegm (int i, int j)
{
    //printf ("[%d, %d]\n", i, j);
    g[j].push_back (i);
    h[i].push_back (j);
}

int getAns (int i, int j)
{
    int currAns = -1;
    if (ans[i - 1] != -1) currAns = max (currAns, N + 1 - ans[i - 1]);
    if (ans[j - 1] != -1) currAns = max (currAns, N - ans[j - 1]);
    return currAns;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &a[i], &b[i]);
for (int i=1; i<=N + 1; i++)
    scanf ("%d", &c[i]), v[i] = -1;
sort (c + 1, c + N + 2), c[N + 2] = 1e9 + 10;
scanf ("%d", &M);
for (int i=1; i<=M; i++)
    scanf ("%d %d", &d[i], &e[i]), refresh (d[i]), refresh (e[i]);
for (int i=1; i<=N; i++)
{
    refresh (a[i]), refresh (b[i]), v[a[i]] ++;
    if (b[i] < a[i])
        adSegm (b[i], a[i] - 1);
}
for (int i=1; i<=N + 1; i++)
    v[i] += v[i - 1];
//for (int i=1; i<=N + 1; i++)
  //  printf ("%d%c", v[i], " \n"[i == N + 1]);
for (int i=N + 1; i>=1; i--)
{
    for (auto lft : g[i])
        S.insert ({lft, i});
    int curr = v[i] + Q(i);
    while (curr < -1 && !S.empty ())
    {
        auto it = S.begin ();
        useSegm (it->first, it->second), S.erase (it), ans[0] ++;
        curr ++;
    }
    if (curr < -1)
    {
        for (int i=1; i<=M; i++)
            printf ("-1\n");
        return 0;
    }
}
S.clear ();
for (int i=1; i<=N + 1; i++)
{
    for (auto rgt : h[i])
        if (used.find ({i, rgt}) != used.end ()) used.erase (used.find ({i, rgt}));
        else S.insert ({rgt, i});
    ans[i] = ans[i - 1];
    int curr = v[i] + Q(i);
    while (curr < 0 && !S.empty ())
    {
        auto it = S.end (); it --;
        useSegm (it->second, it->first), S.erase (it), ans[i] ++;
        curr ++;
    }
    if (curr < 0)
    {
        for (int j=i; j<=N + 1; j++)
            ans[j] = -1;
        break;
    }
}
for (int i=1; i<=M; i++)
    printf ("%d\n", getAns (d[i], e[i]));
return 0;
}


Measured memory_bytes: 19584
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int main() {

	int K;
	cin >> K;
	queue<ll>q;
	for (int i = 1; i <= 9;++i) {
		q.push(i);
	}
	ll current;
	for (int i = 0; i < K;++i) {
		current = q.front(); q.pop();
		if (i == K - 1)break;
		ll amari = current % 10;
		if(current % 10 != 0)q.push(10*current-1+ amari);
		q.push(current*10+ amari);
		if (current % 10 != 9)q.push(10*current+1+ amari);

	}
	cout << current << endl;
}



Measured memory_bytes: 4224
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int ch[26];
string a;
int t;
int dp[200010];
int nex[200010][26];
int func(int here) {
	if(here == t)return 0;
	int &ret = dp[here];
	if (ret != -1)
		return ret;
	ret = 1234567890;
	for (int i = 0; i < 26; i++) {
		ret = min(ret, func(nex[here][i]) + 1);
	}
	return ret;
}
void func1(int here) {
	if (here == t)return;
	int ret = 1234567890;
	for (int i = 0; i < 26; i++) {
		ret = min(ret, func(nex[here][i]) + 1);
	}
	for (int i = 0; i < 26; i++) {
		if (ret == func(nex[here][i]) + 1) {
			printf("%c", i + 'a');
			func1(nex[here][i]);
			return;
		}
	}
}
int main()
{
	memset(dp, -1, sizeof(dp));
	ios::sync_with_stdio(false);
	cin.tie(0);
	string b;
	cin >> b;
	a = " " + b;
	t = a.size();
	for (int i = 0; i < 26; i++)
		ch[i] = t;
	for (int i = t - 1; i >= 0; i--) {
		for (int y = 0; y < 26; y++)
			nex[i][y] = ch[y];
		if(i)
			ch[a[i] - 'a'] = i;
	}
	func(0);
	func1(0);
}

Measured memory_bytes: 22164
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let s = sc.chars();
    let t = sc.chars();
    put!((0..s.len()).filter(|&i| s[i] != t[i]).count());
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
int n,a[20000010];
int small(int i,int j,int k) {
	return a[i]<=k&&a[j]<=k;
}
int big(int i,int j,int k){
	return a[i]>k&&a[j]>k;
} 
int check(int k){
	for(int i=0;i<n-1;i++){
		if (big(n+i,n+i+1,k)||big(n-i,n-i-1,k))
			return 0;
		if (small(n+i,n+i+1,k)||small(n-i,n-i-1,k))
			return 1;
	}
	return small(1,1,k);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		scanf("%d",&a[i]);
	int l=1,r=2*n-1,ans;
	while (l<r){
		int mid=l+r>>1;
		if (check(mid)) r=mid;
			else l=mid+1;
	}
	printf("%d\n",r);
	return 0; 
}

Measured memory_bytes: 4624
using System;

namespace _4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());
            Console.WriteLine((r*r*Math.PI).ToString("f12") + " " + (r*2*Math.PI).ToString("f12"));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9304