akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int MAX = 100000;

struct Node { int parent = -1, left = -1 , right = -1; } ;

void printNodeInfo(int i, Node T[]);

int getDepth(int i, Node T[]);

string getType(Node n);

string getChildrenList(int id, Node T[]);

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

    Node T[n];
    for (int i = 0; i < n; i++) {
        int id, p;
        cin >> id >> p;
        int current, previous = -1;
        for (int j = 0; j < p; j++) {
            cin >> current;
            T[current].parent = id;
            if (previous == -1) {
                T[id].left = current;
            }
            if (previous != -1) {
                T[previous].right = current;
            }
            previous = current;
        }
    }

    for (int i = 0; i < n; i++) {
        printNodeInfo(i, T);
    }

    return 0;
}

void printNodeInfo(int id, Node T[]) {
    cout << "node " << id
         << ": parent = " << T[id].parent
         << ", depth = " << getDepth(id, T)
         << ", " << getType(T[id])
         << ", " << getChildrenList(id, T)
         << endl;
}

int getDepth(int t, Node T[]) {
    int d = 0;
    Node c = T[t];
    while (c.parent != -1) {
        c = T[c.parent];
        d++;
    }
    return d;
}

string getType(Node n) {
    if (n.parent == -1) {
        return "root";
    }
    if (n.left == -1) {
        return "leaf";
    }
    return "internal node";
}

string getChildrenList(int id, Node T[]) {
    Node p = T[id];
    if (p.left == -1) {
        return "[]";
    }
    string s = "[";
    s += to_string(p.left);
    Node c = T[p.left];
    while (c.right != -1) {
        s += ", " + to_string(c.right);
        c = T[c.right];
    }
    s += "]";
    return s;
}


Measured memory_bytes: 5052
#include <iostream>
#define C(a,b)  *(a) == *std::next((a), (b))
#define O(a)    std::cout << (std::distance(T.begin(), itr) + 1) << " " << (std::distance(T.begin(), std::next(itr, (a))) + 1) << std::endl
int main()
{
    std::string T;
    std::cin >> T;
    for (auto itr = T.begin(); itr != T.end(); ++itr)
    {
        if (C(itr, 1))
        {
            O(1);
            return 0;
        }
        else if (C(itr, 2))
        {
            O(2);
            return 0;
        }
    }
    std::cout << "-1 -1" << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

signed main(){
	int m,d;
	int sum=0;
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int x=j;
			int a=x%10;x/=10;
			int b=x%10;
			if(a>1&&b>1&&a*b==i){
				//cout<<i<<' '<<j<<endl;
				sum++;
			}
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
import io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val t = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toLong))
    .toArray

  val dp = Array.ofDim[Long](n)
  dp(0) = 1
  (1 until n)
    .foreach(i => {
      val a = dp(i-1) * t(i-1)(0) / BigDecimal(t(i)(0))
      val b = dp(i-1) * t(i-1)(1) / BigDecimal(t(i)(1))
      dp(i) = if(a > b) { if(a > a.toLong) a.toLong + 1 else a.toLong }
        else { if(b > b.toLong) b.toLong + 1 else b.toLong }
    })

  val ans = t(n-1).sum * dp(n-1)
  println(ans)
}

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

int main(){
    bool flag[100001];
    int c[100002] = {};
    int Q, L, R;
    for(int i=2; i<=100000; i++){
        if(!flag[i]){
            for(int j=i+i; j<=100000; j+=i){
                flag[j]=true;
            }
        }
    }

    for(int i=3; i<=100000; i+=2){
        if(!flag[i] && !flag[(i+1)/2]){
            c[i]++;
        }
    }
    for(int i=3; i<=100000; i++){
        c[i] += c[i-1];
    }

    cin >> Q;
    while(Q--){
        cin >> L >> R;
        cout << c[R]-c[L-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String input;
        int d;
        while ((input = br.readLine()) != null) {
            d = Integer.parseInt(input);
            System.out.println(100 * (600 - d) * (1200 - d));
        }
    }
}

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

S = []
P = []
I = []

for i in range(N) : 
    a, b = input().split()
    S.append(a)
    P.append(100 -int(b))
    I.append(i+1)
    
I2 = [x for x in sorted(zip(S, P, I))]

for i in range(N) : 
    print(I2[i][2])

Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, k ] <- readInts
	putStrLn $ which "YES" "NO" $ k * 2 - 1 <= n

Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    ll lt = 0, lx = 0, ly = 0;
    for (ll i = 0; i < n; i++)
    {
        ll t, x, y;
        cin >> t >> x >> y;
        ll dx = abs(lx - x);
        ll dy = abs(ly - y);
        if (dx + dy > t - lt)
        {
            cout << "No" << endl;
            exit(0);
        }
        else if ((dx + dy - (t - lt)) % 2 != 0)
        {
            cout << "No" << endl;
            exit(0);
        }
        lt = t;
        lx = x;
        ly = y;
    }
    cout << "Yes" << endl;
}

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

int main(){
    long k,s;
    cin >> k >> s;
    long cnt=0;
    for(int i=0;i<=k;++i){
        for(int j=0;j<=k;++j){
            long l=s-i-j;
            if(l<=k && l>=0 && i+j+l==s){
                ++cnt;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<set>
#include<map>
#include<ctime>
#include<iostream>
using namespace std;
char A[4][4];
int main()
{
	while( scanf(" %c%c%c %c%c%c %c%c%c",&A[1][1],&A[1][2],&A[1][3],&A[2][1],&A[2][2],&A[2][3],&A[3][1],&A[3][2],&A[3][3]) != EOF ){
		printf("%c%c%c\n",A[1][1],A[2][2],A[3][3]);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    string s;
    cin >> s;
    for (int i = 1; i <= s.size(); i++){
        if(i % 2 == 1 && s[i-1] == 'L'){
            cout << "No" << endl;
            return 0;
        }
        if(i % 2 == 0 && s[i-1] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;

int main(){
    ll x,k,d;
    scanf("%lld%lld%lld", &x, &k, &d);

    int cnt = 0;
    if(x < 0) x = -x;
    if(x > d){
        if(x/d <= k){
            k -= x/d;
            x -= (x/d)*d;
        }else{
            x -= d*k;
            k = 0;
        }
    }
    ll ans = 0;
    if(k % 2 == 0) ans = x;
    else ans = d-x; 

    printf("%lld", ans);
}

Measured memory_bytes: 1736
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
pls=[]
for i in range(1,2**10):
  bin=format(i,"b").zfill(10)
  pf=0
  for x in range(n):
    cnt=0
    for j in range(10):
      if int(bin[j])==f[x][j]==1:
        cnt+=1
    pf+=p[x][cnt]
  pls.append(pf)
print(max(pls))

Measured memory_bytes: 3188
using System;
using System.Globalization;
using System.Threading;

namespace atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int D = int.Parse(input[1]);
            double result = 0;
            int count = 0;

            for (int i = 0; i < N; i++){
                string[] input2 = Console.ReadLine().Split(' ');
                long x = long.Parse(input2[0]);
                long y = long.Parse(input2[1]);
                x = x * x;
                y = y * y;
                x = x + y;

                result = Math.Sqrt(x);

                if (result <= D) count++;

            }

            Console.WriteLine(count);
         }
    }
}


Measured memory_bytes: 21804
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string S = Console.ReadLine();

		if(S.Contains("7")){
				Console.WriteLine("Yes");
		}else{
				Console.WriteLine("No");
		}

	}
}



Measured memory_bytes: 17412
s=input()
year=int(s.split('/')[0])
month=int(s.split('/')[1])
day=int(s.split('/')[2])
if year<=2018:
    print('Heisei')
elif year==2019:
    if month<=4:
        print('Heisei')
    else:
        print('TBD')
else:
    print('TBD')
    


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1 , -1 , 0 , 0};
int fy4[] = {0 , 0 , 1 , -1};
int Kfx[]= {-2,-2,2,2,1,1,-1,-1}; ///knight move x - exis
int Kfy[]= {1,-1,1,-1,2,-2,2,-2}; ///knight move y- exis
int fx8[]= {1,1,1,0,0,-1,-1,-1};
int fy8[]= {0,1,-1,1,-1,0,1,-1};
#define ll long long int
#define pii pair<int,int>
#define llu unsigned long long
#define inf 1<<28
#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define all(r)(r).begin(),(r).end()
/*
bool status[mx];
void sieve(){
   long long int  i,j;
    for(i=2;i<=mx;i++)
    {
        status[i]=0;
    }
    for( i=2;i<=sqrt(mx);i++){
        if(status[i]==0)
        {
            for(j=i*i;j<=mx;j+=i){
                status[j]=1;
            }
        }
    }
}*/
ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;

    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}
#define dd double
#define sc scanf
#define pr printf
#define VI vector<int>
#define VS vector<string>
#define VC vector<char>
#define VLL vector<long long int>
#define FILE freopen("input.txt","rt",stdin); freopen("output.txt","w",stdout);
#define p_b push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define F(i,a,b) for(i=a;i<=b;i++)
#define sc1(a) scanf("%d",&a)
#define scL1(a) scanf("%lld",&a)
#define scL2(a,b) scanf("%lld%lld",&a,&b)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define fori(N)          for(int i = 0; i<(N); i++)
#define forj(N)         for(int j = 0; j<(N); j++)
#define fork(N)         for(int k = 0; k<(N); k++)
#define forl(N)         for(int l = 0; l<(N); l++)
#define ford(N)         for(int d = 0; d<(N); d++)
#define fori1(N)          for(int i = 1; i<=(N); i++)
#define forj1(N)         for(int j = 1; j<=(N); j++)
#define fork1(N)         for(int k = 1; k<=(N); k++)
#define ford1(N)         for(int d = 1; d<=(N); d++)
#define sqr(x)           (x)*(x)
#define TEST int test,te=0;cin>>test;
#define segment_tree int l=(n*2),r=(n*2)+1,mid=(l+r)/2
#define Mx 100005
#define mx 10005

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    int n,m;
    cin>>n>>m;
    int m1=m;
    map<int,int>mp,mp2;
    int cntp=0,cnta=0;
    vector<int>v1;
    vector<string>v2;
    while(m--){
    	int p;
    	string a;
    	cin>>p>>a;
    	v1.push_back(p);
    	v2.push_back(a);
    	if(mp[p]==1)continue;
    	if(a=="AC"){
    		mp[p]=1;
    		cnta++;
		}
	}
for(int i=0;i<v1.size();i++){
	if(mp[v1[i]]==1 and mp2[v1[i]]==0 and v2[i]=="WA"){
	//	mp2[v1[i]]=1;
		cntp++;
	}
	else if(v2[i]=="AC"){
		mp2[v1[i]]=1;
	}
}
	cout<<cnta<<" "<<cntp<<endl;
}


Measured memory_bytes: 15468
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

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

signed main(){
    ll N,W;
    cin>>N>>W;
    ll w[N+1],v[N+1];
    rep1(i,N){
        cin>>w[i]>>v[i];
    }
    ll dp[N+1][W+1];
    rep0(i,N+1) rep0(j,W+1) dp[i][j]=0;
    rep1(i,N){
        rep0(j,W+1){
            if(j>=w[i]){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    /*rep0(i,N+1){
        rep0(j,W+1){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[N][W]<<endl;

    return 0;
}


Measured memory_bytes: 79104
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

struct Elem {
    int black, blue, id;
    Elem() {}
    Elem(int a, int b, int c) : black(a), blue(b), id(c) {}
    bool operator<(const Elem &e) const {
        int vl = black - blue;
        int vr = e.black - e.blue;
        if(vl != vr) return vl > vr;
        else return blue < e.blue;
    }
};
 
int main() {
    int N; cin >> N;
    vector<int> X(N+1);
    for(int i=1; i<=N; i++) cin >> X[i];
    vector<int> pool;

    // black, blue
    priority_queue<Elem> que;
    for(int i=2; i<=N; i++) {
        int black = X[i], blue = i;
        que.emplace(black, blue, i);
    }

    vector<int> ans(N * N, -1);
    ans[ X[1] - 1 ] = 1;
    for(int t=0; t<N*N; t++) {
        // fprintf(stderr, "ans[%d] = %d\n", t, ans[t]);
        if(ans[t] >= 0) {
            for(int i=1; i<=N-ans[t]; i++) pool.emplace_back(ans[t]);
            continue;
        }

        if(que.size()) {
            Elem cur = que.top(); que.pop();
            int black = cur.black - t, blue = cur.blue, id = cur.id;
            // fprintf(stderr, "t = %d, black = %d, blue = %d, id = %d\n", t, black, blue, id);
            if(black < blue) break;
            assert(blue > 1);
            
            if(blue > 1) {
                ans[t] = id;
                
                if(blue - 1 > 1) {
                    que.emplace(cur.black, blue - 1, id);
                }
                else if(blue - 1 == 1) {
                    ans[ X[id] - 1 ] = id;
                }
                else {
                    for(int i=0; i<N-id; i++) pool.emplace_back(id);
                }
            }
        }
        else {
            if(pool.empty()) break;
            ans[t] = pool.back();
            pool.pop_back();
        }
    }

    // cerr << pool.size() << endl;
    /*
    while(pool.size()) {
        ans.emplace_back(pool.back());
        pool.pop_back();
    }
    */

    if(*min_element(ans.begin(), ans.end()) == -1) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for(size_t i=0; i<ans.size(); i++) cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int MAXN=4e5+5;
char x[MAXN];
int a[MAXN],b[MAXN];
int n;
ll cnt[MAXN],ans;
int calc(int len){
	ll res=0,cnt=0;
	for (int i=1;i<=len;i++){
		res=(res*2ll%mod+a[i])%mod;
	}
	for (int i=0;i<2*n;i+=len*2){
		for (int j=1;j<=len;j++) b[i+j]=a[j];
		for (int j=len+1;j<=2*len;j++) b[i+j]=!a[j-len];
	}
	cnt=1;
	while (cnt<=2*n&&a[cnt]==b[cnt]) cnt++;
	res=(res+(cnt>2*n||a[cnt]>b[cnt]))%mod;
	return res;
}
int main(){
	scanf("%d",&n);
	scanf("%s",x+1);
	for (int i=1;i<=n;i++){
		a[i]=(x[i]=='1');
		a[i+n]=(x[i]!='1');
	}
	for (int i=1;i<=n;i++){
		if (n%i==0&&(n/i)&1) cnt[i]=calc(i);
	}
	for (int i=1;i<=n;i++){
		for (int j=2*i;j<=n;j+=i){
			if (n%j==0&&(n/j)&1) cnt[j]=((cnt[j]-cnt[i])%mod+mod)%mod;
		}
	}
	for (int i=1;i<=n;i++) ans=(ans+2ll*i%mod*cnt[i]%mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4736
a = [13,19,9,5,12,8,7,4,21,2,6,11]
gets
a=gets.split.map(&:to_i)
gets
b=gets.split.map(&:to_i)
def linear(a,n)
  for i in 0..a.size-1
    return 1 if a[i] == n
  end
  return 0
end
ans = 0
for i in 0..b.size-1
  ans += linear(a, b[i])
end

puts ans

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

using namespace std;
char s[100005];
int v[100005],sol2[100005],n,i,q,poz,st,dr,mij,sol,nr;
int main()
{
    cin.getline(s,100005);
    n=strlen(s);
    for (i=0;i<n;i++)
    {
        if ( s[i]=='R'&&s[i+1]=='L')
        {
            v[++q]=i;
        }
    }
    for (i=0;i<n;i++)
    {
        poz=i;
        if (s[i]=='R')
        {
            st=1;
            dr=q;
            sol=0;
            while (st<=dr)
            {
                mij=(st+dr)/2;
                if (v[mij]>=i)
                {
                    sol=v[mij];
                    dr=mij-1;
                }
                else
                {
                    st=mij+1;
                }
            }
            nr=sol-i;
            if (nr%2==0)
            {
                sol2[sol]++;
            }
            else
            {
                sol2[sol+1]++;
            }
        }
        else
        {
            st=1;
            dr=q;
            sol=0;
            while (st<=dr)
            {
                mij=(st+dr)/2;
                if (v[mij]>i)
                {
                    dr=mij-1;
                }
                else
                {
                    sol=v[mij];
                    st=mij+1;
                }
            }
            nr=i-sol;
            if (nr%2==0)
            {
                sol2[sol]++;
            }
            else
            {
                sol2[sol+1]++;
            }
        }
    }
    for (i=0;i<n;i++)
    {
        cout<<sol2[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 1152
a1,b1,a2,b2=map(int,input().split())

import sys
sys.setrecursionlimit(2000000000)

p = 10 ** 9 + 7
N = a2+b2+2  # N は必要分だけ用意する
R = max(a2+1,b2+1)
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  
for i in range(2, R + 1):
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

def comb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

score=comb(a2+b2+2,a2+1,p)-comb(a2+b1+1,a2+1,p)-comb(a1+b2+1,a1,p)+comb(a1+b1,a1,p)
print(score%(10**9+7))

Measured memory_bytes: 167012
#include<stdio.h>
#include<stdlib.h>

#define N 100000
#define INF 100000000

typedef struct{
  int g;
  int b;
  int c;
}data;

int n,A[N];
data D[500000];

void singlesource(int num)
{
  int i,ch=1;

  for(i=0; i<n; i++)A[i]=INF;
  A[0]=0;

  while(ch!=0){
    ch=0;
    for(i=0; i<num; i++){
      if(D[i].c+A[D[i].b]<A[D[i].g]){
	A[D[i].g]=D[i].c+A[D[i].b];
	ch=1;
      }
    }
  }
}

int main()
{
  int i,j,k,p,con=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d%d",&p,&k);
    for(j=0; j<k; j++){
      D[con].b=p;
      scanf("%d%d",&D[con].g,&D[con].c);
      con++;
    }
  }
  singlesource(con);
  for(i=0; i<n; i++)printf("%d %d\n",i,A[i]);
  return 0;
}




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

const ll mod=998244353;
ll n,m,k,c[200005];

ll fp(ll x,ll y)
{
    ll ret=1;
    while(y)
    {
        if(y&1) ret=ret*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ret;
}

int main()
{
    scanf("%lld%lld%lld",&n,&m,&k);
    c[0]=1;ll ans=0;
    for(int i=1;i<=n-1;i++) c[i]=c[i-1]*(n-i)%mod*fp(i,mod-2)%mod;
    for(int i=0;i<=k;i++)
        ans=(ans+m*fp(m-1,n-i-1)%mod*c[n-i-1]%mod)%mod;
    printf("%lld",ans);
    return 0;
}


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

int main() {
    int S;
    cin >> S;
    int h = S / 3600;
    S %= 3600;
    int m = S / 60;
    S %= 60;
    int s = S;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;

	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());

	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i].second;

		if (sum >= k) {
			cout << a[i].first << endl;
			return 0;
		}
	}

	return 0;
}

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


using namespace std;

int main(){
    string s; cin >> s;
    if (s[0] == s.back()) {
        if (s.size() & 1) puts("Second");
        else puts("First");
    } else {
        if (s.size() & 1) puts("First");
        else puts("Second");
    }
}

Measured memory_bytes: 512
// ---------- begin snipet ----------
pub trait MoOperator {
    type Answer;
    fn size(&self) -> usize;
    fn insert(&mut self, x: usize);
    fn delete(&mut self, x: usize);
    fn answer(&self) -> Self::Answer;
}

pub struct MoSolver<S> {
    state: S,
    query: Vec<(usize, usize)>,
}

impl<S: MoOperator> MoSolver<S> {
    fn new(state: S) -> Self {
        MoSolver {
            state: state,
            query: vec![],
        }
    }
    fn add(&mut self, l: usize, r: usize) {
        self.query.push((l, r));
    }
    fn solve_with_size(&mut self, answer: &mut [S::Answer], batch: usize) {
        let state = &mut self.state;
        let size = state.size();
        let mut q = vec![vec![]; size / batch + 1];
        for (k, &(l, r)) in self.query.iter().enumerate() {
            q[l / batch].push((r, l, k));
        }
        let mut x = 0;
        let mut y = 0;
        for (i, mut q) in q.into_iter().enumerate() {
            q.sort_unstable_by_key(|p| p.0);
            if i % 2 == 1 {
                q.reverse();
            }
            for (r, l, k) in q {
                while l < x {
                    x -= 1;
                    state.insert(x);
                }
                while y < r {
                    state.insert(y);
                    y += 1;
                }
                while x < l {
                    state.delete(x);
                    x += 1;
                }
                while r < y {
                    y -= 1;
                    state.delete(y);
                }
                answer[k] = state.answer();
            }
        }
    }
}
// ---------- end Mo algorithm ----------

struct State {
    c: Vec<usize>,
    cnt: Vec<u32>,
    ans: u32,
}

impl MoOperator for State {
    type Answer = u32;
    fn size(&self) -> usize {
        self.c.len()
    }
    fn insert(&mut self, x: usize) {
        let c = &mut self.cnt[self.c[x]];
        if *c == 0 {
            self.ans += 1;
        }
        *c += 1;
    }
    fn delete(&mut self, x: usize) {
        let c = &mut self.cnt[self.c[x]];
        if *c == 1 {
            self.ans -= 1;
        }
        *c -= 1;
    }
    fn answer(&self) -> Self::Answer {
        self.ans
    }
}

fn solve(c: &[usize], ask: &[(usize, usize)]) -> Vec<u32> {
    let state = State {
        c: c.iter().cloned().collect(),
        cnt: vec![0; c.len()],
        ans: 0,
    };
    let mut solver = MoSolver::new(state);
    for &(l, r) in ask {
        solver.add(l, r);
    }
    let mut ans = vec![0; ask.len()];
    solver.solve_with_size(&mut ans, 1024);
    ans
}

use proconio::*;
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        q: usize,
        c: [Usize1; n],
        ask: [(Usize1, usize); q],
    }
    let ans = solve(&c, &ask);
    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 55708
def kai(n):
    a=1
    for i in range(1,n+1):
        a=a*i
    return a

N,M=map(int,input().split())
if N==0 or N==1:
    g=0
else:
    g=kai(N)/(kai(N-2)*2)
if M==0 or M==1:
    k=0
else:
    k=kai(M)/(kai(M-2)*2)
print(int(g+k))

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

int main(){
      int n,m,k;
      scanf("%d %d %d",&n,&m,&k);

      for(int i=0;i<=n;i++){
            for(int j=0;j<=m;j++){
                  int now=i*m+j*n-2*(i*j);
                  if(now==k) {printf("Yes"); return 0;}
            }
      }
      printf("No");
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int a=fsc.nextInt();
        int b=fsc.nextInt();
        fsc.close();
        System.out.println(a<=2*b?0:(a-2*b));
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}

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


int main(){
    int N; cin >> N;
    vector<ll> A(N), sum(N); 
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        if (i == 0) sum.at(i) = A.at(i);
        else sum.at(i) = A.at(i) + sum.at(i-1);
    }
    ll res = -100000;
    for (int i = 0; i < N - 1; i++)
    {
        ll x = sum.at(i), y= sum.at(N-1) - x;
        ll u = max(x, y), v = min(x, y);
        if (res < 0)  res = u - v;
        else if ( res > u - v) res = u- v;
    }
    
    cout << res << endl;
}


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

const int INF = 1e9;

int w, h;
int A[10][10], B[10][10], used[10][10][10][10];

int update(int y, int x){
  
  if( A[y][x] == 0 ) return 0;
  
  for(int i=y;i<h;i++)
    for(int j=x;j<w;j++) used[y][x][i][j] = 0;
  
  int L;
  
  for(int l=min(h-y-1, w-x-1);l>=0;l--){

    int flag = 1, cnt = 0;
    
    for(int i=y;i<=y+l;i++){
      
      for(int j=x;j<=x+l;j++){
	
	if( A[i][j] == 0 ) flag = 0;
	if( B[i][j] ) cnt++;
	
	if( !flag ) break;
	
      }
      
      if( !flag ) break;
      
    }
    
    if( flag ){
      
      if( cnt == 0 ) return 0;
      L = l;
      
      break;
    }
    
  }
  
  for(int i=y;i<=y+L;i++){
    for(int j=x;j<=x+L;j++){
      used[y][x][i][j] = B[i][j];
      B[i][j] = 0;
    }
  }
  
  return 1;
}

void add(int y, int x){
  
  for(int i=y;i<h;i++)
    for(int j=x;j<w;j++) B[i][j] += used[y][x][i][j];
  
}

typedef unsigned long long ull;

map<ull,int> memo[10][10];

ull Hash(int y, int x){
  
  ull res = 0;
  ull base = 1777771;
  
  for(int i=y;i<h;i++){
    int s = 0;
    if( i == y ) s = x;
    for(int j=s;j<w;j++){
      res = res * base + ( B[i][j] + 1 );
    }
  }
  
  return res;
}

int dfs(int y, int x){

  if( y == h - 1 && x == w - 1 ) return B[y][x];
  
  ull H = Hash( y, x );
  
  if( memo[y][x].count( H ) ) return memo[y][x][H];
  
  int res = INF;
  
  int ny = y, nx = x + 1;
  if( nx == w ) ny++, nx = 0;
  
  if( B[y][x] == 0 ) res = dfs( ny, nx );
  
  int r = update( y, x );
  
  res = min( res, r + dfs( ny, nx ) );
  
  add( y, x );
  
  return memo[y][x][H] = res;
}

signed main(){

  while(1){
    
    cin>>w>>h;
    if( !w && !h ) break;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) memo[i][j].clear();
    
    memset(used,0,sizeof(used));
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>A[i][j];
	B[i][j] = A[i][j];
      }
    }
  
    cout << dfs( 0, 0 ) << endl;
  
  }
  
  return 0;
}



Measured memory_bytes: 3700
N,D=map(int,input().split())
X=[]
for i in range(N):
    X.append(list(map(int,input().split())))
count=0
for i in range(N):
    if pow(X[i][0]*X[i][0]+X[i][1]*X[i][1],1/2)<=D:count+=1
print(count)

Measured memory_bytes: 45700
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int productAB = a * b;
    
    if (productAB % 2 == 0) 
      System.out.println("Even");
    else 
      System.out.println("Odd");
    
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int A, B;
    cin >> A >> B;
    cout << ( A <= 8 && B <= 8 ? "Yay!" : ":(" ) << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
from collections import deque
s = deque([i for i in S])
re = False

for i in range(Q):
    q = list(map(str,input().split()))
    if q[0] == "1":
        re = not re
    else:
        b = int(q[1])-1
        if (re and b) or not(re or b):
            s.appendleft(q[2])
        else:
            s.append(q[2])

ans = ""
if re:
    while s:
    	ans += s.pop()
else:
    while s:
        ans += s.popleft()
print(ans)

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;



lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> n;
    
    cout << n * n * n << endl;


//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;
	
ll arr[100000];
int main()
{
	cin >> N;
    rep(i, N){
        cin >> arr[i];
    }
    sort(arr, arr+N);
    ll maxv = 0, index = 0;
    rep(i, N){
        if(maxv < min(arr[i], arr[N-1] - arr[i])){
            maxv = min(arr[i], arr[N-1] - arr[i]);
            index = i;
        }
    }
    cout << arr[N-1] << " " << arr[index];
}


Measured memory_bytes: 1024
package main

import "fmt"

const debug = true

func main() {
	var N int
	fmt.Scan(&N)
	nums := scanNums(N)
	var sumsFromZero = make([]int, N+1) //nums[0]からnums[k]までの部分和
	var sameSums = make(map[int]int)    //部分和が同じものの個数を数え上げたもの

	sumsFromZero[0] = nums[0]
	sameSums[nums[0]]++
	sameSums[0]++

	for i := 1; i < N; i++ {
		k := sumsFromZero[i-1] + nums[i]
		sumsFromZero[i] = k
		sameSums[k]++
	}

	sumsFromZero = append([]int{0}, sumsFromZero...) //空の部分列の和は0

	sum := 0
	for _, v := range sameSums {
		sum += combination(v, 2)
	}

	fmt.Println(sum)
}

func combination(n, r int) (cmb int) {
	a := 1
	b := 1
	for i := 0; i < r; i++ {
		a *= n - i
		b *= r - i
	}
	return (a / b)
}

func scanNums(length int) (nums []int) {
	var num int
	for i := 0; i < length; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,t;
    cin>>n>>t;
    ll left=0;
    ll right = t;
    ll ans = t;
    ll ti;
    cin>>ti;//最初
    rep(i,n-1){
        cin>>ti;
        if(ti>=right){
            left = ti;
            right = ti+t;
            ans+=t;
        }
        else{
            ans+=ti+t-right;
            right = ti+t;
            left = ti;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  int min=1000000000,Max=1;
  for(int i =0; i<N ;i++){
    cin>>A.at(i);
    if(Max <A.at(i)){
      Max=A.at(i);
    }
    if(min >A.at(i)){
      min =A.at(i);
    }
  }
  cout<< Max-min <<endl;
}

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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
	int n;
	cin>>n;
	int a[4]={0};
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		if(s[0]=='A')
			a[0]++;
		else if(s[0]=='W')
			a[1]++;
		else if(s[0]=='T')
			a[2]++;
		else if(s[0]=='R')
			a[3]++;
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl; 
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int h,w,x,y;cin>>h>>w>>x>>y;
    if((h*w)%2&&(x+y)%2){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}



Measured memory_bytes: 3092
#include <cstdio>

int main (){
    int N;
    scanf("%d",&N);
    char cur[3];
    double value;
    double total=0;
    for (int i = 0; i < N; i++){
        scanf("%lf %s",&value,cur);
        if(cur[0]=='B') value*=380000.0;
        total+=value;
    }    
    printf("%lf",total);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>  // ver1.9
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<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 INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
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(14);
  int n;
  string s;
  cin >> n >> s >> n;
  char c=s[n-1];
  rep(i,0,s.size()){
    if(s[i]!=c) s[i]='*';
  }
  cout << s << endl;
  return 0;
}


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

int n;
int check(int i)
{
    if(i==2) return 1;
    if(i%2==0) return 0;
    for(int a=3;a*a<=i;a+=2)
    {
        if(i%a==0) return 0;
    }
    return 1;
}
int solve_a()
{
    int i;
    for(i=n-1;!check(i);i--);
    return i;
}
int solve_b()
{
    int i;
    for(i=n+1;!check(i);i++);
    return i;
}
int main()
{
    while(cin >> n)
    {
        cout << solve_a() << ' ' << solve_b() << endl;
    }
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    n = int(input())
    tmp = Counter(input())

    for i in range(n - 1):
        tmp = tmp & Counter(input())

    print(''.join(sorted(list(tmp.elements()))))


Measured memory_bytes: 3444
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

struct Event {
  int t;
  int type, x;
  bool operator<(Event& e) const {
    return t < e.t || (t == e.t && type < e.type) || (t == e.t && type == e.type && x < e.x);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  
  set<int> xs;
  vector<Event> es;
  vector<int> qs;
  for (int i = 0; i < n; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    es.push_back({l-x, 1, x});
    es.push_back({r-x, -1, x});
  }
  for (int i = 0; i < q; i++) {
    int d;
    cin >> d;
    qs.push_back(d);
  }

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

  int j = 0;
  for (int i = 0; i < q; i++){
    while (j < es.size() && es[j].t <= qs[i]) {
      if (es[j].type == 1) {
        xs.insert(es[j].x);
      } else {
        xs.erase(es[j].x);
      }
      j++;
    }
    int x;
    if (xs.size() > 0) {
      x = *xs.begin();
    } else {
      x = -1;
    }
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 17516
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222




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

  cin >> n;
  if (n == 7 || n == 5 || n == 3) cout << "YES" << endl;
  else cout << "NO" << endl;




  return 0;
}



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s=b-a+d-c-(max(b,d)-min(a,c));
  if(s<=0) cout<<0<<endl;
  else cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
    double x1,x2,y1,y2,X,Y;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    X=x2-x1;
    Y=y2-y1;
    printf("%lf\n",hypot(X, Y));
    return 0;
}

Measured memory_bytes: 664
#include <iostream>

using namespace std;

int main()
{
    int N, M, X, Y, x_max, y_min;
    int temp;
    
    cin >> N >> M >> X >> Y;
    
    x_max = X;
    y_min = Y;
    
    for(int i=0;i<N;i++){
        cin >> temp;
        if(temp>x_max)
            x_max = temp;
    }
    
    for(int i=0;i<M;i++){
        cin >> temp;
        if(temp<y_min)
            y_min = temp;
    }
    
    if(x_max < y_min)
        cout << "No War" << endl;
    else
        cout << "War" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int INF = 1e9;
const int N = 2e5+7;
const int MOD = 1e9+7;

int a[N];

int main(){

  int n; cin >> n;
  REP(i,n){
    int t; cin >> t;
    a[t-1]++;
    a[t]++;
    a[t+1]++;
  }
  int ans = 0;
  REP(i,100000) ans = max(ans,a[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using pll = pair<long long, long long>;
vector<vector<int>> path;
vector<int> x;

vector<pll> plls;

bool dfs(int i) {
  int n = path[i].size();
  if (n == 0) {
    plls[i].first = x[i];
    return true;
  }
  long long minSum = 0, maxSum = 0;
  vector<long long> diffs;
  for (int j = 0; j < n; j++) {
    if (!dfs(path[i][j]))
      return false;
    minSum += min(plls[path[i][j]].first, plls[path[i][j]].second);
    maxSum += max(plls[path[i][j]].first, plls[path[i][j]].second);
    diffs.push_back(abs(plls[path[i][j]].first - plls[path[i][j]].second));
  }
  if (minSum > x[i]) {
    return false;
  }
  int m = x[i] - minSum;
  vector<vector<bool>> dp(n + 1);
  for (int j = 0; j < n + 1; j++)
    dp[j].resize(m + 1);
  dp[0][0] = true;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      if (dp[i][j]) {
        dp[i + 1][j] = true;
        if (j + diffs[i] <= m) {
          dp[i + 1][j + diffs[i]] = true;
        }
      }
    }
  }
  for (int i = 0; i <= m; i++)
    if (dp[n][i])
      ans = i;
  plls[i].first = x[i];
  plls[i].second = maxSum - ans;
  return true;
}

int main() {
  int n;
  cin >> n;
  plls.resize(n);
  path.resize(n);
  x.resize(n);
  vector<int> p(n - 1);
  for (int i = 0; i < n - 1; i++)
    cin >> p[i];
  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < n - 1; i++)
    path[p[i] - 1].push_back(i + 1);
  if (dfs(0)) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
N,M = list(map(int,input().split(" ")))
di = defaultdict(lambda :0)
for i in range(N):
    temp= list(map(int,input().split(" ")))
    temp = temp[1:]
    for i in temp:
        di[i] += 1
ans = 0
for v in di.values():
    if v == N :
        ans+= 1
print(ans)

Measured memory_bytes: 3316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    for(int i=1;i<=5;i++){
        int a;cin >> a;
        if(a!=i){
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3548