akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long n = Long.parseLong(sc.next());
        sc.close();

        // 主処理
        long max = n < b ? Math.min(b, n) : Math.min(b, n) - 1;

        double d = (double) max / b;
        long left = (long) Math.floor(d * a);
        long right = (long) Math.floor(d) * a;
        long num = left - right;

        long result = num;

        // 出力
        System.out.println(result);
    }
}


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

int main() {
  
  int x,A,B,tmp_A,tmp_B;
  cin >> A >> B;
  
  tmp_A = A;
  tmp_B = B;
  x = B/100 - A/100 + 1;
  
  tmp_A = A/1000;
  if (tmp_A/10 + tmp_A%10 *10 < A%100)
    x--;
  
  tmp_B = B/1000;
  if (tmp_B/10 + tmp_B%10 *10 > B%100)
    x--;
  
  cout << x << endl;
  
}


Measured memory_bytes: 256
MOD = 998244353
N, K = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(K)]
lr.sort()

# 考え方は通常のDPだが、そのままだとO(N^2)となる
# 独立した区間なので、区間の和を求める部分の計算量を落とせば良い(dpsumで累積和を計算)
dp = [0]*(N+1)
dp[1] = 1

dpsum = [0]*(N+1)
dpsum[1] = 1

for i in range(2, N+1):
    for l, r in lr:
        li = max(0, i-r)
        ri = i-l
        if ri < 0:
            continue
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= MOD
    dpsum[i] += dp[i]+dpsum[i-1]
    dpsum[i] %= MOD

print(dp[N])


Measured memory_bytes: 77148
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

const int N = 212345;

int n;
vector<int> ns;
vector<int> res;
vector<int> g[N];

void dfs(int pre, int cur, vector<int>& lis) {
    function<void()> callback;

    if (lis.empty() || ns[cur] > lis.back()) {
        lis.push_back(ns[cur]);
        callback = [&]{ lis.pop_back(); };
    } else {
        auto iter = lower_bound(lis.begin(), lis.end(), ns[cur]);
        int idx = distance(lis.begin(), iter);
        int u = lis[idx];
        callback = [&] { lis[idx] = u; };

        lis[idx] = ns[cur];
    }

    res[cur] = lis.size();

    for (auto nxt: g[cur]) {
        if (nxt == pre) {
            continue;
        }
        dfs(cur, nxt, lis);
    }

    callback();
}

int main() {
    input(n);
    ns.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &ns[i]);
    }

    int a, b;
    for (int i = 0; i < n - 1; i++) {
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> lis;

    res.resize(n + 1);
    dfs(-1, 1, lis);

    for (int i = 1; i <= n; i++) {
        printf("%d\n", res[i]);
    }

    return 0;
}



Measured memory_bytes: 47440
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int digit(int x){
    while(x >= 10){
        x /= 10;
    }
    return x;
}
int main(){
    int N;
    cin >> N;
    ll elems[9][9];
    REP(i,9){
        REP(j,9) elems[i][j] = 0;
    }

    for(int i=1; i<10; ++i){
        for(int j=1; j <10; ++j){
            for(int k = 1; k < N+1; ++k){
                if(digit(k)==i && k % 10 == j) elems[i-1][j-1] ++;
            }
        }
    }
    ll ans = 0;
    REP(i,9){
        REP(j,9){
            if(i != j){
                ll x = elems[i][j] * elems[j][i];
                ans += x;
            }
        }
    }
    REP(i,9) ans += elems[i][i] * elems[i][i];
    cout << ans << endl;
}

Measured memory_bytes: 3532
import math
from functools import reduce
from itertools import combinations_with_replacement
k = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)

ls = [i for i in range(1,k+1)]
h = combinations_with_replacement(ls, 3)
ans = 0
for v in h:
    a,b,c = v
    if len(set(v)) ==1:
        ans += math.gcd(math.gcd(a,b),c)
    elif len(set(v)) == 2:
        ans += 3 * math.gcd(math.gcd(a,b),c)
    else:
        ans += 6 * math.gcd(math.gcd(a,b),c)
print(ans)

Measured memory_bytes: 9600
#!/usr/bin/env python3
# coding: utf-8
import collections
import math
def debug(arg):
    if __debug__:
        pass
    else:
        import sys
        print(arg, file=sys.stderr)

def main():
    pass
    N, *A = map(int, open(0).read().split())
    a = dict(enumerate(A, 1))
    dp = collections.defaultdict(lambda: -float("inf"))
    dp[0, 0] = 0 
    dp[1, 0] = 0 
    dp[1, 1] = a[1]
    for i in range(2, N + 1):
        jj = range(max(math.floor(i // 2 - 1), 1), math.ceil((i + 1) // 2) + 1)
        for j in jj:
            x = dp[i - 2, j - 1] + a[i]
            y = dp[i - 1, j]
            dp[i, j] = max(x, y)
    print(dp[N, N // 2])

if __name__ == "__main__":
    main()

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int ans{};
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (a[k] != a[i] && a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k]) ans++;
			}
		}
	}
	cout << ans;
}

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

using namespace std;

string str;

int main()
{
	cin >> str;

	if ((str[0] == str[1] && str[1] == str[2])
		|| (str[1] == str[2] && str[2] == str[3]))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
 
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.length();i++) 
	{
		if(i!=3) 
		{ 
			cout<<a[i]; 
		}
		else 
		{ 
			cout<<8; 
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct node{int x,y,h;}A[110];
int main()
{
	int n,fl=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&A[i].x,&A[i].y,&A[i].h);
		if(A[i].h>0)fl=i;
	}
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
		{
			
			bool flag=true;
			int h=A[fl].h+abs(i-A[fl].x)+abs(j-A[fl].y);
			for(int k=1;k<=n;k++)
				if(A[k].h!=max(h-abs(i-A[k].x)-abs(j-A[k].y),0)){flag=false;break;}
			if(flag)return printf("%d %d %d\n",i,j,h),0;
		}
	return 0;
}


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

int A[20][20];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    memset(A, -1, sizeof(A));

    for(int i=0; i<N; i++)
    {
        int x;
        cin >> x;

        while(x--)
        {
            int a, b;
            cin >> a >> b;

            A[i][a-1] = b;
        }
    }

    int ans = 0;

    for(int i=0; i<(1<<N); i++)
    {
        int flag = 0;

        for(int j=0; j<N; j++)
        {
            if((i & (1<<j)) == 0)
                continue;
            
            for(int k=0; k<N; k++)
            {
                if(A[j][k] == -1)
                    continue;

                if(A[j][k] == 0)
                {
                    if((i & (1 << k)))
                        flag = 1;
                }
                else
                {
                    if((i & (1 << k)) == 0)
                        flag = 1;
                }
            }
        }

        if(flag == 0)
        {
            ans = max(ans, __builtin_popcount(i));
        }
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
包除原理
*/

ll n,a[310],dp[90010]={},dp2[90010]={},mod=998244353,zenbu=1,sum=0,ans=0,inv2,ue=0,mannaka=0;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	dp[0]=1;
	rep(i,n)sum+=a[i];
	rep(i,n)zenbu=(zenbu*3)%mod;
	cerr<<"初期化終了"<<endl;
}

int main(void){
	init();
	rep(i,n){
		reg(j,0,sum)dp2[j]=0;
		reg(j,0,sum){
			dp2[j] = (dp2[j]+dp[j]*2)%mod;//残りの2つに置く
			if(j+a[i]<=sum)dp2[j+a[i]] = (dp2[j+a[i]]+dp[j])%mod;//Rに置く
		}
		reg(j,0,sum)dp[j]=dp2[j];
	}
	reg(i,(sum+1)/2,sum)ue = (ue+dp[i])%mod;
	reg(j,0,sum)dp[j]=0;
	dp[0]=1;
	rep(i,n){
		reg(j,0,sum)dp2[j]=0;
		reg(j,0,sum){
			dp2[j] = (dp2[j]+dp[j])%mod;//Bに置く
			if(j+a[i]<=sum)dp2[j+a[i]] = (dp2[j+a[i]]+dp[j])%mod;//Rに置く
		}
		reg(j,0,sum)dp[j]=dp2[j];
	}
	if(sum%2==0)mannaka=dp[sum/2];
	ans=(zenbu+mod*3-ue*3+mannaka*3)%mod;
	cerr<<sum<<endl;
	cerr<<mannaka<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int W = in.nextInt();
        int H = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        int r = in.nextInt();
        
        boolean inW = (x - r  >= 0) && (W - r >= x) && (x >= 0);
        boolean inH = (H - r  >= 0) && (H - r >= y) && (y >= 0);
        
        System.out.println(inW && inH ? "Yes" : "No");
    }
}



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


int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

#define _INF -2000000001

int main()
{
    int n;
    cin >> n;
    int *a = inputint(n);

    long long f0[2][3];
    long long f1[2][3];

    int wmax = (n % 2 == 0) ? 1 : 2;
    int index = 0;
    f0[0][0] = a[0];
    f0[0][1] = _INF;
    f0[0][2] = _INF;
    f1[0][0] = _INF;
    f1[0][1] = 0;
    f1[0][2] = _INF;
    index = 0;
    for( int i = 1; i < n; i++ )
    {
        int next = (index + 1) % 2;
        for( int w = 0; w <= wmax; w++ )
        {
            f0[next][w] = f1[index][w];
            if( f0[next][w] != _INF ) f0[next][w] += (long long)a[i];

            if( w > 0)
            {
                f1[next][w] = max(f1[index][w - 1], f0[index][w]);
            }
            else
            {
                f1[next][w] = f0[index][w];
            }
        }
        index = next;
    }

    long long ans = max(f0[index][wmax], f1[index][wmax - 1]);
    cout << ans;
    return 0;    
}

Measured memory_bytes: 4400
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int divn2(int n)
{
    int d=n/(-2);
    if(n-d*(-2)>=0) return d;
    else return d+1; 
}

int modn2(int n)
{
    return n- (-2)*divn2(n);
}

string base_n2(int n)
{
  int t=n;
  string ans = "";
  if(t==0) return "0";
  else 
  {
    while(t!=0)
    {
      ans = (char)(modn2(t) + (int)'0') + ans;
      t = divn2(t);
    }
    return ans;
  }
}
 
int main()
{
  int n;
  cin>>n;  
  cout<<base_n2(n)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e5;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,z,w;
vi a;

int main(){
	cin>>n>>z>>w;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vi x(n+1),y(n+1);
	y[0]=0;
	x[n]=inf;
	for(int i=n-1;i>=0;i--){
		x[i]=0;y[i]=inf;
		for(int j=i;j<n;j++) x[i]=max(x[i],y[j+1]);
		for(int j=i;j<n;j++) y[i]=min(y[i],x[j+1]);
		x[i]=max(x[i],abs((i?a[i-1]:w)-a[n-1]));
		y[i]=min(y[i],abs((i?a[i-1]:z)-a[n-1]));
	}
	cout<<x[0]<<endl;
}

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

using namespace std;

int const N = 1e5 + 41;

int n, a[N], ans, b[N];

int getPos(int v){
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(b[m] <= v){
			l = m;
		}else{
			r = m;
		}
	}
	return l;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}
	if(n == 1){
		printf("%d\n", ans);
		return 0;
	}
	if(n == 2){
		if(a[0] > a[1]){
			++ans;
		}
		printf("%d\n",ans);
		return 0;
	}

	sort(b, b+n);
	for(int i=0;i<n;++i){
		if((i % 2) != getPos(a[i]) % 2){
			++ans;
		} 
	}
	ans /= 2;
	printf("%d\n",ans);




	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> v;
  int m = n;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      v.push_back(i);
      n /= i;
    }
  }
  if (n != 1) v.push_back(n);
  cout << m << ":";
  for (int i = 0; i < v.size(); ++i) {
    cout << " " << v[i] << (i == v.size() - 1 ? "\n" : "");
  }
  return 0;
}


Measured memory_bytes: 3164
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int64_t X;
  cin >> X;
  if(X % 100 == 0){
    cout << 1 << endl;
  }
  else if(((X % 100) + 4) / 5 <= X / 100){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
ans = 0
for i in range(n):
    if m >= a[i][1]:
        ans += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        ans += m*a[i][0]
        break
print(ans)

Measured memory_bytes: 27884
#include <cstdio>
using namespace std;

int main()
{
	int N, p, max = 0, i, ans = 0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &p);
		ans += p;
		if (max < p)
			max = p;
	}

	printf("%d\n", ans - max/2);

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;
	ll a[100005], b[100005];
	P sum[100005];
	cin >> n;
	for (int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
		sum[i].first = a[i]+b[i];
		sum[i].second = i;
	}

	sort(sum,sum+n); reverse(sum,sum+n);

	ll as = 0;
	ll bs = 0;

	for (int i = 0;i < n;i++){
		if(i%2 == 0){
			as += a[sum[i].second];
		} else {
			bs += b[sum[i].second];
		}
	}

	cout << as - bs << endl;
	return 0;

}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
long long Mod = 1000000007;
long long Fact[200005] , InvFact[200005];

long long Power( long long base , int e ){
    if( e == 0 ) return 1LL;
    else{
        long long middle = Power( base , e >> 1 );
        if( e & 1 ) return ( ( ( middle * middle ) % Mod ) * base ) % Mod; 
        else return ( middle * middle ) % Mod;
    }
}

void PreProcess( int N ){
    Fact[0] = 1;
    InvFact[0] = Power( Fact[0] , Mod - 2 );

    for( int i = 1 ; i <= N ; ++i ){
        Fact[i] = ( Fact[i - 1] * i ) % Mod;
        InvFact[i] = Power( Fact[i] , Mod - 2 );
    }
}

int main(){
    int N , M , k , i , j;
    scanf( "%d%d%d" , &N , &M , &k );
    PreProcess( N * M );
    long long Ans = 0;
    long long Stan = ( ( ( Fact[N * M - 2] * InvFact[k - 2] ) % Mod ) * InvFact[N * M - k] ) % Mod; 
    long long row , col;

    for( i = 1 ; i <= N ; ++i ){
        for( j = 1 ; j <= M ; ++j ){
            row = ( M * ( ( ( ( ( i - 1LL ) * i ) / 2LL ) % Mod + ( ( ( N - i ) * ( N - i + 1LL ) ) / 2LL ) % Mod ) % Mod ) ) % Mod;
            col = ( N * ( ( ( ( ( j - 1LL ) * j ) / 2LL ) % Mod + ( ( ( M - j ) * ( M - j + 1LL ) ) / 2LL ) % Mod ) % Mod ) ) % Mod;
            Ans = ( Ans + row + col ) % Mod;
        }
    }

    Ans = ( Ans * Stan ) % Mod; 
    Ans = ( Ans * Power( 2 , Mod - 2 ) ) % Mod;
    printf( "%lld\n" , Ans );
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  ll H;
  cin >> H;

  ll ans = 0;

  ll base = 1;
  while (H) {
    ans += base;
    H /= 2;
    base *= 2;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
from sys import stdin


# 最小化問題
def chmin(a,b):
    if a > b: return b
    else: return a


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    w_v_arr = []
    V = 0
    for i in range(N):
        _ = list(map(int,_in[i+1].split(' ')))  # type:list(int)
        w_v_arr.append(_)
        V += _[1]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [[float('inf')] * (V+1) for _ in range(N+1)]  # 最小化問題
    #dp[i][v]:=(i-1)番目までの品物から価値がv以上になるよう選んだときの重さの総和の最小値
    dp[0][0] = 0  # 初期条件

    # 配るDP
    for i in range(N):
        for v in range(0,V+1):
            if v >= w_v_arr[i][1]:
                dp[i+1][v] = chmin(dp[i+1][v],dp[i][v-w_v_arr[i][1]]+w_v_arr[i][0])
            dp[i+1][v] = chmin(dp[i+1][v],dp[i][v])
    cnt = 0
    for v in range(0,V+1):
        if dp[N][v] <= W:
            cnt = v
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 293192
#include <stdio.h>

int main(void) {
    int a, b, sum, ans;
    scanf("%d %d", &a, &b);
    sum = 1; ans = 0;

    if (b == 1) printf("%d\n", ans);
    else {
        for (sum; sum < b;) {
            sum += (a-1);
            ans++;
        }
        printf("%d\n", ans);
    }

    return 0;
}

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

int main(void){
  int N,D;
  cin>>N>>D;
  int checkable=2*D+1;
  if(N%checkable==0){
    cout<<N/checkable<<endl;
  }
  else{
    cout<<N/checkable+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
vector<pair<ll,pll>> v[59];
ll a[59][5009];
pll c[59];
ll n,m;
void update1()
{
	for(ll i=1;i<=n;i++)
	{
		for(auto p:v[i])
		{
			ll x=p.ss.ff;
			ll y=p.ss.ss;
			for(ll j=x;j<=5000;j++)
			{
				a[p.ff][j-x]=min(a[p.ff][j-x],a[i][j]+y);
			}
		}
	}
}
void update2()
{
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=5000;j++)
		{
			ll x=j+c[i].ff;
			x=min(x,(ll)5000);
			a[i][x]=min(a[i][x],a[i][j]+c[i].ss);
		}
		// ll q=inf;
		// for(ll j=2500;j>=0;j--)
		// {
		// 	q=min(q,a[i][j]);
		// 	a[i][j]=q;
		// }
	}
}
void print()
{
	for(ll i=1;i<=20;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			if(a[j][i]>=inf)
				cout<<"inf"<<'\t';
			else
			cout<<a[j][i]<<'\t';
		}
		cout<<endl;
	}
	cout<<endl;
}
void solve()
{
	ll s;
	cin>>n>>m>>s;
	ll x,y,z1,z2;
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y>>z1>>z2;
		v[x].pb({y,{z1,z2}});
		v[y].pb({x,{z1,z2}});
	}
	for(ll i=1;i<=n;i++)
	{
		cin>>c[i].ff>>c[i].ss;
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=5000;j++)
			a[i][j]=inf;
	}
	s=min(s,(ll)5000);
	for(ll i=0;i<=s;i++)
		a[1][i]=0;
	update2();
	for(ll i=1;i<=(2*n);i++)
	{
		//print();
		update1();
		update2();
	}
	for(ll i=2;i<=n;i++)
	{
		ll ans=inf;
		for(ll j=0;j<5000;j++)
		{
			ans=min(ans,a[i][j]);
		}
		cout<<ans<<endl;
	}
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

Measured memory_bytes: 5632
#include <cstdio>
#include <algorithm>

using namespace std;

int a[200'009];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n - m; ++i) {
    ans += a[i];
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 896
H, W = gets.chomp.split.map(&:to_i)
C = []
que = []
H.times do |i|
  s =  gets.chomp
  C << Array.new(W) do |j|
    if s[j] == '#'
      que << [i, j]
      1
    else
      0
    end
  end
end
ans = 0
while que.size > 0
  nq = []
  ans += 1
  que.each do |x, y|
    if x > 0 && C[x-1][y] == 0
      C[x-1][y] = 1
      nq << [x-1, y]
    end
    if y > 0 && C[x][y-1] == 0
      C[x][y-1] = 1
      nq << [x, y-1]
    end
    if x < H-1 && C[x+1][y] == 0
      C[x+1][y] = 1
      nq << [x+1, y]
    end
    if y < W-1 && C[x][y+1] == 0
      C[x][y+1] = 1
      nq << [x, y+1]
    end
  end
  que = nq.dup
end
puts ans - 1

Measured memory_bytes: 87648
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// ���̓t�F�[�Y
        //string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(Console.ReadLine());
        //int M = int.Parse(input[1]);
        
        int i = 0;
        while(true)
        {
            if(isFit(N + i))
            {
                Console.WriteLine((N+i) + "");
                break;
            }
            else
            {
                i++;
            }
        }

        //�o��
        //Console.WriteLine(ret);
    }

    static bool isFit(int N)
    {
        int a = N % 10;
        while(N>0)
        {
            if(N%10 == a)
            {
                N /= 10;
            }else
            {
                return false;
            }
        }
        return true;
    }

}

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

int main() {
	// your code goes here
	int n,total_days,extra;
	
	scanf("%d %d %d",&n, &total_days, &extra);;
	int a[n+1];
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	
	int cnt = n;
	for(int i=0;i<n;i++){
		int j = 1;
		while(((j*a[i])+1)<=total_days){
			j++;
			cnt++;
		}
	}
	
	printf("%d\n",cnt+extra);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}
int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if ((d < b) || (a < b)) {
            cout << "No" << endl;
        }
        else if (c >= b - 1) {
            cout << "Yes" << endl;
        }
        else {
            // c+1からb-1の間にa + k * gcd(b, d)なる数あったらNo
            ll e = gcd(b, d);
            if (b - 1 - c >= e) {
                cout << "No" << endl;
            }
            else if (((c + 1) % e <= a % e) && (a % e <= (b - 1) % e)) {
                cout << "No" << endl;
            }
            else if (((c + 1) % e > (b - 1) % e) && (((c + 1) % e <= a % e) || ((b - 1) % e >= a % e))) {
                cout << "No" << endl;
            }
            else {
                cout << "Yes" << endl;
            }
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

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

  int n, a;
  cin >> n >> a;

  int rem = n % 500 - a;

  if (rem > 0) cout << "No" << "\n";
  else cout << "Yes" << "\n";
}


Measured memory_bytes: 3600
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

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

using namespace std;
typedef long long ll;
/** Problem0114 : Electro-Fly **/
ll gcd(ll a, ll b)
{
	if (b > a) swap(a, b);
    while (b)
	{
		ll tmp = a % b;
		a = b;
		b = tmp;
	}
	
    return a;
}
ll lcm(ll a, ll b)
{
    return a*b / gcd(a, b);
}

int main()
{
	long long a1, m1, a2, m2, a3, m3, x, y, z, i;
	while (1) {
		cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
		if (a1 == 0 && m1 == 0 && a2 == 0 && m2==0 && a3==0 && m3==0)
			break;
		
		x = a1%m1;
		y = a2%m2;
		z = a3%m3;
		
		long long  nx, ny, nz;
		for (nx=1; x!=1; nx++)
			x=(a1*x)%m1;
		
		for (ny=1; y!=1; ny++)
			y=(a2*y)%m2;
		
		for (nz=1; z!=1; nz++)
			z=(a3*z)%m3;
		
		cout <<  lcm(lcm(nx, ny), nz) << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
let x, n = Scanf.scanf "%d %d" (fun x n -> x, n)
let b = Array.make 102 false

let rec f i =
  if i < n then (
    Scanf.scanf " %d" (fun p -> b.(p) <- true);
    f (i + 1)
  )

let rec g i x =
  if b.(x) then
    let i' =
      if i > 0 then -i - 1
      else -i + 1 in
    g i' (x + i)
  else x

let () =
  f 0;
  let ans = g ~-1 x in
  Printf.printf "%d\n" ans


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;

double eps=1.0e-10;
int main(){
  double x1,x2,x3,x4,y1,y2,y3,y4;
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)==8){
    double vec1_x,vec2_x,vec1_y,vec2_y;
    vec1_x=x2-x1;
    vec1_y=y2-y1;
    vec2_x=x4-x3;
    vec2_y=y4-y3;
    if(fabs(vec2_y*vec1_y + vec2_x*vec1_x)<eps)printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

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

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

long long lcm(int a, int b){
    return (long long)a * b / gcd(a, b);
}

int main(){
    int a, b;
    cin >> a >> b;
    ll ans = lcm(a, b);
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B,M;cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> a2(A);
    vector<int> b(B);
    vector<int> b2(B);
    rep(i,A){
        int t;cin >> t;
        a[i] = t;
        a2[i] = t;
    }
    rep(i,B){
        int t;cin >> t;
        b[i] = t;
        b2[i] = t;
    }
    sort(all(a2));
    sort(all(b2));

    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);
    rep(i,M){
        int q,w,e;cin >> q >> w >> e;
        q--;w--;
        x[i] = q;y[i] = w;c[i] = e;
    }

    priority_queue<int,vector<int>,greater<int>> que;

    que.push(a2[0] + b2[0]);

    rep(i,M){
        int tmp = a[x[i]] + b[y[i]] - c[i];
        que.push(tmp);
    }

    cout << que.top() << endl;
}


Measured memory_bytes: 3580
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    long int votes=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        votes+=a[i];
    }
    int m1=0;
    float perc = votes/float(4*m);
    for(int i=0;i<n;i++){
        if(a[i]>=perc){
            m--;
        }
        if(m==0){
            m1=1;
            break;
        }
    }
    if(m1){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }    
    return 0;
}


Measured memory_bytes: 256
/*input
5 6
1 4 5 9 8
3 1
3 2
5 4
1 5
2 4 5
1 2 9
2 3 4
1 5 1
2 2 1
2 5 5


*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a, b;
  cin >> a >> b;
  int ans = 0;
  while (1) {
    int d = a * ans - (ans - 1);
    if (d >= b) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N=3e7+10;
inline int read() {
    int x=0;
    char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
void write(int x) {
    if(x>=10)write(x/10);
    putchar(x%10+48);
}

struct Node {
    int sum,lc,rc;
};
Node dat[N];
int tot;

int insert(int pos,int v,int rt,int l,int r) {
    int p=++tot;
    dat[p]=dat[rt];
    if(r-l==1) {
        dat[p].sum+=v;
        return p;
    }
    int m=(l+r)>>1;
    if(pos<m)dat[p].lc=insert(pos,v,dat[rt].lc,l,m);
    else dat[p].rc=insert(pos,v,dat[rt].rc,m,r);
    dat[p].sum=dat[dat[p].lc].sum+dat[dat[p].rc].sum;
    return p;
}

int query(int left,int rt,int l,int r) {
    if(left<=l)return dat[rt].sum;
    int m=(l+r)>>1,sum=0;
    if(left<m)sum+=query(left,dat[rt].lc,l,m);
    sum+=query(left,dat[rt].rc,m,r);
    return sum;
}
int last[N],root[N];

int main() {
    int n,q;
    n=read();q=read();
    for(int i=1; i<=n; ++i) {
        int x=read();
        if(last[x]) {
            root[i]=insert(last[x],-1,root[i-1],1,n+1);
            root[i]=insert(i,1,root[i],1,n+1);
        } else  root[i]=insert(i,1,root[i-1],1,n+1);
        last[x]=i;
    }
    while(q--) {
        int x,y;
        x=read();
        y=read();
        write(query(x,root[y],1,n+1));
        putchar('\n');
    }
    return 0;
}


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

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String reply = sc.next();
        boolean[] ans = new boolean[N];
        for(int n=0; n<N; n++) ans[n] = (reply.charAt(n)=='o');
        boolean[] animal = new boolean[N];

        animal[0]=true; animal[1]=true;
        for(int n=2; n<N; n++){
            animal[n] = ans[n-1] ^ animal[n-2] ^ animal[n-1];
        }
        if((animal[N-2]^animal[0]==animal[N-1]^ans[N-1]) && (animal[N-1]^animal[1] == animal[0]^ans[0])){
            for(int n=0; n<N; n++) System.out.print(animal[n] ? 'S' : 'W');
            System.out.println();
            return;
        }

        animal[0]=true; animal[1]=false;
        for(int n=2; n<N; n++){
            animal[n] = ans[n-1] ^ animal[n-2] ^ animal[n-1];
        }
        if((animal[N-2]^animal[0]==animal[N-1]^ans[N-1]) && (animal[N-1]^animal[1] == animal[0]^ans[0])){
            for(int n=0; n<N; n++) System.out.print(animal[n] ? 'S' : 'W');
            System.out.println();
            return;
        }
        animal[0]=false; animal[1]=true;
        for(int n=2; n<N; n++){
            animal[n] = ans[n-1] ^ animal[n-2] ^ animal[n-1];
        }
        if((animal[N-2]^animal[0]==animal[N-1]^ans[N-1]) && (animal[N-1]^animal[1] == animal[0]^ans[0])){
            for(int n=0; n<N; n++) System.out.print(animal[n] ? 'S' : 'W');
            System.out.println();
            return;
        }

        animal[0]=false; animal[1]=false;
        for(int n=2; n<N; n++){
            animal[n] = ans[n-1] ^ animal[n-2] ^ animal[n-1];
        }
        if((animal[N-2]^animal[0]==animal[N-1]^ans[N-1]) && (animal[N-1]^animal[1] == animal[0]^ans[0])){
            for(int n=0; n<N; n++) System.out.print(animal[n] ? 'S' : 'W');
            System.out.println();
            return;
        }

        System.out.println("-1");



    }
}


Measured memory_bytes: 35840
#include<bits/stdc++.h>
#include <set>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<n;i++)
int main(){
  int num;
  int i;
  set<string> se;  
  string str;

  cin >> num;
  
  rep0(i,num){
    cin >> str;
    se.insert(str);
  }
 
  cout << se.size() << endl;

}


Measured memory_bytes: 19224
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;



ll a, b;
int main()
{
        set<ll> s;
        for(ll i=1;i<=9;i++) {
                for(ll j=1;j<=9;j++) s.insert(i*j);
        }
        ll n;
        cin >> n;
        if(s.find(n) != s.end()) cout << "Yes\n";
        else cout << "No\n";
        return 0;
}


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

int main() {
    string s;
    cin >> s;

    string sun = "SUN", mon = "MON", tue = "TUE", wed = "WED", thu = "THU", fri = "FRI", sat = "SAT";

    if (s == sun) cout << 7 << endl;
    if (s == mon) cout << 6 << endl;
    if (s == tue) cout << 5 << endl;
    if (s == wed) cout << 4 << endl;
    if (s == thu) cout << 3 << endl;
    if (s == fri) cout << 2 << endl;
    if (s == sat) cout << 1 << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int nx = 0, ny = 0;
	int time = 0;
	bool elf = true;
	rep(i, n) {
		int t, x, y; cin >> t >> x >> y;
		if (x == nx && y == ny) elf = false;
		if (t - time < abs(x - nx) + abs(y - ny) || (t-time)%2 != (abs(x - nx) + abs(y - ny)) % 2) elf = false;
		time = t;
		nx = x; ny = y;
	}
	puts(elf ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int N; cin >> N;
	vector<string> str;
	string s, ans;

	for (int i = 0; i < N; i++) {
		cin >> s;
		str.push_back(s);
	}

	for (int i = 0; i < str[0].length(); i++) {
		int cnt = 0;
		for (int j = 1; j < str.size(); j++) {
			for (int k = 0; k < str[j].length(); k++) {
				if (str[0][i] == str[j][k]) {
					cnt++;
					str[j][k] = '0';
					break;
				}
			}
		}
		if (cnt == N - 1)ans += str[0][i];
	}
	sort(ans.begin(),ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextInt();
    long b = sc.nextInt();
    long c = sc.nextInt();
    // sqrt(a) + sqrt(b) < sqrt(c)
    // a + 2 * sqrt(a*b) + b < c
    // 2 * sqrt(a * b) < c - a - b ...(1) d = c - a - b [d > 0]
    // 4 * (a * b) < d * d ...(2)
    long d = (c - a -b);

    if (d <= 0) {
      System.out.println("No");
      return;
    }

    if (4 * a * b < d * d) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{

    int a, b, c, d, e, f;
    vector<int> x, y;

    cin >> a >> b >> c >> d >> e >> f;

    REP(i, f + 1)
    {
        REP(j, f + 1)
        {
            if (100 * i * a + 100 * j * b <= f )
            {
                x.push_back(100 * i * a + 100 * j * b);
                //cout << x.back() << endl;
            }
        }
    }

    REP(i, f + 1)
    {
        REP(j, f + 1)
        {
            if (i * c + j * d <= f)
            {
                y.push_back(i * c + j * d);
            }
        }
    }

    double maxRate = -1.0;
    int maxX = 0, maxY = 0;

    REP(i, x.size())
    {
        REP(j, y.size())
        {
            if (x[i] + y[j] <= f && 100.0 * (double)y[j] / (double)x[i] <= (double)e)
            {
                if (maxRate < (double)y[j] * 100.0 / ((double)x[i] + (double)y[j]))
                {
                    maxRate = (double)y[j] * 100.0 / ((double)x[i] + (double)y[j]);
                    maxX = x[i];
                    maxY = y[j];
                    //cout << maxY + maxX << endl;
                    //cout << maxRate << endl;
                }
            }
        }
    }

    cout << maxX + maxY << " " << maxY << endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7, maxn = 1e5 + 5, INF = 1 << 60;
vector<ll>fac(maxn), finv(maxn), inv(maxn), a(maxn);

ll cmd(ll n, ll k) {
	if (n < k || n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
	ll n, v; cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i]; mp[a[i]]++;
		if (mp[a[i]] == 2)v = a[i];
	}
	ll L = -1, R;
	for (int i = 0; i < n + 1; i++) {
		if (a[i] == v && L == -1)L = i;
		else if (a[i] == v)R = i;
	}
	fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
	for (ll i = 2; i < maxn; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
	for (ll i = 0; i < n + 1; i++) {
		ll k = cmd(L + (n - R), i);
		ll p = (cmd(n + 1, i + 1) - k + mod) % mod;
		cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 10624
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair < int , int >
#define fi first
#define se second
using namespace std;
typedef long long ll;

const ll LIM = 1e18;
ll N, a[MAX], ans = 1LL; 

int main()
{
    optimiza_io
    cin >> N;
    for(ll i = 1; i <= N; i ++){
        cin >> a[i];
        if(a[i] == 0LL){
            cout << "0\n";
            exit(0);
        }
    }
    for(ll i = 1; i <= N; i ++) {
        if( ans > LIM / a[i] ) {
            ans = -1;
            break;
        }
        ans *= a[i];
    }
    cout << ans << "\n";
    return 0;
}

// CHECAR LIMITES 

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	cin>>n;
	string a,b,c;
	cin>>a>>b>>c;
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]&&b[i]==c[i])continue;
		else if(a[i]==b[i])ans++;
		else if(a[i]==c[i])ans++;
		else if(b[i]==c[i])ans++;
		else ans+=2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
/*      西江月·证明
	即得易见平凡，仿照上例显然。
   留作习题答案略， 读者自证不难。

	反之亦然同理，推论自然成立。
	略去过程QED，由上可知证毕。*/
# pragma GCC optimize (1)
# pragma GCC optimize (2)
# pragma GCC optimize (3)
# pragma GCC optimize ("Ofast")
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#define kkk register
#define ll long long
#define inf 2147098934832ll
using namespace std;
ll read(){ll ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=-1;a=getchar();}while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;}
//一条long long的黄金分割线-----------------------------------------------------------------------------------------------------------------------------------
ll n,m,k,a[1000005],b[1000005],ans;
int main(){
	n=read();m=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read(),a[i]+=a[i-1];
	for(int i=1;i<=m;i++)b[i]=read(),b[i]+=b[i-1];b[m+1]=inf;
	for(int i=0;i<=n;i++){
		ll nk=k-a[i];
		ll ans1=i;
		if(nk>=b[1]){
			ans1+=upper_bound(b+1,b+1+m+1,nk)-b-1;
		}
		if(nk>=0)ans=max(ans,ans1);
	}
	cout<<ans;
	return 0; 
} 

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

using namespace std;

void init(int * par, int * rank, int n){
    for(int i =0; i<n; i++){
        par[i] = i;
        rank[i] = 0;
    }
}

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

void unite(int * par, int * rank, int x, int y){
    x = find(par, rank, x);
    y = find(par, rank, y);
    if(x == y)  return;

    if(rank[x] < rank[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

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

int main(){
    int N, M; 
    cin >> N >> M;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
    }
    int par[N], rank[N];
    init(par, rank, N);
    
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        unite(par, rank, x, y);
    }
    int ans = 0;
    for(int i=0; i<N; i++) if(same(par, rank, p[i], i)) ans ++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type edge struct {
	to   int
	cost int
}

var N, M int
var G [][]edge

const MAX = 1100
const INF = 110000000000000

func main() {
	sc.Split(bufio.ScanWords)

	N, M = nextInt(), nextInt()
	G = make([][]edge, N)

	for i := 0; i < M; i++ {
		u, v, c := nextInt()-1, nextInt()-1, nextInt()
		G[u] = append(G[u], edge{to: v, cost: -c})
	}

	d := make([]int, MAX)
	for i := 0; i < MAX; i++ {
		d[i] = INF
	}
	negative := false
	d[0] = 0

	for iter := 0; iter <= N*2; iter++ {
		for v := 0; v < N; v++ {
			if d[v] >= INF/2 {
				continue
			}
			for _, e := range G[v] {

				if d[e.to] > d[v]+e.cost {
					d[e.to] = d[v] + e.cost
					if e.to == N-1 && iter == N*2 {
						negative = true
					}
				}
			}
		}
	}

	if !negative {
		fmt.Println(-d[N-1])
	} else {
		fmt.Println("inf")
	}

}


Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
    char S[10];
    int /*s_len,*/stack[100],spoint=0;
    //s_len = strlen(S);
    //cout << s_len << endl;
    while(scanf("%s",S)!=EOF){
        if(S[0]=='+'||S[0]=='-'||S[0]=='*'){
            if(S[0]=='+'){
                stack[spoint-2] += stack[spoint-1];
                spoint--;
            }else{
                if(S[0]=='-'){
                    stack[spoint-2] -= stack[spoint-1];
                    spoint--;
                }else{
                    stack[spoint-2] *= stack[spoint-1];
                    spoint--;
                }
            }
        }else{
            stack[spoint] = atoi(S);
            spoint++;
        }
    }
    cout << stack[0] << endl;
    return 0;
}


Measured memory_bytes: 3152