akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)
N, M = map(int, input().split())
n = [i+1 for i in range(N)]
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
import collections
g = 0
for k, v in collections.Counter([uf.find(i) for i in range(N)]).items():
    g = max(v, g)
print(g)

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

struct Edge {
    int to;
    long long weight;
};

vector<vector<Edge>> edges(0);

const long long INF = 2ll << 60;
vector<long long> pos(0, INF);
bool dfs(int from, long long p) {
    if (pos.at(from) != INF) return pos.at(from) == p;

    pos.at(from) = p;
    bool res = true;
    for (int i = 0; i < (int)edges.at(from).size(); i++) {
        int to = edges.at(from).at(i).to;
        long long weight = edges.at(from).at(i).weight;
        res &= dfs(to, p + weight);
    }

    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    edges.resize(n);
    pos.resize(n, INF);
    for (int i = 0; i < m; i++) {
        int l, r; 
        long long d;
        cin >> l >> r >> d;
        l--; r--;
        edges.at(l).push_back(Edge{r, d});
        edges.at(r).push_back(Edge{l, -d});
    }

    for (int i = 0; i < n; i++) {
        if (pos.at(i) == INF) {
            bool res = dfs(i, 0);
            if (!res) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
}  

Measured memory_bytes: 17408
#include <iostream>
#include <string>

using namespace std;

int main() {
  string l;
  int n = 1;
  while (getline(std::cin, l)) {
    if (l == "0")
      break;
    cout << "Case " << n << ": " << l << endl;
    ++n;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int A, B, C;
  cin >> A >> B >> C;
  if (B - A == C - B) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   string s;
   cin >> s;
   int n = s.size();
   int cnt = 0;
   string last = "!";
   string cur = "";
   for (char c : s) {
      cur += c;
      if (cur != last) {
         cnt++;
         last = cur;
         cur = "";
      }
   }
   cout << cnt << "\n";
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
    int N,H;
    cin >> N >> H;
    vector<int>a(N);
    vector<int>b(N);
    rep0(i,N)cin >> a[i] >> b[i];
    int count = 0;
    int maxa = 0;
    sort(all(b));
    reverse(all(b));
    rep0(i,N)maxa = max(maxa,a[i]);
    rep0(i,N){
        if(b[i] >= maxa){
            H -= b[i];
            count++;
            if(H <= 0)break;
        }
        else break;
    }
    if(H <= 0)cout << count << endl;
    else cout << count + (H + (maxa - 1)) / maxa << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    char S[N];
    scanf("%s",S);
    if(S[K-1]=='A'){
        S[K-1]='a';
    }else if(S[K-1]=='B'){
        S[K-1]='b';
    }else{
        S[K-1]='c';
    }
    printf("%s\n",S);

}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    ll n;
    cin >> n;
    vector<ll> t(n);
    ll ans;
    rep(i,n){
        cin >> t[i];
        if(i==0) ans=t[i];
        else ans=lcm(ans,t[i]);
    }
    cout << ans << endl;
    return 0;
} 


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

namespace Entrance_Examination
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = Console.ReadLine().Split(' ');
            float  answer = 0;
            answer = float.Parse(d[0]) / float.Parse(d[1]);
            Console.Write(answer);

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define M_PI 4*atan(1)

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double angm = (double)m/60 * 2 * M_PI;
	double angh = (double)(h + (double)m/60)/12 * 2 * M_PI;
	double ang_between = abs(angm - angh);
	double ans = sqrt(a * a + b * b - 2 * a * b * cos(ang_between));
	cout << fixed << setprecision(15) << ans;
}



Measured memory_bytes: 4172
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
class dice
{
private:
  int men[10];
  int men2[10];
public:
  void set_num();
  void throw_dice(const char c);
  void try_dice();
};
void dice::throw_dice(const char c)
{
  int buf;
  switch(c)
  {
    case 'N':
    {
      buf = men[0];
      men[0] = men[1];
      men[1] = men[5];
      men[5] = men[4];
      men[4] = buf;
      break;
    }
    case 'S':
    {
      buf = men[0];
      men[0] = men[4];
      men[4] = men[5];
      men[5] = men[1];
      men[1] = buf;
      break;
    }
    case 'W':
    {
      buf = men[0];
      men[0] = men[2];
      men[2] = men[5];
      men[5] = men[3];
      men[3] = buf;
      break;
    }
    case 'E':
    {
      buf = men[0];
      men[0] = men[3];
      men[3] = men[5];
      men[5] = men[2];
      men[2] = buf;
      break;
    }
    case 'L':
    {
      buf = men[1];
      men[1] = men[3];
      men[3] = men[4];
      men[4] = men[2];
      men[2] = buf;
      break;
    }
  }
}
void dice::set_num()
{
  for(int i = 0; i< 6; i++)
  {
    cin >> men[i];
  };
  for(int i = 0 ; i < 6; i++)
  {
    cin >> men2[i];
  }
}
void dice::try_dice()
{
  int cnt = 0;
  if(men2[0] == men[2] || men2[0] == men[3])throw_dice('E');
  while(men2[0] != men[0])throw_dice('S');
  while(men2[1] != men[1])
  {
    throw_dice('L');
    if(cnt > 5)break;
  }
  for(int i = 0 ; i < 6; i++)
  {
    if(men[i] != men2[i])
    {
      cout << "No" << endl;
      break;
    }
    if(i == 5)cout << "Yes" <<endl;
  }
}
int main()
{
  dice dice1;
  dice1.set_num();
  dice1.try_dice();
  return 0;
}


Measured memory_bytes: 3096
N = int(input())
a = list(map(int, input().split()))

order = [0]*(N+1)

for i in range(N):
    order[a[i]] = i

ans = 0
checkR = list(range(N+1))
checkL = list(range(N+1))

for i in range(N, 0, -1):
    ans += i*(order[i] - checkR[order[i]] + 1)*(checkL[order[i]] - order[i]+1)
    checkR[checkL[order[i]]+1] = checkR[order[i]]
    checkL[checkR[order[i]]-1] = checkL[order[i]]
print(ans)

Measured memory_bytes: 35624
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, t = ril()
ls = rils(n)
ls.sort()

lim = t + 3001
values = [0] * lim
for a, b in ls:
    for j in reversed(range(lim - a)):
        if j < t:
            values[j + a] = max(values[j + a], values[j] + b)
print(max(values))

Measured memory_bytes: 44012
#include<stdio.h>
#define M 10000000
int N,i,j,F[M];
int main()
{
	for(i=2;i<=M;i++)
		if(!F[i])
			for(j=2*i;j<M;j+=i)
				F[j]=1;
	for(;scanf("%d",&N),N;)
	{
		for(i=N;i>=13;i--)
			if(!F[i]&&!F[i-8]&&!F[i-6]&&!F[i-2])
				break;
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 39660
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int d[maxn],n,m,l,r;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&l,&r);
        for(int a=1,b;a<=l-1;a=b+1){
            b=(l-1)/((l-1)/a);
            int y=(l-1)/a;
            int L=a,R=min(r/(y+1),b);
            //cout<<L<<" "<<R<<endl;
            d[L]+=1,d[R+1]-=1;
        }
        d[l]+=1,d[r+1]-=1;
    }
    for(int i=1;i<=m;i++){
        d[i]=d[i-1]+d[i];
        printf("%d\n",d[i]);
    }

}


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

struct unionfind{
   vector<int>d;
   unionfind(int n):d(n,-1){}
   int root(int x){
     if(d[x]<0){return x;}
     return d[x]=root(d[x]);
   }
   bool unite(int x,int y){
     x=root(x);y=root(y);
     if(x==y){return false;}
     if(d[x]>d[y]){swap(x,y);}
     d[x]+=d[y];
     d[y]=x;
     return true;
   }
   bool same(int x,int y){return root(x)==root(y);}
   int size(int x){return -d[root(x)];}
};
int main(){
  int N,M,K;
  cin>>N>>M>>K;
  
  vector<int>frend(N);
  vector<vector<int>>block(N);
  unionfind uf(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    frend[a]++;
    frend[b]++;
    uf.unite(a,b);
  }
  for(int i=0;i<K;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    block[a].push_back(b);
    block[b].push_back(a);
  }
  for(int i=0;i<N;i++){
    int ans=uf.size(i)-1-frend[i];
    for(int c:block[i]){
      if(uf.same(c,i)){ans--;}
    }
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 9020
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long[] h) {
    h = 0 ~ h;
    return iota(N).map!(i => max(0, h[i + 1] - h[i])).sum;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] h = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        h[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, h);
    else
        solve(N, h).writeln;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
ll a[120000];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	ll bst = a[0];
	for (int i = 0; i < n - 1; ++i) {
		if (abs(2 * a[i] - a[n - 1]) < abs(2 * bst - a[n - 1]))
			bst = a[i];
	}
	cout << a[n - 1] << " " << bst << "\n";
	return 0;
}




Measured memory_bytes: 1024
N = int(input())
P = input().split()
P = [int(t) for t in P]
Q = input().split()
Q = [int(t) for t in Q]


def factorial(n):
    val = 1
    fact = [1]
    for i in range(1, n + 1):
        val *= i
        fact.append(val)
    return fact


factArray = factorial(N)


def position(a):
    used = [False] * N
    pos = 0
    for i in range(N):
        notUsedCount = 0
        for j in range(a[i] - 1):
            if not used[j]:
                notUsedCount += 1
        pos += (notUsedCount * factArray[N - i - 1])
        used[a[i] - 1] = True
    return pos + 1


print(abs(position(P) - position(Q)))


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

int main(){
	int A;
	int B;
	int C;
	int D;
	cin>>A>>B>>C>>D;
	while(C>0){
		C-=B;
		if (C<=0) break;
		A-=D;
	}
	if(A<=0){
		cout<<"No";
	}else{
		cout<<"Yes";
	}
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
   
int main(){
   
   char s[100], t[100], u[200];
 
   scanf("%s",s);
   scanf("%s",t);
   
   strcpy(u,s);
   strcat(u,s);
   
   if(strstr(u,t)) {
     printf("Yes\n");
   } else {
     printf("No\n");
     }
       
   return 0;
   
}

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

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

		set<string> arare;

		for(int i=0; i<N; i++) {
			string s;
			cin >> s;
			arare.insert(s);
		}
			
		if (arare.size() == 3) {
				cout << "Three" << endl;
		} else if (arare.size() == 4) {
				cout << "Four" << endl;
		}

		return 0;
}


Measured memory_bytes: 256
N = int(input())
lst = list(map(int,input().split()))
ans = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      a,b,c = lst[i],lst[j],lst[k]
      if (a != b != c != a) and (a+b > c) and (b+c > a) and (c+a > b):
        ans += 1
print(ans)

Measured memory_bytes: 9196
from collections import Counter

n = int(input())
s = input()
c = Counter({'R': 0,'G': 0, 'B': 0})
c.update(s)
x, y, z = c.values()
print(x * y * z - sum(s[i] != s[(i + j) // 2] != s[j] != s[i]
                      for i in range(n) for j in range(i + 2, n, 2))) 


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

int main(){
	int n;
	cin >> n;
	vector<int> a(0);
//	a.at(0) = 1;
	for(int i=1; i>=0; i++){
		if(pow(6, i) > 100000) break;
		a.push_back(pow(6, i));
	}
	for(int i=1; i>=0; i++){
		if(pow(9, i) > 100000) break;
		a.push_back(pow(9, i));
	}
	sort(a.begin(), a.end());
//	a.push_back(1000000);
	vector<int> b(100001);
	vector<int> c(100001);
	rep(i, 100001) b.at(i) = 1000000;
	b.at(0) = 0;
	rep(i, a.size()){
//		if(a.at(i) == 1) continue;
		for(int j=1; j>=0; j++){
			if(a.at(i)*j > 100000) break;
			b.at(a.at(i)*j) = j;
		}
	}
	rep(i, 100001) c.at(i) = b.at(i);
	vector<int> k(0);
	for(int i=1; i<=100000; i++){
		if(b.at(i) == 1) k.push_back(0);
		rep(j, k.size()) b.at(i) = min(min(b.at(i-1)+1, b.at(i)), b.at(k.at(j))+1);
		rep(j, k.size()) k.at(j)++;
	}
	int kk = 0;
	for(int i=1; i<=100000; i++){
		if(c.at(i) == 1) kk = 0;
		c.at(i) = min(min(c.at(i-1)+1, c.at(i)), c.at(kk)+1);
		kk++;
	}
//	cout << 9*9*9*9 << endl;
	cout << min(b.at(n), c.at(n)) << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll a;cin>>a;
    ll t;
    vector<ll> x(n);
    For(i,0,n) {
        cin>>t;t-=a;
        x[i]=t;
    }
    vector<vector<ll>> dp(64,vector<ll> (5184,0));
    dp[0][2501]=1;
    For(i,0,n){
        For(j,0,5100){
            dp[i+1][j]+=dp[i][j];
            if(j+x[i]>=0) dp[i+1][j+x[i]]+=dp[i][j];
        }
    }
    /*For(i,0,n+1){
        For(j,2490,2510){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    ans=dp[n][2501]-1;
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 2944
import Debug.Trace

main :: IO ()
main = do
    getLine
    k <- readLn :: IO Int
    xs <- map (read :: String -> Int) . words <$> getLine
    putStr $ show (solve k xs) ++ "\n"

solve k [] = 0
solve k (x:xs) = (min x (k - x)) * 2 + solve k xs


Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int d=b/a;
	cout << min(d,c);
	return 0;
}



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

int main() {
  int n,m,x,s0 = 0,se = 0;
  cin >> n >> m >> x;
  for(int i = 0;i < m;i++){
    int a;
    cin >> a;
    if(a < x) s0++;
    else se++;
  }
  cout << min(s0,se) << endl;
}


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

int main(void){
    ll n, m, ans = 0;
    cin >> n >> m;
    vector<ll> h(n), a(m), b(m);
    vector<bool> ok(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
        ok[i] = true;
    }
    for(int i = 0; i < m; i++){
        cin >> a[i];
        cin >> b[i];
    }
    for(int i = 0; i < m; i++){
        if(h[a[i]-1] < h[b[i]-1]){
            ok[a[i]-1] = false;
        } else if(h[a[i]-1] > h[b[i]-1]){
            ok[b[i]-1] = false;
        } else {
            ok[a[i]-1] = false;
            ok[b[i]-1] = false;
        }
    }

    for(int i = 0; i < n; i++){
        if(ok[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5644
# AGC027 A
n, x = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort

s = a.inject(:+)

if s == x
  puts n
elsif s < x
  puts n - 1
else
  ss = 0
  n.times do |i|
    ss += a[i]
    if ss > x
      puts i
      exit
    end
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h> 
  
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define M 1000000007

using namespace std;

signed main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(max(b*d,a*c),max(a*d,b*c));
}

Measured memory_bytes: 3632
#include <stdio.h>

typedef long long ll;

int main() {

	ll N,M;

	scanf("%lld %lld",&N,&M);

	if (2ll * N <= M) {
		ll add = M - (2ll * N);
		printf("%lld\n", N + (add / 4ll));
	}
	else {
		printf("%lld\n",M/2ll);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;

int main(void){
    int w,h; cin >> w >> h;
    int x,y; cin >> x >> y;
    cout << double(h)*double(w)/2.0 << " ";
  	if(x*2 == w && y*2 == h) cout << 1;
  	else cout << 0;
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll x,y;
    cin >> x >> y;
    ll res = 0;
    while(x<=y){
        x *= 2;
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
from sys import exit
import math
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = list(input())
T = list(input())
S = "".join(sorted(S))
T = "".join(sorted(T)[::-1])
print("Yes" if S<T else "No")
# L = len(S)
# T = str(input())


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int ma = 0;
		int mi = 1000000007;

		for (int i = 0; i < n; i++) {
			ma = Math.max(a[i], ma);
			mi = Math.min(a[i], mi);
		}

		System.out.println(ma - mi);
	}

}


Measured memory_bytes: 21716
// template {{{
#include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 100500;
int a[N][3], dp[N][3];
void solve()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) {
            if (j == k) continue;
            dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
        }
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

int main() {

    int n;
    cin >> n;
    vector<int> targets(n + 1, 0);
    rep(i, n) cin >> targets[i + 1];

    vector<int> boxes(n + 1, 0);

    for (int i = n; i >= 1; i--) {
        int sum = 0;
        // 本当はj = iではなくj = i + iで始めるべきだが、どうせboxes[i]は0なので
        for (int j = i; j <= n; j += i) {
            sum += boxes[j];
        }
        if (sum % 2 == targets[i]) continue;
        else boxes[i] = 1;
    }

    int c = 0;
    for (int i = 1; i <= n; i++) if (boxes[i] == 1) c++;
    cout << c << endl;
    for (int i = 1; i <= n; i++) if (boxes[i] == 1) cout << i << endl;

}


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

int maximo(int a, int b){
    if(a > b) return a;
    return b;
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int a, b, k, div = 0, ans = 0;
    cin >> a >> b >> k;

    int max = maximo(a,b);
    for(int i = max; i > 0; i--){
        if(div == k) break;
        if(a%i == 0 and b%i == 0){
            div++;
            ans = i;
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
def floor_sum(n,m,a,b):
  r=0
  x,y,z=0,0,0
  while 1:
    if b>=m:
      x=b//m
    else:
      x=0
    if a>=m:
      y=a//m
    else:
      y=0
    r+=x*n
    b-=x*m
    r+=(y*n*(n-1))>>1
    a-=y*m
    x=(a*n+b)//m
    if x==0:
      break
    y=b-x*m
    z=y//a
    r+=(n+z)*x
    a,b,n,m=m,y-z*a,x,a
  return r

for i in range(int(input())):
  print(floor_sum(*list(map(int,input().split()))))

Measured memory_bytes: 71132
from collections import defaultdict

N, K, L = [int(a) for a in input().split(" ")]
P, Q = zip(*[[int(v) for v in input().split(" ")] for i in range(K)])
R, S = zip(*[[int(v) for v in input().split(" ")] for i in range(L)])

def find(tab, a):
    if tab[a] == -1: return a
    tab[a] = find(tab, tab[a])
    return tab[a]

def union(tab, a, b):
    pa, pb = (find(tab, a), find(tab, b))
    if pa!=pb:
        tab[pb] = pa

loads = [-1]*N
rails = [-1]*N
both = [-1]*N
for p, q in zip(P, Q):
    union(loads, p-1, q-1)

for r, s in zip(R, S):
    union(rails, r-1, s-1)

dic = defaultdict(lambda: 0)
ans = []
for i in range(N):
    key = (find(loads, i), find(rails, i))
    ans.append(key)
    dic[key] += 1

ans = [dic[key] for key in ans]
print(" ".join([str(cnt) for cnt in ans]))


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int dp[100005][2];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  int n=s.size();
  dp[0][0] = 1;
  
  rep(i,n){
    // a+b=0
    if(s[i]=='0'){
      dp[i+1][0]=dp[i][0];
      dp[i+1][1]=dp[i][1];
    }else{
      dp[i+1][1]=(dp[i][0]+dp[i][1])%MOD;
    }
    
    // a+b=1
    if(s[i]=='0'){
      (dp[i+1][1]+=dp[i][1]*2%MOD)%=MOD;
    }else{
      (dp[i+1][0]+=dp[i][0]*2%MOD)%=MOD;
      (dp[i+1][1]+=dp[i][1]*2%MOD)%=MOD;
    }
  }
  int ans=(dp[n][0]+dp[n][1])%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1232
#include<stdio.h>
int main()
{
	int n,r;
	while(scanf("%d",&n),n)
	{
		n=1000-n;r=n/500;r+=(n%=500)/100;r+=(n%=100)/50;r+=(n%=50)/10;r+=(n%=10)/5;r+=(n%=5);
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main()
{
	int x,y;
    cin >> x >> y;
    int a=0,b=0;
    switch(x)
	{
       case 1:
       a+=1;
       break;
       case 2:
       break;
       case 3:
       a+=1;
       break;
       case 4:
      b+=1;
      break;
      case 5:
      a+=1;
      break;
      case 6:
      b+=1;
      break;
      case 7:
      a+=1;
      break;
      case 8:
      a+=1;
      case 9:
      b+=1;
      break;
      case 10:
      a+=1;
      break;
      case 11:
      b+=1;
      break;
      case 12:
      a+=1;
      break;
   }
         switch(y){
       case 1:
       a+=1;
       break;
       case 2:
       break;
       case 3:
       a+=1;
       break;
       case 4:
      b+=1;
      break;
      case 5:
      a+=1;
      break;
      case 6:
      b+=1;
      break;
      case 7:
      a+=1;
      break;
      case 8:
      a+=1;
      case 9:
      b+=1;
      break;
      case 10:
      a+=1;
      break;
      case 11:
      b+=1;
      break;
      case 12:
      a+=1;
      break;
   }
   if(a==2 || b==2){
       cout << "Yes" << endl;
   }
   else{
       cout << "No" << endl;
   }
	return 0;
}

Measured memory_bytes: 3556
A=input()
A=A.rstrip().split(" ")
x1=int(A[0])
y1=int(A[1])
x2=int(A[2])
y2=int(A[3])
#print(x1,y1,x2,y2)
x3=x2+(y1-y2)
y3=y2+(x2-x1)
x4=x1-(y2-y1)
y4=y1+(x2-x1)
print(x3,y3,x4,y4)

Measured memory_bytes: 3064
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,cnt=0;
  cin >> n;
  string s;
  map<string,int> m;
  for(int i=0; i<n; i++) {
    cin >> s;
    m[s]++;
    cnt=max(cnt,m[s]);
  }
  for(auto p:m) {
    if(p.second==cnt) {
      cout << p.first << endl;
    }
  }

}

Measured memory_bytes: 23808
#include<stdio.h>
int main(void)
{
	int a,b,x,y,n;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&x);
	y=a+b;
	if(y>=x && a<=x){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {

	ll s;
	cin >> s;
	ll an = 1;
	while(1){
		if (s == 4 || s == 2 || s == 1) {
			break;
		}
		if (s % 2 == 0) {
			s /= 2;
			an++;
		}
		else {
			s *= 3;
			s++;
			an++;
		}
		
	}
	cout << an+3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll k; cin >> k;
	ll now = 0;
	rep(i,k+1){
		now = now * 10 + 7;
		if(now % k == 0){
			cout << i+1 << endl;
			return 0;
		}
		now %= k;
	}
	puts("-1");
}


Measured memory_bytes: 3624
import math
def count(N,i,li):
    a = 1
    for t in range(N):
        if li[t] == i:
            return a
        a += 1

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
li1 = [i+1 for i in range(N)]
li2 = [i+1 for i in range(N)]
x = N-1
a_num = math.factorial(x) * (a[0]-1)
li1.remove(a[0])
b_num = math.factorial(x) * (b[0]-1)
li2.remove(b[0])
x -= 1

for i in range(1,N):
    a_num += math.factorial(x)*(count(N-i,a[i],li1)-1)
    li1.remove(a[i])
    b_num += math.factorial(x)*(count(N-i,b[i],li2)-1)
    li2.remove(b[i])
    x-=1
print(abs((a_num+1)-(b_num+1)))

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

typedef long long ll;

int main()
{
    ll n, ans = 0;
    std::cin >> n;

    for (ll i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0)
            continue;
        ans += i;
    }

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


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, s[100005], oc, g;

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

int chk(int player){
	int oc = 0;
	
	FI(i, 1, n) if(s[i] & 1) oc++;
	if((n - oc) % 2 == 1) return player;
	else if(oc == 1){
		int g = 0;
		
		FI(i, 1, n) if(s[i] & 1){
			if(s[i] == 1) return 3 - player;
			else s[i]--;
		}
		
		
		FI(i, 1, n) g = gcd(g, s[i]);
		assert(g > 1);
		FI(i, 1, n) s[i] /= g;
		
		return chk(3 - player);
	}
	else return 3 - player;
}

int main(){
	scanf("%d", &n);
	FI(i, 1, n) scanf("%d", &s[i]);
	if(n == 1){
		assert(s[1] == 1);
		printf("Second\n");
		return 0;
	}
	else{
		//count number of odd
		int ans = chk(1);
		if(ans == 1) printf("First\n");
		else printf("Second\n");
	}
}


Measured memory_bytes: 768
import java.util.*;

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

    private static void solve(int N) {
        int[] count = new int[4 * N + 1];
        final int limit = (int) Math.sqrt(N);
        for (int x = 1; x <= limit; x++) {
            for (int y = 1; y <= limit; y++) {
                for (int z = 1, zlimit = 2 * limit - x -y; z <= zlimit; z++) {
                    count[x * (x + y) + y * (y + z) + z * (z + x)]++;
                }
            }
        }

        for (int i = 1; i <= N; i++) {
            System.out.println(count[i]);
        }
    }
}


Measured memory_bytes: 39100
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int h,ans = 0,a;
  cin >> h >> a;
  while(h>0){
    h-=a;
    ans++;
  }

  cout  << ans << endl;
}


Measured memory_bytes: 3592
H, W = map(int, raw_input().split())
board = []
for i in range(0, H):
	board.append(raw_input())

flag = True

for i in range(0, H):
	for j in range(0, W):
		if board[i][j] == '#':
			tmp = False
			if i-1 >= 0:
				if board[i-1][j] == '#':
					tmp = True
			if j-1 >= 0:
				if board[i][j-1] == '#':
					tmp = True
			if i+1 <= H-1:
				if board[i+1][j] == '#':
					tmp = True
			if j+1 <= W-1:
				if board[i][j+1] == '#':
					tmp = True
			flag = flag and tmp

if flag:
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define mod 998244353
#define lowbit(x) x&(-x)
#define HS 173LL
using namespace std;
int read()
{
	int x=0;
	char ch=getchar();
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int h,w;
map<int,int> mp;
multiset<int> st;
int main()
{
	h=read(),w=read();
	for(int i=1;i<=w;i++)
		mp[i]=0;
	for(int i=1;i<=w;i++)
		st.insert(0);
	for(int i=1;i<=h;i++)
	{
		int l=read(),r=read();
		if(r!=w)
		{
			auto it=mp.upper_bound(r+1);
			if(it!=mp.begin())
			{
				--it;
				if(it->first!=r+1)
				{
					int v=it->second+r+1-it->first;
					mp[r+1]=v;
					st.insert(v);
				}
			}
		}
		auto it=mp.lower_bound(l);
		while(it!=mp.end()&&it->first<=r)
		{
			st.erase(st.find(it->second));
			it=mp.erase(it);
		}
		if(!st.empty())
			cout<<*st.begin()+i<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 22392
def _input():
    array  = input().split()
    return int(array[0]), int(array[1])

def result(actual, need):
    port = 1
    count = 0
    while  port < need:
        port -= 1
        port += actual
        count += 1
    return count

if __name__ == "__main__":
    actual, need = _input()
    print(result(actual, need))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#define MOD 1000000007

using namespace std;

long long pow(long long x, int p = MOD - 2) {
    if (p == 0) return 1;
    if (p % 2) return pow(x, p - 1) * x % MOD;
    long long y = pow(x, p / 2);
    return y * y % MOD;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long fact[200000];
    fact[0] = 1; for (int i = 1; i < 200000; i++) fact[i] = fact[i - 1] * i % MOD;
    int h, w, n; cin >> h >> w >> n;
    n++;
    pair<int, int> locs[n];
    locs[0] = make_pair(h, w);
    for (int i = 1; i < n; i++) cin >> locs[i].first >> locs[i].second;
    sort(locs, locs + n);
    long long dp[n];
    for (int i = 0; i < n; i++) {
        dp[i] = fact[locs[i].first + locs[i].second - 2] * pow(fact[locs[i].first - 1] * fact[locs[i].second - 1] % MOD) % MOD;
        for (int j = 0; j < i; j++) {
            if (locs[j].first <= locs[i].first && locs[j].second <= locs[i].second) {
                dp[i] -= dp[j] * fact[locs[i].first + locs[i].second - locs[j].first - locs[j].second] % MOD * pow(fact[locs[i].first - locs[j].first] * fact[locs[i].second - locs[j].second] % MOD) % MOD;
                dp[i] += MOD; dp[i] %= MOD;
            }
        }
    }
    cout << dp[n - 1];
    return 0;
}


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

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  unordered_map<int64_t, int64_t> count;
  int64_t sum = 0;
  count[sum]++;
  rep(i, N) {
    int a;
    cin >> a;
    sum = (sum + a) % M;
    count[sum]++;
  }

  int64_t answer = 0;
  for (auto& n : count) {
    answer += (n.second) * (n.second - 1) / 2;
  }
  cout << answer << endl;
  return 0;
}

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

int main(){
	string s;
	while(cin>>s,s!="#"){
		int a=0,b=1,i=0,c,d;
		vector<int> v;
		while(i<s.size()){
			v.push_back(s[i]=='w'?1:0);
			i+=(s[i]=='w'?4:5);
		}
		reverse(v.begin(),v.end());
		a=v[0];
		for(int j=1;j<v.size();j++){
			a*=2;b*=2;
			a+=(v[j]?1:-1);
		}
		a*=90;c=a;d=b;
		while(d){
			c%=d;
			swap(c,d);
		}
		cout<<a/c;
		if(b!=c)cout<<"/"<<b/c;
		cout<<endl;
	}
}

Measured memory_bytes: 1212
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cstdio>
#include <cmath>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k;
	cin >> n >> k;
	map<int, int> mp;
	REP(i, n) {
		int t;
		cin >> t;
		mp[t]++;
	}
	vi a;
	int m = 0;
	for (const auto &i : mp) {
		a.push_back(i.second);
		++m;
	}
	sort(ALL(a));
	cout << accumulate(a.begin(), a.begin() + (m - k < 0 ? 0 : m - k), 0) << "\n";

	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;
  
  bool flag = true;
  if(s[0]!='A') flag = false;

  int cnt = 0;
  for(int i = 2;i<s.size()-1;i++){
    if(s[i]=='C') cnt++;
  }
  if(cnt!=1) flag = false;

  rep(i,s.size())
    if(s[i]!='A' && s[i]!='C'){
      if(!islower(s[i])) flag = false;
    }

  if(flag) cout << "AC" << endl;
  else cout << "WA" << endl;
  
  return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a,b,c,d;
inline LL gcd(LL x,LL y)
{
	return !y?x:gcd(y,x%y);
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(a<b||d<b||a%b>c)
		{
			printf("No\n");
			continue;
		}
		if(b<c||d%b==0)
		{
			printf("Yes\n");
			continue;
		}
		LL x=a%b,y=gcd(d,b);
		if((((c+1-x)%y+b-c-2)>=y||(c+1-x)%y==0)&&b-c>1)
			printf("No\n");
		else
			printf("Yes\n");
	}
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	A := sc.NextInt()
	B := sc.NextInt()
	if A >= 13 {
		fmt.Println(B)
	} else if A <= 5 {
		fmt.Println(0)
	} else {
		fmt.Println(B / 2)
	}
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x, y float64) float64 {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
n = int(raw_input())
 
c = {"S":[0]*13, "H":[0]*13, "C":[0]*13, "D":[0]*13} 
  
for i in range(n):
  mark, num = raw_input().split()
  c[mark][int(num)-1] = 1
  
for k in ["S", "H", "C", "D"]:
  for j in range(13):
    if c[k][j] == 0:
      print "%s %d" % (k, j+1)

Measured memory_bytes: 6376