akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
INF = float('inf')
weight = [0] * N
value = [0] * N
Max_v = 0
for i in range(N):
    w, v = map(int, input().split())
    weight[i], value[i] = w, v
    Max_v += v

dp = [[INF]*(Max_v+1) for _ in range(N)]
for i in range(0, value[0]+1):
    dp[0][i] = weight[0] if i else 0

for i in range(1, N):
    for vs in range(Max_v+1):
        if vs - value[i] >= 0:
            dp[i][vs] = dp[i-1][vs - value[i]] + weight[i]
        else:
            dp[i][vs] = weight[i]
        dp[i][vs] = min(dp[i][vs], dp[i-1][vs])

for i in reversed(range(Max_v+1)):
    if dp[N-1][i] <= W:
        print(i)
        break


Measured memory_bytes: 310056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(a) (a.begin(),a.end())
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
//dp[i日目][J][O][I]
ll dp[110][100100];
int main(){
  rep(i,110)rep(j,100100)dp[i][j] = INF;
  int n,w;
  cin >> n >> w;
  vector<int>W(n),v(n);
  rep(i,n)cin >> W[i] >> v[i];
  dp[0][0] = 0;
  rep(i,n)rep(j,100001){
    dp[i + 1][j + v[i]] = min(dp[i][j] + W[i],dp[i + 1][j + v[i]]);
    dp[i + 1][j] = min(dp[i + 1][j],dp[i][j]);
  }
  int ans = 0;
  rep(i,100001)if(dp[n][i] <= w)ans = max(ans,i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 89664
#include <bits/stdc++.h>
using namespace std;
int i,j,k,n,m,c,r;
long long ox,x,y,z,a[10010],a2[10010];
map<long long, long long> b,w;
map<long long, int> cnt;
int main() {
  for (j=2; j<100000; j++) {
    for (k=0; k<m && a[k]*a[k]<=j; k++) if (j%a[k]==0) break;
    if (k>=m || a[k]*a[k]>j) {
      a2[m]=1LL*j*j; a[m++]=j;
    }
  }
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%lld",&x); ox=x;
    if (w.count(x)) {
      if (w[x]==-1) r+=2; else cnt[w[x]]++;
      continue;
    }
    for (j=0, y=z=1; j<m && a[j]*a[j]<=x; j++) if (x%a[j]==0) {
      for (c=0; x%a[j]==0; c++) x/=a[j];
      c%=3;
      if (c==1) {
        y*=a[j]; z*=a2[j];
      } else if (c==2) {
        y*=a2[j]; z*=a[j];
      }
    }
    if (x>1000000000 || z>10000000000LL) {
      w[ox]=-1;
      r+=2;
    } else {
      if (x>1) {
        y*=x;
        z*=x*x;
      }
      cnt[y]++;
      b[y]=z;
      b[z]=y;
      w[ox]=y;
    }
  }
  for (auto it=b.begin(); it!=b.end(); it++) if (it->first==1) r+=2;
    else r+=max(cnt[it->first],cnt[it->second]);
  printf("%d\n",r/2);
  return 0;
}


Measured memory_bytes: 27264
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


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

  ll S = B - A;

  ll c = min(C, D), d = max(C, D);

  N--;
  for (ll i = 0; i <= N; i++){
    if (i * C + (i - N) * D <= S && S <= (i - N) * C + i * D){
      cout << "YES" << endl;
      return 0;
    }
  }
  
  
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String [] args) {
        FastReader reader = new FastReader();

        int n = reader.nextInt();
        int [] a = new int [n];
        long [] sum = new long [n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = reader.nextInt();
            sum [i + 1] = sum [i] + a[i];
        }

        long [][] dp = new long [n][n];
        // dp[i][j] -> minimum cost to merge interval i,j

        for (int L = n - 1; L >=0; L--) {
            for (int R = L + 1; R < n; R++) {
                dp [L][R] = Long.MAX_VALUE;
                for (int i = L; i < R; i++) {
                    dp[L][R] = Math.min(dp[L][R], dp[L][i] + dp[i + 1][R] + (sum[R + 1] - sum[L]));
                }
            }
        }

        System.out.println(dp[0][n - 1]);

    }


    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 34748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
#define Inarr(a,n) for(int i=0;i<n;i++)cin>>a[i]
int main(){
    ll n,t,ans;
    cin>>n>>t;
    ans=t;
    vector<ll>time(n);
    Inarr(time,n);
    for(int i=1;i<n;i++){
        if(time[i]-time[i-1]<t)ans+=time[i]-time[i-1];
        else ans+=t;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;

	ll le = 4 * a*b;
	ll q = c - a - b;
	ll ri = q * q;
	if (q < 0) {
		cout << "No" << endl;
		return 0;
	}

	if (le < ri) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto hs = readln.split.to!(int[]);
    hs ~= 0;
    int c;
    foreach (i; 0..N) c += max(0, hs[i] - hs[i+1]);
    writeln(c);
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == b + c || b == c + a || c == a + b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=1e9+7;
const int maxn = 2e6+1000;


int n,a[maxn],k;

LL ksm(LL a,LL b){
    a=(a%mod+mod)%mod;
    LL res = 1;
    while(b){
        if(b&1){
            res = res*a%mod;
        }
        a=a*a%mod;b>>=1;
    }
    return res;
}
bool cmp1(int a,int b){
    return abs(a)>abs(b);
}
bool cmp2(int a,int b){
    return abs(a)<abs(b);
}

int main(){
//    op;
    read(n);read(k);
    int num1=0,num0=0,num2=0;
    fo(i,1,n) {
        read(a[i]);
        if(a[i]>0) num2++;
        else if(a[i]==0) num0++;
        else num1++;
    }
    LL ans =1;
    if(num0>n-k){
        puts("0");return 0;
    }
    if(k==n){
        fo(i,1,n) ans = ans*a[i]%mod;
    }
    else if(num2==0&&(k&1)){
        sort(a+1,a+1+n,cmp2);
        fo(i,1,k) ans = ans*a[i]%mod;
    }
    else{
        int cnt1=0;
        sort(a+1,a+1+n,cmp1);
        fo(i,1,k){
            if(a[i]<0) cnt1++;
            ans=ans*a[i]%mod;
        }
        if(cnt1&1){
            if(cnt1==k){
                ans = ans*ksm(a[k],mod-2)%mod;
                fo(i,k+1,n){
                   if(a[i]>=0){
                       ans=ans*a[i]%mod;break;
                   }
               }
            }
            else {
                LL t1 = 1, t2 = 1, flag1 = 1, flag2 = 1;
                fo(i, 1, k) {
                    if (a[i] < 0) t1 = a[i];
                    else t2 = a[i];
                }

                ans = ans*ksm(t1*t2%mod,mod-2)%mod;

                fo(i, k + 1, n) {
                    if(flag1&&a[i]<0){
                        t1*=a[i];flag1=0;
                    }
                    else if(flag2&&a[i]>=0){
                        t2*=a[i];flag2=0;
                    }
                }
                ans =ans*(max(t1,t2)%mod)%mod;
            }
        }
    }
    ans = (ans%mod+mod)%mod;
    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 4516
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
	IOS;
	int n; cin>>n;
	vector<int> p(n+1),a(n+1);
	p[0]=0;
	int pos;
	int ctr=0,k=0;
	bool flag=false;
	for(int i=0;i<n;i++){
		cin>>p[i];
		a[i]=i+1;
	}
	for(int i=0;i<n;i++){
		if(ctr>2){
			flag=true;
			break;
		}
		if(p[i]!=a[i])
			ctr++;
	}
	if(flag){
		cout<<"NO";
	}
	if(ctr==2 or ctr==0){
		cout<<"YES";
	}
return 0;
}

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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;


int main()
{
	faster
	ll a,b,c,ans,x,y;
	cin>>a>>b>>c;
	if(a>=0)
	{
		x=a/c;
		if(x==b)cout<<a-(c*x)<<nl;
		else if(x>b)cout<<a-(c*b)<<nl;
		else{
			a=a-(c*x)-c;
			x++;
			y=b-x;
			if(y%2==0)cout<<abs(a)<<nl;
			else cout<<a+c<<nl;
		}
	}
	else{
		ans=abs(a);
		x=ans/c;
		if(x==b)cout<<abs(a+c*x)<<nl;
		else if(x>b)cout<<abs(a+(c*b))<<nl;
		else{
			a=a+(c*x)+c;
			x++;
			y=b-x;
			if(y%2==0)cout<<abs(a)<<nl;
			else cout<<abs(a-c)<<nl;
		}
	}
	return 0;

}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
struct res{
	string a;
	int point;
	int num;
};
res trant[105];
int n;
bool up_stair(res x, res b){
	if(x.a==b.a){
		return x.point>b.point;
	}
	return x.a<b.a;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>trant[i].a;
		cin>>trant[i].point;
		trant[i].num=i+1;
	}
	sort(trant,trant+n,up_stair);
	for(int i=0;i<n;i++){
		cout<<trant[i].num<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>
#include <memory>
#include <cassert>

#include <map>
#include <vector>
#include <queue>


using namespace std;

typedef long long LL;

int n, a, b;

int main() {
    cin >> n >> a >> b;
    int c = 0;
    while(n) {
        --n;
        int x, y;
        scanf("%d%d", &x, &y);
        if (x >= a && y >= b)
            ++c;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
from collections import Counter
s=input()
n=len(s)
M=[0]
mod=2019
for i in range(n):
	m=(M[-1]+int(s[n-1-i])%mod*pow(10,i,mod))%mod
	M.append(m)
MC=Counter(M)
r=0
for v in MC.values():
	if v>1:
		r+=v*(v-1)//2
print(r)

Measured memory_bytes: 16740
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(!(a % 3) || !(b % 3) || !((a + b) % 3))	printf("Possible\n");
	else printf("Impossible");
	return 0;
}


Measured memory_bytes: 128
h,w = gets.split.map(&:to_i)
grid = []
h.times do
  grid << gets.chomp
end

dp = Array.new(h){[0]*w}
dp[0][0] = grid[0][0] == "#" ? 1 : 0

h.times do |i|
  w.times do |j|
    cand = []
    cand << dp[i-1][j] + (grid[i-1][j] == "." && grid[i][j] == "#" ? 1 : 0) if i > 0
    cand << dp[i][j-1] + (grid[i][j-1] == "." && grid[i][j] == "#" ? 1 : 0) if j > 0
    dp[i][j] = cand.min if !cand.empty?
  end
end

p dp[h-1][w-1]

Measured memory_bytes: 3964
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Function (on)

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    y <- getl toInt
    solve y <$> replicateM n (getl $ wrds toInt) >>= print
    main

solve :: Int -> [[Int]] -> Int
solve y = fst . maximumBy (compare `on` snd) . map interest
  where
    interest :: [Int] -> (Int, Double)
    interest [b, r, t]
      | t == 1 = (b, 1.0 + fromIntegral y * (fromIntegral r / 100.0))
      | otherwise = (b, (1.0 + fromIntegral r / 100.0) ^ y)
                    
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4556
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll f(ll n, ll x);

int main(){
  ll a,b,x;
  cin >>a>>b>>x;
  ll ans = f(b,x)-f(a-1,x);
  
  cout <<ans<< endl;
}

ll f(ll n,ll x){
  ll ans;
  n==-1 ? ans=0 : ans=n/x+1;
  return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> color(n+2);
    repeat(i, m) {
        int l, r, x; cin >> l >> r >> x;
        color[r].emplace_back( make_pair(l, x) );
    }
    for(auto &e: color) {
        sort(e.begin(), e.end());
    }
    
    auto isok = [&color] (int i, int j, int k) -> bool {
        int m = max(max(i, j), k);
        for(int l = color[m].size() - 1; l >= 0; --l) {
            int cnt = 0;
            pair<int, int> p = color[m][l];
            if (p.first <= i) ++cnt;
            if (p.first <= j) ++cnt;
            if (p.first <= k) ++cnt;
            if (cnt != p.second) return false;
        }
        return true;
    };
    
    vector<vector<vector<int>>> dp;
    dp.resize(n+2);
    for(auto &e: dp) e.resize(n+2);
    for(auto &e: dp) for(auto &f: e) f.resize(n+2, 0);
    dp[0][0][0] = 1;
 
    const int MOD = 1e9 + 7;
    repeat(i, n+1) {
        repeat(j, n+1) {
            repeat(k, n+1) {
                int l = max(max(i, j), k);
                if (isok(i, j, l+1)) dp[i][j][l+1] += dp[i][j][k], dp[i][j][l+1] %= MOD;
                if (isok(i, l+1, k)) dp[i][l+1][k] += dp[i][j][k], dp[i][l+1][k] %= MOD;
                if (isok(l+1, j, k)) dp[l+1][j][k] += dp[i][j][k], dp[l+1][j][k] %= MOD;
            }
        }
    }
    
    int ans = 0;
    repeat(i, n+1) {
        repeat(j, n+1) {
            repeat(k, n+1) {
                int l = max(max(i, j), k);
                if (l == n) {
                    ans += dp[i][j][k];
                    ans %= MOD;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 111360
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n,m;
const int maxn=2e5+5;
set<ll> adj[maxn];
ll vis[maxn];
ll dfs(ll u,ll par)
{
	vis[u]=1;
	ll val=1;
	for(auto v:adj[u])
	{
		if(v==par) continue;
		if(vis[v]) continue;
		val+=dfs(v,u);
	}
	return val;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n>>m;
	rep(i,m)
	{
		ll x,y;
		cin>>x>>y;
		adj[x].insert(y);
		adj[y].insert(x);
	}
	ll ans=0;
	repA(i,1,n)
	{
		if(!vis[i])
		{
			ans=max(ans,dfs(i,0));
		}
	}
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



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

int main(){
  int a,b;
  cin>>a>>b;
  
  if(a>=b*2){cout<<a-b*2<<endl;}
  else{cout<<0<<endl;}
  
  return 0;
}

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

int main()
{
    int n, k, c = 0, i;
    cin >> n >> k;
    int arr[n+1];

    for(i = 1; i <= n; i++) cin >> arr[i];
    n--;
    k--;
    int res = (n + k - 1) / k;
    cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, m;
  cin >> n >> m;
  vi a(m), b(m);
  vector<vi> c(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) {
      int cc;
      cin >> cc;
      c[i].push_back(cc-1);
    }
  }

  const int inf = 101010101;
  vector<vi> dp(m+1, vi(1<<n, inf));
  vi d(m);
  dp[0][0] = 0;

  rep(i, m) {
    rep(j, b[i]) {
      d[i] |= 1<<c[i][j];
    }
  }

  rep(i, m) {
    rep(mask, 1<<n) {
      cmin(dp[i+1][mask], dp[i][mask]);

      cmin(dp[i+1][mask|d[i]], dp[i][mask] + a[i]);
    }
  }

  if (dp[m][(1<<n)-1] == inf) cout << -1 << endl;
  else cout << dp[m][(1<<n)-1] << endl;
}


Measured memory_bytes: 16384
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO
	
	ll n;
	cin >> n;
	
	vector <ll> ans(n + 10, 1);
	for(ll i = 2; i <= n; i ++)	
	{
		if(ans[i] == 1)
		{
			ans[i] = 2;
			for(ll j = 2; i * j <= n; j ++)
			{
				ll val = i * j;
				ll count = 0;
				while(val % i == 0)
				{
					val /= i;
					count ++;
				}
					
				ans[i * j] *= (count + 1);
			}
		}
	}


	ll res = 0;
	for(ll i = 1; i <= n; i ++)
	{
		if(i != 1 && ans[i] == 1)
			ans[i] = 2;
		// debug(i * ans[i])
		res += (i * ans[i]);
	}

	cout << res << endl;
}

Measured memory_bytes: 81336
def myAnswer(N:int,K:int,X:list):
   ans = 0
   for x in X:
      ans+= min(abs(0 - x)*2, abs(K - x)*2 )
   return ans

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   K = int(input())
   X = list(map(int,input().split()))
   print(myAnswer(N,K,X[:]))


if __name__ == '__main__':
   main()

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

int main(void) {
  int n, k, i, x, d_k, total = 0;
  scanf("%d\n%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    d_k = abs(k - x);
    if (d_k > x)
      total += x;
    else
      total += d_k;
  }
  printf("%d\n", total * 2);
  return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n, 0);
        hash2.assign(n, 0);
        power1.assign(n, 1);
        power2.assign(n, 1);
        for(int i = 1; i <  n; ++i) {
            hash1[i] = (hash1[i - 1] * base1 + S[i]) % mod1;
            hash2[i] = (hash2[i - 1] * base2 + S[i]) % mod2;
            power1[i] = (power1[i - 1] * base1) % mod1;
            power2[i] = (power2[i - 1] * base2) % mod2;
        }
    }

    // get hash of S[left:right]
    inline pair<long long, long long> Get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l - 1] * power1[r - l + 1] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l - 1] * power2[r - l + 1] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};

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

    int n;
    cin >> n;

    string s;
    cin >> s;
    s = ' ' + s;
    RollingHash rh(s);


    auto Check = [&](int k) ->bool
    {

        map<pair<ll,ll>,ll> mp;
        for(int i = 1; i <= n -k + 1; ++i)
        {
            pair<ll, ll> x = rh.Get(i, i+ k-1);
            if(!mp.count(x))
            {
                mp[x] = i + k - 1;
            }
            else if(mp[x] < i)
            {
                return true;
            }
        }
        return false;
    };

    int left = 0, right = n / 2 + 1;
    while(right - left > 1)
    {
        int mid = left + (right - left) / 2;
        if(Check(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }
    cout << left;


    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int ans;
string s,a="CODEFESTIVAL2016";
int main()
{
	getline(cin,s);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=a[i])
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();

        int[] ans = solve(r, D, x);
        for (int i=0; i<10; i++) {
            System.out.println(ans[i+1]);
        }
    }

    private static int[] solve(int r, int D, int x) {
        int[] ans = new int[11];

        ans[0] = x;
        for (int i=0; i<10; i++) {
            ans[i+1] = r * ans[i] - D;
        }

        return ans;
    }
}


Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		cout<<s[i]<<t[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
  a *= 100;
  b *= 100;
  int maxy = 0, maxz = a, x, y, z;
  for(int i = 0; a * i <= f; i++){
    for(int j = 0; a * i + b * j <= f; j++){
      for(int k = 0; a * i + b * j + c * k <= f; k++){
        for(int l = 0; a * i + b * j + c * k + d * l <= f; l++){
          int x = a * i + b * j;
          int y = c * k + d * l;
          int z = x + y;
          //if(z == 2634) cout << i << " " << j << " " << k << " " << l << endl;
          //cout << z << endl;
          if(x == 0) continue;
          if(z > f) break;
          if((x / 100) * e < y) break;
          if(y * 100 * maxz > maxy * 100 * z){
            maxy = y;
            maxz = z;
          }
        }
      }
    }
  }
  cout << maxz << " " << maxy << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

int main() {

	int n, x, y; cin >> n >> x >> y;
	vector<int> num(n, 0);
	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			int a = abs(i - j);
			int b = abs(i - x) + 1 + abs(y - j);
			int c = abs(i - y) + 1 + abs(x - j);
			int x = min({ a,b,c });
			if (x < 1 || n - 1 < x) continue;
			num[x]++;
		}
	}
	for (int i = 1; i <= n - 1; i++) {
		cout << num[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    double n;
    int m;
    cin>>n>>m;
    vector<double> v1(n);
    double summ=0;
    for(auto &i:v1) cin>>i,summ+=i;
    double temp=4*m;
    temp+=0.0;
    int cnt=0;
    for(auto i:v1)
    {
        if(i>=(summ/temp)) cnt++;
    }
    if(cnt>=m) cout<<"Yes"<<endl;
    else  cout<<"No"<<endl;
    
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 10968
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli k;
	cin>>k;
	vector<lli> a(k);
	REP(i,0,k)cin>>a[i];

	lli minNum=2,maxNum=2;

/*
	if(a[k-1]!=2){
		cout<<-1<<endl;
		return 0;
	}
	*/

	for(lli i=k-1;i>=0;i--){
		if(DEBUG)cout<<"minNum="<<minNum<<" maxNum="<<maxNum<<endl;
		
		if(maxNum<a[i]){
			cout<<-1<<endl;
			return 0;
		}
		if(minNum>maxNum){
			cout<<-1<<endl;
			return 0;
		}
		
		maxNum = ((maxNum)/a[i]+1)*a[i]-1;
		minNum = ((minNum-1)/a[i]+1)*a[i];
	}
	if(minNum>maxNum){
		cout<<-1<<endl;
		return 0;
	}

	cout<<minNum<<" "<<maxNum<<endl;

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n,m,dp[1001][1001];
const ll mod=1e9+7;
string s;

int main()
{Tie
	cin>>n>>m,dp[0][1]=1;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		for(int j=1;j<=m;j++)
			if(s[j-1]=='.')
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	}
	cout << dp[n][m]<<'\n';
}

Measured memory_bytes: 8064
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, C, D; cin >> A >> B >> C >> D;

    int s = max(A, C);
    int e = min(B, D);

    int ans = max(e - s, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define H 250
#define NIL -200000

int main()
{


  int s[H], i, num;

  for(i = 0 ; i < H ; i++)
    s[i] = NIL;

  scanf("%d",&num);

  for(i = 0 ; i < num ; i++)
    scanf("%d",&s[i]);

  for(i = 0 ; i < num ; i++){
    printf("node %d: ",i+1);
    if(2*i+1 < num){
      if(i ==0 )
        printf("key = %d, left key = %d, right key = %d, \n",s[i],s[i + 1],s[i \
+2]);
      else if(s[2*(i+1)] != NIL  &&  s[2*i+1] != NIL)
        printf("key = %d, parent key = %d, left key = %d, right key = %d, \n",s\
[i],s[(i-1)/2],s[2*i+1],s[2*(i+1)]);
      else if(s[2*(i+1)] == NIL  &&  s[2*i+1] != NIL)
        printf("key = %d, parent key = %d, left key = %d, \n",s[i],s[(i-1)/2],s\
[2*i+1]);
      else
        printf("key = %d, parent key = %d, \n",s[i],s[(i-1)/2]);
    }
    else printf("key = %d, parent key = %d, \n",s[i],s[(i-1)/2]);
  }
  return 0;
}



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

int main(){
  double a,b,x;
  cin >> a >> b >> x;
  
  if(2.0*x>=a*a*b){
    cout << setprecision(10) << (180.0/M_PI)*atan((2.0*b*a*a-2.0*x)/(a*a*a)) << endl;
  }else{
    cout << setprecision(10) << (180.0/M_PI)*atan((a*b*b)/(2.0*x)) << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
const int maxn=300000;
int n,a[maxn+10];
long long tot=0;
using namespace std;
int main (){
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+3*n+1);
	int l=1,r=3*n;
	while(l<r){
		l++; r--;
		tot+=a[r];
		r--;
	}
	cout<<tot;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
    cin >> S;

    if(S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3)) cout << "Yes" << endl;
    else if(S.at(0) == S.at(2) && S.at(2) != S.at(1) && S.at(1) == S.at(3)) cout << "Yes" << endl;
    else if(S.at(0) == S.at(3) && S.at(3) != S.at(1) && S.at(1) == S.at(2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
 
public class Main{
	
	public static final int MAX = 20;
	
    public static void main(String[] args){
    	final Scanner sc = new Scanner(System.in);
    	
    	long[] facts = new long[MAX + 1];
    	facts[0] = 1; 
    	for(int i = 1; i <= MAX; i++){
    		facts[i] = facts[i - 1] * i;
    	}
    	
    	int[] count = new int[26];
    	char[] input = sc.next().toCharArray();
    	
    	for(char c : input){
    		count[c - 'a']++;
    	}
    	
    	final int allow_odd = input.length % 2 == 0 ? 0 : 1;
    	int odd_count = 0;
    	int odd_pos = -1;
    	for(int i = 0; i < 26; i++){
    		if(count[i] % 2 == 1){
    			odd_count++;
    			odd_pos = i;
    		}
    	}
    	
    	if(allow_odd < odd_count){
    		System.out.println(0);
    		return;
    	}
    	
    	if(odd_pos != -1){
    		count[odd_pos]--;
    	}
    	
    	for(int i = 0; i < 26; i++){
    		count[i] /= 2;
    	}
    	
    	int valid = 0;
    	for(int i = 0; i < 26; i++){
    		valid += count[i];
    	}
    	
    	//System.out.println(Arrays.toString(count));
    	
    	long sum = facts[valid];
    	for(int i = 0; i < 26; i++){
    		sum /= facts[count[i]];
    	}
    	
    	System.out.println(sum);
    }
     
}

Measured memory_bytes: 17324
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double area = Math.PI * r * r;
        double length = 2 * Math.PI * r;
        System.out.printf("%f %f", area, length);
        sc.close();
    }
}


Measured memory_bytes: 28328
using System;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        int n = int.Parse(inp[0]);
        int m = int.Parse(inp[1]);

        var inp2 = Console.ReadLine().Split(' ');

        int holiday = n;
        for(int i = 0;i < m;i++) {
            n -= int.Parse(inp2[i]);
        }

        Console.WriteLine(n >= 0 ? n : -1);
    }
}

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

typedef long long ll;

int main() {
  int n;
  
  while( cin>>n && n ) {
    map<int,ll> mp;
    vector<ll> v;

    for( int i=0; i<n; i++ ) {
      int a;
      ll b, c;
      cin >> a >> b >> c;
      if( !mp[a] )v.push_back( a );
      mp[a] += b * c;
    }

    bool isExist = false;
    for( int i=0; i<v.size(); i++ ) {
      if( mp[v[i]] >= 1000000 ) {
	isExist = true;
	cout << v[i] << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1284
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "begin", long, "end");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    if(n < m)
        swap(n, m);
    foreach (_; iota(n))
    {
        write(m);
    }
    writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define fi first
#define se second

typedef long long LL;
typedef std:: pair <LL,int> pair;
const LL INF=1e15;
const int MOD=1000000007;
const int N=200005;
const int E=500005;

struct edge {int x,y; LL w; int next;} e[E];

LL cnt[2][N],dis[2][N];
int ls[N],edCnt,n;

bool vis[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):(v),ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

void add_edge(int x,int y,LL w) {
	e[++edCnt]=(edge) {x,y,w,ls[x]}; ls[x]=edCnt;
	e[++edCnt]=(edge) {y,x,w,ls[y]}; ls[y]=edCnt;
}

void dijk(int st,int ed,LL *dis,LL *cnt) {
	rep(i,0,n) dis[i]=INF; dis[st]=0;
	rep(i,0,n) cnt[i]=0; cnt[st]=1;
	rep(i,0,n) vis[i]=0;
	std:: priority_queue <pair> heap;
	for (heap.push(pair(0,st));!heap.empty();) {
		pair top=heap.top(); heap.pop();
		int x=top.se;
		if (vis[x]) continue; vis[x]=1;
		for (int i=ls[x];i;i=e[i].next) {
			if (dis[x]+e[i].w<dis[e[i].y]) {
				dis[e[i].y]=dis[x]+e[i].w;
				heap.push(pair(-dis[e[i].y],e[i].y));
				cnt[e[i].y]=cnt[x];
			} else if (dis[x]+e[i].w==dis[e[i].y]) {
				cnt[e[i].y]+=cnt[x]; cnt[e[i].y]%=MOD;
			}
		}
	}
}

int main(void) {
	n=read(); int m=read();
	int st=read(),ed=read();
	rep(i,1,m) {
		int x=read(),y=read(),w=read();
		add_edge(x,y,w);
	}
	dijk(st,ed,dis[0],cnt[0]);
	dijk(ed,st,dis[1],cnt[1]);
	LL len=dis[0][ed];
	LL ans=cnt[0][ed]*(cnt[0][ed]-1)%MOD;
	rep(i,1,n) if (dis[0][i]==dis[1][i]&&dis[0][i]*2==len) {
		LL tmp=cnt[0][i]*cnt[1][i]%MOD;
		ans=(ans+MOD-tmp*(tmp-1)%MOD)%MOD;
	}
	for (int i=1;i<edCnt;i+=2) {
		int x=e[i].x,y=e[i].y; LL w=e[i].w;
		if (dis[0][x]>dis[0][y]) std:: swap(x,y);
		if (dis[0][x]+w+dis[1][y]==len&&dis[0][x]*2<len&&dis[1][y]*2<len) {
			LL tmp=cnt[0][x]*cnt[1][y]%MOD;
			ans=(ans+MOD-tmp*(tmp-1)%MOD)%MOD;
		}
	}
	ans=(ans%MOD+MOD)%MOD;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int LIMIT = 1e9 + 7;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

long long divisor(long long n, vector<long long> &d){
  long long cnt = 0;
  for(long long i=1; i*i<=n; i++){
    if(n%i==0){
      d.push_back(i);
      if(i*i!=n){
        d.push_back(n/i);
        cnt++;
      }
      cnt++;
    }
  }
  return cnt;
}

long long divisor_sort(long long n, vector<long long> &d){
  long long cnt = divisor(n, d);
  sort(d.begin(), d.end());
  return cnt;
}

long long gcd(long long a, long long b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

int main(){
	int a,b,k;cin>>a>>b>>k;

  vector<ll> d;
  ll s = divisor_sort(gcd(a,b), d);
  //debug(d);
  //debug(s);
  cout<<d[s-k]<<endl;
}

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

using namespace std;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  int ans = a[2] - a[1];
  a[0] += ans;
  ans += (a[2] - a[0] + 1) / 2;
  if(a[2] % 2 != a[0] % 2) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

bool kaibunCheck(string s, int l, int r){
  int n = s.size();
  if(l < 0 || l > n-1 || l > r || r < 0 || r > n-1) return false;
  bool flag = true;
  for(int i = l; i <= r; i++){
    if(s[i] != s[r-i]) flag = false;
  }
  return flag;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int N = S.size();
  bool flag = true;
  if(!kaibunCheck(S, 0, N-1)) flag = false;
  if(!kaibunCheck(S, 0, (N-1)/2-1)) flag = false;
  if(!kaibunCheck(S, (N+3)/2-1, N-1)) flag = false;
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
    int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int cost=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      
        cost=cost+arr[i]*arr[j];
      
    }
    
  }
  cout<<cost<<endl;
   return 0;
  }

Measured memory_bytes: 256
n = int(input())
cnt = 0
a = [list(map(int, input().split())) for _ in range(n)]
a.reverse()
cnt = 0
for i in range(n) :
  if((a[i][0] + cnt) % a[i][1] != 0) :
    cnt += a[i][1] - ((a[i][0] + cnt) % a[i][1])
print(cnt)

Measured memory_bytes: 27380
n, x, m = map(int, input().split())
init, cr = x, x
hist = [m+1, x]
for idx in range(2, n + 1):
    cr = (cr ** 2) % m
    if cr in hist:
        idx_bef = hist.index(cr)
        remains = n - idx + 1
        ans = sum(hist[1:])
        sum_period = sum(hist[idx_bef:])
        period_num = idx - idx_bef
        ans += sum_period * (remains // period_num)
        ans += sum(hist[idx_bef: idx_bef + remains % period_num])
        print(ans)
        exit()
    else:
        hist.append(cr)
print(sum(hist[1:]))


Measured memory_bytes: 69020
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int y, m, d;
int main(){
  cin >> s;
  sscanf( s.c_str(), "%d/%d/%d",&y, &m, &d);
  if(m > 4) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
  return 0;
  }
  


Measured memory_bytes: 256
N,Q = map(int,input().split())
S = str(input())
l,r = [0]*Q,[0]*Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())
    
count_list = []
count = 0
count_list.append(0)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        count += 1
        count_list.append(count)
    else:
        count_list.append(count)
    
for j in range(Q):
    print(count_list[r[j]-1]-count_list[l[j]-1])



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << " " << max(0,a+b-n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int Abs(re int x){
	return x>0?x:-x;
}
inline int read(){
	re int t=0,f=0;re char v=getchar();
	while(v<'0')f|=(v=='-'),v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return f?-t:t;
}
int a[17],b[17],c[17],n,p[17],h[17],s[17],ch,cs,ans,cnt;
inline void dfs1(re int x,re int y){
	if(x==y+1){
		re int tmp=0;
		for(re int i=1;i<=n;++i){
			re int xx=1e18;
			xx=min(xx,min(Abs(b[i]),Abs(a[i])));
			for(re int j=1;j<=ch;++j)xx=min(xx,Abs(a[i]-h[j]));
			for(re int j=1;j<=cs;++j)xx=min(xx,Abs(b[i]-s[j]));
			tmp+=xx*c[i];
			if(tmp>ans)break;
		}
		ans=min(ans,tmp);
		return;
	}
	h[++ch]=a[p[x]];
	dfs1(x+1,y);
	--ch;
	s[++cs]=b[p[x]];
	dfs1(x+1,y);
	--cs;
}
inline void dfs(re int x,re int y){
	if(x==n+1){
		if(y)return;
		dfs1(1,cnt);
		return;
	}
	p[++cnt]=x;
	if(y)dfs(x+1,y-1);
	--cnt;
	dfs(x+1,y);
}
signed main(){
	n=read();ans=1e18;
	for(re int i=1;i<=n;++i)a[i]=read(),b[i]=read(),c[i]=read();
	for(re int i=0;i<=n;++i){
		if(ans)dfs(1,i);
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 3784
#include<stdio.h>

int main(void){

	int m,f,r;

	while(scanf("%d %d %d",&m,&f,&r)!=EOF){

		if( m==-1 && f==-1 && r==-1)
			break;

		if(m==-1 || f==-1 || m+f < 30)
			printf("F\n");
		else if(m+f < 50 && r < 50)
			printf("D\n");
		else if((m+f < 50 && r >= 50)||m+f < 65)
			printf("C\n");
		else if(m+f < 80)
			printf("B\n");
		else 
			printf("A\n");

	}

	return 0;

}
			

Measured memory_bytes: 584
#include<stdio.h>
int main()
{
    char S[19];
    int i;
    for(i=0;i<19;i++)
    {
        scanf("%c",&S[i]);
    }
    for(i=0;i<19;i++)
    {
       if(S[i]==',')
       {
           S[i]=' ';
       }
       printf("%c",S[i]);
    }

}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int k, s;
    cin >> k >> s;
    int num = 0;
    for (int x = 0; x <= k; ++x) {
        for (int y = 0; y <= k; ++y) {
            if (x + y <= s && s - (x + y) <= k) ++num;
        }
    }
    cout << num << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 1000001;
int N;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  cin >> N;

  vector<int> A(N);
  vector<int> D(MAX_N, 0);
  
  int g = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    g = gcd(g, A[i]);
    D[A[i]]++;
  }
 
  // 重複があるかチェック
  bool pairwise = true;
  for (int i = 2; i <= MAX_N; i++) {
    int cnt = 0;
    for (int j = i; j <= MAX_N; j += i) {
      cnt += D[j];
    }
    
    if (cnt > 1) {
      pairwise = false;
      break;
    }
  }
  
  if (pairwise) {
    cout << "pairwise coprime";
    return 0;
  } 
  
  if (g == 1) {
    cout << "setwise coprime";
    return 0;
  }
  
  cout << "not coprime";
}

Measured memory_bytes: 11088
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
	while(u != NIL && k != u->key) {
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com[0] == 'f') {
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		} else if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}

/*
8
insert 30
insert 88
insert 12
insert 1
insert 20
find 12
insert 17
insert 25
find 16
print
*/


Measured memory_bytes: 21956