akhauriyash/Code-Regression huggingface dataset:
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int ret = -1;

    if (N != 100) {
        ret = N;
    } else {
        ret = 101;
    }

    ret *= pow(100, D);

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner stdIn = new Scanner(System.in);
	int n, data, i, j, t1, t2;
	int[] t = new int[8];
	int[] max = new int[8];
	int[] min = new int[8];

	n = stdIn.nextInt();
	while (n-- > 0) {
	    t1 = 0;
	    t2 = 0;
	    data = stdIn.nextInt();
	    for (i = 0; i < 8; i++) {
		t[7-i] = data % 10;
		data /= 10;
	    }
	    arrayCopy(t, max);
	    arrayCopy(t, min);

	    sortMax(max);
	    sortMin(min);

	    j = 0;
	    for (i = 10000000; i > 0; i /= 10)
		t1 += max[j++] * i;

	    j = 0;
	    for (i = 10000000; i > 0; i /= 10)
		t2 += min[j++] * i;
	    
	    System.out.print(t1 - t2);
	    System.out.println();

	}
	
    }

    public static void arrayCopy(int[] a, int[] b) {
	int i;
	for (i = 0; i < 8; i++) {
	    b[i] = a[i];
	}
    }

    public static void sortMax(int[] a) {
	int i, j, t;
	for (i = 0; i < 8; i++) 
	    for (j = 7; j > i; j--) 
		if (a[j] > a[j-1]) {
		    t = a[j];
		    a[j] = a[j-1];
		    a[j-1] = t;
		}
    }

    public static void sortMin(int[] a) {
	int i, j, t;
	for (i = 0; i < 8; i++) 
	    for (j = 7; j > i; j--) 
		if (a[j] < a[j-1]) {
		    t = a[j];
		    a[j] = a[j-1];
		    a[j-1] = t;
		}
    }
}

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

using namespace std;

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

    vector< vector< long long int > > rates;
    long long int i;

    for(i=0; i<n; i++){
        long long int rate, can;
        cin >> rate >> can ;
        vector<long long int> shop;
        shop.push_back(rate);
        shop.push_back(can);
        rates.push_back(shop);
    }

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

    /*for(i=0; i<n; i++){
        cout << rates[i][0]<< " " << rates[i][1] << endl;
    }*/
    long long int bought =0, cost = 0;
    i = 0;
    while(bought < m){
        long long int dif = m - bought;
        if(rates[i][1] > dif){
            bought += dif;
            cost += dif*rates[i][0];
        } else {
            bought += rates[i][1];
            cost += rates[i][1]*rates[i][0];
            i++;
        }
    }
    cout << cost << endl;
}



Measured memory_bytes: 8684
#include <stdio.h>
int main(){
  int n,x,k,counter;
  while(1){
    scanf("%d %d",&n,&x);
    counter=0;
    if(n==0 && x==0)break;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	for(int k=1;k<=n;k++){
	  if(i+k+j==x && i!=j && j!=k && k!=i)counter++;
	}
      }
    }
    printf("%d\n",counter/6);
  }
  
}



Measured memory_bytes: 1984
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      
        if(a<1200){
        System.out.println("ABC");
        }else if(a>2799){
           System.out.println("AGC");
        }else{
           System.out.println("ARC");
        }
     
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100001],b[100001];
int main()
{
	int n,h;
	cin>>n>>h;
	long long sum=0,num=0,max1=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		max1=max(max1,a[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(b[i]>=max1)
		{
			sum+=b[i];
			num++;
		} 
	}
	if(sum>=h)
	{
		sort(b,b+n);
		int i=0;
		while(sum-b[i]>=h)
		{
			if(b[i]>=max1)
			{
				num--;
		     	sum-=b[i];
			} 
			i++;
		}
		cout<<num<<endl;
		return 0;
	}
	else
	{
		while(sum<h)
		{
			if(h-max1*100000>sum)
			{
				h-=max1*100000;
			    num+=100000;
			}
			else
			{
				h-=max1;
				num++;
			}
		}
		cout<<num<<endl;
		return 0;
	}
}


Measured memory_bytes: 1792
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

lst = [a, b, c, d, e]
cnt = 0

for i in range(0, 4):
    for j in range(i, 5):
        if (lst[j] - lst[i]) > k:
            cnt += 1

print(":(") if cnt > 0 else print("Yay!")

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

int main() {
    unsigned long int X;
    unsigned int happy = 0;
    cin >> X;
    while(X >= 500) {
        X -= 500;
        happy += 1000;
    }
    while(X>=5) {
        X -= 5;
        happy += 5;
    }
    cout << happy;
}

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

template<class c> auto try_out(c a) -> decltype(cerr << a, 0);
char try_out(...);

struct debug {
#ifdef LOCAL
template<class c, class d> debug& operator << (pair<c, d> e) {
	return *this << "(" << e.first << ", " << e.second << ")";
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) != 1, debug&>::type operator << (c a) {
	cerr << boolalpha << a;
	return *this;
}
template<class c> typename enable_if<sizeof(try_out(declval<c>())) == 1, debug&>::type operator << (c a) {
	*this << "[";
	for (auto it = a.begin(); it != a.end(); ++it)
		*this << ","[1 - (it != a.begin())] << *it;
	return *this << "]";
}
#else
template<class c> debug& operator << (c) {
	return *this;
}
#endif
};

#define aty(x) " [" << #x ": " << x << "] "

using ll = long long;






int main() {
	
	int a, b;
    cin >> a >> b;
    
    int ans = 0;
    
    if (a > b) {
        ans += a;
        a--;
    }
    else {
        ans += b;
        b--;
    }
    
    if (a > b) {
        ans += a;
    }
    else {
        ans += b;
    }
    
    
    cout << ans;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

queue<vector<ll>> q;
vi color;
vector<vector<pair<int, int>>> node;

int main(){
    ll N;
    cin >> N;
    rep(i, N){
        color.emplace_back(-1);
        node.emplace_back(vector<pair<int, int>>(0));
    }
    vll u(N-1), v(N-1), w(N-1);
    rep(i, N-1){
        cin >> u[i] >> v[i] >> w[i];
        node[u[i]-1].emplace_back(v[i]-1, w[i]);
        node[v[i]-1].emplace_back(u[i]-1, w[i]);
    }
    q.push({0, 0});
    color[0] = 0;
    while (!q.empty()){
        vll qf = q.front();
        color[qf[1]] = qf[0] % 2;
        rep(i, SZ(node[qf[1]])){
            if(color[node[qf[1]][i].first] != -1) continue;
            q.push({qf[0]+node[qf[1]][i].second, node[qf[1]][i].first});
        }
        q.pop();
    }
    rep(i, N){
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 9780
#include<iostream>
#include<string>
#include<vector>

int h,w,n,sr,sc;

std::string S,T;

std::vector<int> R,L,U,D;

int main(){

    std::cin>>h>>w>>n>>sr>>sc>>S>>T;

    for(int i=0;i<n;i++){
        if(S[i]=='R')R.push_back(1);
        if(T[i]=='L')R.push_back(-1);
        if(S[i]=='L')L.push_back(1);
        if(T[i]=='R')L.push_back(-1);
        if(S[i]=='U')U.push_back(1);
        if(T[i]=='D')U.push_back(-1);
        if(S[i]=='D')D.push_back(1);
        if(T[i]=='U')D.push_back(-1);
    }
    int p;
    bool res=false;

    p=sc;
    for(auto&& x:R){
        if(x==-1&&1<p)p--;
        if(x==1)p++;
        if(w<p){
            res=true;
            goto goal;
        }
    }
    p=sc;
    for(auto&& x:L){
        if(x==-1&&p<w)p++;
        if(x==1)p--;
        if(p<1){
            res=true;
            goto goal;
        }
    }
    p=sr;
    for(auto&& x:U){
        if(x==-1&&p<h)p++;
        if(x==1)p--;
        if(p<1){
            res=true;
            goto goal;
        }
    }
    p=sr;
    for(auto&& x:D){
        if(x==-1&&1<p)p--;
        if(x==1)p++;
        if(h<p){
            res=true;
            goto goal;
        }
    }

    goal:;

    if(res==true)
    std::cout<<"NO"<<std::endl;
    else
    std::cout<<"YES"<<std::endl;
    

    return 0;
}

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

using namespace std;


int main () {

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

  
  if( a < b ) cout <<"a < b"<<endl;
  if( a > b ) cout <<"a > b"<<endl;
  if( a == b ) cout <<"a == b"<<endl;


  return 0;
}



Measured memory_bytes: 3080
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<tuple>
#include<algorithm>
using namespace std;
const int BASE=3;

char s[30];
vector<tuple<int,int,int>> Edge;

int main()
{
    int L;
    scanf("%d",&L);
    for(int i=0;L;i++)
    {
        s[i]=L%BASE+'0';
        L/=BASE;
    }
    int n=strlen(s);
    reverse(s,s+n);
    for(int i=3;i<=n+1;i++)
        for(int j=0;j<BASE;j++)
            Edge.push_back(make_tuple(i-1,i,j*pow(BASE,(n+1)-i)));
    int sum=0;
    for(int i=0;s[i];i++)
    {
        for(int j=0;j<s[i]-'0';j++)
            Edge.push_back(make_tuple(1,i+2,sum+j*pow(BASE,n-i-1)));
        sum+=(s[i]-'0')*pow(BASE,n-i-1);
    }
    printf("%d %u\n",n+1,Edge.size());
    for(auto u:Edge)
        printf("%d %d %d\n",get<0>(u),get<1>(u),get<2>(u));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

class UnionFind {
public:
	//sizeはマイナス値(ex: -2 なら　2)で管理
	//値がマイナスのときそのインデックスは根
	//値が0以上ならその値は親を指す
	vector<int> par;
	UnionFind(int N) {
		par = vector<int>(N,-1);
	}
	
	int root(int A){
		if(par[A]<0)return A;
		return par[A] = root(par[A]);
	}

	int size(int A){
		return -par[root(A)];
	}

	bool connect(int A, int B){
		A = root(A);
		B = root(B);
		if(A==B)return false;
		if(size(A) < size(B)) swap(A,B);
		par[A] += par[B];
		par[B] = A;
		return true;
	}
};

int main() {
	int N,M;cin>>N>>M;
	vector<int> A(M), B(M);
	rep(i,M){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
	}
	vector<ll> ans(M);
	ans[M-1] = (ll)N*(N-1)/2;
	UnionFind Uni(N);
	for(int i = M-1;i>0;i--){
		ans[i-1] = ans[i];
		if(Uni.root(A[i]) != Uni.root(B[i])){
			ans[i-1] -= (ll)Uni.size(A[i])*Uni.size(B[i]);
			Uni.connect(A[i],B[i]);
		}
	}
	rep(i,M) cout << ans[i] << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int MOD = 1000000007, MAX = 2000000007, MAXN = 100005;

ll sumtilln(ll n)
{
    if(n == -1)
        return 0;
    else
        return (n*(n+1))/2;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(ll i=k; i<=n+1; i++)
    {
        ll lowest = sumtilln(i-1), highest = sumtilln(n) - sumtilln(n-i);
        lowest%=MOD;
        highest%=MOD;
        //cout<<i<<' '<<lowest<<' '<<highest<<endl;
        ans+=(highest+MOD-lowest+1);
        ans%=MOD;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 3652
import sun.security.x509.EDIPartyName;

import java.io.*;
import java.util.*;

public class Main {

    static long N;
    static long X;

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

        N = sc.nextLong();
        X = sc.nextLong();

        System.out.println( solve() );
    }

    static long solve() {
        long ans = N;
        long a = X;
        long b = N-X;

        if( a < b ) {
            long t = a;
            a = b;
            b = t;
        }
        while(true) {
            long q = a / b;
            long r = a % b;

            if( r == 0 ) {
                ans += (q * 2 * b) - b;
                break;

            } else {
                ans += b * 2 * q;
                a = b;
                b = r;
            }
        }
        return ans;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

double eps = 1e-10;

class Point {
public:
	double x, y;
	
	Point(double x = 0, double y = 0) : x(x), y(y) {}
	
	Point operator + (const Point& p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (const Point& p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (const double& a) {
		return Point(x * a, y * a);
	}
	Point operator / (const double& a) {
		return Point(x / a, y / a);
	}
	
	bool operator < (const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point& p) const {
		return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
	}
	
	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}
	
};

typedef Point Vector;

// ????????????
bool equals(const double& a, const double& b) {
	return fabs(a - b) < eps;
}

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

// ??´?????????(????????????)
bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}

// ??´?????????(???4???)
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1 - b2);
}

int main() {
	double x1, x2, x3, x4, y1, y2, y3, y4;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4){
		if(isOrthogonal(Point(x1, y1), Point(x2, y2), Point(x3, y3), Point(x4, y4))){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, c;
	cin >> n >> c;
	vector<vector<int>> d(c, vector<int>(c));
	for(int i = 0; i < c; i++) {
		for(int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}
	vector<vector<int>> a(c, vector<int>(3));
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			int t;
			cin >> t;
			t--;
			a[t][(i + j) % 3]++;
		}
	}
	long long ans = LLONG_MAX;
	for(int i = 0; i < c; i++) {
		for(int j = 0; j < c; j++) {
			for(int k = 0; k < c; k++) {
				if(i == j || j == k || k == i) {
					continue;
				}
				long long sum = 0;
				for(int l = 0; l < c; l++) {
					sum += d[l][i] * a[l][0];
					sum += d[l][j] * a[l][1];
					sum += d[l][k] * a[l][2];
				}
				ans = min(ans, sum);
			}
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000
#define norm 0
#define mod 1000000007
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
bool comp(pair<ll,ll>&a,pair<ll,ll>&b)
{
    return a.second<b.second;
}
int main()
{
    IO
   int n;
    cin>>n;
    vector<pair<ll,ll>>vec;
    ll a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        vec.push_back({a,b});
    }
sort(vec.begin(),vec.end(),comp);
    ll cur=0;
    for(int i=0;i<n;i++)
    {
        if(cur+vec[i].first<=vec[i].second)
        {
            cur+=vec[i].first;

        }
        else {cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}



Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

ll binary_pow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) {
      ans *= tmp;
      ans %= mod;
    }
    N /= 2;
    tmp *= tmp;
    tmp %= mod;
  }
  return ans;
}
ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  int S;
  cin >> N >> S;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int mx = S+1;
  vector<vector<ll>> dp(N+1, vector<ll>(mx));
  dp[0][0] = binary_pow(2, N);
  ll ans = 0;
  rep(i, N) {
    if(S-A[i]>=0) {
      (ans += dp[i][S-A[i]] * modinv(2)) %= mod;
    }
    rep(j, mx) {
      (dp[i+1][j] += dp[i][j]) %= mod;
      if(j+A[i] < mx) (dp[i+1][j+A[i]] += dp[i][j] * modinv(2)) %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  ll n; ll k;
  cin >> n >> k;
  ll a[n]; ll f[n];
  rep(i,n)  cin >> a[i];
  sort(a,a+n);  
  rep(i,n) cin >> f[i];
  ll l = -1, r = INF;
  while(r-l > 1) {
    ll m = (r+l)/2;
    ll t = 0;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    rep(i,n) que.push(m/f[i]);
    bool can = true;
    ll z = k;
    rep(i,n) {
      ll p = que.top();
      que.pop();
      if(a[i] > p) z -= a[i] - p;
    }
    if(z >= 0) r = m;
    else l = m;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 7028
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&c^-1;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
char c[yuzu|10];
int main(){
scanf("%s",c);
int cnt=0,i,len=strlen(c);
for (i=0;i<len;++i){
  cnt+=c[i]=='p';
  }
write(len/2-cnt);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll a,b,q;
  cin>>a>>b>>q;
  vll s(a),t(b),x(q);
  rep(i,a)cin>>s[i];
  rep(i,b) cin>>t[i];
  rep(i,q) cin>>x[i];
  sort(all(s));
  sort(all(t));
  ll ans=0;
  rep(i,q){
    ll cu=INF;
    vll k(2),u(2);
     k[0]=lower_bound(all(s),x[i])-s.begin()-1;
     k[1]=upper_bound(all(s),x[i])-s.begin();
     u[0]=lower_bound(all(t),x[i])-t.begin()-1;
     u[1]=upper_bound(all(t),x[i])-t.begin();
    rep(j,2){
      rep(r,2){
        if((j==0&&k[j]<0)||(j==1&&k[j]==a)||(r==0&&u[r]<0)||(r==1&&u[r]==b))continue;
      if(r!=j){
        ll w=max(abs(s[k[j]]-x[i]),abs(t[u[r]]-x[i]));
        ll e=min(abs(s[k[j]]-x[i]),abs(t[u[r]]-x[i]));
        cu=min(cu,2*e+w);
      }
        else cu=min(cu,max(abs(s[k[j]]-x[i]),abs(t[u[r]]-x[i])));
      }
    }
    COUT(cu);
  }
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;

int n,m,x,a,yves=0,chuu=0;
bool toll[101];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	memset(toll, false, 101);
	cin>>n>>m>>x;
	for(int i=0;i<m;i++){
		cin>>a;
		toll[a] = true;
	}
	for(int i=x-1;i>0;i--){
		if(toll[i])
			yves++;
	}
	for(int i=x+1;i<n;i++){
		if(toll[i])
			chuu++;
	}
	cout<<min(yves,chuu);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int>d(n+1);
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i)d[j]++;
  }
  ll ans=0;
  for(int i=1;i<=n;i++)ans+=ll(i)*d[i];
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 42332
from sys import stdin
from collections import deque
inf=float('inf')
def search(A,N):
    dp=[[inf for x in range(N+1)] for j in range(N+1)]

    p=[]
    for i in range(N+1):
        dp[i][i]=0
        if i>=1:
            if i==1:
                p.append(A[i][0])
                p.append(A[i][1])
            else:p.append(A[i][1])
    for l in range(2,N+1):#行を選ぶ
        for i in range(1,N-l+2):
            j=i+l-1
            for k in range(i,j):
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
    return dp[1][-1]

N=int(input())
num_list = [[0, 0]]
for i in range(N):
    num_list.append(list(map(int,stdin.readline().strip().split())))
print(search(num_list,N))


Measured memory_bytes: 6064
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000001;

int main(){
  int x,y,z,k;
  cin >> x >> y >> z >> k;

  vector<long> a  = vector<long>(x);
  vector<long> b  = vector<long>(y);
  vector<long> c  = vector<long>(z);

  REP(i,x){
    cin >> a[i];
  }
  REP(i,y){
    cin >> b[i];
  }
  REP(i,z){
    cin >> c[i];
  }

  vector<long> e = vector<long>();

  REP(i,x){
    REP(j,y){
      e.push_back(a[i]+b[j]);
    }
  }

  sort(e.begin(),e.end(),greater<long>());

  e.resize(k);

  vector<long> ans = vector<long>();

  REP(i,k){
    REP(j,z){
      ans.push_back(e[i] + c[j]);
    }
  }

  sort(ans.begin(),ans.end(),greater<long>());

  REP(i,k){
    cout << ans[i] << endl;
  }
  return 0;
}

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

data = [list(map(int,input().split())) for _ in range(N)]
team = data[0][2]
player = data[0][1]
t1 = 0
t2 = 0
f1 = 0
f2 = 0
for i in range(1,N):
    if data[i][2] == team:
        if data[i][1] != player:
            if team == 0:
                if t1 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    t1 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
                    f1 = (data[i][0]- data[i-1][0])/60
                if t1 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    if f1 > (data[i][0]- data[i-1][0])/60:
                        f1 = (data[i][0]- data[i-1][0])/60
            if team == 1:
                if t2 < ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    t2 = ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2)
                    f2 = (data[i][0] - data[i-1][0])/60
                if t2 == ((data[i][3] - data[i-1][3])**2 + (data[i][4] - data[i-1][4])**2)**(1/2):
                    if f2 > (data[i][0]- data[i-1][0])/60:
                        f2 = (data[i][0]- data[i-1][0])/60
    player = data[i][1]
    team = data[i][2]
if t1 == 0 :
    print(-1,-1)
else:
    print(t1,f1)
if t2 == 0:
    print(-1,-1)
else:
    print(t2,f2)



Measured memory_bytes: 5692
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)
for m in range(M):
    a = -heapq.heappop(A)
    heapq.heappush(A, -(a//2))
print(-sum(A))

Measured memory_bytes: 72088
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
ALL=1<<N
dp=[10**9]*ALL
dp[0]=0
#print(dp)
for i in range(M):
    ndp=dp[:]
    #print(ndp)
    a,b=map(int,input().split())
    c=[int(i)-1 for i in input().split()]

    C=0
    for i in c:
        C|=1<<i

    for S in range(ALL):
        ndp[S|C]=min(ndp[S|C],dp[S]+a)
    dp=ndp
#print(dp)
if dp[-1]==10**9:print(-1)
else:print(dp[-1])


Measured memory_bytes: 43740
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<ll,  ll>;
using edge = int;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main() {
	ll  n;cin >>n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) cin >>a[i];
    pint kouho={2, 2};
	for(int i = n-1; i >= 0; --i){
      ll gl=kouho.first, gr=kouho.second;
      ll nl=(gl+a[i]-1)/a[i];
      ll nr=gr/a[i];

      kouho={nl*a[i], nr*a[i]+a[i]-1};
      // cout << kouho.first << " " << kouho.second << endl;
      if(nl==0 || nr==0 || kouho.first >kouho.second){
        cout << -1 << endl;
        return 0;
      }
    }
    ll ans1 = kouho.first; 
    ll ans2= kouho.second;
	cout << ans1 << " " << ans2 << endl;
}


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

int main()
{
  int n; cin >> n;
  vector<char> c(n);
  vector<int> a(n);
  rep(i, n) {
    string s; cin >> s;
    c[i] = s[0];
    a[i] = s[1]-'0';
  }

  vector<char> c1 = c;
  vector<int> a1 = a;
  for (int i=0; i<n; i++) {
    for (int j=n-1; j>=i+1; j--) {
      if (a1[j] < a1[j-1]) {
        swap(a1[j], a1[j-1]);
        swap(c1[j], c1[j-1]);
      }
    }
  }
  rep(i, n) {
    if (i > 0) cout << " ";
    cout << c1[i] << a1[i];
  }
  cout << endl << "Stable" << endl;

  vector<char> c2 = c;
  vector<int> a2 = a;
  for (int i=0; i<n; i++) {
    int minj = i;
    for (int j=i; j<n; j++) {
      if (a2[j] < a2[minj]) minj = j;
    }
    swap(a2[i], a2[minj]);
    swap(c2[i], c2[minj]);
  }
  rep(i, n) {
    if (i > 0) cout << " ";
    cout << c2[i] << a2[i];
  }
  cout << endl;
  if (c1==c2&&a1==a2) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}



Measured memory_bytes: 3184
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>str;
    if(a<3200)cout<<"red"<<endl;
    else cout<<str;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

template<class T> inline void chmin(T &x, const T &y) {if (x > y) x = y;}

const int INF = 1e9+7;

int n, k;
int h[101000];

int dp[101000];

int main()
{
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> h[i];
  
  for (int i = 1; i < n; ++i) dp[i] = INF;
  
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= k; ++j)
      chmin(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
  
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for(auto &x : p) cin >> x;
    for(auto &x : q) cin >> x;
    vector<int> t = p;
    sort(ALL(t));
    int a = 0, b = 0;
    int i = 1;
    do{
        if(t == p){
            a = i;
        }
        if(t == q){
            b = i;
        }
        i++;
    }while(next_permutation(ALL(t)));
    cout << abs(a - b);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
#include <iomanip>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

string s; cin >> s;
int N = s.size();

//全部勝つと 条件※ が逆になる．
//最初は必ず g 
// 今まで出した g の回数まで p を出せる．
// g を出すごとに p を出せる回数が増える．
// 相手も同じ．s がそれに従う．
// 最初はかならず 引き分け．
// その条件で， 勝つ  > 引き分け > 負け の優先順位で選ぶ．
// わざと負けて g を増やすということもある．

int score = 0, cg = 0, cp = 0;
for (char c : s){
    if (c == 'g'){ // 相手が g ．勝つか，引き分けるか．
        if (cp < cg){ // p を出せる．勝てる．
            ++cp; 
            ++score;
        } 
        else ++cg; // p を出せない．引き分ける．
    }
    else{ // 相手が p．引き分けか，負けるかしかない．
        if (cp < cg) ++cp; // p を出せる．引き分け．
        else { // p を出せない．負け
            ++cg;
            --score;
        }
    }
}

cout << score <<  "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 512
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			
			int[] a = new int[n+m+1];
			a[0] = 0;
			
			for(int i=0;i<n;i++) a[i+1] = sc.nextInt();
			for(int j=0;j<m;j++) a[j+n+1] = sc.nextInt();
			
			sort(a);
			int max = 0;
			for(int i=0;i<n+m;i++) {
				max = max(max, a[i+1]-a[i]);
			}
			
			System.out.println(max);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    for d in reversed(range(1, M // N + 1)):
        if M % d == 0:
            print(d)
            return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define S size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define SE second
#define ld long double



using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ld area(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3){
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}
 
ll dp[3001][3001];
bool vis[3001][3001];
ll n;
vector <ll> v;



ll solve(ll l, ll r){
    if(vis[l][r]){
        return dp[l][r];
    }
    vis[l][r]=1;
    if(l==r ){
        dp[l][r]=v[l-1];
        return dp[l][r];
    }
    
    dp[l][r]= max(v[l-1]-solve(l+1,r),v[r-1]-solve(l,r-1));
    return dp[l][r];
    
}

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cin>>n;
    REP(i,0,n){
        ll x;
        cin>>x;
        v.PB(x);
    }
    REP(i,0,301){
        REP(j,0,301){
            dp[i][j]=0;
        }
    }
    cout<<solve(1,n);
    
    
    
    
}


Measured memory_bytes: 78464
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            if (n < 1200)
                out.println("ABC");
            else if (n < 2800)
                out.println("ARC");
            else
                out.println("AGC");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final String S=sc.next();
    String[] s=S.split("/");
    int y=Integer.parseInt(s[0]);
    int m=Integer.parseInt(s[1]);
    int d=Integer.parseInt(s[2]);
    boolean flg=false;
    if(y<=2019){
      if(m<=4){
        if(d<=30){
          flg=true;
        }
      }
    }
    if(flg){
      System.out.println("Heisei");
    }else{
      System.out.println("TBD");
    }
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

void input()
{
    long n,a,b;
    cin>>n>>a>>b;
    if (n==1)
	{
		if (a==b) cout<<1; else cout<<0;
	}
    else if (a>b) cout<<0;
    else cout<<(n-2)* (b-a)+1;
}

void solve()
{

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
   // freopen(TASK".inp","r",stdin);
   // freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 7;
typedef long long ll;
const int mod =  998244353;
ll inv[MAXN], n, a, b, k, fac[MAXN], ans;
ll exgcd(const ll &a, const ll &b, ll &x, ll &y) {
	if (!b) return x = 1, y = 0, a;
	ll g = exgcd(b, a % b, y, x);
	y = y - (a / b) * x;
	return g;
}
inline ll gcd(ll a, ll b) {while(ll t = a % b) a = b, b = t; return b;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll C(int n, int m) {return fac[n] * inv[m] % mod * inv[n-m] % mod;}
int main(void) {  
  cin >> n >> a >> b >> k;
  if (n * (a+b) < k) return puts("0"), 0;
  ll x, y, g = exgcd(a, b, x, y);
  if (k % g) return puts("0"), 0;
  x *= k / g; y *= k / g;
  ll t = lcm(a, b), dx = t / a, dy = t / b;
  if (x < y) swap(a, b), swap(x, y), swap(dx, dy);
  if (y < 0) {
  	ll d = (dy - 1 - y) / dy;
  	y += dy * d;
  	x -= dx * d;
	}
	if (x > n) {
		ll d = (x - n + dx - 1) / dx;
		x -= dx * d;
		y += dy * d;
	}
	if (x > n || y > n) return puts("0"), 0;
  inv[1] = fac[1] = 1;
  for(int i = 2; i <= n; ++i) fac[i] = fac[i-1] * i % mod;
  ll xx, yy;
	exgcd(fac[n], mod, xx, yy);
	inv[n] = (xx + mod) % mod;
  for(int i = n-1; i >= 0; --i) inv[i] = (inv[i+1] * (i+1)) % mod;
  while(x >= 0 && y <= n) 
  	ans = (ans + C(n, x) * C(n, y) % mod) % mod, x -= dx, y += dy;
	cout << ans;
  return 0;
}

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

typedef long long ll;

int n, k;
int a[100005]; ll b[100005];

int del[100005];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d%lld", a + i, b + i);
	
	ll ans = 0;
	
	for (int t = 30; t >= 0; --t) {
		if (!(k & (1 << t))) {
			for (int i = 1; i <= n; ++i) if (a[i] & (1 << t)) del[i] = 2;
			continue;
		}
		
		for (int i = 1; i <= n; ++i) if (!del[i] && a[i] & (1 << t)) del[i] = 1;
		
		ll tmp = 0;
		for (int i = 1; i <= n; ++i) if (!del[i]) tmp += b[i];
		
		for (int i = 1; i <= n; ++i) if (del[i] == 1 && a[i] & (1 << t)) del[i] = 0;
		
		ans = std::max(ans, tmp);
	}
	
	ll tmp = 0;
	for (int i = 1; i <= n; ++i) if (del[i] != 2) tmp += b[i];
	ans = std::max(ans, tmp);
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 1792
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
const int MOD=1e9+7;
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(auto& it:v)cin>>it;
	int ans=0;
	for(auto it:v)ans=__gcd(ans,it);
	cout<<ans<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	string S;
	cin >> S;
	long long ans = 0;

	for (int bit = 0; bit < (1<<S.size() - 1); ++bit) {
		string splitNumS;
		for (int i = 0; i < S.size(); ++i) {
			splitNumS.push_back(S[i]);
			if (bit & (1 << i)) {
				splitNumS.push_back('+');
			}
			//cout << splitNumS[i] << endl;
		}
		/*
		for (int i = 0; i < splitNumS.size(); ++i) {
			cout << splitNumS[i] << endl;
		}
		*/
		//cout << splitNumS << endl;
		//splitNumSの計算
		long long temp1 = 0;
		long long total = 0;
		for (int i = 0; i < splitNumS.size(); ++i) {
			temp1 += splitNumS[i] - '0';
			if (i >= splitNumS.size() - 1) {
				total += temp1;
			}
			else if (splitNumS[i+1] == '+') {
				total += temp1;
				++i;
				temp1 = 0;
			}
			else {
				temp1 *= 10;
			}
		}
		//cout << total << endl;
		ans += total;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define MAXN 100000

using namespace std;

vector < int > g[MAXN + 1], r[MAXN];
int a[MAXN + 1], h[MAXN + 1];
bool done[MAXN + 1], viz[MAXN + 1];

void dfs1(int x) {
    viz[x] = 1;
    r[h[x]].push_back(x);
    for (auto &y : g[x]) {
        if (viz[y] == 0) {
            h[y] = h[x] + 1;
            dfs1(y);
        }
    }
}

void dfs2(int x) {
    done[x] = 1;
    for (auto &y : g[x])
        if (done[y] == 0)
            dfs2(y);
}

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

    for (int i = 1; i <= n; i++)
        cin >> a[i];

    int ans = 0;
    if (a[1] != 1)
        ans = 1;

    for (int i = 2; i <= n; i++)
        g[a[i]].push_back(i);

    dfs1(1);

    for (int i = n - 1; i > 0; i--) {
        for (auto &x : r[i]) {
            if (done[x] == 0) {
                int e = x, cnt = 1;
                while (a[e] != 1 && cnt < k) {
                    cnt++;
                    e = a[e];
                }
                if (a[e] != 1)
                    ans++;
                dfs2(e);
            }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 16896