akhauriyash/Code-Regression huggingface dataset:
int main(){
	int x, y, s;
	int i, j, n, r1, r2, _i;
	while(scanf("%d%d%d", &x, &y, &s), s){
		r1 = x + 100;
		r2 = y + 100;
		n = 0;
		for(i = 1; i < s; i++){
			_i = i * r1 * 0.01;
			for(j = i; i + j <= s; j++){
				x = _i + (int)(j * r1 * 0.01);
				if(x == s){
					y = (int)(i * r2 * 0.01) + (int)(j * r2 * 0.01);
					if(n < y){
						n = y;
					}
				}
			}
		}
		printf("%d\n", n);
	}
	return 0;
}

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

int main ()
{
    string str;
    while(1)
    {
        cin >> str;
        if (str[0] == '0' && str[1] == '\0') break;
        
        int sum = 0;
        for (int i = 0;i < str.size();i++)
        {
            sum += str[i] - '0';
        }
        cout << sum << endl;
    }
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	
	set<string> st;
	string s;
	cin>>s;
	st.insert(s);
	char f=s[s.size()-1];

	rep(i,n-1){
		cin>>s;
		if(st.count(s)==1){
			cout << "No";
			return 0;
		}
		st.insert(s);
		char h=s[0];
		if(f!=h){
			cout << "No";
			return 0;
		}
		f=s[s.size()-1];
	}
	cout << "Yes" << endl;

}

Measured memory_bytes: 256
toInt :: (String -> Int)
toInt x = read x ::Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y

whichTileMin x = min ptnALen ptnBLen
  where ptnALen = length (filter (== False) (zipWith (==) x (cycle "01")))
        ptnBLen = length (filter (== False) (zipWith (==) x (cycle "10")))

main :: IO ()
main = do
  a <- getLine
  print $ whichTileMin a

Measured memory_bytes: 7164
import java.util.Scanner;
public class Main{
    static int[]A;
    static String[]mark;
    static int[]num;
    public static void main(String args[]){
	int i,n,j;
	Scanner scat=new Scanner(System.in);
	n=scat.nextInt();
	A =new int[n];
	mark = new String[n];
	num=new int[n];
	for(i=0;i<n;i++){
	    mark[i]=scat.next();
	    A[i]=scat.nextInt();
	    num[i]=i;
	}
	quickSort(0,n-1);
	System.out.println(hantei());
	for(j=0;j<n;j++){
	    System.out.println(mark[j]+" "+A[j]);
	}
    }
    public static  void quickSort(int p,int r){
	int q;
	if(p<r){
	    q=partition(p,r);
	    quickSort(p,q-1);
	    quickSort(q+1,r);
    }
    }
	public static int partition(int p,int r){
	    int j,i,x;
	    int hz;
	    String hzs;
	x=A[r];
	i=p-1;
	for(j=p;j<r;j++){
	    if(A[j]<=x){
		i++;
		hz=A[i];
		A[i]=A[j];
		A[j]=hz;
		hz=num[i];
		num[i]=num[j];
		num[j]=hz;
		hzs=mark[i];
		mark[i]=mark[j];
		mark[j]=hzs;
		
	    }
	}
	hz=A[i+1];
	A[i+1]=A[r];
	A[r]=hz;
      	hz=num[i+1];
       	num[i+1]=num[r];
       	num[r]=hz;
	hzs=mark[i+1];
      	mark[i+1]=mark[r];
       	mark[r]=hzs;		
	return i+1;
	}
       static String hantei(){
       	int i;
	for(i=0;i<A.length-1;i++){
	 if(A[i]==A[i+1]){
		if(num[i]>num[i+1]){
		         return "Not stable";
		   }
				}
	}
		return "Stable";
       }	
}



Measured memory_bytes: 104172
#include<iostream>
#include<cstring>
#include<cstdio> 
#define INF 0x3f3f3f3f
 
using namespace std;
 
const int N=20;
int c[N];
int n,m,x;
int a[N][N];
int ans=INF;
int main()
{
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<(1<<n);i++){
		int sum=0;//记录每种状态所花的钱 
		int res[N];//记录每种算法掌握程度 
		memset(res,0,sizeof(res));
		for(int j=0;j<n;j++){
			if(i&(1<<j)){//如果选择j+1本书 
				for(int k=1;k<=m;k++){
					res[k]+=a[j+1][k];
				}
				sum+=c[j+1];
			}
		}
		bool flag=0;
		for(int j=1;j<=m;j++){
			if(res[j]<x){
				flag=1;
				break;
			}
		}
		if(!flag) ans=min(sum,ans);
	}
	if(ans==INF) puts("-1");
	else cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	cout << max(0, A-B*2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, a, b;
/**********************************************/

int main(){
    cin >> n >> a >> b;
    if((a-b) % 2 == 0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
}


Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, D = map(int, input().split())
    if N < (D * 2 + 1):
        ans = 1
    else:
        q, r = divmod(N, D * 2 + 1)
        ans = q + 1 if r > 0 else q
    print(ans)


if __name__ == '__main__':
    solve()


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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(n+1,0)));
    vector<P> a[310];
    for (int i = 0;i < m;++i) {
        int l,r,x;
        cin >> l >> r >> x;
        a[r].push_back(P(l,x));
    }
    // dp[0][0][1] = dp[0][1][0] = dp[1][0][0] = 1;
    dp[0][0][0] = 1;
    for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) for (int k = 0;k < n;++k) {
        int mx = max({i,j,k});
        bool ok = true;
        for (P& p : a[mx+1]) {
            int cnt = 0;
            if (j >= p.first) cnt++;
            if (k >= p.first) cnt++;
            if (cnt != p.second-1) ok = false;
        }
        if (ok) (dp[mx+1][j][k] += dp[i][j][k]) %= mod;
        ok = true;
        for (P& p : a[mx+1]) {
            int cnt = 0;
            if (i >= p.first) cnt++;
            if (k >= p.first) cnt++;
            if (cnt != p.second-1) ok = false;
        }
        if (ok) (dp[i][mx+1][k] += dp[i][j][k]) %= mod;
        ok = true;
        for (P& p : a[mx+1]) {
            int cnt = 0;
            if (i >= p.first) cnt++;
            if (j >= p.first) cnt++;
            if (cnt != p.second-1) ok = false;
        }
        if (ok) (dp[i][j][mx+1] += dp[i][j][k]) %= mod;
    }
    ll ans = 0;
    for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) {
        (ans += dp[i][j][n]) %= mod;
        (ans += dp[i][n][j]) %= mod;
        (ans += dp[n][i][j]) %= mod;
    }
    /*
    for (int i = 0;i < n+1;++i) {
        for (int j = 0;j < n+1;++j) p_ary(dp[i][j],0,n+1,k);
        cout << endl;
    }
    */
    cout << ans << endl;
    return 0;
}

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

int main(){
  int x, n;
  cin >> x >> n;
  vector<int> pn(n);
  for(int i=0; i<n; ++i) cin >> pn[i];
  int ans;
  for(int i=0; i<105; ++i){
    bool ansis = true;
    for(int j=0; j<n; ++j){
      if(pn[j] == x-i) ansis = false;
    }
    if(ansis){ans = x-i; break;}
    ansis = true;
    for(int j=0; j<n; ++j){
      if(pn[j] == x+i) ansis = false;
    }
    if(ansis){ans = x+i; break;}
  }
  cout << ans << endl;
}

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

struct query{
	int a;
	int b;
	int o;
};

int main() {
	while (1) {
		int R, C, Q; cin >> R >> C >> Q;
		if (!R)break;
		vector<query>qs;
		for (int i = 0; i < Q; ++i) {
			int a, b, o; cin >> a >> b >> o;
			qs.push_back(query{ a,b,o });
		}
		vector<int>rstatus(R), cstatus(C);
		int rvalid = R, cvalid = C;
		int ans = 0;
		for (int i = Q - 1; i >= 0;--i) {
			query q(qs[i]);
			if (q.o == 1) {
				if (q.a == 0) {
					if (!rstatus[q.b]) {
						rstatus[q.b] = 1;
						ans += cvalid;
						rvalid--;
					}
				}
				else {
					if (!cstatus[q.b]) {
						cstatus[q.b] = 1;
						ans += rvalid;
						cvalid--;
					}
				}
			}
			else {
				if (q.a == 0) {
					if (!rstatus[q.b]) {
						rstatus[q.b] = -1;
						rvalid--;
					}
				}
				else {
					if (!cstatus[q.b]) {
						cstatus[q.b] = -1;
						cvalid--;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    ll n,k;
    cin >> n >> k;
    vl count(n,0);
    rep(i,n){
        int a;cin >> a;
        count[a-1]++;
    }
    sort(all(count));
    reverse(all(count));
    ll ans=0;
    rep(i,k){
        ans+=count[i];
    }
    cout << n-ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;
#define i64  long long

void solve(void)
{
  int K,X;
  cin>>K>>X;
  int VALUE = 0;
  for (int i = 0; i < 2*K - 1; i++)
  {
    VALUE = X - K + 1 + i;
    if((VALUE >=-1000000)&&(VALUE <= 1000000))
    {
      cout<<VALUE<<" ";
    }
  }
  
  return;
  
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n; cin >> n;
	while(n--){
		int num[10];
		char c;
		int flg = 0;
		for(int i=0;i<10;i++) {
			cin >> c;
			if(c=='K' || c=='Q' || c=='J' || c=='T') num[i] = 10;
			else if(c=='A') {
				num[i] = 11;
				if(i==0 || i==1) flg++;
			}
			else num[i] = c - '0';
		}
		int sum = num[0] + num[1];
		int now = 2;
		if(sum == 21) cout << "blackjack" << endl;
		else{
			while(now<=9){
				if(sum <= 16) {
					sum += num[now];
					if(num[now] == 11) flg++;
					now++;
				}
				else if(sum == 17 && flg!=0){
					sum += num[now];
					if(num[now] == 11) flg++;
					now++;
				}
				else {
					if(sum >= 22 && flg!=0){
						flg--;
						sum -= 10;
					}
					else break;
				}
			}
			if(sum >= 22) cout << "bust" << endl;
			else cout << sum << endl;
		}
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
int n; cin>>n;
int dp[n+1][3],a[n+1][3];
for(int i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
}
dp[0][0]=a[0][0];
dp[0][1]=a[0][1];
dp[0][2]=a[0][2];
for(int i=1;i<n;i++){
    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<'\n';
return 0;
}


Measured memory_bytes: 5996
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

long long N;
vector<long long> A, B, C;

int main() {
  cin >> N;
  rep(i, N) {
    int x;
    cin >> x;
    A.push_back(x);
  }
  rep(i, N) {
    int x;
    cin >> x;
    B.push_back(x);
  }
  rep(i, N) {
    int x;
    cin >> x;
    C.push_back(x);
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  long long ans = 0;
  rep(i, N) {
    long long b = B[i];
    long long a, c;
    a = lower_bound(A.begin(), A.end(), b) - A.begin();
    c = upper_bound(C.begin(), C.end(), b) - C.begin();
    ans += a * (C.size()-c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6352
#include <stdio.h>
#include <string.h>

#define MAXSIZE 100000

int main(void){
    char s[MAXSIZE],d[]="dream",e[]="erase";
    scanf("%s",s);
    int len_s=strlen(s),p=0,i;
    while(p<len_s){
        if(s[p]=='d'){
            for(i=0;i<5;i++){
                if(s[p]==d[i]){
                    p++;
                }else{
                    printf("NO\n");
                    return 0;
                }
            }
            if(s[p]=='e'){
                p++;
                if(s[p]=='r'){
                    p++;
                    if(s[p]=='a') p-=2;
                }
            }
        }else if(s[p]=='e'){
            for(i=0;i<5;i++){
                if(s[p]==e[i]){
                    p++;
                }else{
                    printf("NO\n");
                    return 0;
                }
            }
            if(s[p]=='r'){
                p++;
            }
        }else{
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int n = S.size();
  int res = 0;
  int num = 0;
  for(int i = 0; i < n; i++){
    if(S.at(i) == 'o')res++;
    else if(S.at(i) == 'x')num++;
  }
  if(num >= 8)cout << "NO" << endl;
  else cout << "YES" << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> L(n);
  for (int i = 0; i < n; i++) cin >> L[i];
  
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      for (int k = j; k < n; k++) {
        if ((L[i] != L[j]) && (L[j] != L[k]) && L[i] != L[k]) {
          if ((L[i] + L[j] > L[k]) && (L[j] + L[k] > L[i]) && (L[k] + L[i] > L[j])) {
            cnt++;
          }
        } else continue;
      }
    }
  }
  
  cout << cnt << endl;
}

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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ld t,x;
    cin >> t >> x;
    cout << t/x<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    long int ALLTIME=0;
    long int t[200000]={};
    long int N,T,i;
    scanf("%ld %ld",&N,&T);
    for(i=0;i<N;i++){
        scanf("%d",&t[i]);
    }
    for(i=0;i<N;i++){
        if(i==0){
            ALLTIME+=T;
        }else{
            if(t[i-1]+T<t[i]){
                ALLTIME+=T;
            }else{
                ALLTIME+=t[i]-t[i-1];
            }
        }
    }
    printf("%ld\n",ALLTIME);
    return 0;
}

Measured memory_bytes: 1664
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()
N = int(input()) # 1行, 単数
arg = list(map(int, input().split())) # 1行, 配列

A = arg[0]
B = arg[1]
flag = "NG"

if A == B:
  if A % N == 0:
    flag = "OK"
else:
  for i in range(A,B+1):
    if i % N ==0:
      flag = "OK"
      break

print(flag)


Measured memory_bytes: 61700
import sys
input = sys.stdin.readline



M, W = map(int, input().split())                                # M: 品物の種類 W: 重量制限
single = False                                                   # True = 重複なし

price_list = [0]
weight_list = [0]
for _ in range(M):
    price, weight = map(int, input().split())
    price_list.append(price)
    weight_list.append(weight)


################################################################################################################################################

dp_min = 0                                                      # 総和価値の最小値

# dp[item <= M ][weight <= W]
dp = [[dp_min] * (W + 1) for _ in range(M + 1)]                 # 左端と上端の境界条件で W, M を一個ずつ多めに取る

for item in range(M+1):                                         # 左端の境界条件
    dp[item][0] = 0                                             # 重さ 0 を実現するのに必要な品物の個数は 0 個

# for weight in range(W+1):                                     # 上端の境界条件
#     dp[0][weight] = dp_max                                    # 0 種類の品物で実現できる重量は存在しない　（dpの初期化で自動的に課せる場合が多い）


for item in range(1,M+1):                                       # 境界条件を除いた M 回のループ（※ f[item] = g.f[item-i] の漸化式なので、list index out of range となる）
    for weight in range(1, W + 1):
        if weight < weight_list[item]:                          # weight (重量価値) < weight_list[item] (品物の重量) の時は無視してよい
            dp[item][weight] = dp[item - 1][weight]
        else:
            temp = dp[item - single][weight - weight_list[item]] + price_list[item]  # single = True: 重複なし
            if temp > dp[item-1][weight]:
                dp[item][weight] = temp
            else:
                dp[item][weight] = dp[item-1][weight]

print(dp[M][W])


Measured memory_bytes: 15704
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,l;
    string str;
    cin>>k;
    cin>>str;
    l=str.size();
    if(l>k)
    {
        for(int i=0;i<k;i++)
        {
            cout<<str[i];
        }
        cout<<"..."<<endl;
    }
    else if(l<=k)
    {
        for(int i=0;i<l;i++)
        {
            cout<<str[i];
        }
    }

}


Measured memory_bytes: 3596
input_list = []
for i in range(2):
    input_list.append(input().split())
A = int(input_list[0][0])
B = int(input_list[0][1])
S = input_list[1][0]

if S[0:A].isdigit() and S[A] == '-' and S[A+1:A+B+1].isdigit():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    int x;
    cin >> x;
    vector<int> ans;
    ans.push_back(1);
    repr(i,2,32) {
        int j=i*i;
        while (j<=x) {
            ans.push_back(j);
            j*=i;
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans[ans.size()-1] << endl;
}

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

using namespace std;

int main() {
  int32_t n;
  cin >> n;

  vector<long double> p(n+1, 0);
  for (int32_t i = 1; i <= n; ++i) {
    cin >> p[i];
  }

  vector<vector<long double>> dp(n+1, vector<long double>(n+1, 0.0));
  dp[0][0] = 1.0;
  for (int32_t i = 1; i <= n; ++i) {
    long double pi = p[i];
    long double qi = 1.0 - pi;
    dp[i][0] = dp[i-1][0] * qi;
    for (int32_t j = 1; j <= i; ++j) {
      dp[i][j] = dp[i-1][j-1] * pi + dp[i-1][j] * qi;
    }
  }

  long double sum = 0.0;
  for (int32_t j = n / 2 + 1; j <= n; ++j) {
    sum += dp[n][j];
  }

  cout << fixed << setprecision(10) << sum << endl;
}


Measured memory_bytes: 141056
from collections import Counter as c
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=c(a)
d=[0]*m
e=[0]*m
for i in b.keys():
    t=b[i]
    d[i%m]+=t
    e[i%m]+=t//2
z=0
for i in range(1,(m+1)//2):
    x,y=d[i],d[-i]
    if x>y:
        z+=d[-i]+min(e[i],(d[i]-d[-i])//2)
    else:
        z+=d[i]+min(e[-i],(d[-i]-d[i])//2)
if m%2==0:
    z+=d[m//2]//2
z+=d[0]//2
print(z)

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

typedef long long ll;

int main() {
    int N, A, p = 0;
    cin >> N;
    rep(i, N) {
        cin >> A;
        p = (p + A) % 2;
    }
    if (p) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int i;
  int j;
  int flag = 0;
  for(i=0;i<41;i++){
    for(j=0;j<16;j++){
      if((i*4+j*7)==N){
        flag = 1;
      }
    }
  }
  if(flag == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int N=100005;ll A=2,B=1;
vector<ll> h(100005);

bool C(ll x){
    vector<ll> v(N);
    REP(i,N)v[i]=max(0LL,h[i]-B*x);
    ll cnt=0;
    REP(i,N){
        cnt+=(v[i]%(A-B)==0?v[i]/(A-B):v[i]/(A-B)+1);
    }
    return (cnt<=x?true:false);
}

int main(){
    cin>>N>>A>>B;
    REP(i,N)cin>>h[i];
    ll lb=0,ub=1LL<<30;
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }
    cout<<ub<<endl;
    return 0;
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    VI l_aim(3);
    cin >> n;
    REP(k, 3) cin >> l_aim[k];
    VI l(n);
    REP(i, n) cin >> l[i];
    
    int ans = 1e9;
    REP(i, pow(4, n)) {

        // assign
        VI role_cnt(3, 0), l_concat(3, 0);
        int temp_i = i;
        REP(j, n) {
            int role = temp_i % 4;
            if(role < 3) {
                role_cnt[role]++;
                l_concat[role] += l[j];
            }
            temp_i /= 4;
        }
        bool is_valid = true;
        REP(k, 3) is_valid *= role_cnt[k];
        if(!is_valid) continue;

        // calc MP
        int mp = 0;
        REP(k, 3) {
            mp += abs(l_aim[k] - l_concat[k]);
            mp += 10 * max(role_cnt[k] - 1, 0);
        }
        ans = min(ans, mp);
    }

    cout << ans << ln;
    return 0;
}


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

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

struct UnionFind {
  // 子は親のID,親は-サイズ
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];

  // Kruskal 法で使用する枝
  using P = pair<int, int>;
  using Edge = pair<ll, P>;
  vector<Edge> G;

  // x 軸方向にソートして隣接している部分のみ
  vector<int> ids(n);
  iota(ids.begin(), ids.end(), 0);
  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
  for (int i = 0; i < ids.size() - 1; ++i) {
    int u = ids[i], v = ids[i + 1];
    G.emplace_back(Edge(x[v] - x[u], P(u, v)));
  }

  // y 軸方向にソートして隣接している部分のみ
  sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
  for (int i = 0; i < ids.size() - 1; ++i) {
    int u = ids[i], v = ids[i + 1];
    G.emplace_back(Edge(y[v] - y[u], P(u, v)));
  }

  // Kruskal 法
  sort(G.begin(), G.end());
  UnionFind uf(n);
  ll res = 0;
  for (auto e : G) {
    int u = e.second.first, v = e.second.second;
    ll cost = e.first;
    if (uf.same(u, v)) continue;
    uf.unite(u, v);
    res += cost;
  }
  cout << res << endl;
}

Measured memory_bytes: 8432
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	if strings.Count(s, "R") > strings.Count(s, "B") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

namespace MyProgram{
    class AtCoder{
        static void Main(){
            var input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = input[0];
            long M = input[1];
            long result = 0;
            if(2*N<M){
                result = N+ (M-2*N)/4;
            }else{
                result = Math.Min(N,M/2);
            }

            Console.WriteLine(result);
        }
    } 
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
int n;
int a[100005][3];
ll dp[100005][3];
ll solve(int index, int last) {
    if (index == n)
        return 0;
    if (dp[index][last] != 0) {
        return dp[index][last];
    }
    ll ans = 0;
    for (int i = 0; i < 3; i++) {
        if (i == last) continue;
        ans = max(ans, solve(index + 1, i) + a[index][i]);
    }
    return dp[index][last] = ans;
}

int main() {
    IO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    cout << max(solve(0,0),max(solve(0,1),solve(0,2)));
    return 0;
}


Measured memory_bytes: 9984
# -*- coding: utf-8 -*-


def main():
    from itertools import product

    n, m = map(int, input().split())
    xyz = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for op1, op2, op3 in list(product([1, -1], repeat=3)):
        tmp = [[0, 0, 0]] * n

        for index, value in enumerate(xyz):
            tmp[index] = sum([op1 * value[0], op2 * value[1], op3 * value[2]])

        camdidates = sorted(tmp, reverse=True)
        ans = max(ans, sum(camdidates[:m]))

    print(ans)


if __name__ == '__main__':
    main()


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


int main() {
  string S;
  cin >> S;
  bool al[26];
  rep(i, 26) al[i] = false;
  
  rep(i, S.size()) al[S[i] - 'a'] = true;
  
  bool a = true;
  rep(i, 26){
    if(!al[i]){
      cout << (char)(i + 'a') << endl;
      a = false;
      break;
    }
  }
  if(a) cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll minimum(vector<ll> &v){
    ll tmp=-243434;
    for(int i=0;i<v.size();i++){
        if(tmp<v[i])
            tmp=v[i];
    }
    return tmp;
}
int main() {
    ll n,k;
    cin>>n;
    cin>>k;
    ll a[n];
    ll memo[n];
    vector<ll> v;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        memo[i]=-1;
    memo[0]=0;
    memo[1]=abs(a[1]-a[0]);

    for(int i=2;i<n;i++){
        for(int j=i;j>0;j--){
            ll tmp=memo[j-1]+abs((a[i]-a[j-1]));
            v.push_back(tmp);
            if(j-1==i-k)
                break;
        }
        sort(v.begin(),v.end());
        memo[i]=v[0];
        v.clear();
    }
    cout<<memo[n-1]<<endl;
    }



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += (ll) i * (n - i + 1);
	}
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		if(u > v) swap(u, v);
		ans -= (ll) u * (n - v + 1);
	}
	cout << ans << endl;

}





Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N;cin>>N;
    int keta = 0;
    int top = N;
    int nokori;
    while(true){
        keta++;
        if(top < 10)break;
        top /= 10;    
    }
    int bottom = N % 10;
    nokori = N - top * pow(10,(keta-1)) - bottom;
    //cout << top << " " << bottom << " " << nokori << endl;
    
    vvi number(10,vector<int>(10,0));
    for(int i = 1; i<= 9; i++){
        if(i < top){
            for(int k = 1; k<=9; k++){
                for(int j = 1; j <= keta; j++){
                    if(j == 1 && i == k)number[i][k]++;
                    else if(j==2)number[i][k]++;
                    else{
                        number[i][k] += pow(10,j-2);
                    }
                }
            }
        }
        else if(i == top){
            for(int k = 1; k<=9; k++){
                for(int j = 1; j <= keta; j++){
                    if(j == 1 && i == k)number[i][k]++;
                    else if(j < keta){
                        number[i][k] += pow(10,j-2);
                    }
                    else{
                        if(k <= bottom){
                            if(j == 2)number[i][k]++;
                            else number[i][k] += nokori/10+1;
                            
                        }
                        else{
                            if(nokori/10>=1)number[i][k] += nokori/10;
                        }
                    }
                }
            }
        }
        else{
            for(int k = 1; k<=9; k++){
                for(int j = 1; j < keta; j++){
                    if(j == 1 && i == k)number[i][k]++;
                    else if(j==2)number[i][k]++;
                    else{
                        number[i][k] += pow(10,j-2);
                    }
                }
            }
        }

    }

    /*FOR(i,1,10){
        FOR(k,1,10){
            cout<<number[i][k]<<" ";
        }
        cout<<endl;
    }*/
    int ans = 0;
    FOR(i,1,10){
        FOR(k,1,10){
            ans += number[i][k] * number[k][i];
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  int sum=0;
  for(auto &e: a) {
    sum+=e;
  }
  std::vector<int> div;
  for (int i = 1; i <= sqrt(sum); ++i)
  {
    if(sum%i==0) div.insert(div.end(),{i,sum/i});
  }
  sort(div.begin(),div.end());
  int ans;
  for(auto &e: div) {
    std::vector<int> tmp;
    for(auto &f: a) {
      tmp.emplace_back(f%e);
    }
    int tmp_sum=0;
    for(auto &g: tmp) {
      tmp_sum+=g;
    }
    if(tmp_sum%e!=0) continue;
    sort(tmp.begin(), tmp.end(),greater<int>());
  
    tmp.erase(tmp.begin(),tmp.begin()+tmp_sum/e);
    int sum2=0;
    for(auto &h: tmp) {
      sum2+=h;
    }
    if(sum2<=k) ans=e;
  }
  cout<<ans;
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	n, err := strconv.Atoi(nextString())
	return n, err
}

func f(x int) int {
	return x * x
}

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

	for {
		d, err := nextInt()
		if err != nil {
			break
		}

		area := 0
		for i := 0; i < 600/d; i++ {
			x := i * d
			area += f(x) * d
		}
		fmt.Println(area)
	}
}



Measured memory_bytes: 1096
if __name__ == "__main__":
    N = int(input())
    A = []
    for x in range(N):
        y = int(input())
        y -= 1
        A.append(y)
    pos = 0
    cnt = 0
    visited = set()
    while (cnt <= N + 1):
        visited.add(pos)
        if (pos == 1):
            print (cnt)
            exit()
        pos = A[pos]
        cnt += 1
        if pos in visited:
            break

    print (-1)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	cout << (a <= c && c <= b ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
/**
 * Created by hiramekun at 22:08 on 2019-10-24.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll x, a, b;
    cin >> x >> a >> b;
    if (b <= a) {
        cout << "delicious" << '\n';
    } else if (b - a <= x) {
        cout << "safe" << '\n';
    } else {
        cout << "dangerous" << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

int a, b;




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

	if (a >= 13) cout << b << endl;
	else if (a >= 6) cout << b / 2 << endl;
	else cout << 0 << endl;

	return 0;
}



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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        int A, P;
        std::cin >> A >> P;

        std::cout << (A * 3 + P) / 2 << std::endl;
    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 256
#ALDS1_12_A Minimum Spanning Tree
import sys


n = int(input())
G = []
for i in range(n):
    input_list = list(map(int, sys.stdin.readline().strip().split()))
    adj = [j if j != -1 else float('inf') for j in input_list]
    adj[i] = 0
    G.append(adj)

p = ['unexplored'] * n  # 親を保存するリスト
d = [float('inf')] * n  # 距離を保存するリスト

p[0] = 0
d[0] = 0
u = 0

for _ in range(n):
    mincost = float('inf')
    for i in range(n):
        if (p[i] == 'unexplored') & (d[i] < mincost):
            mincost = d[i]
            u = i  # u is child

    for i in range(n):
        if (p[i] != 'unexplored') & (G[i][u] == mincost):
            p[u] = i
            break
            
    for i in range(n):
        if G[u][i] < d[i]:
            d[i] = G[u][i]
    # print(p)

ans = 0
for i in range(1, n):
    ans += G[p[i]][i]
print(ans)



Measured memory_bytes: 5960
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <utility>
#include <set>
#include <map>
using namespace std;

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

int n;
const int maxn = 1e5+1;
ll a[maxn*3];
ll l[maxn*3], r[maxn*3];

int main()
{
  scanf("%d", &n);
  for (int i = 1; i <= 3*n; ++i)
    scanf("%lld", a+i);
  ll tmp = 0;
  multiset<ll> res;
  for (int i = 1; i <= n; ++i)
    {
      tmp += a[i];
      res.insert(a[i]);
    }
  l[n] = tmp;
  for (int i = n+1; i <= 2*n; ++i)
    {
      if (*res.begin() < a[i])
	{
	  tmp -= *res.begin();
	  res.erase(res.begin());
	  res.insert(a[i]);
	  tmp += a[i];
	}
      l[i] = tmp;
    }
  tmp = 0;
  res.clear();
  for (int i = 3*n; i >= 2*n+1; --i)
    {
      tmp += a[i];
      res.insert(a[i]);
    }
  r[2*n+1] = tmp;
  for (int i = 2*n; i >= n+1; --i)
    {
      multiset<ll>::iterator it = res.end();
      --it;
      if (*it > a[i])
	{
	  tmp -= *it;
	  tmp += a[i];
	  res.erase(it);
	  res.insert(a[i]);
	}
      r[i] = tmp;
    }
  ll ans = -2e18;
  for (int i = n; i <= 2*n; ++i)
    {
      ans = max(ans, l[i]-r[i+1]);
    }
  printf("%lld\n", ans);
	
}


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

int main(){
	long long int a,b,c[200010],ans =1e9;
  
  cin >> a >>b ;
  
  for(int i=0;i<a;i++)
    cin >> c[i];
  
   for (int i=0;i<a-b+1;i++){
     
    ans=min(ans,abs(c[i])+abs(c[i+b-1]-c[i]));
     
    ans=min(ans,abs(c[b+i-1])+abs(c[i+b-1]-c[i]));
  }
  cout << ans <<endl;
}
  
  

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

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    auto S = sread();
    foreach (i; 0 .. S.length - 1)
    {
        if (S[i .. i + 2] == "AC")
        {
            writeln("Yes");
            return;
        }
    }
    writeln("No");
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

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


int inf = 1e+9;

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = inf;
  //ABセットで決め打ち全探索を考える
  rep(i,200000) {
    int cost = max(0,X-i) * A + max(0,Y-i) * B + 2 * C * i;
    ans = min(cost,ans);
  }
  cout << ans << endl;
  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main(){
	int N, L, *T;
	cin >> N >> L;

	int sum = 0;
	int min = abs(L);

	T = new int[N];

	for(int i = 0;i < N;++i){
		sum += L + i;
		if(abs(min) > abs(L + i)){
			min = L + i;
		}
	}
	cout << sum - min << endl;

	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 repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問状況

// 入力
int n;
double p[3000];

// DP テーブル
double dp[3000][3000];

int main() {
    cin >> n;
    rep(i, n) {
        cin >> p[i];
    }

    // 初期条件
    dp[0][0] = 1.0;

    // DP ループ
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    // 答え
    double res = 0.0;
    for (int j = n/2 + 1; j <= n; ++j) res += dp[n][j];
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 49876
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		for(int i = 1; i <=N; i+=2){
			int count = 0;
			for(int j = 1; j<= i; j++){
				if(i % j == 0) {
				 count++;
			 	}
			}
			if(count == 8) {
				ans++;
			}
		}
		System.out.print(ans);
	}
}



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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>>  var(n, vector<int>(m, INF))
#define vecb2(var, n, m)   vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m)  vector<vector<ll>>   var(n, vector<ll>(m, INF))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "YES" : "NO");}
//----------------------------------------------------------------

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

  prtok(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]);
}


Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
	typedef long long int lli;
	const int MaxN=55;
	#define fst first
	#define snd second
int main(){
	lli v,N,i,p,t=0;
	cin>>v>>N;
	for(i=0;i<N;i++){
		cin>>p;	
		t+=p;
	}
	if(t>v){
		cout<<"-1";
	} else cout<<v-t;
}

Measured memory_bytes: 3168