akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie   
    int l, r, d ;
    cin >> l >> r >> d ;
    int ans = 0 ; 
    rep(i, l, r+1) {
        if(i%d == 0) ans++ ;
    }
    cout << ans << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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


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

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (; l <= r; l++)
    {
        if (l % d == 0)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
signed main(){
  int N;
  cin>>N;
  vector<int> A(64,0);
  for(int j=0;j<N;j++){
    int B;
    cin>>B;
    bitset<64> C(B);
    for(int i=0;i<64;i++)
      if(C.test(i))
        A[i]++;
  }
  int ans=0;
  for(int i=0,j=1;i<64;i++,j=j*2%mod)
    ans=(ans+j*(A[i]*(N-A[i])%mod))%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 3520
#include<cstdio>
#include<queue>
#include<vector>
#include<list>
#define NMAX 10005
using namespace std;
short n;
list<short> result;
vector<short> Graphics[NMAX];
int inDegree[NMAX];
bool state[NMAX];

void bfs(short index){
    queue<short> temp;
    temp.push(index);
    state[index] = true;
    while(!temp.empty()){
        short nowNode = temp.front();
        temp.pop();
        result.push_back(nowNode);
        int maxSize = Graphics[nowNode].size();
        for(int i = 0;i<maxSize;i++){
            short nextNode = Graphics[nowNode][i];
            inDegree[nextNode]--;
            if(!inDegree[nextNode] && !state[nextNode]){
                state[nextNode] = true;
                temp.push(nextNode);
            }
        }
    }
}

void topo(){
    for(short i =0;i<n;i++)
        if(!inDegree[i]&&!state[i])
            bfs(i);
    for(auto it:result)
        printf("%d\n", it);
}

int main(){
    int edge;
    short out, in;
    scanf("%hd%d", &n, &edge);
    while(edge--){
        scanf("%hd%hd", &out, &in);
        Graphics[out].push_back(in);
        inDegree[in]++;
    }
	topo();
    return 0;
}



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

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

  int N, D, X; cin >> N >> D >> X;
  int ans = X;
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    ans += (D - 1) / A + 1;
  }
  cout << ans << "\n";
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

constexpr int N_MAX = 1e5;
constexpr int K_MAX = 1e5;

vector<double> pk(K_MAX+1);;

int N;
int K;

// win probability at k
double probk(int k) {
  if (k >= K) {
    return 1.0;
  }
  if (k==0) {
    return 0;
  }

  double ret = 1.0;
  while (k<K) {
    k *= 2;
    ret *= 0.5;
  }

  return ret;
}

int main(int argc, char** argv) {
  cin >> N >> K;

  double ret = 0.0;
  for (int i=1; i<=N; i++) {
    ret += 1.0/double(N)*probk(i);
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;//edition 02
vector<int> arr1;
int n, q;
bool flag = false;

bool solve(int target, int sum, int i)
{
    if(sum != target && i >= n)
        return false;
    if(sum == target)
    {
        flag = true;
        return true;
    }
    solve(target, sum + arr1[i], i + 1);
    solve(target, sum, i + 1);
    return flag;
}
int main()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        int t;
        cin >> t;
        arr1.push_back(t);
    }
    cin >> q;
    for(int i = 0; i < q; i ++)
    {
        int t;
        cin >> t;
        int judge = solve(t, 0, 0);
        if(judge == 0)
            cout << "no" << endl;
        else if(judge == 1)
            cout << "yes" << endl;
        flag = false;
    }
    return 0;
}


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

long long a[82],sum=1000,t=0;

int main(){
	long long n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]>=a[i+1])
		{
			continue;
		}
		else
		{
			t=sum/a[i];
			sum=sum%a[i];
			sum=sum+a[i+1]*t;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3608
//i hate _____
#include<bits/stdc++.h>

#define ll long long int 
#define ld long double 
#define pb push_back
#define mk make_pair
#define ii pair<int,int>

using namespace std;
double pi=2*acos(0.0);

/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/

template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << " " << x;
        return os << '}'; 
}

void solve(){
    ll n; cin>>n;
    vector<ll>a(n+1); ll ans=0;
    for (ll i=1;i<=n;i++){
        for (ll j=i;j<=n;j+=i){
            a[j]++;
        }
        ans+=(i*a[i]);
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int test_cases=1;// cin>>test_cases;
    for (int tc=1;tc<=test_cases;tc++){
        solve();
        //cout << "Case " << tc << ": " << solve() <<endl;
        //cout << "Case " << tc << ": "<<fixed<<setprecision(2)<<solve()<<endl;
    }
    return 0;
}
/*
    problems are the sign of life
*/


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second

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

int t, a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	if (t == 1)
		cout << "Hello World";
	else
		cin >> a >> b, cout << a + b;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <deque>
using namespace std;
int main(){
	string s;
	int q;
	bool gya=0;
	cin>>s;
	deque<char> ans;
	for(int i=0;i<s.size();i++){
		ans.push_back(s[i]);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int t;
		cin>>t;
		if(t==1){
			if(gya==0){
				gya=1;
			}else{
				gya=0;
			}
		}else{
			int f;
			cin>>f;
			char c;
			cin>>c;
			if(f==1){
				if(gya==0){
					ans.push_front(c);
				}else{
					ans.push_back(c);
				}
			}else{
				if(gya==0){
					ans.push_back(c);
				}else{
					ans.push_front(c);
				}
			}
		}
	}
	if(gya==0){
		while(!ans.empty()){
			cout<<ans.front();
			ans.pop_front();
		}
		cout<<endl;
	}else{
		while(!ans.empty()){
			cout<<ans.back();
			ans.pop_back();
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 896
# 入力値を文字列で返す
def gets_s()
  gets.chomp
end

s = gets_s

while true
  s = s[0, s.size-2]
  left  = s[0, s.size/2]
  right = s[s.size/2, s.size]
  if left == right
    puts s.size
    exit
  end
end


Measured memory_bytes: 1788
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = InputNumList();
            WriteLine(a[0] + a[1] >= 24 ? a[0] + a[1] - 24 : a[0] + a[1]);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



Measured memory_bytes: 13268
DBG = !true
require 'prime'

R = 1000000007

def factorialp(n, q)
  ((n-q+1)..n).inject(1,:*)
end

def comb(n,q)
  return factorialp(n,q) / (factorialp(q,q))
end

def ff(q,k)
  if k == 0
    return 1
  elsif k == 1
    return q
  elsif q == 1
    return 1
  else
    sum = 0
    for i in 0..k
      sum += ff(q-1, k-i)
    end
    return sum
  end
end

def fff(q,k)
  a = Array.new(q+1)
  for i in 1..q
    a[i] = Array.new(k+1)
  end
  for i in 1..q
    a[i][0] = 1
    a[i][1] = i
  end
  for j in 2..k
    a[1][j] = 1
  end

  for qq in 2..q
    for kk in 2..k
      a[qq][kk] = a[qq][kk-1] + a[qq-1][kk]
    end
  end

  return a[q][k]
end

def f(q,k)
  print "f q:#{q} k:#{k}\n" if DBG
  return fff(q, k-q)
end

def h(n, k)
  sum = 0
  #if n > k
    for q in 1..[k,n].min
      sum += (f(q,k) * comb(n,q)) % R
    end
  #else
  #  for q in 1..k
  #    sum += f(q,k) % R
  #  end
  #end
  return sum
end

def g(n,m)
  facs = m.prime_division
  prod = 1
  for i in 0...facs.size
    prod = (prod * h(n, facs[i][1])) % R
  end
  return prod
end

# # # # main # # # #

n,m = gets.split.map{|x| x.to_i}
print g(n,m)


Measured memory_bytes: 3964
from collections import defaultdict as dd
N, M = map(int, input().split())
p = dd(int)
mod = 10 ** 9 + 7
maxps = 0
i = 2
while i <= 10 ** 9:
  if M <= 1:
    break
  while M % i == 0:
    p[i] += 1
    maxps = max(maxps, p[i])
    M //= i
  i += 1
if len(p.keys()) == 0 and M > 1:
  p[M] = 1
class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
res = 1
f = Factorial(maxps + N, mod)
for i in p.keys():
  res *= f.combi(p[i] + N - 1, p[i])
print(res % mod)

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

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> pass(n);

    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        pass[a].emplace_back(b);
    }

    
    bool flag = false;

    rep(i, pass[0].size()) {
        int t = pass[0][i];

        if((int)pass[t].size() == 0) continue;

        sort(pass[t].rbegin(), pass[t].rend());
        if(pass[t][0] == n-1) flag = true;
    }

    if(flag) {
        cout << "POSSIBLE" << endl;
        return 0;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
}

Measured memory_bytes: 11312
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int R;
    cin >> R;

    if(R < 1200)
        cout << "ABC" << endl;
    else if(R < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;    
}

Measured memory_bytes: 256
//--------------------------------------------------------------------------------
// Code By:
//					######                  #               ######
//					##   #                  #               #
//					#####      ##       #####      ##       #   ###
//					##   #              #   #               #   # #
//					##    #	            #####               ##### #
//---------------------------------------------------------------------------------

#include<bits/stdc++.h>
using namespace std;

                             /* ----------------------------- START of Template ---------------*/
#define ll long long int
#define FOR(x,to) for(x=0;x<(to);x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<long long int> >
#define vll vector<long long int>
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SZ(X) ((int)(X).size())
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second

void getZarr(string str, vll &Z)
{
    ll n = str.length();
    ll L, R, k;
    L = R = 0;
    for (ll i = 1; i < n; ++i)
    {
        if (i > R)
        {
            L = R = i;
            while (R<n && str[R-L] == str[R])
                R++;
            Z[i] = R-L;
            R--;
        }
        else
        {
            k = i-L;
            if (Z[k] < R-i+1)
                Z[i] = Z[k];
            else
            {
                L = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
   } } }}
vector<ll>isprime;
void seive(ll size){
	isprime.resize(size+1,1);
	ll i,j;
	isprime[0]=0;
	isprime[1]=0;
	for(i=2;i*i<=size;i++){
		if(isprime[i]){
			for(j=2;j*i<=size;j++)isprime[i*j]=0;
		}
	}
}
ll power(ll x,unsigned ll y, ll m){
	if(y==0)return 1;
	ll p=power(x,y/2,m);
	p=(p*p)%m;
	if(y%2!=0)p=(p*x)%m;
	return p;
}
ll modinverse(ll a,ll m){
	return power(a,m-2,m);
}


                       /* ----------------------          End Of Template --------------------------------*/

ll findans(){
	ll n,ans=0,i,j,k;
	cin>>n;
	vll v(n);
	for(i=0;i<n;i++)cin>>v[i];
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			for(k=j+1;k<n;k++){
				vll vt;
				if(v[i]!=v[j]&&v[j]!=v[k]&&v[k]!=v[i]){
					vt.PB(v[i]);
					vt.PB(v[j]);
					vt.PB(v[k]);
					sort(ALL(vt));
					if(vt[0]+vt[1]>vt[2])ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;



}

int main(){
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t,i;
//	cin>>t;
t=1;
	for(i=0;i<t;i++){
		findans();
	}
return 0;
}





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

void main()
{
    auto K = readln.split[1].to!int;
    auto ps = readln.split.to!(int[]);
    sort(ps);
    int r;
    foreach (i; 0..K) r += ps[i];
    writeln(r);
}

Measured memory_bytes: 2768
#include<bits/stdc++.h>
using namespace std;
long long int H,W,M,a,b,mah,maw,n[300001],m[300001],ma=0,n1=0,m1=0,h[1000000],w[1000000];
int main() {
	cin>>H>>W>>M;
	for (int i=1; i<=M; i++) {
		cin>>n[i]>>m[i];
		h[n[i]]+=1;
		w[m[i]]+=1;
	}
	a=0;
	b=0;
	for (int i=1; i<=H; i++)
		if (h[i]>mah)
			mah=h[i];
	for (int i=1; i<=H; i++)
		if (h[i]==mah) {
			a++;

		}

	for (int j=1; j<=W; j++)
		if (w[j]>maw)
			maw=w[j];
	for (int i=1; i<=W; i++)
		if (w[i]==maw) {
			b++;

		}
	ma=a*b;

	for (int z=1; z<=M; z++)
		if ((h[n[z]]==mah)&&(w[m[z]]==maw)) m1++;

	if (ma==m1)
		cout<<maw+mah-1;
	else cout<<maw+mah;
	return 0;
}

Measured memory_bytes: 13020
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
//#define ll long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};
#define double long double

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    n++;
    vec pos(n+5,1);
    //map<int, int> m;
    vec m(n + 5, 0);
    vec v(n);
    fo(i,n){
        cin >> v[i];
    }
    if(n==1){
        if(v[0]==1){
            cout << 1;
            return 0;
        }
        else{
        cout<<-1;
        return 0;}
    }
    if(v[0]!=0){
        cout << -1;
        return 0;
    }
    int in = 0;
    int ans = 0;
    int curr = 0;
    foo(i,1,n){
        int vall = v[i];
        if(i==n-1)
            vall--;
        while(vall>0){
            if(in>=i){
                cout << -1;
                return 0;
            }
            int fii = pos[in]+curr;
            //db3(i, vall, fii);
            if(fii>vall){
                ans += (vall) * (i - in);
                m[i] -= vall;
                m[in + 1] += vall;
                pos[in] -= vall;
                vall = 0;
            }
            else{
                ans += (fii) * (i - in);
                m[i] -= fii;
                m[in + 1] += fii;
                vall -= fii;
                in++ ;
                curr += m[in];
            }
        }
        //deb(in);
        // deb(pos[in] + m[in]);
    }
    cout << n + ans;
    

}


Measured memory_bytes: 5556
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define D 9 
#define MAXN (1 << 18)
#define MAXW (100010)

int dp[(1 << D)][MAXW];
int v[MAXN];
int w[MAXN];

int n, q;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i < (1 << D); i++) {
		int (& prevdp)[MAXW] = dp[i / 2];
		for (int j = 0; j + w[i] < MAXW; j++) {
			dp[i][j + w[i]] = prevdp[j] + v[i];
		}
		for (int j = 0; j < MAXW; j++) {
			dp[i][j] = max(prevdp[j], dp[i][j]);
		}
		for (int j = 1; j < MAXW; j++) {
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int cur, cap;
		cin >> cur >> cap;
		vector<int> items;
		while (cur >= (1 << D)) {
			items.push_back(cur);
			cur >>= 1;
		}
		int m = items.size();
		int bestval = 0;
		for (int mask = 0; mask < (1 << m); mask++) {
			int curv = 0;
			int curw = 0;
			for (int j = 0; j < m; j++) {
				if (mask & (1 << j)) {
					curv += v[items[j]];
					curw += w[items[j]];
				}
			}
			if (curw > cap) {
				continue;
			}
			curv += dp[cur][cap - curw]; 
			bestval = max(curv, bestval);
		}
		cout << bestval << endl;
	}
	return 0;
}


Measured memory_bytes: 205332
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a, b; cin >> a >> b;
	int c = b-a;
	int d = b-c;
	int count = 0;
	rep(i, c){
		count += i+1;
	}
	print(count - b);
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(void)
{
    int cost1,cost2,cost3,zettai1,zettai2;
    int sum,sum2,high,low;
    int katei1,katei2;
    cin >> cost1 >> cost2 >> cost3;
    
    if(cost1 - cost2 >= 0)
        if(cost1 - cost3 >= 0)
            high = cost1;
        else
            high = cost3;
    else
        if(cost2 - cost3 >= 0)
            high = cost2;
        else
            high = cost3;
            
    if(cost1 - cost2 <= 0)
        if(cost1 - cost3 <= 0)
            low = cost1;
        else
            low = cost3;
    else
        if(cost2 - cost3 <= 0)
            low = cost2;
        else
            low = cost3;
    
    sum = cost1 + cost2 + cost3 - high - low;
    
    katei1 = pow(sum - low,2);
    katei2 = pow(sum - high,2);
    
    zettai1 = pow(katei1,0.5);
    zettai2 = pow(katei2,0.5);
    
    sum2 = zettai1 + zettai2;
    
    cout << sum2 << endl;
    //まずは順番通りに
    /*
    zettai1 = pow(pow(cost2 - cost1,2),0.5);
    zettai2 = pow(pow(cost3 - cost2,2),0.5);
    
    sum1 = zettai1 + zettai2;
    */
    
}

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

ll INF = 1LL << 60;
using G = vector<map<int, int>>;

int 
main() {

  ll A, B, X; cin >> A >> B >> X;
  if(B > X){
    cout << (A * X) / B << endl;
    return 0;
  } else if(B == X){
    --X;
    cout << (A * X) / B << endl;
    return 0;
  }

  ll ans = X / B;
  if(ans > 1){
    --ans;
    cout << ((A * ans) / B) - (A * (ans / B)) << endl;
  } else{
    ans = B - 1;
    cout << ((A * ans) / B) - (A * (ans / B)) << endl;
  }


  return 0;

}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll x,k,d;
  cin >> x >> k >> d;

  ll mod = x%d;
  ll modM = mod-d;
  
  if( abs(x)/d > k){
    if(x>0) cout << abs(x - (d*k)) << endl;
    else cout << abs(x + d*k) << endl;
  }else{
    if(x>0){
      if((x/d - k)%2==0) cout << x%d << endl;
      else cout << abs(x%d - d) << endl;
    }else{
      if((abs(x)/d - k)%2==0) cout << abs(x%d) << endl;
      else cout << abs(x%d + d) << endl;
    }
  }
 
  return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>
int main(void){
    int n,x,g=0,i;
    int d[101],l[101];
    
    scanf("%d%d",&n,&x);
    for(i=0;i<n;i++)
        scanf("%d",&l[i]);
    
    d[0]=0;
    for(i=1;i<=n;i++){
        d[i]=d[i-1]+l[i-1];
    }
    for(i=0;i<=n;i++){
        if(d[i]<=x)g++;
    }
    printf("%d",g);
    
  return 0;
}

Measured memory_bytes: 1728
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
s = []
for i in range(n):
        x = 0
        for j in range(m):
                x += a[i][j] * b [j]
        s.append(x+c)
print(sum(x>0 for x in s))

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

int main() {
	long long x, y, z;
	long long ans;
	
	while (cin >> z) {
		ans = 1145141919810;
		if (!z) break;
		for (x = 1; x < z; x++) {
			for (y = 1 ; y < z; y++) {
				if (z * z * z >= x * x * x + y * y * y) {
					ans = min(ans, z*z*z - x*x*x - y*y*y);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<vll> dp(c+1, vll(d+1));

    for (ll i = a; i <= c; i++) {
        for (ll j = b; j <= d; j++) {
            if (i == a and j == b)
                dp[i][j] = 1;
            else {
                dp[i][j] = ((j*dp[i-1][j])%mod + (i*dp[i][j-1])%mod - ((i-1)*(j-1)*dp[i-1][j-1])%mod)%mod;
                dp[i][j] = (dp[i][j] + mod)%mod;
            }
        }
    }

    /*FOR (i, 0, c+1) {
        FOR (j, 0, d+1) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/

    cout << dp[c][d] << "\n";
}

int main() {
    io;
    int t =1;
    tc(t) {
        solve();
    }
}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 73664
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace abc153_c
{
    static class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().ToLongArray();
            // モンスターの数
            var n = items[0];
            // 必殺技の回数
            var k = items[1];
            // モンスターの体力
            var h = Console.ReadLine().ToLongArray();

            // 攻撃の回数
            var cnt = 0L;

            // 必殺技を使えばモンスターを殺せる
            // →必殺技は、体力の多いモンスターに使う
            var length = h.Length - k;
            if (length > 0)
            {
                Array.Sort(h);
                for (var i = 0; i < length; i++)
                {
                    cnt += h[i];
                }
            }

            Console.WriteLine($"{cnt}");
        }

        static long ToLong(this string s)
        {
            return long.Parse(s);
        }

        static long[] ToLongArray(this string s, char separator = ' ')
        {
            var items = s.Split(separator);
            var ret = new long[items.Length];
            for (int i = 0; i < items.Length; i++)
            {
                ret[i] = items[i].ToLong();
            }
            return ret;
        }
    }
}


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

int main()
{
    int a[101], b, cnt = 0;
    for( int i = 1; i <= 100; i++ )
        a[i] = 0;

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

    for( int i = 1; i <= 100; i++ )
    {
        if( a[i] == 2 )
            cnt++;
        else if( a[i] == 4 )
            cout << "yes" << endl;
        else;
    }

    if( cnt == 2 )
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;

const ll MAX_N = 2e5 + 10;
ll n, ans;
ll cnt[MAX_N];
string s, march = "MARCH";

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> s;
		cnt[s[0] - 'A']++;
	}

	for (ll mask = 0; mask < 32; mask++)
		if (__builtin_popcount(mask) == 3) {
			ll res = 1;
			for (int i = 0; i < 5; i++)
				if ((mask >> i) & 1)
					res *= cnt[march[i] - 'A'];

			ans += res;
		}

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int n = (int)s.size();
  int cnt = 0;
  for(int i = 0; i < n; ++i)cnt += s[i] == 'o';
  cout << (cnt + 15 - n >= 8 ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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






int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    for(int i(0); i < N; ++i) std::cin >> A[i];
    std::sort(std::rbegin(A), std::rend(A));
    int kakutei(0), idx(0);
    std::vector<int> v(2, 0);
    for(int i(0); i < N; ++i){
        if(idx == i) continue;
        if(A[idx] == A[i]){
            v[kakutei] = A[i];
            ++kakutei;
            idx = i + 1;
        }
        else idx = i;
        if(kakutei == 2) break;
    }
    std::cout << (long long)v[0] * v[1] << std::endl;
    return 0;
}


Measured memory_bytes: 640
N, W = map(int, input().split())
lstW = []
lstV = []
for i in range(N):
    w, v = map(int, input().split())
    lstW.append(w)
    lstV.append(v)

dp = [[10**9]*(10**5+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(10**5+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if dp[i][j] + lstW[i] <= W:
            dp[i+1][j+lstV[i]] = min(dp[i+1][j+lstV[i]], dp[i][j]+lstW[i])
ans = []
for i in range(max(lstV)*N+1):
    if dp[-1][i] <= W:
        ans.append(i)
print(max(ans))

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

using namespace std;

int main()
{
    char s[200];
    char t[200];
    char ans[400];
    int n;
    int counter = 0;
    cin >> n >> s >> t;
    int i,j;
    
    for(i = 0;i <= n * 2;i += 2)
    {
        ans[i] = s[counter];
        ans[i + 1] = t[counter];
        counter++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << ” = ” << (x) << ” (L” << __LINE__ << “)” << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
       return l.first<r.first || (l.first==r.first && l.second > r.second);
       });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


using Graph = vector<vector<int> >;

int main() {
   int a,b;
   cin>>a>>b;
   cout<<(b%a==0 ? a+b : b-a)<<endl;





   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    Int sum = accumulate(begin(A), end(A), 0LL) / 2;
    vector<Int> B(N);
    Int tmp = 0;
    for (int i = 1; i < N-1; i += 2) tmp += A[i];
    B[0] = sum - tmp;
    for (int i = 1; i < N; i++) B[i] = A[i-1] - B[i-1];
    for (int i = 0; i < N; i++) {
        cout << B[i] * 2 << " \n"[i == N-1];
    }
    return 0;
}

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

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        public float nextFloat() {
            return Float.parseFloat(next());
        }

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

        public void resetST() {
            st = null;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int a=sc.nextInt();
        long sum = (long) (a+ Math.pow(a,2)+Math.pow(a,3));
        System.out.println(sum);
	// write your code here
    }
}


Measured memory_bytes: 32676
#include<bits/stdc++.h>
using namespace std;
long long dp[101][100001];

int main()
{
    int n, w, y, x, maxi=0;
    cin>>n>>w;
    vector<pair<long long, int> >vec(n);
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        vec[i].first=x;
        vec[i].second=y;
        maxi+=y;
    }
    for(int i=0;i<=n;i++)
    {
    for(int j=0;j<=maxi;j++)
    {
        if(i==0&&j==0)
        {
            dp[i][j]=0;
        }
        else if(i==0&&j>=1)
        {
            dp[i][j]=1e15;
        }
        else if(vec[i-1].second<=j)
        {
            dp[i][j]=min(dp[i-1][j], vec[i-1].first+dp[i-1][j-vec[i-1].second]);
        }
        else
        {
            dp[i][j]=dp[i-1][j];
        }
    }
    }

    long long ans1=INT_MIN;
    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=maxi;j++)
        {
            if((dp[i][j]<=w)&&(j>=ans1))
            {
                ans1=j;
            }
        }
    }cout<<ans1<<endl;
    return 0;

}



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

struct Node {
  int key;
  Node *prev, *next;
};

Node *nil;

// 双方向リストの要素の探索
Node* listSearch(int key){
  Node *cur = nil->next; // 番兵の次の要素から辿る
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

// 双方向リストの初期化
void init(){
  // malloc: 指定したサイズだけメモリを動的に確保する
  nil = (Node *)malloc(sizeof(Node));

  // ->: ポインタ変数からメンバにアクセスするための演算子
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;

  while(1){
    if ( cur == nil ) break;
    if ( isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

// 双方向リストの要素の削除
void deleteNode(Node *t){
  if (t == nil) return; // t が番兵の場合は処理しない
  t->prev->next = t->next;
  t->next->prev = t->prev;

  // free(): 必要のなくなったメモリを開放する
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  // 検索したノードを削除
  deleteNode(listSearch(key));
}

// 双方向リストへの要素の挿入
void insert(int key){
  Node *x;
  x = (Node *)malloc(sizeof(Node));
  x->key = key;

  // 番兵の直後に要素を追加
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();

  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {
      insert(key);
      np++;
      size++;
    } else if ( com[0] == 'd' ) {
      if (strlen(com) > 6) {
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}



Measured memory_bytes: 34464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n, m;
    cin >> n >> m;
    struct edge {ll to, cost; };
    vector<vector<edge>> g(n);
    for(int i = 0; i < m; i++)
    {
        int l, r, c;
        cin >> l >> r >> c;
        l--;r--;
        edge e1;
        e1.to = l;
        e1.cost = c;
        edge e2;
        e2.to = r;
        e2.cost = c;
        g[l].push_back(e2);
        g[r].push_back(e1);
    }
    for(int i = 1; i < n; i++)
    {
        edge e = {i-1, 0};
        g[i].push_back(e);
    }
    vector<ll> d(n);
    ll INF = 1e16;
    for(int i = 0; i < n; i++) d[i] = INF;
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));
    while(!que.empty())
    {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;
        for(edge e : g[v])
        {
            if(d[e.to] > d[v] + e.cost)
            {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    if(d[n-1] == INF) cout << -1 << endl;
    else cout << d[n-1] << endl;
}


Measured memory_bytes: 12536
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <functional>
#include <ios>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
const ll InF = 1e15;

int main() {
  int N,K;
  cin>>N>>K;
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i < K) {
      int kaisu;
      kaisu = (int)log2((K - 1) / i) + 1;
      int tmp = N * pow(2,kaisu);
      ans += (double)1 / tmp;
    } else {
      ans += (double)1 / N;
    }
  }
  cout<<setprecision(12)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  char b;
  cin >> b;
  if(b == 'A') cout << 'T';
  else if(b == 'C') cout << 'G';
  else if(b == 'G') cout << 'C';
  else cout << 'A';
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int main(){
	FAST
	int n, m;
	cin>>n>>m;
	if(n<=m) cout<<"unsafe\n";
	else cout<<"safe\n";
}


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

  ll r = 0;
  ll g = 0;
  ll b = 0;
  
  for(int i = 0;i < N;i++){
    if(S[i] == 'R')  ++r;
    if(S[i] == 'G')  ++g;
    if(S[i] == 'B')  ++b;
  }
  
  ll cnt;
  cnt = r * g * b;
  
  for(int i = 0;i < N;i++){
    for(int j = i ;2 * j < N + i;j++){
      if(S[i] != S[j] && S[j + (j - i)] != S[i] && S[j + (j - i)] != S[j])  cnt-=1;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3628
import sys
import math
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())

    ans = []
    n = N
    for _ in range(N):
        n, mod = divmod(n, K)
        ans.append(mod)
        if n == 0:
            break

    print(len(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

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

    if(s[n-1]=='s')s+="es";
    else s+='s';

    cout << s << endl;

    return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
const ll MOD = 1e9 + 7;

int main()
{
	scanf("%d%d",&N,&M);
	vector<ll> A(N),B(M);
	FOR(i,0,N){
		scanf("%lld",&A [i]);
	}
	FOR(i,0,M){
		scanf("%lld",&B [i]);
	}

	ll t = 0;
	FOR(i,0,N - 1){
		(t += (A [i + 1] - A [i]) * (i + 1) * (N - (i + 1))) %= MOD;
	}

	ll ans = 0;
	FOR(i,0,M - 1){
		ll r = t * (i + 1) % MOD;
		(r *= M - (i + 1)) %= MOD;
		(ans += r * (B [i + 1] - B [i])) %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}


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

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

int a[2005], memo[2][2005];

//残りx枚、相手のカードがpre
int rec(int x, bool turn, int pre){
    if(memo[turn][x]!=-1) return memo[turn][x];
    int res = turn?0:IINF;
    for(int i=x-1;i>0;i--){
        if(turn)res = max(res,rec(i,!turn,a[i]));
        else res = min(res,rec(i,!turn,a[i]));
    }
    if(turn)res = max(res,abs(a[0]-pre));
    else res = min(res,abs(a[0]-pre));
    return memo[turn][x] = res;
}

int main() {
    int n, z, w;
    cin >> n >> z >> w;
    REP(i,n)cin >> a[i];
    reverse(a,a+n);
    a[n] = z;
    REP(i,2)fill(memo[i],memo[i]+2005,-1);
    cout << rec(n,true,w) << endl;
    return 0;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        int total = 500*a + 100*b + 50*c;
        if (X == total) count++;
      }
    }
  }
  cout << count << endl;
}  


Measured memory_bytes: 256
<?php
$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$w = (int)$input[1];

// $ws = [];
// $vs = [];
// for ($i=1; $i <= $n; $i++) { 
	// $input = explode(' ', trim(fgets(STDIN)));
// 	$input = fscanf(STDIN, "%d %d");
// 	$ws[$i] = (int)$input[0]; //w
// 	$vs[$i] = (int)$input[1]; //v
// }
// usort($list, function($x, $y){
// 	return $x["w"] - $y["w"];
// });
// $new_list = [];
// foreach ($list as $k => $v) {
// 	$new_list[$k+1] = $v;
// }
// $list = $new_list;
// var_dump($list);

// $dp[$i][$j] = $i番目までの品物で、重さ$w以下で達成可能な価値の最大値
$dp = [];
for ($i=0; $i <= $n; $i++) { 
	$dp[$i] = [0];
}
for ($i=0; $i <= $w; $i++) { 
	$dp[0][$i] = 0;
}

for ($i=1; $i <= $n; $i++) { 
	$input = fscanf(STDIN, "%d %d");
	$wn = (int)$input[0]; //w
	$vn = (int)$input[1]; //v
	for ($j=1; $j <= $w; $j++) { 
		if ($j >= $wn) {
			$dp[$i][$j] = max(
				$dp[$i-1][$j],
				$dp[$i-1][$j-$wn] + $vn
			);
		}else{
			$dp[$i][$j] = $dp[$i-1][$j];
		}
	}
}
echo $dp[$n][$w];

Measured memory_bytes: 420328