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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for(ll i = 2; i*i <= n; ++i) {
    while(n%i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}

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

    ll a, b; cin >> a >> b;
    map<ll, int> mp;
    for(auto e : prime_factor(a)) mp[e.first]++;
    for(auto e : prime_factor(b)) mp[e.first]++;
    int ans = 1;
    for(auto e : mp) if(e.second == 2) ans++;
    cout << ans << '\n';
    return 0;
}


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

int main(){
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
    freopen("op.txt", "w", stdout);
#endif
	long long n, w;
	cin >> n >> w;
	vector<long long> v(n +1), wt(n +1);
	long long max_val = 0;
	for(int i = 0; i < n; ++i){
		cin >> wt[i +1] >> v[i +1];
		max_val += v[i +1];
	}
	long long dp[n +1][max_val +1], res = 0;

	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= max_val; ++j){
			dp[i][j] = w +1;
			dp[i][0] = 0;
		}
	}
	dp[0][0] = 0;
	for(int i = 1; i <= n; ++i){
		for(long long j = 1; j <= max_val; ++j){
			if(v[i] <= j){
				dp[i][j] = min(dp[i -1][j], dp[i -1][j - v[i]] + wt[i]);
			}else{
				dp[i][j] = dp[i -1][j];
			}
			if(dp[i][j] <= w)
				res = max(j, res);
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 82328
import math
N=input()
N,M=N.split()
N=int(N)
M=int(M)
Nk=1
Mk=1

if math.fabs(N-M)>1:
    print(0)
    quit()


for i in range(1,N+1):
    Nk=Nk*i%(1000000000+7)
for i in range(1,M+1):
    Mk=Mk*i%(1000000000+7)

if N!=M:
    print(int((Nk*Mk)%(1000000000+7)))
else:
    res=Nk*Mk*2
    print(int(res)%(1000000000+7))


quit()

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

using Int = long long int;
using UInt = unsigned long long int;

Int Ceil(int a, int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return a/ b + 1;
    }
}

int main(void) {
    Int n;
    cin >> n;
    Int rt, ra;
    cin >> rt >> ra;
 
    Int t, a;
    for (Int i = 1; i < n; ++i) {
        cin >> t >> a;
        Int times;
        if (rt > t && ra > a) { 
            Int times_a = ra / a;
            Int times_t = rt / t;
            if (ra % a != 0) {
                ++times_a;
            }
            if (rt % t != 0) {
                ++times_t;
            }
            times = max(times_a, times_t);
        } else if (rt <= t && ra > a) {
            times = Ceil(ra, a);
        } else if (rt > t && ra <= a) {
            times = Ceil(rt, t);
        } else {
            times = 1;
        }
        rt = t * times;
        ra = a * times;
    }
    cout << rt + ra << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {

    int N;
    cin >> N;

    unordered_map<string, int> hash;

    string S[N];
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    long ans = 0;
    for (int i = 0; i < N; i++) {
        sort(S[i].begin(), S[i].end());
        if (hash.find(S[i]) != hash.end()) {
            ans += hash[S[i]];
            hash[S[i]] += 1;
        } else {
            hash[S[i]] = 1;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 17572
#include <stdio.h>
#include <stdlib.h>

#define max(a, b) ((a)>(b)?(a):(b))


struct node {
	struct node *left;
	struct node *right;
	int index;
	int activity;
};

struct node *
insert(struct node *p, int act, int index)
{
	int cmp;
	if (p == NULL) {
		p = (struct node *)malloc(sizeof(struct node));
		p->left = (struct node *)NULL;
		p->right = (struct node *)NULL;
		p->index = index;
		p->activity = act;
		return p;
	} else {
		if ( act < p->activity) {
			p->left = insert(p->left, act, index);
			return p;
		} else if (act >= p->activity) {
			p->right = insert(p->right, act, index);
			return p;
		} else {
			printf("This case is not exist");
		}
	}
}

int depthNode(struct node *p, int n, int *idx) {
	if (p->left == NULL) {
		idx[n] = p->index;
		n++;
	} else {
		n = depthNode(p->left, n, idx);
		idx[n] = p->index;
		n++;
	}
	
	if (p->right == NULL) {
		return n;
	} else {
		n = depthNode(p->right, n, idx);
	}
	return n;
}

int main()
{
	int i, j, N;
	int ix, iy;
	long *A;
	long **DP;
	int *Index;
	int ret;
	int act;
	int n;
	
	struct node *root = (struct node *)NULL;
	
	ret = scanf("%d", &N);
	A = (long *) malloc(sizeof(long)*N);
	DP = (long **) malloc(sizeof(long *)*N);
	
	for (ix = 0; ix < N; ix++) {
		DP[ix] = (long *) malloc(sizeof(long)*N);
		for (iy = 0; iy < N; iy++)
			DP[ix][iy] = 0;
	}
	
	Index = (int *) malloc(sizeof(int)*N);
	
	for (i = 0; i < N; i++) {
		ret = scanf(" %ld", &A[i]);
		root = insert(root, A[i], i);
	}

	n = depthNode(root, 0, Index);
	
	for (i = 0; i < N; i++)
		DP[i][i] = A[Index[0]]*abs(Index[0] - i);
		
	for (i = 1; i < N; i++) {
		for (ix = 0; ix + i < N;ix++) {
			iy = ix + i;
			DP[ix][iy] = 0;
			DP[ix][iy] = max(DP[ix][iy],
							 max(DP[ix+1][iy] + A[Index[i]]*abs(Index[i]-ix),
								 DP[ix][iy-1] + A[Index[i]]*abs(Index[i]-iy)));
		}
	}
	printf("%ld\n",DP[0][N-1]);
	fflush(stdout);
	free(A);
	free(Index);
	return EXIT_SUCCESS;
}


Measured memory_bytes: 33108
#include <bits/stdc++.h>
#define tam 100010
#define inf 1000000000

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;

int dp[2][3];

bool comp(int a, int b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < 3; ++i)
	{
		cin >> dp[0][i];
	}
	int c = 1;
	int arr[3];
	for (int i = 1; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> arr[j];
		}
		for (int j = 0; j < 3; ++j)
		{
			dp[c][j] = max(dp[c][j], arr[j] + max(dp[(c + 1) % 2][(j + 1) % 3], dp[(c + 1) % 2][(j + 2) % 3]));
		}
		c++;
		c %= 2;
	}
	c++;
	c %= 2;
	cout << max(max(dp[c][0], dp[c][1]), dp[c][2]) << "\n";
	return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(a.begin(), a.end());
    int b = a[n/2];
    long long res = 0;
    for (auto& x: a) {
        res += abs(x-b);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
 
int main(void){
 
    int n;
	int i;
    double x1;
	double x2;
	double x3;
	double y1;
	double y2;
	double y3;
    double xp;
	double yp;
	double r;
 
    scanf("%d", &n);
     
    for(i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
        r = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
        xp = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1) + (x3 * x3 + y3 * y3) * (y1 - y2)) / r;
        yp = ((x1 * x1 + y1 * y1) * (x3 - x2) + (x2 * x2 + y2 * y2) * (x1 - x3) + (x3 * x3 + y3 * y3) * (x2 - x1)) / r;
        r = hypot(xp - x1, yp - y1);
        printf("%.03lf %.03lf %.03lf\n", xp, yp, r);
    }
     
    return (0);
}

Measured memory_bytes: 672
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

ll lmin(ll x,ll y){
    if(x <= y) return x;
    else return y;
};

int main(){
    int n; cin >> n;
    vector<int> a(n);
    ll ans = 0;
    ll m = 1e10;
    ll cnt = 0;
    rep(i,n){
        cin >> a[i];
        ans += abs(a[i]);
        if(a[i] < 0) cnt++;
        m = lmin(m, abs(a[i]));
    }
    if(cnt % 2 == 0) cout << ans << endl;
    else cout << ans - m*2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
map<int,int> mp;

int main(){
	int n;
	scanf("%d",&n);
	int fl = 0;
	for(int i = 1;i <= n;i++){
		int a;
		scanf("%d",&a);
		if(mp[a] == 0)
			mp[a]++;
		else fl = 1;
	}
	if(fl) printf("NO\n");
	else printf("YES\n");
	return 0; 
}

Measured memory_bytes: 9600
Q = int(input())
queries = []
for i in range(Q):
    l, r = map(int, input().split())
    queries.append((l, r))

N = 10**5 + 1
is_prime = [True] * N
is_prime[0] = False
is_prime[1] = False
for i in range(4, N, 2):
    is_prime[i] = False
for i in range(3, N, 2):
    if i*i > N: break
    if is_prime[i]:
        for j in range(2*i, N, i):
            is_prime[j] = False

def is_ok(x):
    if (x % 2 == 0) or not is_prime[x]:
        return False
    return is_prime[(x + 1) // 2]

cum_ok = [None] * N
c = 0
for i in range(N):
    if is_ok(i):
        c += 1
    cum_ok[i] = c

for l, r in queries:
    print(cum_ok[r] - cum_ok[l-1])


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

int main() {
	int N, M, ans = 0;
	cin >> N >> M;
	vector<string> A(N), B(N);
	for (string& i : A) cin >> i;
	for (string& i : B) cin >> i;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			if (A[i][j] != B[i][j]) ++ans;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 11124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = ((ll)2<<30)-1;

ll dat[2<<18], add[2<<18];
int segn = 1;
void init(int n){
	while(segn < n)segn *= 2;
	for(int i = 0;i < segn*2;i++)dat[i] = INF;
	for(int i = 0;i < segn*2;i++)add[i] = -1;
}

void lazy_update(int k, int l, int r){
	if(add[k] == -1)return ;
	dat[k] = add[k];
	add[k*2+1] = add[k];
	add[k*2+2] = add[k];
	add[k] = -1;
}

void update(int a, int b, int x, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return ;
	if(a <= l && r <= b){
		add[k] = x;
		lazy_update(k, l, r);
		return ;
	}
	update(a, b, x, k*2+1, l, (l+r)/2);
	update(a, b, x, k*2+2, (l+r)/2, r);
	dat[k] = min(dat[k*2+1], dat[k*2+2]);
}

ll get(int a, int b, int k, int l, int r){
	lazy_update(k, l, r);
	if(b <= l || r <= a)return INF;
	if(a <= l && r <= b)return dat[k];
	ll vl = get(a, b, k*2+1, l, (l+r)/2);
	ll vr = get(a, b, k*2+2, (l+r)/2, r);
	return min(vl, vr);
}

int main(){
	int n, q, c, s, t, x;
	scanf("%d%d", &n, &q);
	init(n);
	for(int i = 0;i < q;i++){
		scanf("%d", &c);
		if(!c){
			scanf("%d%d%d", &s, &t, &x);
			update(s, t+1, x, 0, 0, segn);
		}else{
			scanf("%d%d", &s, &t);
			ll res = get(s, t+1, 0, 0, segn);
			printf("%lld\n", res);
		}
	}
	return 0;
}


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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 2e5 + 5;

long long psm[DIM];

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        cin >> psm[i];
        psm[i] += psm[i - 1];
    }
    
    long long ans = numeric_limits<long long> :: max() / 2;
    for (int i = 1; i < n; ++i)
        ans = min(ans, abs(psm[i] - (psm[n] - psm[i])));
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		if(n==m) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 22740
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100000
int x[N+5],y[N+5],c[N+5],y1[N+5];
int n,k,ans,cnt;
int main()
{
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++) 
  {
    char ch;
    scanf("%d %d %c",&x[i],&y[i],&ch);
    x[i]%=(2*k);
    y[i]%=(2*k);
    if(ch=='W')
      c[i]=1;
  }
  for(int i=0;i<=k;i++)
  {
    cnt=0;
    fill(y1,y1+2*k+1,0);
    for(int j=1;j<=n;j++)
    {
      bool p=(i<=x[j]&&x[j]<i+k);
      bool q=(0<=y[j]&&y[j]<k);
      if(p^q==c[j])
        cnt++,y1[y[j]]++;
      else
        y1[y[j]]--;
    }
    for(int j=0;j<=k;j++)
    {
      ans=max(max(cnt,n-cnt),ans);
      if(j!=k)
        cnt=cnt-y1[j]-y1[k+j];
    }
  }
  printf("%d\n",ans);
}




Measured memory_bytes: 1280
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  s = input()
  mi_ = float("inf")
  slen = len(s)
  for i in range(0,slen-2):
    mi_ = min(mi_,abs(int(s[i:i+3]) -753))
  print(mi_)
  
if __name__ == '__main__':
  main()

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

using namespace std;

#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005


int main()
{
	ll t;
	cin >> t;
	cout << t*t << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(int i=0; i<n; i++)
#define forp(i,a,b) for(int i=a;i<b;i++)
#define forn(i,a,b) for(int i=a;i>=b;i--)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100001;
int spf[MAXN];
int gcd(int x, int y){ return y?gcd(y,x%y):x; }

void precal(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int t;
    string s,b[4];
    b[0]="AC"; b[1]="WA"; b[2]="TLE"; b[3]="RE";
    cin>>t;
    int a[4];
    rep(i,4) a[i]=0;
    while(t--){
        cin>>s;
        rep(i,4) if(s==b[i]) a[i]++;
    }
    rep(i,4){
        cout<<b[i]<<" x "<<a[i]<<nl;
    }
    return 0;
}

Measured memory_bytes: 3156
N, K = (int(i) for i in input().split())  
X = [int(i) for i in input().split()] 
ans = 10 ** 18
for i in range(N):
  if i + K > N:
    break
  l = X[i]
  r = X[i + K - 1]
  
  if l >= 0:
    ans = min(ans, r)
  elif r <= 0:
    ans = min(ans, -l)
  else:  
    if r < -l:
      ans = min(ans, r * 2 + -l)
    else:
      ans = min(ans, -l * 2 + r)
    
print(ans)

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

namespace ALDS1_10_A
{
    class Program
    {
        static void Main(string[] args)
        {
            Fibonacci fibonacci = new Fibonacci();
            Console.WriteLine(fibonacci.GetValue(int.Parse(Console.ReadLine())));
            //Console.ReadLine();
        }
    }

    class Fibonacci
    {
        int[] fibonacci;

        public Fibonacci()
        {
            this.fibonacci = new int[45];
            this.fibonacci[0] = 1;
            this.fibonacci[1] = 1;
        }

        public int GetValue(int index)
        {
            if (this.fibonacci[index] == 0)
            {
                this.fibonacci[index] = this.GetValue(index - 1) + this.GetValue(index - 2);
            }
            return this.fibonacci[index];
        }
    }
}



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

public class MainClass
{
	public static void Main(string[] args)
	{
		string[] inputs = Console.ReadLine().Split(' ');
		int width = int.Parse(inputs[0]);
		int height = int.Parse(inputs[1]);
		inputs = Console.ReadLine().Split(' ');
		int w = int.Parse(inputs[0]);
		int h = int.Parse(inputs[1]);
		
		bool[,] cells = new bool[width, height];
		for(int i = 0; i < h; i++)
		{
			for(int x = 0; x < width; x++)
			{
				cells[x,i] = true;
			}
		}
		for(int i = 0; i < w; i++)
		{
			for(int x = 0; x < height; x++)
			{
				cells[i, x] = true;
			}
		}
		
		int c = 0;
		for(int x = 0; x < width; x++)
		{
			for(int y = 0; y < height; y++)
			{
				if(!cells[x,y]) c++;
			}
		}
		Console.WriteLine(c);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    INT a,b,n;
    INT ans;
    cin >> a >> b >> n;
    if(b-1<=n){
        ans = a*(b-1)/b;
    }
    else{
        ans = n*a/b - (n/b);
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        int k = scn.nextInt();
        int A, B, C;

        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= (k - i); j++) {
                int l = k-i-j;
                A = a * (int) Math.pow(2, i);
                B = b * (int) Math.pow(2, j);
                C = c * (int) Math.pow(2, l);
                if (C > B && B > A) {
                    System.out.println("Yes");
                    return;
                }

            }
        }

        System.out.println("No");


        scn.close();

    }


}


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

int main () {
  int N,K;
  cin >> N >> K;
  vector<int> name(N);
  for (int i=0; i<N; i++){
    cin >> name[i];
  }
  sort(name.begin(),name.end());
  int cnt = 0;
  for (int i=0; i<K; i++){
    cnt += name[i];
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
import math
N , H = map(int , input().split())
slash = []
throw = []
for _ in range(N):
    a , b = map(int , input().split())
    slash.append(a)
    throw.append(b)
count = 0
#print(slash)
slash_max = max(slash)
#print(throw)
throw.sort(reverse = True)
#print(throw)
while H > 0:
    #print(H)
    if not throw or throw[0] < slash_max :
        count += math.ceil(H / slash_max)
        break
    else:
        H -= throw[0]
        throw.pop(0)
        #print(throw)
    count += 1
print(count)


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

int main(){
  int N; 
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    cin >> A[i];
  }
  sort (A.begin(), A.end());
  int ans = 0;
  rep(i, N-1){
    ans += A[i+1] - A[i];
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
a,b=[int(i) for i in input().split()]

bin_b = bin(b)[2:]
bit_len = len(bin_b)
bin_a = bin(a)[2:].zfill(bit_len)

ans_bit = []

a_odd = a + (1 - a%2)
odd_num = (b-a_odd)//2 + 1
if odd_num % 2 == 0:
  ans_bit.append('0')
else:
  ans_bit.append('1')

for i in range(1,bit_len):
  keta = bit_len - i - 1
  amari_a = 0
  if bin_a[keta] == '1':
    amari_a = 2**i - a % 2**i
  amari_b = 0
  if bin_b[keta] == '1':
    amari_b = b % 2**i + 1
  
  no_change = amari_a + amari_b
  if no_change % 2 == 0:
    ans_bit.append('0')
  else:
    ans_bit.append('1')
ans = ''.join(ans_bit[::-1])
ans = int(ans,2)

print(ans)

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

int main()
{
    int N, K;
    std::cin >> N >> K;
    std::vector<int> f(N);

    for (int i = 0; i < N; i++)
    {
        std::cin >> f[i];
    }
    std::sort(f.begin(), f.end());

    int ans = 0;
    for (int i = 0; i < K; i++)
    {
        ans += f[i];
    }

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

Measured memory_bytes: 3632
#include<stdio.h>

int main(void){

	int i, j, n[3],min, temp;

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

	for (i = 0; i < 3; i++){
		min = i;
		for (j = i + 1; j < 3; j++){

			if (n[min]>n[j]){
				min = j;
			}
		}

		temp = n[min];
		n[min] = n[i];
		n[i] = temp;
	}

	
		j = 0;
		printf("%d %d %d\n", n[j],n[j+1],n[j+2]);
	
	

	return 0;
}

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


int dp[100001][10];

int main(){
	int n,m;
	int a[10];
	string id;

	cin>>n>>id;
	cin>>m;
	for(int i=0;i<m;i++)cin>>a[i];
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			if(id[i]=='*'){
				for(int k=0;k<m;k++){
					int x=a[k];
					if((n-i)%2==0){
						x*=2;
						if(10<=x)x=x/10+x%10;
					}
					dp[i+1][(j+x)%10]+=dp[i][j];
				}
			}else{
				int x=id[i]-'0';
				if((n-i)%2==0){
					x*=2;
					if(10<=x)x=x/10+x%10;
				}
				dp[i+1][(j+x)%10]+=dp[i][j];
			}
		}
	}
	cout<<dp[n][0]<<endl;
	return 0;
}

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

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	map<ll,ll> mp;
	rep(i,N){
		ll a;
		cin >> a;
		A[i] = a;
		mp[a]++;
	}
	ll mx = 0;
	for(auto e:mp) mx += e.second*(e.second-1)/2;
	rep(i,N){
		ll b = mp[A[i]];
		ll ans = mx - (b*(b-1)/2) + (b-1)*(b-2)/2;
		cout << ans << endl;
	}
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge;

int main(){
  string s;
  cin>>s;
  int a[26];
  int count =0;
  lp(i,s.size()){
    if('a'<=s[i]&&s[i]<='z'){
      count++;
    }
  }
  lp(i,count){
    char c;
    int hoge;
    cin>>c>>hoge;
    a[c-'a']=hoge;
  }
  int stat=0;
  while(s.size()!=1){
    lp(i,s.size()){
      if(i==0) continue;
      if(s[i-1]=='['&&'a'<=s[i]&&s[i]<='z'&&s[i+3]==']'){
	string bef=s.substr(0,i-1);
	string cont=s.substr(i-1,5);
	string aft=s.substr(i+4,s.size()-i+5);
	int x,y;
	x=a[cont[1]-'a'];
	y=a[cont[3]-'a'];
	if(x==0){
	  a[cont[3]-'a']--;
	  cont=cont.substr(3,1);
	}
	else if(y==0){
	  a[cont[1]-'a']--;
	  cont=cont.substr(1,1);
	}
	else stat=1;
	s=bef+cont+aft;
	if(stat==1) break;
      }
    }
    if(stat==1) break;
  }
  if(stat==1||a[s[0]-'a']!=0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define N 200


int main () {
	string s;
	int l;

	cin >> s;

	l = s.size();

	for(int i=0;i<l-8;i++){
		cout << s[i];
	}

	cout << endl;
	

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <tuple>
using namespace std;

int main() {
    int p, q;
    while (cin >> p >> q, p) {
        vector<vector<int>> a(p, vector<int>(3));
        vector<int> b(p);
        {
            map<char, int> cnt;
            for (int i = 0; i < p; i++) {
                a[i][0] = cnt['('] - cnt[')'];
                a[i][1] = cnt['{'] - cnt['}'];
                a[i][2] = cnt['['] - cnt[']'];
                string s; cin >> s;
                int& ind = b[i];
                while (ind < s.size() && s[ind] == '.') ind++;
                for (auto c: s) cnt[c]++;
            }
        }
        set<tuple<int, int, int>> se;
        for (int r = 1; r <= 20; r++) {
            for (int c = 1; c <= 20; c++) {
                for (int s = 1; s <= 20; s++) {
                    bool ok = true;
                    for (int i = 0; i < p; i++) {
                        ok &= a[i][0] * r + a[i][1] * c + a[i][2] * s == b[i];
                    }
                    if (ok) se.emplace(r, c, s);
                }
            }
        }
        vector<int> res(q); {
            map<char, int> cnt;
            for (int i = 0; i < q; i++) {
                set<int> ans;
                for (auto &t: se) {
                    int tmp = 0;
                    tmp += (cnt['('] - cnt[')']) * get<0>(t);
                    tmp += (cnt['{'] - cnt['}']) * get<1>(t);
                    tmp += (cnt['['] - cnt[']']) * get<2>(t);
                    ans.emplace(tmp);
                }
                res[i] = ans.size() == 1 ? *ans.begin() : -1;
                string s; cin >> s;
                for (auto c: s) cnt[c]++;
            }
        }
        for (int i = 0; i < q; i++) cout << res[i] << " \n"[i == q - 1];
    }
    return 0;
}


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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int N;
string S[200];
vector<int> edges[200];

bool bipart(){
    UnionFind uf(2*N);
    for(int i=0; i<N; i++) for(int j : edges[i]){
        uf.unite(i+N, j);
        uf.unite(j+N, i);
    }
    for(int i=0; i<N; i++) if(uf.same(i, i+N)) return false;
    return true;
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> S[i];
        for(int j=0; j<N; j++) if(S[i][j] == '1') edges[i].push_back(j);
    }
    if(!bipart()){
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    for(int s=0; s<N; s++){
        vector<int> dist(N, -1);
        dist[s] = 1;
        queue<int> que;
        que.push(s);
        while(que.size()){
            int i = que.front(); que.pop();
            for(int j : edges[i]) if(dist[j] == -1){
                dist[j] = dist[i]+1;
                que.push(j);
            }
        }
        int res = *max_element(dist.begin(), dist.end());
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, M;
vector<V> G;
itn cnt[202020];

int f(int i) {
    if (cnt[i] != -1)
        return cnt[i];
    int ret = 0;
    for (auto nxt : G[i]) {
        chmax(ret, f(nxt) + 1);
    }
    return cnt[i] = ret;
}

void solve() {
    cin >> N >> M;
    G.resize(N);
    FOR(M) {
        itn x, y;
        cin >> x >> y;
        x--;
        y--;
        G[y].pb(x);
    }
    FOR(N)
    cnt[i] = -1;
    int ans = 0;
    FOR(N)
    chmax(ans, f(i));
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n, x ;
    cin >> n >> x ;
    x-- ;
    vll pos(n+2) ;
    ll ans = 0;
    ll m = n ;
    
    while(x>=0){
        pos[0] = m ;
        ll k = 0 ;
        FOR(i,1,n+2){
            pos[i] = pos[i-1] + (k+1) ;
            k = 2*(k+1) ;
        }
        REP(i,n+1){
            if(pos[i]<= x && x < pos[i+1]){
                ans += pow(2,i) ;
                if(i==m+1){
                    ans-- ;
                }
                x -= pos[i] ;
                m = i-1; 

            }
        }
        if(m<0){
            break ;
        }
        x-- ;
    }



    cout << ans <<endl;



    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 4064
# 入力
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

def solution():
    N = input_int()
    As = input_ints()
    ans = gcd(As)
    print(ans)

if __name__ == '__main__':
    solution()

Measured memory_bytes: 21088
N = int(input())
x = []
y = 0
for i in range(N+1):
    if i % 3 == 0 and i % 5 == 0:
        x.append("FizzBizz")
    elif i % 3 == 0:
        x.append("Fizz")
    elif i % 5 == 0:
        x.append("Bizz")
    else:
        x.append(i)
        y += i
print(y)

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

int main() {
    string s;
    cin >>s;
    int sl = s.size();
    bool kaibun = true;
    for (int i = 0; i < sl; i++) {
        if (i < sl/2 + 1) {
            if (s.at(i) != s.at(sl - i - 1)) {
                kaibun = false;
                break;
            }
        }
        if (i < sl/4 + 1) {
            if (s.at(i) != s.at((sl - 1)/2 - i - 1)) {
                kaibun = false;
                break;
            }
        }
        if (i >= (sl + 3) /2 - 1 && i < sl * 3 / 4) {
            if (s.at(i) != s.at(sl  - (i - sl/2))) {
                kaibun =false;
                break;
            }
        }
    }
    if (kaibun) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

int main(){
  int N,sum=0;
  cin >>N;
  
  vector<int> h(N);
  
  for (int i=0;i<N;i++){
    cin>>h.at(i);
  }
  for (int i=1;i<N;i++){
    int x=0;
    for (int j=0;j<i;j++){
      if(h.at(i)>=h.at(j)){
        x++;
      }
    }
    if (x==i){
      sum++;
    }
  }
  cout <<sum+1<<endl;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << max(c - (a-b),0) << endl;
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
const int MAX = 2020;
int sm_v[MAX][MAX]={};
int sm_p[MAX][MAX]={};
int sm_q[MAX][MAX]={};

int count_v(int x1,int y1,int x2,int y2){
  return (sm_v[x1][y1]+sm_v[x2][y2])-(sm_v[x1][y2]+sm_v[x2][y1]);
}

int count_p(int x1,int y1,int x2,int y2){
  return (sm_p[x1][y1]+sm_p[x2][y2])-(sm_p[x1][y2]+sm_p[x2][y1]);
}

int count_q(int x1,int y1,int x2,int y2){
  return (sm_q[x1][y1]+sm_q[x2][y2])-(sm_q[x1][y2]+sm_q[x2][y1]);
}

int count_e(int x1,int y1,int x2,int y2){
  return count_p(x1+1,y1,x2,y2)+count_q(x1,y1+1,x2,y2);
}

signed main(){
  int h,w,q;
  cin>>h>>w>>q;
  vector<string> st(h);
  for(int i=0;i<h;i++) cin>>st[i];

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      sm_v[i+1][j+1]=(st[i][j]=='1');
      sm_p[i+1][j+1]=(st[i][j]=='1')&&(0<i&&st[i-1][j]=='1');
      sm_q[i+1][j+1]=(st[i][j]=='1')&&(0<j&&st[i][j-1]=='1');
    }
  }

  for(int i=0;i<=h;i++){
    for(int j=1;j<=w;j++){
      sm_v[i][j]+=sm_v[i][j-1];
      sm_p[i][j]+=sm_p[i][j-1];
      sm_q[i][j]+=sm_q[i][j-1];
    }
  }

  for(int i=1;i<=h;i++){
    for(int j=0;j<=w;j++){
      sm_v[i][j]+=sm_v[i-1][j];
      sm_p[i][j]+=sm_p[i-1][j];
      sm_q[i][j]+=sm_q[i-1][j];
    }
  }

  for(int i=0;i<q;i++){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--;y1--;
    cout<<count_v(x1,y1,x2,y2)-count_e(x1,y1,x2,y2)<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 53760
x = int(input())


def is5(n):
    mi = 0
    ma = n
    while mi != ma:
        mm = (mi + ma) // 2
        if mm ** 5 >= n:
            ma = mm
        else:
            mi = mm + 1
    return mi ** 5 == n, mi


a = 0
while True:
    bb = a ** 5 - x
    if bb >= 0:
        ok, b = is5(bb)
        if ok:
            print(a, b)
            break
    else:
        ok, b = is5(-bb)
        if ok:
            print(a, -b)
            break
    a += 1


Measured memory_bytes: 9128
//“First, solve the problem. Then, write the code.” – John Johnson
/* Author: Mihir Arora*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long int power(long long int x, unsigned long long int y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
} 
inline void solve()
{
      //lets begin; 
   ll n;
    cin>>n; 
    if(n%1000==0)
    cout<<0; 
    else
    cout<<1000-n%1000; 
    //check one last time before submitting(-50); 
}
int main()
{
// 	int t; 
//     cin>>t; 
//     while(t--)
//     {
        solve(); 
    //     cout<<"\n"; 
    // }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const long long MOD = 998244353;

class Combination {
    //a^p%mod
    ll powmod(ll a, ll p) {
        ll ans = 1LL;
        ll mul = a;
        // p >>=1 <-> p=(p >> 1)
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    ll mod;
    vector<ll> fact;
    vector<ll> revFact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    ll get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

int main(){
    ll N, A, B, K;
    cin >> N >> A >> B >> K;

    Combination cm = Combination(N, MOD);

    ll ans = 0;
    for(int i = 0; i <= N; i++){
        ll b = K - i * A;
        if(0 <= b && b <= B * N && b % B == 0){
            int j = b / B;

            ans += cm.get(N, i) * cm.get(N, j);
            ans %= MOD;
        }
    }

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


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

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    vector<int> a1, a2;
    
    for(int i = 0; i < N; i++) {
        int inp; cin >> inp;
        a1.push_back(inp);
    }
    for(int i = 0; i < N; i++) {
        int inp; cin >> inp;
        a2.push_back(inp);
    }
   
    int maxNum = 0;
    int i, j;
    for (int k = 1; k <= N; k++) {
        int sum = 0;
        for(i = 0; i < k; i++) {
            sum += a1[i];
        }
        for(j = i - 1; j < N; j++) {
            sum += a2[j];
        }
        maxNum = max(maxNum, sum);
    }
    cout << maxNum << endl;
    
    return 0;
}


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

int main() {
	int x;
	cin >> x;
	if (x == 3 || x == 5 || x == 7) cout << "YES" << endl;
	else cout << "NO" << endl;

}

Measured memory_bytes: 256
N = int(input())
trans = []
for i in range(5):
    trans.append(int(input()))
narrow = min(trans)
if N % narrow != 0:
    pair = N // narrow + 1
else:
    pair = N // narrow
print(str(pair+4))
#1組目が着くのは5分後
#2->6
#3->7

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

int main(){

  int N=0;
  cin>>N;

  for(int i=1;i<10;i++){
    
    if(N%i==0 && N/i<10){cout<<"Yes";return 0;}

  }
  
  cout<<"No"<<endl;

  
}


Measured memory_bytes: 256
#B問題
N = int(input())
C = [int(input()) for i in range(N)]
mod = 10**9+7
D = []

for i in range(N-1):
    if C[i] != C[i+1]:
        D.append(C[i])
D.append(C[-1])

M = len(D)
dp = [0 for i in range(M+1)]
dp[0] = 1
count = [0 for i in range(2*10**5+1)]

for i in range(1,M+1):
    dp[i] = dp[i-1]
    dp[i]+=count[D[i-1]]
    dp[i]%=mod
    count[D[i-1]]+=dp[i-1]
    count[D[i-1]]%=mod
    
print(dp[M])
    
    

Measured memory_bytes: 25972
#include <stdio.h>
int main()
{
	long long a,b;
	char c;
	scanf("%lld",&a);
	scanf(" %c ",&c);
	scanf("%lld",&b);
	if(c=='-')
	{
		printf("%lld",a-b);
	}
	else
	{
		printf("%lld",a+b);
	}
return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int H, W;
bool S[21][21];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '.') {
        S[i][j] = true;
        cnt++;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j]) {
        vector<vector<int>> dist(21, vector<int>(21, INF));
        dist[i][j] = 0;
        queue<pair<int, int>> q;
        q.emplace(i, j);
        while (!q.empty()) {
          int h, w;
          tie(h, w) = q.front();
          q.pop();
          if (w > 0 && S[h][w - 1] && dist[h][w - 1] == INF) {
            q.emplace(h, w - 1);
            dist[h][w - 1] = dist[h][w] + 1;
            ans = max(ans, dist[h][w - 1]);
          }
          if (w < W - 1 && S[h][w + 1] && dist[h][w + 1] == INF) {
            q.emplace(h, w + 1);
            dist[h][w + 1] = dist[h][w] + 1;
            ans = max(ans, dist[h][w + 1]);
          }
          if (h > 0 && S[h - 1][w] && dist[h - 1][w] == INF) {
            q.emplace(h - 1, w);
            dist[h - 1][w] = dist[h][w] + 1;
            ans = max(ans, dist[h - 1][w]);
          }
          if (h < H - 1 && S[h + 1][w] && dist[h + 1][w] == INF) {
            q.emplace(h + 1, w);
            dist[h + 1][w] = dist[h][w] + 1;
            ans = max(ans, dist[h + 1][w]);
          }
        }
      }
    }
  }

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

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

constexpr int MAX_N = (1 << 18) + 10;

int N;
int V[MAX_N], W[MAX_N];

int usLen;
int us[110];
int esLen, fsLen;
pair<int, int> es[1010], fs[1010];

int main() {
  for (; ~scanf("%d", &N); ) {
    for (int u = 1; u <= N; ++u) {
      scanf("%d%d", &V[u], &W[u]);
    }
    int Q;
    scanf("%d", &Q);
    for (int q = 0; q < Q; ++q) {
      int X, L;
      scanf("%d%d", &X, &L);
      usLen = 0;
      for (int u = X; u; u >>= 1) {
        us[usLen++] = u;
      }
      const int half = usLen / 2;
      esLen = 1 << half;
      fsLen = 1 << (usLen - half);
      for (int i = 0; i < half; ++i) {
        for (int h = 0; h < 1 << i; ++h) {
          es[h | 1 << i].first = es[h].first + W[us[i]];
          es[h | 1 << i].second = es[h].second + V[us[i]];
        }
        inplace_merge(es, es + (1 << i), es + (1 << (i + 1)));
      }
      for (int i = 0; i < usLen - half; ++i) {
        for (int h = 0; h < 1 << i; ++h) {
          fs[h | 1 << i].first = fs[h].first + W[us[half + i]];
          fs[h | 1 << i].second = fs[h].second + V[us[half + i]];
        }
        inplace_merge(fs, fs + (1 << i), fs + (1 << (i + 1)));
      }
      int ans = 0;
      int mx = 0;
      for (int g = 0, h = fsLen; h--; ) {
        for (; g < esLen && es[g].first + fs[h].first <= L; ++g) {
          chmax(mx, es[g].second);
        }
        if (g > 0) {
          chmax(ans, mx + fs[h].second);
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}


Measured memory_bytes: 5888