akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;
    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }
    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }
    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }
    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }
    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }
    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)


int N,K;
vector<vector<int>> to;
modint ans;
void INPUT(){
    cin>>N>>K;
    ans = K;
    to.resize(N);
    rep(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);        
    }
}

void dfs(int x, int pre = -1){
    if(pre == -1){
        int b = to[x].size();
        int c = K-1;
        ans *= C(c, b) * fact(b);//cPb
    }
    else{
        int b = to[x].size()-1;
        int c = K-2;
        ans *= C(c, b) * fact(b);
    }
    for(auto nx: to[x]){
        if(nx == pre)continue;
        dfs(nx, x);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    INPUT();
    dfs(0);
    cout<<ans<<endl;
}

Measured memory_bytes: 20992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll A,B,C,K; cin>>A>>B>>C>>K;
	if(A>K) cout<<K;
	else if(A+B>K) cout<<A;
	else cout<<A-(K-A-B);
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
	int a, b,c;
	cin >> a >> b;
	c = (a + 1) / 2;
	if (c < b)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
}

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
const long long mod = 1000000007;

int main() {
    int N;
    cin >> N;
    if(N > 194){
        cout << 5 << endl;
        ED
    }
    if(N > 188){
        cout << 4 << endl;
        ED
    }
    if(N > 164){
        cout << 3 << endl;
        ED
    }
    if(N > 134){
        cout << 2 << endl;
        ED
    }
    if(N > 104){
        cout << 1 << endl;
        ED
    }
    cout << 0 << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<long long> data(n);
  for(int i=0; i<n; i++) cin >> data[i];
  sort(data.begin(),data.end());
  
  int answer=0;
  int tmp=0;
  while(tmp<n){
    int cc=data[tmp],f=0;
    while(tmp<n && data[tmp] == cc){
      f++;
      tmp++;
    }
    answer += f%2;
  }

  cout << answer << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
 
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
 
int T,n;
ll dp[101][31];

int main(){
	while(cin >> T && T){
		rep(i,101)rep(j,31)dp[i][j] = INF;
		dp[0][0] = 0;
		vector<ll> t(T);
		rep(i,T)cin >> t[i];
		cin >> n;
		vector<ll> v(101,23);
		rep(i,n){
			ll d,M;
			cin >> d >> M;
			d--;
			v[d] = min(M,v[d]);
		}
		rep(i,100){
			rep(j,T){
				if(t[j] <= v[i])dp[i+1][(j+1)%T] = min(dp[i+1][(j+1)%T],dp[i][j]);
				dp[i+1][1%T] = min(dp[i+1][1%T],dp[i][j] + 1);
			}
		}
		ll ans = INF;
		// rep(i,md+1){
		// 	rep(j,T)cout << dp[i][j] << " ";
		// 	cout << endl;
		// }
		rep(i,T)ans = min(ans,dp[100][i]);
		cout << ans << endl;
	}
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll L[100001],R[100001];
	vpll LR;
	scan(N);
	rep(i,N){
		scan(L[i]>>R[i]);
		LR.push_back({L[i],R[i]});
	}
	sort(ALL(LR));
	ll Rml[100002],Rmr[100002],Lxl[100002],Lxr[100002];
	fill(Rml,Rml+N+1,INFl);
	fill(Rmr,Rmr+N+1,INFl);
	fill(Lxl,Lxl+N+1,0LL);
	fill(Lxr,Lxr+N+1,0LL);
	Rml[0]=LR[0].second;
	Lxl[0]=LR[0].first;
	rep1(i,N-1){
		Rml[i]=min(Rml[i-1],LR[i].second);
		Lxl[i]=max(Lxl[i-1],LR[i].first);
	}
	Rmr[N-1]=LR[N-1].second;
	Lxr[N-1]=LR[N-1].first;
	brep(i,N-1){
		Rmr[i]=min(Rmr[i+1],LR[i].second);
		Lxr[i]=max(Lxr[i+1],LR[i].first);
	}
	ll ans=0;
	rep(i,N-1){
		ll g1=max(0LL,Rml[i]-LR[i].first+1);
		ll g2=max(0LL,Rmr[i+1]-LR[N-1].first+1);
		ans=max(ans,g1+g2);
	}


	rep(i,N){
		ll lmax,rmin;
		if(i==0) lmax=Lxr[1];
		else if(i==N-1) lmax=Lxl[i-1];
		else lmax=max(Lxl[i-1],Lxr[i+1]);
		if(i==0) rmin=Rmr[1];
		else if(i==N-1) rmin=Rml[i-1];
		else rmin=min(Rml[i-1],Rmr[i+1]);
		ans=max(ans,max(0LL,rmin-lmax+1)+LR[i].second-LR[i].first+1);
	}
	prin(ans);
	return 0;
}


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

char FLIP[2][128];

std::string solve(std::string S, unsigned K) {
    unsigned N = S.size();
    unsigned steps = 0, flips = 0, i = 0;
    for (; i < N && steps < K; ++steps) {
        if (S[i] == FLIP[flips % 2]['A']) {
            S[i] = FLIP[flips % 2]['B'];
        }
        else {
            ++i;
            ++flips;
        }
    }

    if (N % 2 == 1 && i == N) {
        flips += K - steps;
    }

    std::string T(N, '\0');
    for (unsigned j = 0; j < N; ++j) {
        if (i < N) {
            T[j] = FLIP[flips % 2][S[i++]];
        }
        else {
            unsigned f = j == 0 ? flips + 1 : N - j + 1;
            T[j] = FLIP[f % 2]['A'];
        }
    }
    return T;
}

int main() {
    std::ios::sync_with_stdio(false);
    FLIP[0]['A'] = 'A';
    FLIP[0]['B'] = 'B';
    FLIP[1]['A'] = 'B';
    FLIP[1]['B'] = 'A';

    for (unsigned N, K; std::cin >> N >> K;) {
        std::string S;
        std::cin >> S;

        std::cout << solve(S, K) << '\n';
    }
}


Measured memory_bytes: 1176
/*
 *  Created on: 12-July-2020
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb push_back
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
#define PI acos(-1)
#define maxn 1000005

#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"

#define prAr(a, n) {for(int i = 0; i < n; i++) {cout<<a[i]<<" ";} cout<<"\n";}
#define inAr(a, n) for(int i = 0; i < n; i++) cin>>a[i];
#define prMat(a, n, m) {for(int i = 0; i < n; i++) {for(int j = 0; j < m; j++) {cout<<a[i][j]<<" ";} cout<<"\n";} }
#define inMat(a, n, m) {for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin>>a[i][j]; }
#define nl cout<<"\n";

using namespace std;

void solve()
{
    int n, k; cin >> n >> k;
    int a[n];
    fi (i,0,n) cin >> a[i];
    lli dp[n];
    dp[0] = 0;
    fi(i,1,n)
    {
        dp[i] = LLONG_MAX;
        fi(j,1,k+1)
        {
            if(i-j >= 0) dp[i] = min(dp[i], abs(a[i] - a[i-j]) + dp[i-j]);
        }
    }
    cout << dp[n-1];
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("/Users/administrator/Desktop/CODES/compile/testcase","r",stdin);
    // freopen("output.txt","w",stdout);
    // time_t start, end;
    int t = 1;
    // cin >> t;
    // time(&start);
    while(t--)
    {
        solve();
    }
    // time(&end);
    // double time_taken = double(end - start);
    // cerr << "Time taken by program is : " << fixed << time_taken << setprecision(5) << "seconds";
    return 0;
}


Measured memory_bytes: 4808
#include <stdio.h>

long int dp[110000][3]={0};
long int happy[110000][3];

long int max(long int a,long int b){
    if(a>b) return a;
    else return b;
}

int main(){
    int n;
    long int ans=0;
    scanf("%d", &n);
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) scanf("%ld", &happy[i][j]);

    for(int i=1;i<=n;i++) for(int j=0;j<3;j++){
        dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+happy[i-1][j];
    }
    for(int j=0;j<3;j++) if(ans<dp[n][j]) ans=dp[n][j];
    printf("%ld", ans);
    return 0;
    }


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<bool> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll x = 0;
    rep(i,n){
        x = (x^a.at(i));
    }
    rep(i,n){
        cout << ((a.at(i))^x) ;
        if(i!=n-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4748
#include  <stdio.h>

int main()
{
  long int a, b, r, LCM;
  
  
  while(scanf("%ld %ld", &a, &b) != EOF){
    
    LCM = a * b;
    
    if(a < b){
      r = a;
      a = b;
      b = r;
    }
    
    r = a % b;
    
    while(r != 0){
      a = b;
      b = r;
      r = a % b;
    }
    
    printf("%ld %ld\n", b, LCM / b);
  }
  
  return 0;
}
  

Measured memory_bytes: 1756
import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * math.cos(deg_a)
    x_a = a * math.sin(deg_a)

    y_b = b * math.cos(deg_b)
    x_b = b * math.sin(deg_b)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input().split()]
    print(solve(a, b, h, m))

Measured memory_bytes: 9452
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner userInput = new Scanner(System.in);
        int output = 0;
        for (int i = 0; i < 5; i++) {

            int findOutput = userInput.nextInt();
            if (findOutput == 0) {
                output = i + 1;
            }
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 35704
import sys
input=sys.stdin.readline

import heapq as hq

x,y,z,k=map(int,input().split())
A=list(reversed(sorted(map(int,input().split()))))
B=list(reversed(sorted(map(int,input().split()))))
C=list(reversed(sorted(map(int,input().split()))))
P=[]
hq.heapify(P)
for a in A:
    for b in B:
        hq.heappush(P,-(a+b))
Q=[]
hq.heapify(Q)
for i in range(min(x*y,3000)):
    p=-hq.heappop(P)
    for c in C:
        hq.heappush(Q,-(p+c))
for i in range(k):
    print(-hq.heappop(Q))

Measured memory_bytes: 153652
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		long[]B = new long[N];
		for(var i=0;i<N-2;i=i+2){
			B[i+2] = B[i] + (A[i+1] - A[i])*2;
		}
		B[1] = B[N-1] + (A[0] - A[N-1]) * 2;
		for(var i=1;i<N-2;i=i+2){
			B[i+2] = B[i] + (A[i+1] - A[i])*2;
		}
      	long sumA = 0;
      	long sumB = 0;
      	for(var i=0;i<N;i++){
          sumA += A[i];
          sumB += B[i];
        }
      	for(var i=0;i<N;i++){
          B[i] += (sumA-sumB)/N;
        }
		Console.Write(B[0]);
		for(var i=1;i<N;i++){
			Console.Write(" "+B[i]);
		}
	}
}

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

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}




//overflowするときは1を返す
int is_mul_overflow(long long a, long long b) {
	float mul_log;

	if (a == 0 || b == 0) {
		return 0;
	}

	mul_log = log10f(a) + log10f(b);


	if (mul_log > 18.0) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {

	int count, a[6];

	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < 5; i++) {
		if (a[i] == 0) {
			count = i+1;
		}
	}

	cout << count << endl;

	cin >> count;

	return 0;


}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
    ll a;
    cin>>a;
    ll temp = 3*a*a;
    cout<<temp;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<ctime>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}

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

int main(int argc, char **argv)
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

#ifdef LOCAL_DEFINE
   freopen("in.txt", "r", stdin);
#endif

   int n, l;
   cin >> n >> l;
   int mn = INT_MAX, ans = 0;
   for (int i = 0; i < n; ++i)
   {
      if (abs(l + i) < abs(mn))
         mn = l + i;
      ans += l + i;
   }

   cout << ans - mn << '\n';

   return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = str(input())

# もっとも左の文字に合わせるだけ。
now = S[0]
cnt = 0
encode = []

for i in range(1, N):
    if now != S[i]:
        cnt += 1
    now = S[i]

print(min(N-1, N-1 - cnt + 2 * K))


Measured memory_bytes: 3316
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int n;
ll x, sum;
ll b[125252], l[125252], u[125252];
pair<ll, int> a[125252];

bool is_ok(ll mid){
	ll k=mid/x, k2=mid%x, tmp=0;
	FORR(i, max(0ll, n-k), n){
		tmp+=a[i].first;
	}
	ll ma=0;
	FORR(i, 0, max(0ll, n-k)){
		int j=a[i].second;
		CHMAX(ma, u[j]*k2-(u[j]-l[j])*b[j]);
		CHMAX(ma, l[j]*k2);
	}
	if(tmp+ma>=sum){
		return true;
	}
	ll mi=1e12;
	FORR(i, max(0ll, n-k), n){
		int j=a[i].second;
		CHMIN(mi, u[j]*(x-k2));
		CHMIN(mi, u[j]*x-l[j]*k2-(u[j]-l[j])*b[j]);
	}
	tmp-=mi;
	if(n-k>0){
		tmp+=a[n-k-1].first;
	}
	return tmp>=sum;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	cin>>n>>x;
	REP(i, n){
		cin>>b[i]>>l[i]>>u[i];
	}
	sum=0;
	REP(i, n){
		sum+=b[i]*l[i];
	}
	REP(i, n){
		a[i]=make_pair(u[i]*x-(u[i]-l[i])*b[i], i);
	}
	sort(a, a+n);
	ll lb=-1, ub=1e12;
	while(ub-lb>1){
		ll mid=(lb+ub)/2;
		if(is_ok(mid)){
			ub=mid;
		}
		else{
			lb=mid;
		}
	}
	cout<<ub<<'\n';
	return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b, c;
    cin >> a >> b >> c;

    outYes(a <= c && c <= b);
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, k;
bool res[1111];

int main() {
    cin >> n >> k;
    rep(i, k) {
        li d;
        cin >> d;
        rep(j, d) {
            li a;
            cin >> a;
            a--;
            res[a] = true;
        }
    }
    li ans = 0;
    rin{
        if (!res[i])ans++;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3536
from itertools import combinations
import numpy as np
def main():
    N, M, X = map(int, input().split())
    books = np.array([list(map(int,input().split())) for i in range(N)])
    value = select(N, M ,X, books)
    print(value)



def select(N, M, X, books):
    kouho = []
    selected = range(0, N)
    skills = books[:, 1:]
    for i in range(N, -1, -1):
        for perm in combinations(selected, i):
            selected_skills = skills[list(perm)]
            s = selected_skills.sum(axis=0)
            if len(s[s<X]) > 0:
                continue
            else:
                kouho.append(perm)
    if len(kouho) == 0:
        return -1
    value = min([sum([books[i][0] for i in k]) for k in kouho])
    return value


if __name__ == '__main__':
    perm = main()
    

Measured memory_bytes: 27712
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

int32_t main(){_
   
   cin>>n;

   int ans = (n/500) * 1000 + ((n%500)/5) * 5;

   cout<<ans;
   

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){
  int num,square,N;
  cin >> N;
  square = 0;
  vector<int> sum(N);
  for(int i = 0; i < N; i++){
    cin >> sum.at(i);
  }
  for(int j = 0; j < N; j++){
    num = num + sum.at(j);
    square = square + (sum.at(j) * sum.at(j));
  }
  cout << (num * num - square) / 2;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc143/tasks/abc143_e
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int INF = 1e9 + 5;

template <typename T> using Matrix = vector<vector<T>>;
template <typename T> void warshall_floyd(Matrix<T> &g, T INF) {
    REP(k, g.size()) REP(i, g.size()) REP(j, g.size()) {
        if (g[i][k] == INF || g[k][j] == INF)
            continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, L, Q;
    cin >> N >> M >> L;
    Matrix<int> g(N + 1, vector<int>(N + 1, INF));
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a][b] = g[b][a] = c;
    }
    warshall_floyd(g, INF);
    REP(i, g.size())
    REP(j, g.size()) g[i][j] = (g[i][j] <= L ? 1 : INF);
    warshall_floyd(g, INF);
    cin >> Q;
    REP(i, Q) {
        int a, b;
        cin >> a >> b;
        cout << (g[a][b] == INF ? -1 : g[a][b] - 1) << "\n";
    }

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    if(a + b == 15 || a * b == 15){
        if(a + b == 15)cout << '+' << endl;
        if(a * b == 15)cout << '*' << endl;
    }else{
        cout << 'x' << endl;
    }
}


Measured memory_bytes: 256
MAX_PRIME = 10 ** 6
is_prime = [1] * MAX_PRIME
primes = []
is_prime[0] = 0
is_prime[1] = 0
for i in range(MAX_PRIME):
    if is_prime[i]:
        primes.append(i)
        for j in range(2, ((MAX_PRIME-1)//i) + 1):
            is_prime[i*j] = 0

def factorization(n):
    factor = {}
    for p in primes:
        if p ** 2 > n:
            break
        while n % p == 0:
            n //= p
            if p not in factor:
                factor[p] = 1
            else:
                factor[p] += 1
    if n > 1:
        factor[n] = 1
    return factor

n = int(input())
ans = 1
for _, c in factorization(n-1).items():
    ans *= c + 1

f = factorization(n)
k = list(f.keys())
def dfs(num, i):
    ret = 0
    if i == len(k):
        if num != 1:
            x = n
            while x % num == 0:
                x //= num
            if x % num == 1:
                ret += 1
        return ret
    else:
        p = k[i]
        for j in range(f[p]+1):
            ret += dfs(num * p ** j, i+1)
        return ret

print(dfs(1, 0) + ans - 1)

Measured memory_bytes: 14020
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	int k;
	cin >> k;
	vector<ll>a(k + 1);
	rep(i, k) cin >> a[i + 1];
	vector<ll>nl(k + 1, 0), nr(k + 1, 0);
	nl[k] = nr[k] = 2;
	for (int i = k - 1; i >= 0; i--) {
		nl[i] = a[i + 1] * ((nl[i + 1] + a[i + 1] - 1) / a[i + 1]);
		nr[i] = a[i + 1] * ((nr[i + 1] + a[i + 1] ) / a[i + 1]) - 1;
	}
	if (nl[0] > nr[0]) cout << -1 << endl;
	else cout << nl[0] << " " << nr[0];



	return 0;
}





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

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (ll)n; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int n, h, w;
    cin >> n >> h >> w;
    vector<pair<int, int>> v(n);
    rep(i, n) cin >> v[i].first >> v[i].second;
    int ans = 0;
    rep(i, n) if (h <= v[i].first && w <= v[i].second) ans++;
    cout << ans << endl;
}

int main(void)
{
    solve();
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
 
int main() {
    double a, b, x, ans = 0, c;
    cin >> a >> b >> x;
    map<long, int>cnt;
    if ((a * a * b) / 2 >= x){
        cout << 57.295779513 * atan(b / ((2 * x) / (b * a))) << endl;
    }else{
        cout << 57.295779513 * atan((2 * a * a * b - 2 * x)/ (a * a * a)) << endl;
    }
}

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=1e6+10;

int n;
map <ll,int> mp;
ll D[maxn];
pair<ll,int> d[maxn];
int sz[maxn];
ll f[maxn];
vector <int> e[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		ll x;
		scanf("%lld",&x);
		d[i]=MP(x,i);
		mp[x]=i;
		D[i]=x;
	}
	sort(d+1,d+n+1);
	reverse(d+1,d+n+1);
	memset(sz,0,sizeof(sz));
	memset(f,0,sizeof(f));
	for (int i=1;i<n;i++) {
		sz[d[i].se]++;
/*		if (n-2*sz[i]<=0) {
			puts("-1");
			return 0;
		}
*/		ll want=d[i].fi-(ll)(n-2*sz[d[i].se]);
		if (mp.find(want)==mp.end()) {
			puts("-1");
			return 0;
		}
		e[d[i].se].pb(mp[want]);
		e[mp[want]].pb(d[i].se);
		sz[mp[want]]+=sz[d[i].se];
		f[mp[want]]+=(ll)sz[d[i].se]+f[d[i].se];
	}
	if (f[d[n].se]!=D[d[n].se]) {
		puts("-1");
		return 0;
	}
	for (int i=1;i<=n;i++)
		for (int j=0;j<e[i].size();j++) {
			if (e[i][j]>i) printf("%d %d\n",i,e[i][j]);
		}
	return 0;
}


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

int main(){
  int x;
  cin >> x;
  int ans = 1;
  for (int b = 2; b <= x; b++) {
    int power = b * b;
    for (int p = 2; ; p++) {
      if (power > x) break;
      ans = max(ans, power);
      power *= b;
    }
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define All(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
#define Graph vector<vector<int>>
using namespace std;

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

        vl a(n);
        rep(i,n)cin>>a[i];

        vl wa(n+1,0);
        rep(i,n)wa[i+1]=wa[i]+a[i];

        vl mod(n+1);
        rep(i,n+1)mod[i]=wa[i]%m;

        map<long,long> M;
        rep(i,n+1)M[mod[i]]++;
        
        long ans=0;
        each(it,M)ans+=it.second*(it.second-1)/2;
        cout<<ans<<endl;
}

Measured memory_bytes: 6528
use std::cmp::{max, min};

use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let s = read::<String>();

  let mut answer1 = 0;
  let mut answer2 = 0;

  for (i, v) in s.chars().enumerate() {
    if i % 2 == 0 {
      if v != '0' {
        answer1 += 1;
      }
      if v != '1' {
        answer2 += 1;
      }
    } else {
      if v != '1' {
        answer1 += 1;
      }
      if v != '0' {
        answer2 += 1;
      }
    }

  }

  println!("{}", min(answer1, answer2));
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> data(6);
  int judge =0 ;
  for (int i = 0; i < 3; i++) {
    cin >> data.at(i);
  }
  
  
  for(int k = 1; k<= data.at(2) ; k++){
    if(k%data.at(0) == 0){
    judge += data.at(1);
    }
  }
  
      cout << judge << endl;
  
  
  
}


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

int main() {
  int n,m; cin >> n >> m;
  vector<int> l(m),r(m);
  rep(i, m) {
    cin >> l[i] >> r[i];
  }
  if (m == 1) {
    cout << r[0] - l[0] + 1 << endl;
    return 0;
  }
  int now_l = max(l[0], l[1]);
  int now_r = min(r[0], r[1]);
  for (int i=2; i<m; i++) {
    now_l = max(now_l, l[i]);
    now_r = min(now_r, r[i]);
  }
  cout << max(now_r - now_l + 1, 0) << endl;
}

Measured memory_bytes: 1024
n=gets.to_i
all=[]
flag=[]
n.times.each do
    v=gets.split.map(&:to_i)
    all<<v
    if v[0]==v[1]
    flag<<1
    else
    flag<<0
    end
    
end

for i in 1..flag.length-2
    if flag[i-1]==1 && flag[i]==1 && flag[i+1]==1
        puts "Yes"
        exit
    end
    
end
puts "No"


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX=(int)1e5;
vector<int> B(NMAX+2, 0);

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  vector<int> a(N);
  int b = 0;
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
    if(a[i] == 0) b++, B[1]++, B[0]++;
    else {
      B[a[i]-1]++;
      B[a[i]]++;
      B[a[i]+1]++;
    }
  }
  sort(B.begin(),B.end(), greater<int>());
  cout << max(B[0], b) << endl;

  return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += B[A[i] - 1]
    if i < N - 1 and A[i] + 1 == A[i + 1]:
        ans += C[A[i] - 1]
        
print(ans)


Measured memory_bytes: 38384
S = input()
a = S[0]

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
def start(x,s,f):
  # x 以降での最初の出発時刻
  if x <= s:
    return s
  return (x+f-1)//f*f

N = int(input())
CSF = [[int(x) for x in input().split()] for _ in range(N-1)]

def F(i):
  x = 0
  for c,s,f in CSF[i:]:
    x = start(x,s,f)
    x += c
  return x

for i in range(N):
  print(F(i))

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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int t = sc.NextInt();

        Console.WriteLine((int)((t + 0.5) / a) * b);
    }
}

class UnionFindTree
{
    private int[] p;
    private int[] d;

    public UnionFindTree(int size)
    {
        p = new int[size];
        d = new int[size];
        for (int i = 0; i < size; i++) p[i] = i;
    }

    public int Find(int x)
    {
        if (p[x] == x) return x;
        return p[x] = Find(p[x]);
    }

    public void Unite(int x, int y)
    {
        int px = Find(x);
        int py = Find(y);
        if (px == py) return;

        if (d[px] < d[py])
        {
            p[px] = py;
        }
        else
        {
            p[py] = px;
            if (d[px] == d[py]) d[px]++;
        }
    }

    public bool Same(int x, int y)
    {
        return Find(x) == Find(y);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main(){
	for (int i = 0; i < 90000; ++i)
	{
		int a,b;
		cin >> a >> b;
		if(a==0){
			break;
		}
		else{
		for (int j = 0; j < a; ++j)
		{
				if(j%2==0){
					for (int k = 0; k < b; ++k)
					{
						if (k%2==0)
						{
							cout << "#";
						}
						else{
							cout << ".";
						}
				}
			}
				else{
					for (int k = 0; k < b; ++k)
					{
						if(k%2==0){
							cout << "." ;
						}
						else{
							cout << "#" ;
						}
						
					}
				}
				cout << "\n";
				
			}
			
		}
		cout << "\n" ;
	}
	

}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n;
  cin >> n;

  vector<int> a(n);
  for(int i=0;i<n;++i){
    cin >> a[i];
  }

  int cnt = 0;
  int kk = 1;
  for(int i=0;i<n;++i){
    if(a[i]==kk){
      kk++;
      cnt++;
    }
  }

  if(kk==1) cout << -1 << "\n";
  else cout << n-cnt << "\n";
	 
  return 0;
}


Measured memory_bytes: 1024
n, x = [int(x) for x in input().split()]
children = [int(x) for x in input().split()]
children.sort()
for i, child in enumerate(children):
    if x < child or (i==len(children)-1 and x!=child):
        print(i)
        break
    else:
        x -= child
else:
    print(len(children))

Measured memory_bytes: 3060
#include <stdio.h>
#include <utility>
#include <vector>
#include <queue>
using namespace std;

typedef long long int ll;
constexpr int kN = int(1E5 + 10), kM = int(5E5 + 10);
constexpr ll kInf = ll(1E16 + 10);

#define F first
#define S second
#define PB push_back

struct Edge {
	int to, cost;
};

vector<Edge> graph[kN];
ll dis[kN];

int main() {
	int n, m, s, l, r, c;
	pair<ll, int> nxt;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	scanf("%d%d%d", &n, &m, &s);
	while (m--) {
		scanf("%d%d%d", &l, &r, &c);
		graph[l].PB({r, c});
	}
	
	for (int i = 0; i < n; i++) dis[i] = kInf;
	dis[s] = 0;
	pq.push({0, s});
	while (!pq.empty()) {
		nxt = pq.top();
		pq.pop();
		if (nxt.F > dis[nxt.S]) continue;
		for (Edge i : graph[nxt.S]) if (dis[nxt.S] + i.cost < dis[i.to]) {
			dis[i.to] = dis[nxt.S] + i.cost;
			pq.push({dis[i.to], i.to});
		}
	}
	for (int i = 0; i < n; i++) if (dis[i] == kInf) printf("INF\n");
	else printf("%lld\n", dis[i]);
}



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

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double radi = PI*2*(h/12.0 + m/60.0/12.0 - m/60.0);
  double rsq = (a*a + b*b) - (2*a*b) * cos(radi);
  printf("%.10f\n", sqrt(rsq));
  return 0;
}

Measured memory_bytes: 4176
n = int(input())
li = list(map(int,input().split()))
a = 1
if 0 in li:
    print(0)
else:
    li = sorted(li, reverse=True)
    for i in li:
        if a >= 10**18+1:
            break
        else:
            a *= i
    if a >= 10**18 + 1:
        print('-1')
    else:
        print(a)

Measured memory_bytes: 84556
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int a[1000005];
unordered_map<int, int> mp;
int num[1000010];
int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    int n;
    cin >> n;

    //bool cjs = false;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        //if(a[i] == 1) cjs = true;
        mp[a[i]] = 1;
        num[a[i]]++;
    }
//    if(cjs) {
//        puts("not coprime");
//        exit(0);
//    }
    bool dyh = false;
    for(int i = 2; i < 1000005; i++){
        bool flag = false;
        for(int j = 1; i * j < 1000010; j++){
            if(mp[i * j] == 1 and num[i * j] > 1) {
                dyh = true;
                break;
            }
            if(mp[i * j] == 1 and flag) {
                dyh = true;
                break;
            }
            if(mp[i * j] == 1 and !flag) flag = true;
        }
    }
    if(dyh){
        int tmp = a[0];
        for(int i = 1; i < n; i++){
            tmp = __gcd(tmp, a[i]);
        }
        if(tmp == 1){
            puts("setwise coprime");
        }else puts("not coprime");
    }
    else {
        puts("pairwise coprime");
    }
    return 0;
}

Measured memory_bytes: 50384
a = list(input())
b = list(input())
c = list(input())
a.append("null")
b.append("null")
c.append("null")
cmp=a.pop(0)
while cmp!="null":
    if cmp=="a":
        cmp=a.pop(0)
    if cmp=="b":
        cmp=b.pop(0)
    if cmp=="c":
        cmp=c.pop(0)
if len(a)==0: print("A")
elif len(b)==0: print("B")
elif len(c)==0: print("C")

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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> v;
    v.resize(n+1);
    for(int i=2; i<=n; i++)
    {
        int a;
        cin >> a;
        v[a].PB(i);
    }

    for(int i=1; i<=n; i++)
    {
        cout << v[i].size() << "\n";
    }
    return 0;
}


Measured memory_bytes: 14216
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int N=sc.nextInt(),X=sc.nextInt(),T=sc.nextInt(),res=0;
        res+=(N/X)*T;
        if(N%X!=0){
            res+=T;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 35728
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0) return ;
			int ans=0;
			for(int i=0; i<n/4; i++){
				ans += in.nextInt();
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

mat Mult(mat A,mat B){
  assert(A[0].size() == B.size());
  int n = A.size(),m = B.size(),l = B[0].size();
  mat C(A.size(),vec(B[0].size(),0));

  for(int i=0;i<n;i++)
    for(int j=0;j<l;j++)
      for(int k=0;k<m;k++) C[i][j]+=(A[i][k]*B[k][j]);
 
  return C;
}

signed main(){
  int n,m,l;
  cin>>n>>m>>l;
  mat A(n,vec(m)),B(m,vec(l));
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin>>A[i][j];
  
  for(int i=0;i<m;i++)
    for(int j=0;j<l;j++) cin>>B[i][j];

  mat C = Mult(A,B);
  for(int i=0;i<C.size();i++){
    for(int j=0;j<C[0].size();j++){
      if(j)cout<<" ";
      cout<<C[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3304
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
    val out = PrintWriter(System.out)
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val m = sc.nextLong()
    val py = mutableListOf<City113>()
    (0 until m).forEach { i ->
        py.add(City113(i, sc.next().toInt(), sc.next().toLong()))
    }
    problem113c(n, m, py, out)
}

fun problem113c(
    n: Long,
    m: Long,
    py: MutableList<City113>,
    out: PrintWriter
) {
    var current = 0
    var count = 0
    py.sorted().forEachIndexed { i, city ->
        if (current != city.p) {
            count = 0
            current = city.p
        }
        count++
        var ps = current.toString()
        while (ps.length < 6) {
            ps = "0$ps"
        }
        var cs = count.toString()
        while (cs.length < 6) {
            cs = "0$cs"
        }
        city.ans = ps + cs
    }
    py.sortedBy { it.city }.forEach { println(it.ans) }
    out.flush()
}

class City113(val city: Long, val p: Int, val y: Long, var ans: String = "") : Comparable<City113> {
    override fun compareTo(other: City113): Int {
        val diff = this.p - other.p
        if (diff != 0) return diff
        return (this.y - other.y).toInt()
    }
}

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

long long int func(int n)
{
    if( n == 1 ) return 1;
    else return (func(n-1) * n) % 1000000007;
}

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

    int ans = (int)func(N);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
      static List<int> L = new List<int>();
      static List<int> R = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      Read5();
result=R.Min()-L.Max()+1;
      if(R.Min()<L.Max()){result=0;}
                    Console.WriteLine(result.ToString());     
    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {
for(int i=0;i<K;i++){
        string[] tmp = Console.ReadLine().Split(' ');
L.Add(int.Parse(tmp[0]));
  R.Add(int.Parse(tmp[1]));
}
    }


}

Measured memory_bytes: 19272