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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    int i,n,cnt=0;
    string a;
    cin>>n>>a;
    char ch='.';
    rep0(i,sz(a))
    {
        if(a[i]!=ch)
        {
            cnt++;
            ch=a[i];
        }
    }
    pf("%d",cnt);
}

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point
{
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {return Point(x + p.x, y + p.y); }
    Point operator - (Point p) {return Point(x - p.x, y - p.y); }
    Point operator * (double a) {return Point(x * a, y * a);}
    Point operator / (double a) {return Point(x / a, y / a);}

    double abs() {return sqrt(norm());}
    double norm() {return x * x + y * y;}
    
    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const{
        return equals(x, p.x) && equals(y, p.y);
    }
};typedef Point Vector;

typedef vector<Point> Polygon;

struct Segment {
    Point p1, p2;
};

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

int contains(Polygon g, Point p){
    int n = g.size();
    bool x = false;
    for (int i = 0; i < n; i++)
    {
        Point a = g[i] - p, b = g[(i+1)%n] - p;
        if (fabs(cross(a, b)) < EPS && dot(a, b) < EPS)return 1;
        if (a.y > b.y)swap(a, b);
        if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x;
    }
    return (x ? 2 : 0);
}
int main(){
    int g; cin >> g;
    Polygon G;
    for (int i = 0; i < g; i++)
    {
        int x, y; cin >> x >> y;
        Point p = Point(x, y);
        G.push_back(p);
    }
    int q; cin >> q;
    for (int i = 0; i < q; i++)
    {
        int x, y; cin >> x >> y;
        Point p = Point(x, y);
        cout << contains(G, p) << endl;
    }
    
}


Measured memory_bytes: 3096
#include <stdio.h>
#include<math.h>
int main ()
{
    int a,b,s,j=0,x,y;
    while(scanf("%d %d",&a,&b)==2)
    {
       j=0;s=b;
        do
        {
            s=s/10;
            a=a*10;
        }while(s);
        x=a+b;
        y=sqrt(x);
        if(y*y==x)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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


int main() {
    int N, M;
    std::cin >> N >> M;

    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    std::sort(A.begin(), A.end(), [](auto lhs, auto rhs) {return lhs < rhs;});

    std::vector<std::pair<int, int>> re(M, std::pair<int, int>());
    for (int i = 0; i < M; i++) {
        std::cin >> re[i].first >> re[i].second;
    }

    std::sort(re.begin(), re.end(), [](auto lhs, auto rhs) {return lhs.second > rhs.second;});

    long long int s = 0;
    int re_idx = 0;
    for (int i = 0; i < N; i++) {
        int val = A[i];
        if (re_idx < M && re[re_idx].second > val) {
            val = re[re_idx].second;
            re[re_idx].first--;
            if (re[re_idx].first == 0) {
                re_idx++;
            }
        }
        s += static_cast<long long int>(val);
    }
    std::cout << s << std::endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"
//; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

class UFT{
private:
    vector<int> par;
    vector<ll> num;
    int find(int x){ return (par[x] == x) ? x : (par[x] = find(par[x])); };
public:
    UFT(int n){ par = vector<int>(n); num = vector<ll>(n, 1); for(int i = 0; i < n; i ++) par[i] = i; };
    bool same(int x, int y){ return find(x) == find(y); };
    ll unite(int x, int y){
        if(!same(x = find(x), y = find(y))){
            par[x] = y;
            ll ret = num[x] * num[y];
            num[x] = num[y] = (num[x] + num[y]);
            return ret;
        }
        return 0;
    };
    void print() const{ for(int i = 0; i < par.size(); i ++) cout << par[i] << " "; cout << "\n"; };
};

int main(void){
    Cin(int, n, m);
    Cins2(int, m, a, b);
    
    reverse(Range(a));
    reverse(Range(b));
    
    vector<ll> c(m);
    
    UFT uft(n);
    ll ans = (ll)n*(n-1)/2;
    For(i, m){
        c[i] = ans;
        ans -= uft.unite(a[i]-1, b[i]-1);
    }
    
    reverse(Range(c));
    Couts(c);
    
}


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

int main() {
  ll h, w;
  cin >> h >> w;
  if(h%3==0 || w%3==0) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = LLONG_MAX;
  ll a = w/3 -10;
  ll b = h/2 -10;
  rep(i,20)rep(j,20) {
    ll c = a+i;
    ll d = b+j;
    if(c<=0 || d<=0) continue;
    if(c>=w || d>=h) continue;
    ll s1 = c*h;
    ll s2 = (w-c)*d;
    ll s3 = h*w - s1 - s2;
    if(s1<=0 || s2<=0 || s3<=0) continue;
    ll smax = max(s1,max(s2,s3));
    ll smin = min(s1,min(s2,s3));
    ans = min(ans,smax-smin);
  }
  ll o = h/3 -10;
  ll p = w/2 -10;
  rep(i,20)rep(j,20) {
    ll q = o+i;
    ll r = p+j;
    if(q<=0 || r<=0) continue;
    if(q>=h || r>=w) continue;
    ll s1 = q*w;
    ll s2 = (h-q)*r;
    ll s3 = h*w - s1 - s2;
    if(s1<=0 || s2<=0 || s3<=0) continue;
    ll smax = max(s1,max(s2,s3));
    ll smin = min(s1,min(s2,s3));
    ans = min(ans,smax-smin);
  }
  ans = min(ans,h);
  ans = min(ans,w);
  cout << ans << endl;
  return 0;
}

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

struct DisjointSets {
	vector <int> rank; //this array stores the rank of parent (negs) for parent nodes and the parent of each node for non parent node
	DisjointSets(int n) {
		rank = vector <int> (n, -1); //initially all are equal to -1, i.e. all are parents of themselves
	}
	int findPar(int x) { //returns the value of parent node of each node
		if (rank[x] < 0) return x; //negative rank implies that the element is a parent; return the value of parent
		return rank[x] = findPar(rank[x]); //recursively call 'find' until an element with negative rank is reached and finally assign rank[x] = the value of parent
	}
	bool unite(int x, int y) {//performs union of x and y
		x = findPar(x);
		y = findPar(y);
		if (x == y) return false; //if parents of both are equal that means both elements are in same sets; return from function
		if (rank[y] > rank [x]) swap(x, y); //x now has the higher rank; rank based union
		rank[x] += rank[y]; //x is now the parent of y; add the rank of y (i.e. the number of elements attached to y) to x
		rank[y] = x; //y is no longer a true parent; so rank[y] now has the value of x (its parent)
		return true; 	
	}

};

int main() {
	int t = 1; 
	//cin>>t;
	while (t--) {
		int n, m;
		cin>>n>>m;
		DisjointSets S(n);
		int a, b;
		for (int i = 0; i < m; i++) {
			cin>>a>>b;
			a--; b--;
			S.unite(a, b);
		}
		int ans = -(*min_element(S.rank.begin(), S.rank.end()));
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4064
t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[y+1][x+1] = L[y+1][x]+1
		if grid[y][w-x-1]==".":
			R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[y+1][x+1] = U[y][x+1]+1
		if grid[h-y-1][x]==".":
			D[h-y][x+1] = D[h-y+1][x+1]+1
a = 0
for y in range(1,h+1):
	for x in range(1,w+1):
		a = max(a, L[y][x] + R[y][x] + U[y][x] + D[y][x] -3)
print(a)

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

int main(){
    string s;
    cin >> s;
    int a, b;
    a = s.find('A');
    b = s.rfind('Z');
    cout << b - a + 1 << endl;
}
   

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s,st,nd;
    cin>>s;

    for(int i=0;i<s.size()/2;i++)
    {
        st+=s[i];
    }

    //cout<<st<<endl;

    for(int i=(s.size()/2)+1;i<s.size();i++)
    {
        nd+=s[i];
    }

    //cout<<nd<<endl;
    
    if(st==nd)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
def otoshidama():
    N, Y = map(int,input().split())
    for i in range(N + 1):
        for j in range(N - i + 1):
                if Y == 1000*i + 5000*j + 10000*(N - j - i):
                    print(N - j - i, j, i)
                    return
    print(-1,-1,-1)
    return
otoshidama()


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

using namespace std;
typedef long long ll;

int main() {
  ll n, p;
  cin >> n >> p;
  bool eflg = true;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (eflg && a[i] % 2 != 0) eflg = false;
  }

  if (eflg)
    if (p)
      cout << 0 << endl;
    else
      cout << (ll)pow(2, n) << endl;
  else
    cout << (ll)pow(2, n - 1) << endl;

  return 0;
}

Measured memory_bytes: 256
a,b=(int(x) for x in input().split())
c,d=(int(x) for x in input().split())
g=int(input())
f=b-d
if(a>=c):
    e=a-c
elif(c>a):
    e=c-a
if(f*g>=e):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int d, n;
int main() {
   cin >> d >> n;
   if (d==2 && n==100) {cout << 1010000; return 0;}
   cout << (n!=100 ? n*pow(100, d) : 101*pow(100,d));  
}

Measured memory_bytes: 3904
import sys
import itertools
sys.setrecursionlimit(10000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    l = sorted(list(map(int,input().split())))
    cnt = 0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]:
                    if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                        cnt+=1
    print(cnt) 

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};
ll mod=1e9+7;
ll dp[100010];
bool ok[100010];

int main()
{
    ll n;
    cin>>n;
    vector<ll> d(n);
    for (int i = 0; i < n; i++)
    {
        cin>>d[i];
    }
    sort(all(d));
    ll ans = d[n/2]-d[n/2-1];
    cout<<ans<<endl;
    
    return 0;
}

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

typedef long long ll;

int main() {
  int N, m = -1;
  vector<int> A;
  cin >> N;
  for (int i=0; i<N; i++) {
    int tmp;
    cin >> tmp;
    m = max(m, tmp);
    A.push_back(tmp);
  }
  sort(A.begin(), A.end());

  ll ans = N, now = 0;
  while (2 * A[now] < m) {

    ll can = A[now];
    for (int comp=now+1; comp<N; comp++) {
      if (A[comp] <= 2 * can) {
        can += A[comp];
      } else {
        ans -= (comp - now);
        A[comp] += can;
        now = comp;
        break;
      }
      if (comp == N-1) {
        now = N-1;
        break;
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

typedef long long i64;
int main() {
  i64 a, b, c, d;
  std::cin >> a >> b >> c >> d;
  i64 lcm = c / std::__gcd(c, d) * d;
  std::cout << (b - a + 1) - (b / c - (a - 1) / c + b / d - (a - 1) / d - b / lcm + (a - 1) / lcm) << std::endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  vi hand(5);
  while(1){
    vi n(3,0);
    cin>>hand[0];
    if(hand[0]==0)break;
    hand[0]--;
    n[hand[0]]++;
    rep(i,4){
      cin>>hand[1+i];
      hand[1+i]--;
      n[hand[1+i]]++;
    }
    if(n[0]&&n[1]&&n[2])
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]==5 || n[1]==5 || n[2]==5)
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]&&n[1])//gu choki                      
      rep(i,5)
        if(hand[i])cout<<"2"<<endl;
        else cout<<"1"<<endl;
    else if(n[0]&&n[2])//gu pa                         
      rep(i,5)
        if(hand[i])cout<<"1"<<endl;
        else cout<<"2"<<endl;
    else
      rep(i,5)
        if(hand[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
  }
}

Measured memory_bytes: 3088
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
b=[a[0]]
for i in range(1,n):
 b.append(b[-1]+a[i])

from collections import Counter
c= Counter(b)
k=0
for i,j in c.items():
  if i==0:
    k+=j
    if j>1:
      k+=j*(j-1)//2
  elif j>1:
    k+=j*(j-1)//2
print(k)

Measured memory_bytes: 113224
import java.util.Scanner;

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int ans = 0;

		if (a <= b) {
			ans = a;
		} else {
			ans = a - 1;
		}

		System.out.println(ans);
	}

}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) cin >> v[i];
  sort(v.begin(), v.end());

  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    v[2] *= 2;
  }
  cout << accumulate(v.begin(), v.end(), 0) << endl;
}


Measured memory_bytes: 256
def minimumLen(s, t):
    n = len(s)
    failed = [-1 for i in xrange(n)]
    pos = -1
    for i in xrange(1, n):
        while pos!=-1 and t[pos+1]!=t[i]:
            pos = failed[pos]
        if t[pos+1]==t[i]:
            pos += 1
        failed[i] = pos
    pos = -1
    for c in s:
        while pos!=-1 and t[pos+1]!=c:
            pos = failed[pos]
        if t[pos+1]==c:
            pos += 1
    return n*2-(pos+1)

def main():
    n = int(raw_input().strip())
    s = raw_input().strip()
    t = raw_input().strip()
    print minimumLen(s, t)

if __name__ == '__main__':
    main()


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

vector<ll>adj[205];
ll n;

int main()
{
    cin>>n;

    string str[n];
    for(ll i=0;i<n;i++)
    {
        cin>>str[i];
        for(ll j=0;j<n;j++)
        {
            if(str[i][j] == '1')
            {
                adj[i].push_back(j);
                adj[j].push_back(i);
            }
        }
    }

    ll ans = 0;
    for(ll i=0;i<n;i++)
    {
        vector<ll>vis(n,0);
        vector<ll>level(n+1);
        queue<pair<ll,ll>>que;
        que.push(make_pair(i,0));
        vis[i] = 1;

        ll mx_level = 0;
        while(!que.empty())
        {
            ll v = que.front().first;
            ll l = que.front().second;
            que.pop();
            level[v] = l;
            mx_level = l;

            for(auto it:adj[v])
            {
                if(vis[it]) continue;
                vis[it] = 1;
                que.push(make_pair(it,l+1));
            }
        }

        /*
        cout<<"mx : "<<mx_level<<"\n";
        for(auto it:level)
            cout<<it<<" ";
        cout<<"\n";
*/

        ll flg = 0;
        for(ll i=0;i<n;i++)
        {
            for(auto it2:adj[i])
            {
                if(level[it2] == level[i]-1 || level[it2] == level[i]+1)  continue;
                flg = 1;
                break;
            }
        }
        if(flg == 0)    ans = max(ans,mx_level+1);
    }
    if(ans == 0)    cout<<-1;
    else            cout<<ans;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  sort(d.begin(), d.end());
  int a=d[n/2-1], b=d[n/2], ans=0;
  if(a!=b){
      for(int i=a+1; i<=b; i++){
          ans++;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

using namespace std;

int main(){
    const double dTolerance = 1.0e-10;
    double x1, x2, y1, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    int q;
    scanf("%d", &q);
    
    for (int i = 0; i < q; i++){
        double x, y;
        scanf("%lf %lf", &x, &y);
        if (fabs(x1 - x2) < dTolerance) {
            printf("%.10lf %.10lf\n", 2 * x1 - x, y);
        } else if (fabs(y1 - y2) < dTolerance){
            printf("%.10lf %.10lf\n", x, 2 * y1 - y);
        } else {
            double dt = ((x2 - x1) * (x2 - x) + (y2 - y1) * (y2 - y)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            double ds = ((x2 - x1) * (x - x1) + (y2 - y1) * (y - y1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            printf("%.10lf %.10lf\n", 2 * (dt * x1 + ds * x2) - x, 2 * (dt * y1 + ds * y2) - y);
        }
    }
    return 0;
}


Measured memory_bytes: 2748
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF ((1<<30)-1+(1<<30))
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

string str;

int main()
{
	cin >> str;
	
	int ope = 0, k;
	for (int i = 0; i < str.length() - 1; i++) {
		if (str[i] == str[i + 1]) {
			ope = 1; k = i+1;
			break;
		}
		if (i != str.length() - 1) {
			if (str[i] == str[i + 2]) {
				ope = 2; k = i + 1;
				break;
			}
		}
	}
	if (ope == 1)printf("%d %d\n", k, k + 1);
	else if (ope == 2)printf("%d %d\n", k, k + 2);
	else printf("-1 -1\n");

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

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

  map<ll, ll> nums;
  ll sum = 0;

  nums[sum]++;
  for(int i = 0; i < N; i++){
    ll a;
    cin >> a;
    sum += a;
    nums[sum % M]++;
  }

  ll ans = 0;
  for(auto i : nums){
    ans += i.second * (i.second-1) / 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4224
#include <iostream>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;             //入力
  if(a+b==15){
  cout << "+" << "\n";    //出力
  }else if(a*b==15){
  cout << "*" << "\n";    //出力
  }else{
  cout << "x" << "\n";    //出力
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long int n, a, b, set,setNum, remainBall;

	scanf("%ld%ld%ld",&n, &a, &b);
	
	/* 青と赤のボールを1セットとし、n番目までに完全な形で並ぶセット数を数える */
	set = a + b;
	setNum = n / set;
	remainBall = n % set;

	/* 残りのボール数が1セット当たりの青ボール数以下なら、残りのボールはすべて青 */
	if (remainBall <= a)
	{
		printf("%ld", a * setNum + remainBall);
	}
	else
	{
		printf("%ld", a * setNum + a);
	}

	return 0;
}

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

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    Dice d = new Dice(scanner.nextInt(),scanner.nextInt(),scanner.nextInt(),scanner.nextInt(),scanner.nextInt(),scanner.nextInt());
  //  d.input();
    String ops = scanner.next();
    for(int i = 0;i<ops.length();i++){
      if(ops.charAt(i) == 'E'){
        d.E();
      }
      if(ops.charAt(i) == 'N'){
        d.N();
      }
      if(ops.charAt(i) == 'S'){
        d.S();
      }
      if(ops.charAt(i) == 'W'){
        d.W();
      }
    }
    d.PrintTop();

  }
}

class Dice{
  int top,down,right,left,up,bottom;
  int b_top,b_down,b_right,b_left,b_up,b_bottom;

  Dice(int d1,int d2,int d3,int d4,int d5,int d6){
    this.top=  d1;
    this.down =  d2;
    this.right =  d3;
    this.left =  d4;
    this.up =  d5;
    this.bottom =  d6;

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;

  }
/*
  public void input(){
    Scanner scanner = new Scanner(System.in);
    this.top=  scanner.nextInt();
    this.down =  scanner.nextInt();
    this.right =  scanner.nextInt();
    this.left =  scanner.nextInt();
    this.up =  scanner.nextInt();
    this.bottom =  scanner.nextInt();

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;
  }
  */

  public void PrintTop(){
    System.out.println(this.top);
  }

  public void E(){
    this.top = this.b_left;
    this.down =  this.b_down;
    this.right =  this.b_top;
    this.left =  this.b_bottom;
    this.up =  this.b_up;
    this.bottom =  this.b_right;

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;
  }

  public void W(){
    this.top = this.b_right;
    this.down =  this.b_down;
    this.right =  this.b_bottom;
    this.left =  this.b_top;
    this.up =  this.b_up;
    this.bottom =  this.b_left;

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;
  }

  public void N(){
    this.top = this.b_down;
    this.down =  this.b_bottom;
    this.right =  this.b_right;
    this.left =  this.b_left;
    this.up =  this.b_top;
    this.bottom =  this.b_up;

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;
  }

  public void S(){
    this.top = this.b_up;
    this.down =  this.b_top;
    this.right =  this.b_right;
    this.left =  this.b_left;
    this.up =  this.b_bottom;
    this.bottom =  this.b_down;

    this.b_top = this.top;
    this.b_down = this.down;
    this.b_right = this.right;
    this.b_left = this.left;
    this.b_up = this.up;
    this.b_bottom = this.bottom;
  }
}


Measured memory_bytes: 26336
MAXN = 10**5 + 1

# c[i]: [0,i]での素数の個数
f = [False] * (MAXN)
for i in range(2,MAXN):
    if not f[i]:
        for j in range(i+i,MAXN,i):
            f[j] = True
c = [0] * (MAXN)
for i in range(3,MAXN):
    if not f[i] and not f[(i+1)//2]:
        c[i] += 1
    c[i] += c[i-1]

Q = int(input())
for _ in range(Q):
    L,R = map(int,input().split())
    print(c[R] - c[L-1])

Measured memory_bytes: 52056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int keta = to_string(n).length();;
  int sum = 9;
  
  if(keta == 1){
    cout << n;
    return 0;
  }
  
  if( (keta % 2) == 0){
    for(int i=3;i< keta;i += 2){
      sum += pow(10,i-1) * 9;
    }
    cout << sum;
    return 0;
  }
  else{
    sum += n - (pow(10,keta-1)) + 1;
    for(int i=3;i< keta -1 ;i += 2){
      sum += pow(10,i-1) * 9;
    }
    cout << sum;
    return 0;
  }
  
}

/*
1 -> 1-9: 9
3 -> 100-999:900 
5 -> 1000-9999:9000 
7 -> 10000:
9 -> 100000
*/

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

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			var s = cin.ArrayInt(3);
			Array.Sort(s);
            Console.WriteLine(s[0]+s[1]);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
def main():
    # n = int(input())
    n, t = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    ct = []
    for _ in range(n):
        ct.append(list(map(int, input().split())))

    mini = 10**10
    for i in range(n):
        if ct[i][1] <= t and ct[i][0] < mini:
            mini = ct[i][0]

    if mini == 10**10:
        print("TLE")
    else:
        print(mini)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62592
n = int(input())
ls_a = list(map(int, input().split()))

k = 1
cnt = 0

for i in range(n):
    if ls_a[i] != k:
        cnt += 1
    elif ls_a[i] == k:
        k += 1

if k == 1:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 26140
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>
#include <unordered_map>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define map unordered_map

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
map<ll,ll> ma;
priority_queue<pll> pq;

void mainmain(){
	ll n,q;
	cin>>n>>q;
	pq.push(mkp(0,-1));
	rep(i,q){
		ll a,b;
		cin>>a>>b;
		// ma[a]+=b;
		ll c=ma[a]+=b;
		pq.push(mkp(c,-a));
		while(1){
			pii top=pq.top();
			// if(top.S==-a&&b<0&&top.F>c){
			if(ma[-top.S]!=top.F){
				pq.pop();
				continue;
			}
			else{
				cout<<-top.S<<" "<<top.F<<endl;
				break;
			}
		}
	}
}

}
main() try{
    mainmain();
}
catch(...){
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

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

	int ans=0;
	rep(i,n){
		for(int j=i+1;j<n;j++) if(a[i]<a[j]) {
			for(int k=j+1;k<n;k++) if(a[j]<a[k]) {
				if(a[i]+a[j]>a[k]) ans++;
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3800
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(1e5 + 5)], B[int(1e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i <= N; i++) scanf("%lld", A + i);
  for (int i = 0; i < N; i++) scanf("%lld", B + i);

  ll ans = 0;
  for (int i = 0; i < N; i++){
    if (B[i] < A[i]){
      ans += B[i]; A[i] -= B[i];
      B[i] = 0;
    }else{
      ans += A[i]; B[i] -= A[i];
      if (B[i] < A[i + 1]){
        ans += B[i]; A[i + 1] -= B[i];
      }else{
        ans += A[i + 1]; A[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

const int infty = 1000000007;

typedef long long ll;

ll merge(int* left, int* mid, int* right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int* L;
  L = new int[n1+1];
  int* R;
  R = new int[n2+1];
  for (auto i = 0; i < n1; i++) {
    L[i] = *(left+i);
  }
  L[n1] = infty;
  for (auto i = 0; i < n2; i++) {
    R[i] = *(mid+i);
  }
  R[n2] = infty;
  int* pl = L;
  int* pr = R;
  for (int* pk = left; pk < right; pk++) {
    if (*pl <= *pr) {
      *pk = *pl;
      pl++;
    } else {
      *pk = *pr;
      pr++;
    }
  }
  delete [] L;
  delete [] R;
  return (ll)(right-left);
}

ll merge_sort(int* left, int* right) {
  ll ans = 0;
  if (left+1 < right) {
    int* mid = left+(right-left)/2;
    ans += merge_sort(left, mid);
    ans += merge_sort(mid, right);
    ans += merge(left, mid, right);
  }
  return ans;
}

int S[500010];

int main() {
  int n;
  cin >> n;
  for (auto i = 0; i < n; i++) {
    cin >> S[i];
  }
  int ans = merge_sort(S, S+n);
  for (auto i = 0; i < n; i++) {
    cout << S[i];
    if (i == n-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6872
using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n];
            int[] y = new int[n];

            for(int i = 0; i < n; ++i)
            {
                var split = Console.ReadLine().Split(" ");
                x[i] = int.Parse(split[0]);
                y[i] = int.Parse(split[1]);
            }

            int count = 0;
            bool yes = false;
            for(int i = 0; i < n; ++i)
            {
                if(x[i] == y[i])
                {
                    count++;
                    if(count >= 3)
                    {
                        yes = true;
                        break;
                    }
                }
                else
                {
                    count = 0;
                }
            }

            Console.WriteLine(yes ? "Yes" : "No");
        }
    }
}


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

# 整数の入力
dish = []

for i in range(5):
    dish.append(int(input()))

mod_dish = [5] * -1

# dish(各々の調理時間)を10で割った余りを算出
for j in range(len(dish)):
    mod_dish.append(dish[j] % 10)

# 余りが0以上、かつ最小のものを一番最後に注文すればよさそう：一番下にもっていく
for k in range(len(dish)-1):
    if mod_dish[k] < mod_dish[k+1] or mod_dish[k+1] == 0:
        mod_dish[k],mod_dish[k+1] = mod_dish[k+1],mod_dish[k]
        dish[k],dish[k+1] = dish[k+1],dish[k]

time = 0

for l in range(len(dish)):
    if l != len(dish) -1 and mod_dish[l] != 0:
        dish[l] = dish[l] + (10 - mod_dish[l])
    
    time += dish[l]

print(str(time))


Measured memory_bytes: 3064
n, m = map(int, input().split())
h_lis = list(map(int, input().split()))
ab_lis = [list(map(int, input().split())) for _ in range(m)]
ans=[True]*n

for ab_li in ab_lis:
    #print(ab_li)
    if h_lis[ab_li[0]-1] > h_lis[ab_li[1]-1]:
        ans[ab_li[1]-1] = False
    elif h_lis[ab_li[0]-1] < h_lis[ab_li[1]-1]:
        ans[ab_li[0]-1] = False
    else:
        ans[ab_li[0]-1], ans[ab_li[1]-1] = False, False
#print(ans)
print(sum(ans))

Measured memory_bytes: 31944
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;


 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] infos = new int[1001];
    for(int i = 0; i <= 1000; i++){
      infos[i] = 0;
    }
    for(int i = 1; i <= n; i++){
      int nowcost = sc.nextInt();
      for(int j = nowcost; j <= 1000; j++){
        if(infos[j] != 0){break;}
        infos[j] = i;
      }
    }

    int[] votes = new int[n];
    for(int i = 0; i < n; i++){
      votes[i] = 0;
    }

    for(int i = 0; i < m; i++){
      votes[infos[sc.nextInt()] - 1]++;
    }

    int max = 0;
    int maxind = -1;
    for(int i = 0; i < n; i++){
      if(max < votes[i]){
        max = votes[i];
        maxind = i + 1;
      }
    }
    System.out.println(maxind);
  }
 
  
 
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;

      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }

      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

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

vector<vector<int>> G;
vector<int> indeg;  // 入次数
vector<bool> visited;
vector<int> ans;

void bfs(int s) {
  queue<int> q;
  q.push(s);
  visited.at(s) = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int nx : G.at(cur)) {
      indeg.at(nx)--;
      if (indeg.at(nx) == 0 && !visited.at(nx)) {
        visited.at(nx) = true;
        ans.at(nx) = cur + 1;  // nx の親は cur + 1
        q.push(nx);
      }
    }
  }
}

int main() {
  int N, M; cin >> N >> M;
  G.resize(N);
  indeg.resize(N);
  visited.resize(N);
  ans.resize(N);
  for (int i = 0; i < N-1+M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
  }
  for (int i = 0; i < N; i++) {
    for (int e : G.at(i)) indeg.at(e)++;
  }
  for (int i = 0; i < N; i++) {
    if (indeg.at(i) == 0 && !visited.at(i)) bfs(i);
  }
  for (int v : ans) cout << v << endl;
}

Measured memory_bytes: 9528
A,B,C,D,E,F=$<.read.split.map(&:to_i)
# A,B,C,D,E,F='6 10 24 30 1 907'.split.map(&:to_i)

ws = []
ss = []

31.times do |a|
    31.times do |b|
        ws << A*a + B*b
    end
end

ss = Array.new(31*E,false)
ss[0] = true
0.upto(31*E) do |i|
    if (0<=i-C && ss[i-C]) || (0<=i-D && ss[i-D])
        ss[i] = true
    end
end

n = 0
wmax = A
smax = 0
ws.each do |w|
    ss.each.with_index do |s,i|
        if s && 100*w + i <= F && i <= E*w
            m = i/(100*w+i).to_f
            if n < m
                wmax = w
                smax = i
                n = m
            end
        end
    end
end

puts [100*wmax+smax, smax].join(' ')


# ws = []

# ws = Array.new(30,false)
# ws[0] = true
# 1.upto(30) do |i|
#     if (0<=i-A && ws[i-A]) || (0<=i-B && ws[i-B])
#         ws[i] = true
#     end
# end

# ss = Array.new(30*E,false)
# ss[0] = true
# 0.upto(30*E) do |i|
#     if (0<=i-C && ss[i-C]) || (0<=i-D && ss[i-D])
#         ss[i] = true
#     end
# end

# n = 0
# wmax = 100*A
# smax = 0
# ws.each.with_index do |wb,i|
#     next unless wb
#     ss.each.with_index do |sb,s|
#         next unless sb
#         w = i*100
#         if w + s <= F && s <= E*w/100
#             m = s/(w+s).to_f
#             if n < m
#                 wmax = w
#                 smax = s
#                 n = m
#             end
#         end
#     end
# end

# puts [wmax+smax, smax].join(' ')

Measured memory_bytes: 14284
//Don't give up too easy bhai
#pragma GCC optimize("-O3")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define double long double
#define inf 1e18

typedef pair<int,int> pii;
 
#define forall(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define vi vector<int>
#define vd vector<double>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define br cout<<"\n"
#define whatis(x) cerr << "var "<<#x << " ==> " << x<<"\n"
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define T int __t;cin>>__t;while(__t--)

void solve()
{
    
}

signed main()
{
    fast;

    int n,m,k;cin>>n>>m>>k;
    int a[n],b[m],pa[n+1]={0},pb[m+1]={0};
    forall(i,0,n) cin>>a[i];
    forall(i,0,m) cin>>b[i];

    forall(i,0,n) pa[i+1] = pa[i] + a[i];
    forall(i,0,m) pb[i+1] = pb[i] + b[i];
    // forall(i,0,n+1) cout<<pa[i]<<" "; br;
    // forall(i,0,m+1) cout<<pb[i]<<" ";

    int ans=0,j=m;
    forall(i,0,n+1)
    {
        if(pa[i]>k) break;
        while( pb[j] > k-pa[i] ) j--;
        ans = max(ans,i+j);
    } 
    cout<<ans;


    return 0;
}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
using namespace std;
long long n, ans, a[1000000], b[1000000], x;
int main() {
	cin>>n;
	for (int i = 0; i < n+1; i++) cin>>a[i];
	for (int i = 0; i < n; i++) {
		cin>>b[i];
		ans += min(b[i],a[i]);
		if (b[i] - a[i] > 0) {
			b[i] -= a[i];
			ans += min(b[i],a[i+1]);
			if (a[i+1] > b[i]) a[i+1] -= b[i];
			else a[i+1] = 0;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 5120
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sun Dec  2 04:51:26 2018
//
package main

import (
	"fmt"
	"sort"
)

var n, m, x, y int

func main() {
	fmt.Scan(&n, &m, &x, &y)

	xs := make([]int, n)
	ys := make([]int, m)

	for i := range xs {
		fmt.Scan(&xs[i])
	}
	sort.Ints(xs)
	max := xs[len(xs)-1]

	for i := range ys {
		fmt.Scan(&ys[i])
	}
	sort.Ints(ys)
	min := ys[0]

	sort.Ints(ys)
	for i := x + 1; i <= y; i++ {
		if max < i && i <= min {
			fmt.Println("No War")
			return
		}
	}
	fmt.Println("War")
}


Measured memory_bytes: 512
N,M=map(int,input().split())
twice=(N==M)+(abs(N-M)<=1)

n=m=1
while N:
    n*=N
    n%=10**9+7
    N-=1

while M:
    m*=M
    m%=10**9+7
    M-=1

print((n*m*twice)%(10**9+7))

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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++) cin >> p.at(i);

	int ans = 0;
	for(int i = 1; i < n - 1; i++) {
		if(p.at(i) > p.at(i - 1) && p.at(i) < p.at(i + 1)) ans++;
		else if(p.at(i) < p.at(i - 1) && p.at(i) > p.at(i + 1)) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
pos=[]
for i in range(n):
  x,y,h = map(int, input().split())
  pos.append([x,y,h])

pos = sorted(pos, key=lambda x: x[2])
tx,ty,th = pos[-1]
def solve():
  for cx in range(101):
    for cy in range(101):
      H = th+abs(tx-cx)+abs(ty-cy)
      for x,y,h in pos:
        if h != max(H-abs(x-cx)-abs(y-cy), 0):
          break
      else:
        return(cx,cy,H)

cx,cy,H=solve()
print(cx,cy,H)

Measured memory_bytes: 3064
class Weight
  def initialize
    @results = []
    while weight = $stdin.gets do 
      weight = weight.chomp.to_i
      @results << to_binary(weight)
    end

    @results.each do |binary|
      puts binary_to_integer(binary.reverse).join(' ')
    end
  end

  def to_binary(val)
    array = []
    while(val > 1) do
      array << val%2
      val /= 2
    end
    array << val
    array.reverse
  end

  def binary_to_integer(array)
    result = []
    array.each_with_index do |val, index|
      result.push(2**index) if val != 0
    end
    return result
  end
end

w = Weight.new

Measured memory_bytes: 2340
#topological sort
from collections import deque,defaultdict
#n:ノードの数　m:エッジ辺の数
n,m=map(int,input().split())
#m個の有向辺　xi -> yi
edges=[tuple(map(int,input().split())) for i in range(m)]

in_cnt=defaultdict(int) #i番目のノードの入力辺の数
outs=defaultdict(list) #i番目のノードからi0,i1,i2,・・・番目のノードに辺が存在する時outs{i:[i0,i1,i2・・・]}

for out_node,in_node in edges:
    in_cnt[in_node-1]+=1
    outs[out_node-1].append(in_node-1)

topo_sort=[] #ソートされた結果を代入する
q=deque([i for i in range(n) if in_cnt[i]==0]) #入力の存在しないノードを入れる

dp=[0]*n
while q:
    v1=q.popleft()
    topo_sort.append(v1)
    for v2 in outs[v1]:
        in_cnt[v2]-=1
        dp[v2]=dp[v1]+1
        if in_cnt[v2]==0:
            q.append(v2)
print(max(dp))           


Measured memory_bytes: 55072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
        cout<<r*x-d<<endl;
        x=r*x-d;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,n,a[10000],max,min;
    long sum=0;
    scanf("%d",&n);
    for(i=0;i<=n-1;i+=1){
        scanf("%d",&a[i]);
        sum=sum+a[i];
        if(i==0){
            max=a[0];
            min=a[0]; 
        }
        else if(min>a[i]){
            min=a[i];
        }
        else if(max<a[i]){
            max=a[i];
        }
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 640