akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

  int n, k;
  cin >> n >> k;

  vector<int> A(n);
  rep(i, 0, n) {
    cin >> A[i];
  }

  sort(All(A));
  int mi = A[0];

  // dp[0][]: first, dp[1][]: second
  // dp[][K]: K個の石のとき勝てるかどうか
  vector<vector<bool>> dp(2, vector<bool> (100005, false));

  rep(i, mi, k+1) { // i現在ある石
    rep(j, 0, 2) { // jプレイヤー
      if (dp[j][i]) continue;

      int opposite;
      if (j == 0) {
        opposite = 1;
      } else {
        opposite = 0;
      }

      rep(l, 0, n) {
        int al = A[l];
        if (i - al >= 0) {
          if (!dp[opposite][i-al]) { // iからal個とったら相手が負ける
            dp[j][i] = true;
            break;
          }
        }
      }
    }
  }

  if (dp[0][k]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void dfs(int i, int p, vector<v32> &adj, v64 &par)
{
	par[i] = p;
	for (int j : adj[i])
	{
		if (j != p)
			dfs(j, i, adj, par);
	}
	return;
}

void solve()
{
	ll n, m;
	cin >> n;
	vector<v32> adj(n + 1, v32());
	map<p64, ll> idx;
	ll u, v, curr = 1;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		idx[{min(u, v), max(u, v)}] = curr++;
	}
	v64 edges;
	cin >> m;
	for (ll i = 0; i < m; i++)
	{
		cin >> u >> v;
		if (u > v)
			swap(u, v);
		v64 par(n + 1, 0);
		dfs(u, 0, adj, par);
		ll curr = v, mask = 0;
		while (curr != u)
		{
			ll x = min(par[curr], curr), y = max(par[curr], curr);
			mask |= (1ll << (idx[{x, y}] - 1));
			curr = par[curr];
		}
		edges.push_back(mask);
	}
	ll ans = 0;
	for (ll i = 0; i < (1ll << m); i++)
	{
		ll mask = 0, ctr = 0;
		for (ll j = 0; j < m; j++)
		{
			if (i & (1ll << j))
				mask |= edges[j], ctr++;
		}
		ll c = 0;
		while (mask)
		{
			c += (mask % 2);
			mask /= 2;
		}
		db(c);
		ans += pow(-1, ctr) * (1ll << (n - 1 - c));
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 384
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    """
    nCr mod m
    """
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
ans = mod * 2 + pow(2, n, mod) - 1 - combination(n, a) - combination(n, b)
print(ans % mod)


Measured memory_bytes: 3064
#include<stdio.h>
#define N 200

struct{int a,b;} d[N];

int main(){
    int i,j,l,s,k;
    for(i=0; i<N,scanf("%d %d",&d[i].a,&d[i].b)!=EOF; i++);
    l=i;
    for(i=0;i<l;i++){        
        s=d[i].a+d[i].b;
        for(j=1,k=0; s>=j; j*=10,k++);
        printf("%d\n",k);        
    }
    return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


//-------------------------------------------

int main() {
  
  int N,s;
  cin >> N;  
  LL A = INF*10, S=0;
  
  REP(i,N){
    LL X;
    cin >> X;
    if(X < 0){
      s++;
      X *= -1;
    }
    S += X;
    chmin(A,X);
  }
  if(s%2==0||A==0){
    cout << S << endl;
  }
  else cout << S-2*A << endl;
  return 0;
}

Measured memory_bytes: 384
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let n = Int(readLine()!)!
    if n % 1000 == 0 {
        print(0)
    } else {
        print((n / 1000 + 1) * 1000 - n)
    }
}

main()


Measured memory_bytes: 7728
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue> 
#include <cassert>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define INF 2000000000
#define MOD 998244353

using namespace std;

struct Node {
	int val[2];
};
Node t[800000];
int n;
int arr[200000];
int pos[200001];
priority_queue < pair < int, pair <int, int> > > pq;

void build(int v, int l, int r) {
	if (l == r) {
		t[v].val[l % 2] = arr[l];
		t[v].val[1 - l % 2] = INF;
		return; 
	}
	int mid = (l + r) / 2;
	build(2 * v, l, mid);
	build(2 * v + 1, mid + 1, r);
	t[v].val[0] = min(t[2 * v].val[0], t[2 * v + 1].val[0]);
	t[v].val[1] = min(t[2 * v].val[1], t[2 * v + 1].val[1]);
}

void setVal(int v, int l, int r, int index, int val) {
	if (l == r) {
		t[v].val[0] = t[v].val[1] = val;
		return;
	}
	int mid = (l + r) / 2;
	if (index <= mid)
		setVal(2 * v, l, mid, index, val);
	else
		setVal(2 * v + 1, mid + 1, r, index, val);
	for (int i = 0; i < 2; i++) 
		t[v].val[i] = min(t[2 * v].val[i], t[2 * v + 1].val[i]);	
}

int get(int v, int l, int r, int wl, int wr, int flag) {
	if (wl > wr)
		return INF;
	if (wl == l && wr == r) 
		return t[v].val[flag];
	int mid = (l + r) / 2;
	return min(get(2 * v, l, mid, wl, min(mid, wr), flag), 
		get(2 * v + 1, mid + 1, r, max(mid + 1, wl), wr, flag));
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		pos[arr[i]] = i;
	}
	for (int i = 0; i < 4 * n; i++) 
		t[i].val[0] = t[i].val[1] = INF;
	build(1, 0, n - 1);
	pq.push(make_pair(-t[1].val[0], make_pair(0, n - 1)));
	for (int i = 0; i < n; i += 2) {
		pair < int, pair <int, int> > p = pq.top();
		pq.pop();
		int l = pos[-p.first];
		int next = get(1, 0, n - 1, l + 1, p.second.second, 1 - (p.second.first % 2));
		int r = pos[next];
		pair < int, pair <int, int> > f, s, tt;
		f.second = make_pair(p.second.first, l - 1);
		s.second = make_pair(l + 1, r - 1);
		tt.second = make_pair(r + 1, p.second.second);
		// cout << f.second.first << " | " << f.second.second << endl;
		// cout << s.second.first << " | " << s.second.second << endl;
		// cout << tt.second.first << " | " << tt.second.second << endl;
		if (f.second.second - f.second.first > 0) {
			f.first = -get(1, 0, n - 1, f.second.first, f.second.second, f.second.first % 2);
			pq.push(f);
		}
		if (s.second.second - s.second.first > 0) {
			s.first = -get(1, 0, n - 1, s.second.first, s.second.second, s.second.first % 2);
			pq.push(s);
		}
		if (tt.second.second - tt.second.first > 0) {
			tt.first = -get(1, 0, n - 1, tt.second.first, tt.second.second, tt.second.first % 2);
			pq.push(tt);
		}
		printf("%d %d ", -p.first, next);
	}
	printf("\n");
	return 0;
}	

Measured memory_bytes: 9976
#include<stdio.h>
int main(void){
        int n,i;
        int a[100];
        scanf("%d",&n);

        for(i=0;i<n;i++){
                scanf("%d ",&a[i]);
        }

        for(i = n-1;i >=0;i--){
                if( i != 0) {
                       printf("%d ",a[i]);
                  }
                else {
printf("%d",a[i]);
break;
}
        }
       printf("\n");
        return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct FordFulkerson{
    struct Edge {
        int to,cap,rev;
        Edge(int to=0,int cap=0,int rev=0) :
            to(to),cap(cap),rev(rev){}
    };

    int V;
    vector<vector<Edge> > G;
    vector<bool> used;

    FordFulkerson(int V) : V(V) {
        G.resize(V);
        used.assign(V,false);
    }

    void add_edge(int from,int to,int cap) {
        G[from].pb(Edge(to,cap,G[to].size()));
        G[to].pb(Edge(from,0,G[from].size()-1));
    }

    int dfs(int v,int t,int f) {
        if(v==t) return f;
        used[v]=true;
        for(int i=0;i<G[v].size();i++) {
            Edge &e=G[v][i];

            if(!used[e.to] && e.cap>0) {
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0) {
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s,int t) {
        int flow=0;
        while(1) {
            used.assign(V,false);
            int f=dfs(s,t,INF);
            if(f==0) break;
            flow+=f;
        }

        return flow;
    }
    void dump() {
        rep(i,V) {
            printf("%d size=%d\n",i,G[i].size());
            rep(j,G[i].size()) {
                Edge e=G[i][j];
                printf(" %d->%d cap:%d rev=%d\n",i,e.to,e.cap,e.rev);
            }
        }
    }
    int get_cap(int v,int u) {
        rep(i,G[v].size()) if(G[v][i].to==u) return G[v][i].cap;
        return -INF;
    }
};
int n,m;
int s,t;
int main() {
    cin>>n>>m;
    FordFulkerson ff(n);
    map<P,int> in;
    rep(i,m) {
        int x,y;
        cin>>x>>y;
        x--,y--;
        ff.add_edge(x,y,1);
        ff.add_edge(y,x,1);
        in[P(x,y)]=i+1;
    }
    cin>>s>>t;
    s--,t--;
    cout<<ff.max_flow(s,t)<<endl;
    vector<int> ans;

    for(auto e : in) {
        if(ff.get_cap(e.fr.fr,e.fr.sc)>0) ans.pb(e.sc);
    }

    cout<<ans.size()<<endl;
    rep(i,ans.size()) cout<<ans[i]<<endl;

    return 0;
}

Measured memory_bytes: 1384
def main():
    s = input()

    if s[0]==s[1] and s[1] == s[2]:
        if s[0]=='R':
            print(3)
        else:
            print(0)
    elif s[0] == s[2]:
        print(1)
    else:
        if s[0]==s[1] and s[0]=='R':
            print(2)
        elif s[1]==s[2] and s[1]=='R':
            print(2)
        else:
            print(1)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9128
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC113A
{
    static class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int X = int.Parse(input1[0]);
            int Y = int.Parse(input1[1]);

                Console.WriteLine(X + Y/2);
                return;
            }

        }




    }





Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    for(int i = a;i <= b;i ++) {
        if(i % c == 0) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/python

import math
import sys

def F(a, b):
    return max(len(str(a)), len(str(b)))

def main(argv):
    for line in sys.stdin:
        n = int(line)

        small= 0
        for i in xrange(int(math.sqrt(n)), 0, -1):
            if n % i == 0:
                small = i
                break

        print F(small, n / small)

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#include<iostream>
using namespace std;
int main()
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    while(1)
    {
        C=C-B;
        if(C<=0)
        {
            break;
        }
        A=A-D;
        if(A<=0)
        {
            break;
        }
    }
    if(C<=0)
    {
        cout<<"Yes"<<endl;
    }
    else if(A<=0)
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int p, q, r, a, b, c, ans;
  cin >> p >> q >> r;
  a=p+q;
  b=q+r;
  c=r+p;
  ans=min({a,b,c});
    cout << ans;
  return 0;
}

Measured memory_bytes: 256
def d_decrease(K):
    # 1つ要素を選び、値を+Nし、それ以外の要素を-1する。この操作後に、
    # 選んだ要素の値が最大となり、その他の要素の値が負でない
    # ようにしたい。そのためには、range(N)という数列を考え、0番からN-1番の順に
    # 上の操作を行っていくことをK回行えばいい。N回操作を行うごとに数列全体の要素が
    # 1ずつ増えるので、最後の K%N 回だけシミュレーションすればいい。
    N = 50  # Nの値の制約による
    q, r = K // N, K % N  # q回数列全体は+1され、r回シミュレーションする
    seq = list(map(lambda x: x + q, range(N)))
    for i in range(r):
        seq[i] += N
        for j in range(N):
            if i != j:
                seq[j] -= 1
    ans = '{}\n'.format(N) + ' '.join(map(str, seq))
    return ans

K = int(input())
print(d_decrease(K))

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X, K, D;
  cin >> X >> K >> D;

  X = abs(X);

  ll po = X / D;

  if (K <= po) {
    cout << X - (K * D) << endl;
  } else if ((K - po) % 2 == 0) {
    cout << X - (po * D) << endl;
  } else {
    cout << abs(X - (po * D) - D) << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int a,b,c; 
int main() {
	cin>>a>>b>>c;
	if(a==b&&b==c) cout<<"No";
	else if(a!=b&&b!=c&&c!=a) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<cstdio>
using namespace std;
long long int c(long long m,long long n)
{
    long long ans=1;
    for(long long k=1; k<=n; k++)
    {
        ans=(ans*(m-n+k))/k;
    }
    return ans;
}
int main()
{
    long long  l, k;
    while(cin >> l >> k)
    {
        long long  i, j;
        long long sum = 0;
        for( i=1; i<=(l+1)/2; i++)
        {
            sum++;
            for( j=1; j<=i; j++ )
            {
                if( i-j+k*j + i-1 > l) break;
                sum += c(i,j);
            }
        }
        printf("%lld\n",sum);
    }
return 0;
}


Measured memory_bytes: 3216
/* author:hellojim */
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
ll a[200100];
ll ans;
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n;
	rep(i,n)cin>>a[i];
	forn(i,1,n-1)
	{
		if(a[i]<a[i-1])
		{
			ans+=(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 5176
#include <iostream>

using namespace std;

class UnionFind{
	int* groups;
	int* _counts;
	int N;
	public:
	UnionFind(int n){
		N = n;
		groups = new int[N];
		_counts = new int[N];
		for(int i = 0; i < N; i ++){
			groups[i] = i;
			_counts[i] = 0;
		}
	}
	int get_root(int i){
		int n = i;
		while(groups[n] != n){
			n = groups[n];
		}
		int root = n;
		n = i;
		while(groups[n] != n){
			int m = groups[n];
			groups[n] = root;
			n = m;
		}
		return root;
	}
	void set_root(int i, int root){
		int n = i;
		while(true){
			int m = groups[n];
			groups[n] = root;
			if(n == m){
				return;
			}
			n = m;
		}
	}
	void combine(int i, int j){
		set_root(i, get_root(j));
	}
	
	bool in_same_group(int i, int j){
		return get_root(i) == get_root(j);
	}
	
	int* counts(){
		for(int i = 0; i < N; i ++){
			_counts[i] = 0;
		}
		for(int i = 0; i < N; i ++){
			_counts[get_root(i)] ++;
		}
		for(int i = 0; i < N; i ++){
			_counts[i] = _counts[get_root(i)];
		}
		return _counts;
	}
	
};

int main(void){
	int N, M, K;
	
	cin >> N;
	cin >> M;
	cin >> K;
	
	UnionFind groups(N);
	
	int minus_list[N];
	for(int i = 0; i < N; i ++){
		minus_list[i] = 0;
	}
	
	for(int i = 0; i < M; i ++){
		int a, b;
		cin >> a;
		cin >> b;
//		cout << a << "-" << b << endl;
		a --;
		b --;
		groups.combine(a, b);
		minus_list[a] --;
		minus_list[b] --;
	}
	
	for(int i = 0; i < K; i ++){
		int c, d;
		cin >> c;
		cin >> d;
		c --;
		d --;
//		cout << c << "/" << d << endl;
		if(groups.in_same_group(c, d)){
//			cout << "in " << c << "," << d << endl;
			minus_list[c] --;
			minus_list[d] --;
		}else{
//			cout << "no " << c << "," << d << endl;
		}
	}
	
	int* counts = groups.counts();
	
/*
	for(int i = 0; i < N; i ++){
		cout << counts[i];
		if(i < N - 1){
			cout << " ";
		}
	}
	cout << endl;

	for(int i = 0; i < N; i ++){
		cout << minus_list[i];
		if(i < N - 1){
			cout << " ";
		}
	}
	cout << endl;
*/
	for(int i = 0; i < N; i ++){
		cout << counts[i] + minus_list[i] - 1;
		if(i < N - 1){
			cout << " ";
		}
	}
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
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 ll = long long;

using namespace std;

int main() {
    
    string s;
    cin >> s;
    s.back() == 's' ? s += "es" : s += "s";
    cout << s << endl;


    return 0;
}


Measured memory_bytes: 3620
using System;

public class Program
{
    static void Main()
    {
        string line = Console.ReadLine().Trim();
        var zeikomiKingaku = long.Parse(line);

        var zeinukiKingaku = CalcZeinuki(zeikomiKingaku);
        Console.WriteLine(zeinukiKingaku == 0 ? ":(" : zeinukiKingaku.ToString());
    }

    /// <summary>
    /// 税抜き金額算出
    /// ※理論値が存在しない場合は、0を出力
    /// ※1～9の場合は税抜 = 税込
    /// </summary>
    /// <param name="zeikomiKingaku"></param>
    /// <returns></returns>
    private static int CalcZeinuki(double zeikomiKingaku)
    {
        var calczeinukiKingaku = Math.Ceiling(zeikomiKingaku / 1.08);
        var checkKingaku = Math.Floor((int)calczeinukiKingaku * 1.08);

        return zeikomiKingaku != checkKingaku && calczeinukiKingaku > 9 ? 0 : (int)calczeinukiKingaku;
    }
}


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

import sys

for line in sys.stdin:
    w = float(line)
    if w <= 48.00:
        print "light fly"
    elif w <= 51.00:
        print "fly"
    elif w <= 54.00:
        print "bantam"
    elif w <= 57.00:
        print "feather"
    elif w <= 60.00:
        print "light"
    elif w <= 64.00:
        print "light welter"
    elif w <= 69.00:
        print "welter"
    elif w <= 75.00:
        print "light middle"
    elif w <= 81.00:
        print "middle"
    elif w <= 91.00:
        print "light heavy"
    else:
        print "heavy"

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream&
operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

// 1-based index!
template<typename T>
struct BIT {
    vector<T> data;
    BIT(size_t n) : data(n + 1, 0) { }
    T sum(int i){
        assert(0 <= i);
        T s = 0;
        for(; i > 0; i -= i & -i) s += data[i];
        return s;
    }
    T sum(int i,int j){
        if(i == 0) return 0;
        assert(0 < i and i <= j);
        return sum(j) - sum(i - 1);
    }
    void add(int i, T x){
        assert(0 < i);
        for(; i < data.size(); i += i & -i) data[i] += x;
    }
};

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

    int N; cin >> N;
    vector<int> A(N), B(N);
    int M = 0;
    rep(i, N) {
        int a, b; cin >> a >> b;
        a--; b--;
        A[i] = a; B[i] = b;
        set_max(M, b + 1);
    }
    vector<int> imos(M);
    vector<int> sum_s(M), sum_e(M);
    rep(i, N) {
        int a = A[i], b = B[i];
        imos[a]++; imos[b]--;
        A[i] = a; B[i] = b;
        sum_e[b]++;
        sum_s[a]++;
    }
    rep(i, M - 1) {
        imos[i + 1] += imos[i];
        sum_e[i + 1] += sum_e[i];
        sum_s[M - i - 2] += sum_s[M - i - 1];
    }
    int ans1 = *max_element(all(imos));
    int ans0 = 0;
    rep(i, N) {
        int a = A[i], b = B[i];
        int not_intersect = sum_e[a] + sum_s[b];
        set_max(ans0, N - not_intersect);
    }
    cout << ans0 << " " << ans1 << endl;
    return 0;
}

Measured memory_bytes: 5424
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    import scala.io.StdIn._
    val n = readInt()
    val hs = readLine.split(" ").map(_.toInt)

    var ans = 0
    var active = 0
    for (i <- 0 until n) {
      if (active >= hs(i)) {
        active = hs(i)
      } else {
        ans += hs(i) - active
        active = hs(i)
      }
    }

    println(ans)
  }
}


Measured memory_bytes: 27344
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  map<ll, int> mp;
  for(ll i=0; i<n; i++) mp[i-a[i]]++;

  ll ans = 0;
  for(ll i=0; i<n-1; i++){
    mp[i-a[i]]--;
    ans += mp[a[i]+i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 27288
z[75][75];s,d,t,a,*p,j;main(i){for(;scanf("%d%d",&s,&d)*d++;printf("%d\n",s)){for(memset(z,t=9,2e4);s--;)for(j=i=d;--i;a?*p>a?*p=a:0,*z[t]>*p?t=i:0:0)scanf("%d",&a),p=z[i];for(;--j;)for(s=j;--s;a?z[s][j]=z[j][s]=a:0)scanf("%d",&a);for(s=i=0;d+~i++;t=a)for(s+=*z[t],*z[t]=0,a=j=d;--j;*p&&*z[a]>*p?a=j:0)p=z[j],*p=fmin(*p,p[t]);}}

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

using namespace std;
using ll = long long;

# define var auto

int main() {
    int num,w;
    cin >> num >> w;
    vector<vector<int>> wv(num,vector<int>(2));
    ll s;
    for(var i=0;i<num;i++)
    {
        cin >> wv[i][0] >> wv[i][1];
        s+=wv[i][1];
    }
    vector<ll> dp(s+1);
    for(var i=1;i<=s;i++)
        dp[i]=1000000000000;
    for(var i=0;i<num;i++)
    {
        vector<ll> newdp(s+1);
        for(var j=0;j<=s;j++)
            if(j-wv[i][1]>=0)
                newdp[j]=min(dp[j],dp[j-wv[i][1]]+wv[i][0]);
            else newdp[j]=dp[j];
        dp=newdp;
    }
    for(var i=s;i>=0;i--)
        if(dp[i]<=w){
            cout << i << endl;
            break;
        }
    return 0;
}

Measured memory_bytes: 1792
import sys
N = int(input())
T,A = map(int,input().split())
array_hight = list(map(int,input().split()))

min = max(array_hight)
point = ''
for I in array_hight:
    if abs(A - (T - (I * 0.006))) < min:
        min = abs(A - (T - (I * 0.006)))
        point = array_hight.index(I)
print(int(point)+1)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
typedef pair<ll,ll> lp;
int main() {
  int n;
  cin >> n;
  vector<lp> p;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    p.emplace_back(b,a);
  }
  sort(rng(p));

  ll t = 0;
  for(auto it: p){
    if(t+it.se > it.fi){
      cout<<"No"<<endl;
      return 0;
    }
    t+=it.se;
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> broken(n + 1);
  rep(i, m)
  {
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(n + 2);
  const int mod = 1000000007;
  dp[n] = 1;
  for (int i = n - 1; i >= 0; i--)
  {
    if (broken[i])
    {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DEBUG
using Console = Atcoder.Helper.HelperConsole;
using AtcoderHelper = Atcoder.Helper.AtcoderHelper;
#endif

namespace Atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
#if DEBUG
            var url = @"https://atcoder.jp/contests/abc141/tasks/abc141_a";
            AtcoderHelper.RunTestCases(url);
        }
        public static void Code()
        {
#endif
            const string S = "Sunny";
            const string C = "Cloudy";
            const string R = "Rainy";
            var a = Console.ReadLine();

            if(a == S) { Console.WriteLine(C); }
            if(a == C) { Console.WriteLine(R); }
            if(a == R) { Console.WriteLine(S); }
        }
    }
}


Measured memory_bytes: 11092
n = gets.to_i
@h = gets.split.map(&:to_i)

@count = 0


def calc(s, e)
  return if @h[s..e].all?{|a| a == 0}
  min = @h[s..e].min
  (s..e).each{|i| @h[i] -= min}
  @count += min
  l = -1

  (s..e).each do |i|
    if (i == e)
      if (@h[e] != 0) && (l == -1)
        @count += @h[e]
      elsif @h[e] != 0
        calc(l, e)
      elsif l != -1
        calc(l, e - 1)
      end
    else
      if @h[i] == 0
        if l != -1
          calc(l, i - 1)
        end
        l = -1
      else
        l = l == -1 ? i : l
      end
    end
  end
end

calc(0, n - 1)

puts @count

Measured memory_bytes: 2044
a, b = map(int, input().split())
s = list(input())
ans = "Yes"

for i in range(len(s)):
    if i + 1 <= a or i - 1 >= a:
        if not s[i].isdigit():
            ans = "No"
            break
    else:
        if s[i] != "-":
            ans = "No"
            break

print(ans)


Measured memory_bytes: 2940
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()



int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for2(i,0,n) cin >> a[i];
    sort(all(a));
    cout << a[n-1] << ' ';
    int t = 0;
    b[0] = min(a[0],a[n-1]-a[0]);
    for2(i,1,n-1){
        b[i] = min(a[i],a[n-1]-a[i]);
        if(b[t] < b[i]) t = i;
    }
    cout << a[t] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int h1, m1, h2, m2;
  cin >> h1 >> m1 >> h2 >> m2;
  int k;
  cin >> k;
  int have = h2 * 60 + m2 - (h1 * 60 + m1);
  cout << max(0, have - k) << '\n';
}



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

int main(){
	int n;
  	long c=0;
  	cin >> n;
  	vector<int> a(n*3);
  	for(int i = 0;i<n*3;i++)
      	cin >>a[i];
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  	for(int i = 1; i<2*n;i+=2) {
      	c += a[i];
    }
  	
  	cout << c <<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<string, int> m;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		m[s]++;
		ans = max(ans, m[s]);
	}
	vector<string> res;
	for (auto i : m) {
		if (i.second == ans) {
			res.push_back(i.first);
		}
	}
	sort(res.begin(), res.end());
	for (auto i : res) {
		cout << i << "\n";
	}
}



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

const int N = 100005;
multiset<int> ms[N];

vector<int> con[N];
int comp;
int a[N];
bool vis[N];
void dfs(int s){
	ms[comp].insert(a[s]);
	vis[s] = 1;
	for(int v : con[s]) if(!vis[v]) dfs(v);
}

vector<int> vec;
int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= m; i++){
		int u, v;
		cin >> u >> v;
		u++; v++;
		con[u].push_back(v);
		con[v].push_back(u);
	}
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(!vis[i]){
			comp++;
			dfs(i);
			ans += *ms[comp].begin();
			ms[comp].erase(ms[comp].begin());
			for(int x : ms[comp]) vec.push_back(x);
		}
	}
	if(comp == 1){
		printf("0\n");
		return 0;
	}

	sort(vec.begin(), vec.end());
	int req = comp - 2;
	if(vec.size() < req){
		printf("Impossible\n");
		return 0;
	}
	for(int i = 0; i < req; i++) ans += vec[i];
	printf("%lld\n", ans);
}


Measured memory_bytes: 16256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int H, W;
string S[100];

int dp[100][100][2];
int solve(int y, int x, bool c){
    if(y >= H || x >= W) return 1e9;
    if(y == H-1 && x == W-1){
        if(!c && S[y][x] == '#') return 1;
        return 0;
    }
    if(dp[y][x][c] != -1) return dp[y][x][c];
    
    int ret;
    if(!c && S[y][x] == '#'){
        ret = min(solve(y+1, x, !c), solve(y, x+1, !c)) + 1;
    }
    else if(c && S[y][x] == '.'){
        ret = min(solve(y+1, x, !c), solve(y, x+1, !c));
    }
    else{
        ret = min(solve(y+1, x, c), solve(y, x+1, c));
    }
    return dp[y][x][c] = ret;
}

signed main(){
    cin >> H >> W;
    rep(i, H) cin >> S[i];
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, 0) << endl;
}

Measured memory_bytes: 384
if __name__ == '__main__':
    from sys import stdin
    from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import numpy as np
    import math
    # import random
    input = stdin.readline

    p = 1000000007

    def pow_k(x, n):
        """
        O(log n)
        """
        if n == 0:
            return 1

        K = 1
        while n > 1:
            if n % 2 != 0:
                K *= x
            x *= x
            x = x%p
            n //= 2

        return (K * x)%p

    n = int(input())
    ab_0 = 0
    a_0 = 0
    b_0 = 0
    a_div_b_dict = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            ab_0 += 1
            continue
        if a == 0:
            a_0 += 1
            continue
        if b == 0:
            b_0 += 1
            continue
        if a*b > 0:
            front = ''
        else:
            front = '-'
        ab_gcd = math.gcd(a, b)
        a = str(abs(a//ab_gcd))
        b = str(abs(b//ab_gcd))
        a_div_b_dict[front+a.zfill(19)+b.zfill(19)] += 1
    # print(a_div_b_dict)
    visited = set()
    ans = 1
    for_loop = dict(a_div_b_dict)
    for key, value in for_loop.items():
        # print(visited)
        if key in visited:
            continue
        if key[0] == '-':
            front = key[1:20]
            back = key[20:]
            inverse = back + front
            visited.add(inverse)
            num = pow_k(2, value) + pow_k(2, a_div_b_dict[inverse])-1
            ans = (ans*num)%p
        else:
            front = key[:19]
            back = key[19:]
            inverse = '-' + back + front
            visited.add(inverse)
            num = pow_k(2, value) + pow_k(2, a_div_b_dict[inverse])-1
            ans = (ans*num)%p
    ans *= (pow_k(2, a_0) + pow_k(2, b_0)-1)
    ans += ab_0
    print((ans-1)%p)



Measured memory_bytes: 93060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  if(n>=30)
    cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 3648
# Problem B - Contests

# input process
N = int(input())
A, B = map(int, input().split())
P_list = list(map(int, input().split()))

# initizaliation
combi_1 = []
combi_2 = []
combi_3 = []

# count step
for p in P_list:
    if p<=A:
        combi_1.append(p)
    elif p>=(A+1) and p<=B:
        combi_2.append(p)
    else:
        combi_3.append(p)

# output process
ans = min(len(combi_1), len(combi_2), len(combi_3))
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  ll a = 1, b = 1;
  rep(i, n) {
    ll c, d;
    cin >> c >> d;

    if (a%c == 0 && a/c * d >= b) {
      b = a/c * d;
    } else if (b%d == 0 && b/d * c >= a) {
      a = b/d * c;
    } else {
      ll x = max(a/c, b/d) + 1;
      a = c * x; 
      b = d * x; 
    }
  }
  cout << a+b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}





int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    long long H, N;
    while (cin >> H >> N) {
        vector<long long> A(N);
        long long S = 0;
        for (int i = 0; i < N; ++i) cin >> A[i], S += A[i];
        if (S >= H) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


















Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

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

	vector<int> cake(t);
	int sum = 0;
	REP(i, t) {
		scanf("%d", &cake[i]);
		sum += cake[i];
	}
	int ans = 0;
	REP(i, t) {
		if(cake[i] > (sum - cake[i]))
			ans += cake[i] - (sum - cake[i])-1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
# 全探索する

import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

P = [None] * N
for i in range(N):
  P[i] = list(map(int,readline().split()))

ans = 10 ** 18 * 4 + 1
for ix in range(N-1):
  for jx in range(ix,N):
    # X軸が決まる
    left = P[ix][0]
    right = P[jx][0]
    if left > right:
      left,right = right,left
    for iy in range(N-1):
      for jy in range(iy,N):
        up = P[iy][1]
        down = P[jy][1]
        if up < down:
          up,down = down,up
        d = abs(up - down) * abs(right - left)
        if d > ans:
          continue
        cnt = 0
        for i in range(N):
          if left <= P[i][0] <= right and down <= P[i][1] <= up:
            cnt += 1
        if cnt >= K:
          ans = d
print(ans)

Measured memory_bytes: 60380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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 main(){
  ll a, b;
  cin >> a >> b;
  ll c = a *25/ 2 ;
  bool z = true;
  for (ll i = c-1; i <= c + b; i++){
    if(i*2/25==a&&i/10==b){
      z = false;
      print(i);
      break;
    }
  }
  if(z){
    print(-1);
  }
}

Measured memory_bytes: 256