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

#define loop(i,n) for(int i=0;i<(n);i++)
#define pool(i,n) for(int i=(n)-1;i>=0;i--)
#define cont(i,n) for(int i=1;i<=(n);i++)
#define tnoc(i,n) for(int i=(n);i>=1;i--)
#define circ(i,a,b) for(int i=(a);i<=(b);i++)
#define cric(i,a,b) for(int i=(b);i>=(a);i--)
#define sub(i,a) for(int i=a;i;i=((i-1)&(a)))
#define subs(i,a) for(int i=a;i>=0;i=(!i?-1:((i-1)&(a))))
#define subt(i,a) for(int i=((a-1)&a);i;i=((i-1)&(a)))
#define subst(i,a) for(int i=((a-1)&a);i>=0;i=(!i?-1:((i-1)&(a))))
#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))
#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)
#define parse(i,s) for(int i=0;s[i];i++)

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mak make_pair

#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1 y1II11II11III11I1III11II111IIII1II1I1
#define ws WSrAkIoi2333wSraKIoIWSraKiOi
#define left left_jTjTJtJtIoiiOiioIAuaU66666jtIOIau
#define hash whYusEthiSnamE_caNyoUusEothERnaMesliKeHSH

#define Mask(a) (1ll<<(a))
#define Maskx(a,x) ((a)<<(x))
#define Full(a) ((1ll<<(a))-1)
#define Bit(a,x) (((a)>>(x))&1)
#define all(a) (a).begin(),(a).end()
#define SZ(a) ((int)((a).size()))

typedef long long ll;
typedef long double lf;

const int Inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const lf inF=11451419198101145141919810.1145141919810;
const lf pi=acosl(-1);
/* Source code starts here */

int n;
lf a[1<<18],b[1<<18];
vector<lf> as,bs,cs;

bool inline check(int x,int y,int z){
	return ((as[y]+cs[y])-(as[x]+cs[x]))*(z-y)<=((as[z]+cs[z])-(as[y]+cs[y]))*(y-x);
}

lf inline calc(int x,int y){
	return ((as[x]+cs[x])+(as[y]+cs[y]))*(y-x+1)/2-as[y]-cs[y];
}

int main(){
	scanf("%d",&n);
	int mxpos=1;
	cont(i,n){
		scanf("%Lf",a+i);
		if(a[i]>a[mxpos]) mxpos=i;
	}
	cont(i,n) scanf("%Lf",b+i);
	circ(i,mxpos,n) as.push_back(a[i]),bs.push_back(b[i]);
	cont(i,mxpos) as.push_back(a[i]),bs.push_back(b[i]);
	n=SZ(as);
	cs.resize(n);
	circ(i,2,n-1) cs[i]=2*cs[i-1]-2*bs[i-1]-cs[i-2];
	lf ans=0;
	vector<int> stk;
	loop(i,n){
		while(SZ(stk)>=2&&check(stk[SZ(stk)-2],stk.back(),i)){
			ans-=calc(stk[SZ(stk)-2],stk.back());
			stk.pob();
		}
		if(SZ(stk)) ans+=calc(stk.back(),i);
		stk.pub(i);
	}
	loop(i,n-1) ans-=cs[i];
	ans/=n-1;
	printf("%.15Lf\n",ans);
	return 0;
}

Measured memory_bytes: 20516
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100
#define LARGENUM 1000000007
int color[MAX], d[MAX], n, M[MAX][MAX];
typedef pair <int, int> P;
vector <P> adj[MAX];

int ShortestPath[MAX][MAX];

void dijkstra(int s){
    priority_queue<P> PQ;
    vector <int> parent[MAX];
    rep(i, n) {
        d[i] = LARGENUM;
        color[i] = WHITE;
    }
    d[s] = 0;
    PQ.push(P(0, s));
    color[0] = GRAY;
    while (!PQ.empty()){
        P f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        if (d[u] < f.first * -1) continue;
        rep(j, adj[u].size()){
            int v = adj[u][j].second;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].first){
                d[v] = d[u] + adj[u][j].first;
                PQ.push(make_pair(d[v] * -1, v));
                color[v] = GRAY;
                while(!parent[v].empty()) parent[v].pop_back();
                parent[v].push_back(u);
            }
            else if(d[v] == d[u] + adj[u][j].first){
                d[v] = d[u] + adj[u][j].first;
                PQ.push(make_pair(d[v] * -1, v));
                color[v] = GRAY;
                parent[v].push_back(u);
            }
        }
    }
    rep(i, n){
        rep(j, parent[i].size()){
            ShortestPath[i][parent[i][j]] = WHITE;
        }
    }
}

int main(){
    int m, a, b, c, count = 0;
    cin >> n >> m;
    rep(i, m){
        cin >> a >> b >> c;
        M[a-1][b-1] = c;
        M[b-1][a-1] = c;
        adj[a-1].push_back(P(c, b-1));
        adj[b-1].push_back(P(c, a-1));
    }
    rep(i, n){
        rep(j, n){
            if (M[i][j] == 0) {
                ShortestPath[i][j] = BLACK;
            }
            else {
                ShortestPath[i][j] = GRAY;
            }
        }
    }
    rep(i, n) dijkstra(i);
    rep(i, n) {
        rep(j, n) if (ShortestPath[i][j] == GRAY) count++;
    }
    cout << count / 2 << endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
	static int h;
	static int w;
	static char[][] grid;
	static long[][] dp;
	static long k=1000000007;

	static long dp(int i, int j) {
		if (i == h && j == w) {
			return 0;
		}
		if (grid[i][j] == '#') {
			return 0;
		}
		if (grid[i][j] == 'g') {
			return 1;
		}
		if (dp[i][j] != -1) {
			return dp[i][j];
		}
		long x = 0;
		if (i < h - 1 && j < w - 1) {
			x = dp(i + 1, j)%k + dp(i, j + 1)%k;
		} else if (i < h && j == w - 1) {
			x = dp(i + 1, j)%k;
		} else if (i == h - 1 && j < w) {
			x = dp(i, j + 1)%k;
		}
		return dp[i][j] = x;
	}

	public static void main(String[] args) throws IOException {
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		h = Integer.parseInt(st.nextToken());
		w = Integer.parseInt(st.nextToken());
		grid = new char[h][w];
		for (int i = 0; i < h; i++) {
			String s = br.readLine();
			for (int j = 0; j < w; j++) {
				grid[i][j] = s.charAt(j);
			}
		}
		grid[h - 1][w - 1] = 'g';
		dp = new long[h][w];
		for (long[] i : dp) {
			Arrays.fill(i, -1);
		}
		out.println(dp(0, 0)%k);
		out.close();
	}
}


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

#define int long long

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

string S;

signed main() {
    cin >> S;
    if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    if (S.length() == 26) {
        for (int i = 25; i >= 1; i--) {
            if (S[i] > S[i - 1]) {
                for (int j = 25; j >= i; j--) {
                    if (S[j] > S[i - 1]) {
                        swap(S[j], S[i - 1]);
                        cout << S.substr(0, i) << endl;
                        return 0;
                    }
                }
            }
        }
    }
    bool ap[26] = {};
    for (int i = 0; i < S.length(); i++) {
        ap[S[i] - 'a'] = true;
    }
    for (int i = 0; i <= 26; i++) {
        if (!ap[i]) {
            S += ('a' + i);
            cout << S << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
char c;
ll sum=0;
main(){
	register int i;
	for(i=1;i<=2;i++){
		cin>>c;
		if(c=='D')sum++;
	}
	sum%=2;
	if(sum==0)cout<<"H"<<endl;
	else cout<<"D"<<endl;
} 

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int n,k,cnt=1;
   cin>>n>>k;

   while(n >= k){
      n /= k;
      ++cnt;
   }
   cout<<cnt<<'\n';
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

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

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

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

int main(void)
{
    ll a = 1000000000+7;
    int N;
    ll ans = 1;
    cin >> N;

    for(int i = 1;i <= N;i++){
        ans = ans*i%a;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
const int maxn=2e5+5;

int main() 
{

    int t;
    cin >> t;

    rep(w,t){
        int n,k,ans;

        cin >> n >> k;

        int A[n];
        int X[n-1];
    
        rep(i,n){
            cin >> A[i];
            if(i)X[i-1] = A[i] - A[i-1];       
        }

        sort(X,X+n-1);
        reverse(X,X+n-1);

        ans = A[n-1] - A[0];

        rep(i,min(k-1,n-1)){
            ans -= X[i];
        }
    
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
    ll n;cin>>n;
    ll a,b;cin>>a>>b;
    ll x=0;
    rep(i,n-2){
        ll t;cin>>t;
        x^=t;
    }
    ll dif=a+b-x;
    if(dif%2||dif<0)dame(-1);
    dif>>=1;
    rep(i,50)if((dif>>i&1)&&(x>>i&1))dame(-1);
    ll A=0,B=0;
    rep(i,50){
        if(dif>>i&1){
            A+=1ll<<i;
            B+=1ll<<i;
        }
        else if(x>>i&1)B+=1ll<<i;
    }
    if(A+B!=a+b)dame(-1);
    if(A>a)dame(-1);
    for(int i=49;i>=0;i--){
        if((B>>i&1)&&!(A>>i&1)){
            if(A+(1ll<<i)<=a)A+=1ll<<i;
        }
    }
    if(A==0)dame(-1);
    out(a-A);
}

Measured memory_bytes: 3592
def l():
    return [int(x) for x in input().split()]
def main():
    H,W=l()
    ch,cw=l()
    dh,dw=l()
    ch-=1
    cw-=1
    dw-=1
    dh-=1
    s=[[-2 if x=='#' else -1 for x in list(input())] for _ in range(H)]
    pad1=[-2,-2]
    pad2=[[-2]*(W+4)]*2
    s=pad2+[pad1+x+pad1 for x in s]+pad2
    move1=[(-1,0),(1,0),(0,-1),(0,1)]
    move2=list(set([(i,j) for i in range(-2,3) for j in range(-2,3)])-set(move1)-set([(0,0)]))
    q1=[(0,ch+2,cw+2)]
    q2=[]
    s[ch+2][cw+2]=0
    def mark(c,h,w):
        #if 0<=h<H and 0<=w<W and s[h][w]==-1:
        if s[h][w]==-1:
            s[h][w]=c
            q1.append((c,h,w))
    while q1:
        #print(q1)
        c,h,w=q1.pop()
        for i,j in move1:
            mark(c,h+i,w+j)
        q2.append((c+1,h,w))
        if not q1:
            for c,h,w in q2:
                for i,j in move2:
                    mark(c,h+i,w+j)
            q2=[]
    ans=s[dh+2][dw+2]
    if ans>=0:
        print(ans)
    else:
        print(-1)
main()


Measured memory_bytes: 115352
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    double a,b,h,m;
    cin >> a>> b>> h>> m;
    int q=((h*60+m)/60-(h*60+m)/720)/1;
    double p=(((h*60+m)/60-(h*60+m)/720)-q)*(2*M_PI);
    //cerr<<p<<endl;
    double ans=sqrt(abs(a*a+b*b-2*a*b*cos(p)));
    printf("%.10lf\n",ans);
    return 0;
}



Measured memory_bytes: 4240
from sys import stdin

n,x = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

from itertools import accumulate

li2 = list(accumulate(li))
li2.append(0)
li2.sort()
print(len([i for i in li2 if i <= x]))

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << H*W-h*W-w*(H-h) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> S;
    ans = 1;
    int ind = 1;
    char prev = S[0];
    bool flag = 0;
    while (ind < S.size()) {
        if (flag) {
            ind++;
            ans++;
            flag = 0;
        } else {
            if (S[ind - 1] == S[ind]) {
                if (ind + 1 < S.size()) {
                    ind += 2;
                    ans++;
                    flag = 1;
                } else {
                    ind++;
                }
            } else {
                ind++;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A[110000],n;
long long ans[110000];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	long long tot=0;
	for (int i=1;i<=n;i++) tot+=A[i];
	long long one=1ll*n*(n+1)/2;
	if (tot%one){
		printf("NO\n"); return 0;
	}
	long long t=tot/one; A[n+1]=A[1];
	for (int i=2;i<=n+1;i++){
		long long w=A[i-1]-A[i]+t;
		if (w<0||w%n){
			printf("NO\n"); return 0; 
		}
	}
	printf("YES\n");
	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n;
  cin >> n;
  vector<int> x(n);
  arep(i, x) cin >> i;

  vector<int> fow(n + 1), bac(n + 1);

  rep(i, 0, n) fow[i + 1] = gcd(fow[i], x[i]);
  reps(i, n - 1, 0) bac[i] = gcd(bac[i + 1], x[i]);

  int ans = 0;
  rep(i, 0, n) chmax(ans, gcd(fow[i], bac[i + 1]));

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

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

int main()
{
	long long i1, i2, i3, i4, i5;
	cin >> i1 >> i2 >> i3 >> i4 >> i5;
	if (i1 == 0)
		cout << 1;
	else if (i2 == 0)
		cout << 2;
	else if (i3 == 0)
		cout << 3;
	else if (i4 == 0)
		cout << 4;
	else
		cout << 5;

	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
	int S,h,m,s;
	
	scanf("%d",&S);
	
	s=S%60;
	m=(S%(60*60))/60;
	h=S/(60*60);

	printf("%d:%d:%d\n",h,m,s);
return 0;
}

Measured memory_bytes: 592
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *

N = int(input())
A = list(map(int, input().split()))
k = 0
for a in A:
    k += 1/a
print(1/k)


Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#define long long

using namespace std;

int main() {
	float n;
	cin>>n;
	if(floor(ceil(n/1.08)*1.08)==n){
		cout<<ceil(n/1.08);
	}
	else{
		if(floor(floor(n/1.08)*1.08)==n){
			cout<<floor(n/1.08);
		}
		else{
			cout<<":(";
		}
	}
	
}



Measured memory_bytes: 3720
import math

n,d = map(int,input().split())
x_lst = []
for _ in range(n):
	x_lst.append(list(map(int,input().split())))

cnt=0
for i in range(n):
	for j in range(i+1,n):
		val = 0
		for y,z in zip(x_lst[i],x_lst[j]):
			val += (y-z)**2
		
		a = math.sqrt(val)
		if a == int(a):
			cnt+=1
print(cnt)



Measured memory_bytes: 38384
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let n = scan::<i32>();
    println!("{}", n*(n+1)/2);
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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


int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  res += v[0] / 2;
  v[0] %= 2;

  for (int i = 1; i < n; i++) {
    if(v[i] >= 1 && v[i-1] % 2 == 1){
      res++;
      v[i]--;
    }
    res += v[i] / 2;
    v[i] %= 2;
    // print(v);
  }

  cout << res << endl;
}


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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    char c[100];
    int i;
    for (i = 0; i < 100; i++) {
      cin >> c[i];
    }

    vector<int> menber(n);
    int ba = 0;

    for (i = 0; i < 100; i++) {
      menber[i % n]++;
      if (c[i] == 'S') {
        ba += menber[i % n];
        menber[i % n] = 0;
      } else if (c[i] == 'L') {
        menber[i % n] += ba;
        ba = 0;
      }
    }

    sort(menber.begin(), menber.end());
    for (i = 0; i < n; i++) {
      cout << menber[i] << ' ';
    }
    cout << ba << endl;


  }
  return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
    #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 FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 1000000000000000000LL
    #define MOD 1000000007
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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

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


    int main()
    {
        char str[222];
        scanf("%s",str);
        int n=strlen(str);
        for(int i=n-2;i;i-=2)
        {
            if(strncmp(str,str+i/2,i/2) ==0)
            {printf("%d\n",i);
            return 0;}
        }return 0; 
    }//strncmp関数：文字列一致で0を返す

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

int main() {
  char a; cin >> a;
  if ('a' <= a && a <='z')
    cout << 'a' << endl;
  else cout << 'A' << endl;
  return 0;
}

Measured memory_bytes: 3620
import math

a, b, n = map(int, input().split())
maxr = 0
minr = 0
ans = 0
if b < n:
    maxr = b + 1
    minr = abs(b - 1000000) if abs(b - 1000000) < b else 0
else:
    maxr = n + 1
    minr = abs(n - 1000000) if abs(n - 1000000) < n else 0
for i in range(minr, maxr):
    c = math.floor((a * i) / b) - math.floor(i / b) * a
    ans = max(ans, c)
print(ans)


Measured memory_bytes: 9140
#include <iostream>
#include <map>
#include <utility>

int main() {

  using namespace std;
  int N;
  cin >> N;
  multimap<int, int, greater<int>> sorted_map;
  for (int i = 1; i < N + 1; i++) {
    int v;
    cin >> v;
    sorted_map.insert(make_pair(-v, i));
  }

  for (auto const &entry : sorted_map) {
    std::cout << entry.second << ' ';
  }
  return 0;
}


Measured memory_bytes: 5504
/*
 * ----------------------------------------------------------------------------
 (: Bismillahir Rahmanir Rahim :) 
 * File: /root/Programming/Atcoder/A_Circle_Pond.cpp
 * Project: /root/Programming/Atcoder
 * Created Date: Sunday, April 19th 2020, 6:04:13 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sun Apr 19 2020
 * Modified By: Grim Firefly :)
 * -----
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;
typedef set<int> seti;
typedef set<ll> setl;
typedef queue<int> qui;
typedef deque<int> dqui;

//Debug Setting up
#define watch(x) cout << (#x) << " is " << x << endl
#define watchara(wow)  \
    for (auto x : wow) \
    cout << x << " "

//defining something
#define SZ 10000

//main function start

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

    double x;
    scanf("%lf", &x);
    printf("%.20lf\n", 2.0 * x * PI);

    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0;i < N;++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int A = 0, B = 0;
	for (int i = 0;i < a.size();i += 2) {
		A += a[a.size() - 1 - i];
		if (i + 1 < a.size()) {
			B += a[a.size() - 2 - i];
		}
	}
	cout << A - B << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

vector<ll> memo(90, 0);

int main() {
	int n;
	cin >> n;
	memo[0] = 2;
	memo[1] = 1;
	for (int i = 2; i <= n; i++) {
		memo[i] = memo[i - 1] + memo[i - 2];
	}
	cout << memo[n] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int a,b;
    static int sum = 0;

    public static void solve(int currentnum,int currentsum,int currentindex){
        if(currentindex==a){
            if(currentsum==b){
                sum++;
            }
           // System.out.println(currentindex+" "+currentsum);
            return;
        }
        for(int i=currentnum+1;i<=9-a+1+currentindex;i++){
            solve(i,currentsum+i,currentindex+1);

        }
    }

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        while(true){
            a=sc.nextInt();
            b=sc.nextInt();
            if(a==0&&b==0){
                break;
            }
            sum = 0;
            solve(-1,0,0);
           list.add(sum);
        }
        sc.close();
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
}



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

#define ll long long 
#define ull unsigned long long
#define all(c) c.begin(),c.end()
#define pb push_back

const ll INF = 1e9+5;

using namespace std;

int main(){
	int n,k ;
	cin >> n >> k;
	vector<ll>arr(n),dp(n,INF);
	for(int i = 0 ; i < n ; ++i )
		cin >> arr[i];
	dp[0]=0;
	for(int i = 0 ; i < n ; ++i ){
		for(int j = 1 ; j <= k ; ++j ){
			if(i+j<n){
				dp[i+j] = min(dp[i+j],dp[i] + abs(arr[i]-arr[i+j]));
			}
		}
	}	cout << dp.back() << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
bool f(int n) {
	int a[5];
	for (int i = 0; i < 5; i++) {
		a[i] = n % 10;
		n /= 10;
	}
	return (a[0] == a[4] && a[1] == a[3]);
}
int main() {
	int a, b; cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) if (f(i))ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    vi l(n, -1), r(n, -1);
    forn(i, n){
        if (i > 0) l[i] = i - 1;
        if (i + 1 < n) r[i] = i + 1;
    }
    int ans = n;
    queue<int> q;
    forn(i, n - 1){
        if (s[i] == 'S' && s[i + 1] == 'T') q.push(i);
    }
    while (!q.empty()){
        int i = q.front();
        q.pop();
        ans -= 2;
        int j = r[i], i1 = l[i], j1 = r[j];
        if (i1 == -1 || j1 == -1) continue;
        r[i1] = j1;
        l[j1] = i1;
        if (s[i1] == 'S' && s[j1] == 'T') q.push(i1);
    }
    cout << ans << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 5156
W, H, N = [int(x) for x in input().split()]
A = [[0] * (W) for i in range(H)]

for i in range(N):
    x_i, y_i, a_i = [int(x) for x in input().split()]
    for y in range(H):
        for x in range(W):
            if a_i == 1:
                if x <  x_i: A[y][x] = 1
            elif a_i == 2:
                if x >= x_i: A[y][x] = 1
            elif a_i == 3:
                if y <  y_i: A[y][x] = 1
            else:
                if y >= y_i: A[y][x] = 1
cnt = 0
for y in range(H):
    for x in range(W):
        if A[y][x] == 0: cnt += 1

print(cnt)


Measured memory_bytes: 3064
#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,d;
  cin >> n >> d;
  vector<vector<int>> vec(n);
  rep(i,n){
    rep(j,d){
      int s;
      cin >> s;
      vec[i].push_back(s);
    }
  }

  int ans=0;
  rep(i,n-1){
    for(int j =i+1; j < n; j++){
      float s=0;
      rep(k,d){
        s += (vec[i][k]-vec[j][k])*(vec[i][k]-vec[j][k]);
      }
      s = sqrt(s);
      //cout << s << endl;
      if(ceil(s) == floor(s)){
        ans++;
        //cout << ans << endl;
      }
      //else{
        //cout << ans << endl;
      //}
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H;
  int W;

  //HWを受け取る
  cin >> H;
  cin >> W;

  //入力された文字列を配列で受け取る(H個)
  vector<string> vec(H);
  for (int i =0; i < H; i++){
      cin >> vec.at(i);
  }

  //#をWの数+2でfor出力する
  for (int i = 0; i < W + 1; i++ ){
      cout << "#";
  }
  cout << "#" << endl;

  //配列をHの数だけfor出力する
  //頭と終わりに#をつける
   for (int i = 0; i < vec.size(); i++) {
      cout << "#";
      cout << vec.at(i);
      cout << "#" << endl;
 }
    for (int i = 0; i < W + 1; i++ ){
      cout << "#";
  }
  cout << "#" << endl;

  
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int x, y;
    cin >> x >> y;

    int ans = 0;

    if(x == 1) {
        ans += 3;
    }
    else if(x == 2) {
        ans += 2;
    }
    else if(x == 3) {
        ans++;
    }

    if(y == 1) {
        ans += 3;
    }
    else if(y == 2) {
        ans += 2;
    }
    else if(y == 3) {
        ans++;
    }

    if(x == 1 && y == 1) {
        ans += 4;
    }

    ans *= 100000;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
ll r, c;
int n, cnt1, cnt2;
struct Seg
{
	ll x1, y1, x2, y2;
}a[maxn];
#define mp(a, b) make_pair(a, b)
typedef pair<ll, int> pli;
vector<pli> b;
vector<Seg> f;
void no() { puts("NO"); exit(0);}
Seg rev(Seg ret)
{
	swap(ret.x1, ret.x2);
	swap(ret.y1, ret.y2);
	return ret;
}
void rot()
{
	swap(r, c);
	for(int i = 1; i <= n; ++i)
	{
		swap(a[i].x1, a[i].y1);
		swap(a[i].x2, a[i].y2);
		a[i].x1 = r - a[i].x1;
		a[i].x2 = r - a[i].x2;
	}
}
bool cmp(const Seg & i, const Seg & j) { return i.y1 < j.y1;}
bool check(const Seg & i, const Seg & j)
{
	if(i.y2 != j.y2) return i.y2 < j.y2;
	if(i.y2 == 0) return i.x2 < j.x2;
	else
	{
		assert(i.y2 == c);
		return i.x2 > j.x2;
	}
}
void solve()
{
	if(b.empty()) return;
	stack<int> s;
	sort(b.begin(), b.end()); 
	for(auto v : b)
	{
		if(v.second > 0) s.push(v.second);
		else if(v.second < 0)
		{
			if(s.top() + v.second != 0) no();
			s.pop();
		}
		else if(!s.empty()) no();
	}	
	if(f.empty()) return;
	sort(f.begin(), f.end(), cmp);
	for(int i = 1; i < f.size(); ++i)
		if(!check(f[i - 1], f[i]))
			no();
} 
int main()
{
	cin >> r >> c >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
		if(abs(a[i].x1 - a[i].x2) == r) ++cnt1;
		else if(abs(a[i].y1 - a[i].y2) == c) ++cnt2;
	}
	if(cnt1 && cnt2) no();
	for(int k = 0; k < 4; ++k, rot())
	{
		b.clear();
		f.clear();
		for(int i = 1; i <= n; ++i)
		{
			if(a[i].x1 == 0 && a[i].x2 == 0)
			{
				if(a[i].y1 < a[i].y2)
				{
					b.emplace_back(a[i].y1, i);
					b.emplace_back(a[i].y2, -i);
				}
				else
				{
					b.emplace_back(a[i].y2, i);
					b.emplace_back(a[i].y1, -i);
				}
			}
			else if(a[i].x1 == 0)
			{
				if(a[i].x2 == r || a[i].y2 == 0 || a[i].y2 == c)
				{
					b.emplace_back(a[i].y1, 0);
					f.push_back(a[i]);
				}
			}
			else if(a[i].x2 == 0)
			{
				if(a[i].x1 == r || a[i].y1 == 0 || a[i].y1 == c)
				{
					b.emplace_back(a[i].y2, 0);
					f.push_back(rev(a[i]));
				}
			}
		}
		solve();
	}
	puts("YES");
	return 0;
}
/*
2 2 2
0 0 2 2
0 1 2 0
*/

Measured memory_bytes: 9748
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]
    print(len(set(S)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 36600
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <set>
#define LL long long
#define mp make_pair
#define x first
#define y second

using namespace std;

const int maxn=1010;
const int maxm=5010;
const int oo=1000000000;
const int modulo=1000000007;

int n;
int p[maxn], l[maxn], r[maxn];
vector<int> adj[maxn];
int f[maxm];

void input(){
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        scanf("%d", &p[i]);
        adj[p[i]]. push_back(i);
    }
    for (int i = 1; i <= n; i++) scanf("%d", &l[i]);
}

void init(){

}

bool dfs(int x){
    int sum = 0, sumn = 0;
    for (int i = 0; i < adj[x].size(); i++){
        if (!dfs(adj[x][i])) return false;
        sumn += min(l[adj[x][i]], r[adj[x][i]]);
        sum += l[adj[x][i]] + r[adj[x][i]];
    }
    if (sumn > l[x]) return false;
    for (int i = 0; i <= l[x]; i++) f[i] = 0;
    f[sumn] = 1;
    for (int i = 0; i < adj[x].size(); i++)
        for (int j = l[x]; j >= 0; j--)
            if (f[j] == 1 && j + abs(l[adj[x][i]] - r[adj[x][i]]) <= l[x])
                f[j + abs(l[adj[x][i]] - r[adj[x][i]])] = 1;
    int i = l[x];
    while (f[i] == 0) i--;
    r[x] = sum - i;
    return true;
}

void solve(){
    if (dfs(1)) cout << "POSSIBLE"; else cout << "IMPOSSIBLE";
}

void output(){

}

int main(){
//	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
	std::ios::sync_with_stdio(false);
	input();
	init();
	solve();
	output();

	return(0);
}


Measured memory_bytes: 384
n, m = gets.split.map &:to_i

drink = {}

pay = 0

a = []
b = []

n.times {
	a_t, b_t = gets.split.map &:to_i
	a << a_t
	b << b_t
}

index = (0...n).to_a.sort{ |p, q| a[p] <=> a[q] }

index.each{ |i|
	if b[i] >= m then
		pay += a[i] * m
		break
	else
		m -= b[i]
		pay += a[i] * b[i]
	end
}

puts pay

Measured memory_bytes: 5764
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll a[10][10];
    rep(i,3)rep(j,3) cin>>a[i][j];
    ll n;
    cin>>n;
    ll b[100];
    rep(i,n) cin>>b[i];
    ll c[10][10];
    rep(i,3)rep(j,3) c[i][j]=0;
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(a[j][k]==b[i]) c[j][k]=1;
            }
        }
    }
    bool ok=false;
    rep(i,3){
        if(c[i][0]==1&&c[i][1]==1&&c[i][2]==1) ok=true;
        if(c[0][i]==1&&c[1][i]==1&&c[2][i]==1) ok=true;
    }
    if(c[0][0]==1&&c[1][1]==1&&c[2][2]==1) ok=true;
    if(c[0][2]==1&&c[1][1]==1&&c[2][0]==1) ok=true;
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
	std::string str;
	std::cin >> str;
	int y,m,d;
	std::string tmpy = "";
	std::string tmpm = "";
	std::string tmpd = "";
	for (int i=0;i<str.length();i++){
		//std::cout << str[i] << std::endl;
		if (i<4){
			tmpy = tmpy+str[i];
		}else if (5 <= i && i <= 6 ){
			tmpm = tmpm+str[i];
		}else if(i >=8){
			tmpd = tmpd+str[i];
		}
	}
	y = std::atoi(tmpy.c_str());
	m = std::atoi(tmpm.c_str());
	d = std::atoi(tmpd.c_str());
	//std::cout << y << "  " << m << "  " << d << std::endl;
	if(y>2019){
		std::cout << "TBD";
	}else{
		if(y==2019){
			if(m>=5){
				std::cout << "TBD";
			}else{
				std::cout << "Heisei";
			}
		}else{
			std::cout << "Heisei";
		}
	}
	return 0;
}

Measured memory_bytes: 256
import math
def lcm(a,b):
  return (a*b)//math.gcd(a,b)
def co(num):
  return format(num, 'b')[::-1].find('1')
N,M=map(int,input().split())
L=list(map(int,input().split()))
L2=[co(i) for i in L]
if len(set(L2))!=1:
  print(0)
  exit()
L=[i//2 for i in L]
s=L[0]
for i in range(N):
  s=lcm(s,L[i])
c=M//s
print((c+1)//2)

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

int main(){
    while(1){
        int d,w,h;
        cin >> d >> w >> h;
        if(d==0) break;

        int diag = min(d*d +w*w, min(w*w +h*h, h*h +d*d));
        int n;
        cin >> n;
        for(int i=0; i<n; i++){
            int r;
            cin >> r;
            if(diag < 4*r*r){
                cout << "OK" << endl;
            }else{
                cout << "NA" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  char c;
  while(cin>>n&&n){
    vector<int> card(n+1,0);
    for(int i=0;i<100;++i){
      cin>>c;
      switch(c){
      case 'M':
        ++card[i%n];
        break;
      case 'S':
	card[n]=card[n]+card[i%n]+1;
	card[i%n]=0;
	break;
      case 'L':
	card[i%n]=card[i%n]+card[n]+1;
	card[n]=0;
      }
    }
    sort(card.begin(),card.end()-1);
    for(int i=0;i<n+1;++i){
      if(i) cout<<" ";
      cout<<card[i];
    }
    cout<<endl;
  }	   
  return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    t = t.substr(0, s.size());
    if (s == t) cout << "Yes";
    else cout << "No" << '\n';
    return 0;
}

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

int main() {
    vector<bool> b(10);
    for (int i = 0; i < 4; i++) {
        int a;
        cin >> a;
        b.at(a) = true;
    }    
    cout << (b[1] && b[9] && b[7] && b[4] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val ign, str = sc.next()
  val sb = new StringBuilder

  val (l, r, cnt) = Range(0, str.length)
    .map(str.charAt)
    .foldLeft((0, 0, 0)) {
      case ((l, r, cnt), c) =>
        (c, cnt) match {
          case ('(', _) =>
            (l + 1, r, cnt + 1)
          case (')', 0) =>
            (l, r + 1, cnt)
          case (')', _) =>
            (l - 1, r, cnt - 1)
        }
    }

  val ans = Stream.concat(Range(0, r).map(_ => '('), str.toStream, Range(0, l).map(_ => ')'))
    .foreach(sb.append)
  println(sb.toString())
}


Measured memory_bytes: 25544
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    string s; cin >> s;
    int Q; cin >> Q;
    int cnt = 0;
    deque<string>str;
    str.push_back(s);
    for(int k = 0; k < Q; ++k){
        int query;  cin >> query;
        if(query == 1){
            ++cnt;
        } else {
            int f; cin >> f;
            string s_; cin >> s_;
            if(f == 1){
                if(cnt % 2 == 0)str.push_front(s_);
                else str.push_back(s_);
            } else {
                if(cnt % 2)str.push_front(s_);
                else str.push_back(s_);
            }
        }
    }
    string ans = accumulate(str.begin(), str.end(), ""s,[](string res,string t){return res += t;});
    if(cnt % 2)reverse(ans.begin(),ans.end());
    cout << ans  << endl;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n;
    cin >> n;
    int64 sum = 0;
    vector<int64> a(n);
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    int64 sum2 = 0;
    int64 ans = LLINF;
    REP(i,n-1){
        sum2 += a[i];
        ans = min(ans, abs(sum - 2 * sum2));
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1792