akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
static const int INF = 99999999;
struct SEdge
{
	int To;
	int Cost;
	int Time;
};
int V, E;
vector<int> d;
vector< vector<SEdge> > G;

void Dijkstra_Cost(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		int v = p.second;
		if(d[v] < p.first)
		{
			continue;
		}
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Cost)
			{
				d[e.To] = d[v] + e.Cost;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void Dijkstra_Time(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > PQue;
	PQue.push(P(0, s));
	while(!PQue.empty())
	{
		P p = PQue.top();
		PQue.pop();
		int v = p.second;
		if(d[v] < p.first)
		{
			continue;
		}
		for(int i = 0; i < G[v].size(); ++i)
		{
			SEdge e = G[v][i];
			if(d[e.To] > d[v] + e.Time)
			{
				d[e.To] = d[v] + e.Time;
				PQue.push(P(d[e.To], e.To));
			}
		}
	}
}

void solve()
{
	while(cin >> E >> V, E || V)
	{
		d.clear();
		d.resize(V);
		for(int i = 0; i < G.size(); ++i)
		{
			G[i].clear();
		}
		G.clear();
		G.resize(V);
		for(int i = 0; i < E; ++i)
		{
			int From, To, Cost, Time;
			cin >> From >> To >> Cost >> Time;
			--From;
			--To;
			SEdge e1, e2;
			e1.To = To;
			e2.To = From;
			e1.Cost = e2.Cost = Cost;
			e1.Time = e2.Time = Time;
			G[From].push_back(e1);
			G[To].push_back(e2);
		}
		int n;
		cin >> n;
		for(int i = 0; i < n; ++i)
		{
			int p, q, r;
			cin >> p >> q >> r;
			--p;
			--q;
			if(r == 0)
			{
				Dijkstra_Cost(p);
			}
			else
			{
				Dijkstra_Time(p);
			}
			cout << d[q] << endl;
		}
	}
}

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

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

#define CMAX 26

void solve()
{
  ll D; cin >> D;
  vector<ll> c(CMAX + 1); rep1(i, CMAX) cin >> c[i];
  vector<vector<ll>> s(D + 1, vector<ll>(CMAX + 1));
  rep1(i, D) rep1(j, CMAX) cin >> s[i][j];

  vector<ll> t(D + 1); rep1(i, D) {cin >> t[i];}
  vector<ll> last(CMAX + 1, 0);
  /*  rep1(i, CMAX) last[i] = 0;
    rep1(i, CMAX) {
      cerr << last[i] << " ";
    } cout << endl;
  */
  ll sat = 0;
  ll dis;
  for(ll day = 1; day <= D; day++) {
    //cerr << day << ":\n";
    sat += s[day][t[day]];
    //cerr << "sat:" << sat << endl;
    last[t[day]] = day;
    /*rep1(i, CMAX) {
      cerr << last[i] << " ";
    } cout << endl;
    */
    dis = 0;
    rep1(i, CMAX) {
      dis += c[i] * (day - last[i]);
    }
    //cerr << "dis:" << dis << "\n";
    
    sat -= dis;

    cout << sat << endl;
  }

  
  
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9 + 7;

int main(){
	int k;
	ll sum = 0;
	cin>>k;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				sum += __gcd(__gcd(i, j), l);
			}
		}
	}
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;

int main(void) {
	int S, L;
	string N;
	int ans;
	bool flag = false;

	while(1) {
flag=false;
		cin >> N;
		if(N[0] == N[1] && N[1] == N[2] && N[2] == N[3]) {
			flag = true;
			if(N[0] == '0')
				break;
		}

		if(!flag) {
			for(ans = 0; atoi(N.c_str()) != 6174; ans++) {
				sort(N.begin(), N.end());
				S = atoi(N.c_str());
				sort(N.begin(), N.end(), greater<int>());
				L = atoi(N.c_str());
				int tmp = L - S;

				for(int i = 1000, j = 0; i; i /= 10, j++) {
					N[j] = tmp / i + '0';
					tmp %= i;
				}
			}
		}

		if(flag)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
     Scanner sc = new Scanner(System.in);
     int n = 0;
     int k = 0;
     if(sc.hasNextInt())
            n = sc.nextInt();
            k = sc.nextInt();
        int[] dp = new int[n];
     for(int i = 0 ; i < n ; i++)
     {
         dp[i] = sc.nextInt();
     }
     int[] x = new int[n];
     Arrays.fill(x,Integer.MAX_VALUE);
     x[0] = 0;
     for(int i = 0 ; i < n ; i++)
     {
         for(int j = i+1 ; j <= i+k ; j++)
         {
             if(j < n)
             {
                 x[j] = Math.min(x[j] , x[i]+Math.abs(dp[i]- dp[j]));
             }
         }
     }
     System.out.println(x[n-1]);


    }
}


Measured memory_bytes: 51804
ds = [0]
tmp = 0
for c in input():
  tmp += [-1, 1][c == 'A']
  ds.append(tmp)

dt = [0]
tmp = 0
for c in input():
  tmp += [-1, 1][c == 'A']
  dt.append(tmp)

q = int(input())
for i in range(q):
  a, b, c, d = map(int, input().split())
  if abs((ds[b] - ds[a-1]) - (dt[d] - dt[c-1])) % 3 == 0:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 11396
import bisect
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
bka=[0]*N
bkb=[0]*M
bka[0]=A[0]
bkb[0]=B[0]

for i in range(1,N):
    bka[i]+=bka[i-1]+A[i]
for j in range(1,M):
    bkb[j]+=bkb[j-1]+B[j]
ans=0
c=bisect.bisect_left(bkb,K)
if c != M:
    if bkb[c] == K:
        c +=+ 1
ans = max(ans, c)
for i in range(N):
    count=i+1
    k=K-bka[i]
    if k<0:continue
    c = bisect.bisect_left(bkb,k)
    b=c
    if c!=M:
        if bkb[c]==k:
            c+=count+1
        else:c+=count
    else:c+=count
    ans=max(ans,c)
print(ans)

Measured memory_bytes: 48976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,n) for(int i = (a); i < (n); ++i)
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vp(v,N) for(int i=0;i<N;i++) { cout << v[i].first << " " << v[i].second << endl; } cout << endl;
using namespace std;
typedef long long ll;

void Main()
{
	int N, M; cin >> N >> M;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	sort(A.begin(), A.end());
	// debug_v(A,N)
	vector<pair<int, int>> CB;
	rep(i,M) {
		int b, c; cin >> b >> c;
		CB.push_back(make_pair(c, b));
	}
	sort(CB.begin(), CB.end(), greater<pair<int,int>>());
	// debug_vp(CB,M)
	int cur = 0;
	ll res = 0;
	rep(i,M) {
		int less_cnt = upper_bound(A.begin(), A.end(), CB[i].first) - A.begin() - cur;
		int can_cnt = min(less_cnt, CB[i].second);
		if (can_cnt < 0) continue;
		cur += can_cnt;
		res += (ll)CB[i].first * (ll)can_cnt;
		// cout << less_cnt << " " << " " << can_cnt << endl;
		// cout << upper_bound(A.begin(), A.end(), CB[i].first) - A.begin() << endl;
	}
	REP(i,cur,N) {
		res += (ll)A[i];
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

N=int(input())
H=list(map(int,input().split()))
A=list(map(int,input().split()))


#Segment tree（区間の最大値を求めるバージョン）
for i in range(30):#要素数以上の2のベキを見つける
    if N<=2**i:
        seg_el=2**i#Segment treeの台の要素数
        break

SEG=[0]*(2*seg_el-1)#Segment treeを一次元リストとして作る

def update(n,x,seg_el):#A[n]=xに更新（反映）
    i=n+seg_el-1
    while i>=0:
        SEG[i]=max(x,SEG[i])
        i=(i-1)//2

def getvalues(a,b,k,l,r):#区間[a,b)での,SEG[k],つまり区間[l,r)に関する最大値を調べる
    if r<=a or b<=l:#区間[a,b)が対象区間の外にあれば,infを出力
        return -float("inf")
    if a<=l and r<=b:#区間[a,b)が対象区間の中にあればSEG[k]を出力
        return SEG[k]
    vl=getvalues(a,b,k*2+1,l,(l+r)//2)#それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け（木の子ノード二つを見る）
    vr=getvalues(a,b,k*2+2,(l+r)//2,r)
    return max(vl,vr)

for i in range(N):
    h,a=H[i],A[i]
    x=getvalues(0,h,0,0,seg_el)
    update(h-1,x+a,seg_el)

print(getvalues(0,N,0,0,seg_el))

Measured memory_bytes: 121168
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	ll a, b, x;
	cin >> a >> b >> x;
	cout << (a ? b / x - (a - 1) / x : b / x + 1) << '\n';
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll sum0[300001][80],sum1[300001][80];


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

    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    //各位ごと右から累積和しておく
    
    for(int bit=0;bit<61;bit++){
        for(int i=n-1;i>=0;i--){
            if((a[i]>>bit)&1){
                sum1[i][bit]=sum1[i+1][bit]+1;
                sum0[i][bit]=sum0[i+1][bit];
            }else{
                sum0[i][bit]=sum0[i+1][bit]+1;
                sum1[i][bit]=sum1[i+1][bit];
            }
        }
    }
    ll ans=0,num=1;
    for(int bit=0;bit<61;bit++){
        rep(i,n){
            if((a[i]>>bit)&1){
                ans=(ans+(sum0[i+1][bit]* (num%mod)  )%mod)%mod;
            }else{
                ans=(ans+(sum1[i+1][bit]* (num%mod)  )%mod)%mod;
            }
        }
        num=(num*2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 377600
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include<sstream>
#include <vector>
#include <set>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
const int N = 2e5 + 5;

 
  
 
int32_t  main() {

	IOS;
  
	int n;

	cin >> n; 

	vector<int> v(1000001); 
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;

		v[tmp]++; 
	} 

	vector<int> vis(1000001,0);
	int ans = 0;
	for (int i = 1; i <=1000000; i++) {

		if (v[i] == 0 || vis[i] == 1)
			continue;
		
		if (v[i] == 1 && !vis[i])
			ans++;

		for (int j = i; j <= 1000000; j += i) {
			vis[j]=1;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 18424
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int x, y;
    cin>>x>>y;

    int f = 0;
    if(y >= (2*x) && ((y - (2*x)) % 2 == 0))
    {
        int b = (y - (2*x)) / 2;
        if(x >= b) f = 1;
    }

    if(f) cout<<"Yes\n";
    else cout<<"No\n";

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    // sort(L.begin(), L.end());
    // L.erase(unique(L.begin(), L.end()), L.end());
    int size = L.size();
    for(int i = 0; i < size-2; i++) {
        for(int j = i+1; j < size - 1; j++) {
            for(int k = j+1; k < size; k++) {
                if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i] && L[i] + L[j] > L[k] && L[j] + L[k] > L[i] &&
                   L[k] + L[i] > L[j]) {
                    count++;
                }
            }
        }
            
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  int64_t k, a, b;
  cin >> k >> a >> b;
  
  if (b-a <= 2) cout << k + 1 << endl;
  else {
    if (k - (a-1) <= 1) cout << k + 1 << endl;
    else {
      k -= (a-1);
      if (k % 2 == 0) cout << k/2*(b-a) + a << endl;
      else cout << k/2*(b-a) + (a+1) << endl;
    }
  } 
}


Measured memory_bytes: 3596
n = int(input())
buttons = [int(input()) for _ in range(n)]
pushed = [False] * n
b = 0
ans = 0
while True:
    ans += 1
    pushed[b] = True
    b = buttons[b] - 1
    if pushed[b]:
        ans = -1
        break
    if b == 1:
        break
        
print(ans)


Measured memory_bytes: 7888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long n = sc.nextLong();
		long m = sc.nextLong();
		long sum;
		if (m - n * 2 > 0) {
			sum = n;
			sum += (m - n * 2) / 4;
		} else {
			sum = m / 2;
		}
		System.out.println(sum);
	}
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int max = 0;
    vector<int> l(n);
    for(int i = 0;i < n;i++)cin >> l.at(i);
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    for(int i = 0;i < k;i++)max+= l.at(i);
    cout << max << endl;
}

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

int p[800];
int d[800];
int n;
int am1[800][800];

typedef struct{
  int hate;
  int cost;
} hoge_t;

hoge_t maxlength(int l){
  hoge_t tmphoge; tmphoge.hate = l; tmphoge.cost = 0;
  hoge_t tmpmax;  tmpmax.hate = l;  tmpmax.cost = 0;

  for(int i = 0 ; i < n ; i++){
    if(am1[l][i] > 0){
      int t = am1[l][i];
      am1[l][i] = 0;
      am1[i][l] = 0;

      tmphoge = maxlength(i);

      if(tmphoge.cost + t > tmpmax.cost){
        tmpmax.cost = tmphoge.cost + t;
        tmpmax.hate = tmphoge.hate;
      }

      am1[l][i] = t;
      am1[i][l] = t;
    }
  }
  return tmpmax;
}

int main(void){
  cin >> n;
  int leafcost[800];
  int num[800];

  while(n != 0){
//    p[0] = -500;

    for(int i = 0 ; i < 800 ; i++){
      for(int j = 0 ; j < 800 ; j++){
        am1[i][j] = 0;
      }
      leafcost[i] = 0;
    }

    for(int i = 1 ; i < n ; i++){
      cin >> p[i];
      p[i]--;
    }

    for(int i = 1 ; i < n ; i++){
      cin >> d[i];
    }

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        am1[i][j] = 0;
      }
      num[i] = 0;
    }


    for(int i = 1 ; i < n ; i++){
      am1[i][p[i]] = d[i];
      am1[p[i]][i] = d[i];
      num[i]++;
      num[p[i]]++;
      leafcost[i] += d[i];
      leafcost[p[i]] += d[i];
    }

    /* ?????????????????? */
    int leafcosts = 0;
    for(int i = 0 ; i < n ; i++){
//      cout << "num[" << i << "] = " << num[i] << "\n";
      if(num[i] == 1){
        for(int j = 0 ; j < n ; j++){
          if(am1[i][j] != 0){
            am1[i][j] = 0;
            am1[j][i] = 0;
            leafcosts += leafcost[i];
//            cout << "leafcost[" << i << "] += " << leafcost[i] << "\n";
          }
        }
      }
    }



    /* total cost of non-leaf */
    int sum = 0;
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        sum += am1[i][j];
      }
    }

    int ptr = 0;
    while(num[ptr] <= 1){ptr++;}

/*
    cout << "ptr: " << ptr << "\n";
*/
    hoge_t fst = maxlength(ptr);
    hoge_t snd = maxlength(fst.hate);

/*
    cout << "leafcosts:" << leafcosts << "\n";
    cout << "sum      :" << sum       << "\n";
    cout << "fst.cost :" << fst.cost  << "\n";
    cout << "fst.hate :" << fst.hate  << "\n";
    cout << "snd.cost :" << snd.cost  << "\n";
    cout << "snd.hate :" << snd.hate  << "\n";
*/
    cout << leafcosts + (3 * sum)/2 - snd.cost << "\n";
    cin >> n;
  }
}

Measured memory_bytes: 5604
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
typedef struct _data
{
    int node;
    int weight;
}Data;
vector<Data> vec[100005];
int N, M, chk[100005], dist[100005], result;

void BFS()
{
    queue<Data> q;
    for(int j = 1; j <= N; j++)
    {
        if(chk[j] == 0)
        {
            chk[j] = 1;
            q.push({j, 0});
        }
        while(!q.empty())
        {
            Data temp;
            temp = q.front();
            q.pop();
            for(int i = 0; i < vec[temp.node].size(); i++)
            {
                Data next;
                next.node = vec[temp.node][i].node;
                next.weight = temp.weight + vec[temp.node][i].weight;
                if(chk[next.node] == 0)
                {
                    chk[next.node] = 1;
                    dist[next.node] = next.weight;
                    q.push(next);
                }
                else
                {
                    if(dist[next.node] != next.weight)
                    {
                        result = 1;
                        return;
                    }
                }
            }
        }
    }
}

int main()
{
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; i++)
    {
        int l, r, d;
        scanf("%d %d %d", &l, &r, &d);
        vec[l].push_back({r, d});
        vec[r].push_back({l, -d});
    }
    BFS();
    for(int i = 1; i <= N; i++)
    {
        if(chk[i] == 0)
        {
            result = 1;
            break;
        }
    }
    result == 0 ? printf("Yes") : printf("No");
}

Measured memory_bytes: 9984
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
using namespace std;


int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(b, a));
    }

    sort(v.begin(), v.end());
    
    int cnt = 0;
    int max = 0;
    for(int i = 0; i < M; i++){
        if(v[i].second > max){
            max = v[i].first-1;
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1400
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main{
    static IntStream REPS(int v){return IntStream.range(0,v);}
    static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
    static IntStream INS(int n) {return REPS(n).map(i->getInt());}
    static Scanner s=new Scanner(System.in);
    static int getInt(){return Integer.parseInt(s.next());}
    public static void main(String[]$){
        int[]a=new int[114];
        ++a[getInt()];
        --a[getInt()];
        ++a[getInt()];
        --a[getInt()];
        Arrays.parallelPrefix(a,Integer::sum);
        System.out.println(Arrays.stream(a).filter(i->i==2).count());
    }
}

Measured memory_bytes: 29012
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int mes[16][16];
int N;

int func(int b)
{
	queue<int> q;
	int t[16];
	rep(i, 0, N)
	{
		if ((b >> i) & 1)
		{
			q.push(i);
			t[i] = 1;
		}
		else
		{
			t[i] = -1;
		}
	}
	while (!q.empty())
	{
		int p = q.front();
		q.pop();
		rep(i, 0, N)
		{
			if (mes[p][i] == -1)continue;
			if (t[i] != -1)
			{
				if (mes[p][i] != t[i])
				{
					return 0;
				}
			}
			else
			{
				t[i] = mes[p][i];
				if (mes[p][i] == 1)
				{
					q.push(i);
				}
			}
		}
	}

	int res = 0;
	rep(i, 0, N)
	{
		if (t[i] == 1)res++;
	}
	return res;
}

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

	int A;
	cin >> N;
	rep(i, 0, N)
	{
		rep(j, 0, N)mes[i][j] = -1;
		cin >> A;
		int x, y;
		rep(j, 0, A)
		{
			cin >> x >> y;
			x--;
			mes[i][x] = y;
		}
	}

	int ans = 0;
	rep(i, 0, 1 << N)
	{
		chmax(ans, func(i));
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0; i < n; i++) cin >> p.at(i);
  sort(p.begin(), p.end());
  int s = 0;
  for(int j=0; j < k; j++) s = s + p.at(j);
  cout << s << endl;
}


Measured memory_bytes: 3608
def DICE(dice,dir):
    if dir == "N":
        dice[0],dice[1],dice[4],dice[5] = dice[1],dice[5],dice[0],dice[4]
    elif dir == "S":
        dice[0],dice[1],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[1]
    elif dir == "E":
        dice[0],dice[2],dice[3],dice[5] = dice[3],dice[0],dice[5],dice[2]
    elif dir == "W":
        dice[0],dice[2],dice[3],dice[5] = dice[2],dice[5],dice[0],dice[3]
    return dice

tmp = raw_input().split()
s = raw_input()
for i in s:
    tmp = DICE(tmp, i)
print tmp[0]


Measured memory_bytes: 4676
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

struct node {
	int val;
	node *lt, *rt;
	
	node() { val = 0; lt = rt = NULL; }
	
	void insert(LL l, LL r, LL tar) {
//		printf(">> insert %lld %lld %lld\n", l, r, tar);
		val++;
		if (l == r) return;
		LL mid = l + (r - l) / 2;
		if (tar <= mid) {
			if (lt == NULL) lt = new node();
			lt->insert(l, mid, tar);
		} else {
			if (rt == NULL) rt = new node();
			rt->insert(mid + 1, r, tar);
		}
	}
	
	int query(LL l, LL r, LL tal, LL tar) {
//		printf(">> query %lld %lld %lld %lld\n", l, r, tal, tar);
		if (tal <= l && r <= tar) return val;
		
		LL mid = l + (r - l) / 2, ret = 0;
		
		if (tal <= mid && lt != NULL)
			ret += lt->query(l, mid, tal, tar);
		if (tar > mid && rt != NULL)
			ret += rt->query(mid + 1, r, tal, tar);
		
		return ret;
	}
} root;

int n, k, x, y, z;
LL ans, a[200055];

const LL MX = 1e15;

int main () {
	
	scanf("%d%d", &n, &k);
	
	FOR(i, 0, n) scanf("%lld", a + i);
	
	FOR(i, 0, n) a[i] -= k;
	
	FOR(i, 1, n) a[i] += a[i - 1];
	
	root.insert(-MX, MX, 0);
	
	FOR(i, 0, n) {
		ans += root.query(-MX, MX, -MX, a[i]);
		root.insert(-MX, MX, a[i]);
	}
	
	printf("%lld\n", ans);
	
	return 0;
	
}

Measured memory_bytes: 188288
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,x,mn,hh,la,ans;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		hh=0;
		mn=(int)log2(x);
		if(x!=(1<<mn))hh=1;
		if(la<mn)ans+=mn-la,la=mn;
		 else if(la>mn)la=mn,hh=0;
		if(hh)ans++,la++;
	}
	printf("%d",ans);
}

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

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    x -= a;
    x %= b;
    cout << x << endl;
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
const int MOD = 1000000007;

class UnionFind{
public:
  vector<ll> par; //Ë¶™„ÇíË°®„ÅôÈÖçÂàó
  vector<ll> siz; //ÂêÑÈõÜÂêà„ÅÆ„Çµ„Ç§„Ç∫
  vector<ll> amt; //ÂêÑÈõÜÂêà„ÅÆË¶ÅÁ¥†Êï∞
  UnionFind(ll n): par(n), siz(n, 1LL), amt(n, 1LL){
    for(ll i = 0; i < n; i++) par[i] = i;
  }
  ll root(ll x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }
  bool unite(ll x, ll y){
    x = root(x);
    y = root(y);
    ll x_amt = amt[x];
    ll y_amt = amt[y];
    if(x == y) return false;
    if(siz[x] < siz[y]){
      par[x] = y;
      amt[y] = x_amt + y_amt;
    }else{
      par[y] = x;
      if(siz[x] == siz[y]) siz[x]++;
      amt[x] = x_amt + y_amt;
    }
    return true;
  }
  bool same(ll x, ll y){
    return root(x) == root(y);
  }
  ll amount(ll x){
    return amt[root(x)];
  }
};

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  UnionFind uni(N);
  vector<int> F[N];
  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    F[a].push_back(b);
    F[b].push_back(a);
    uni.unite(a,b);
  }
  vector<int> B[N];
  for(int i = 0; i < K; i++){
    int c,d;
    cin >> c >> d;
    c--; d--;
    B[c].push_back(d);
    B[d].push_back(c);
  }
  for(int i = 0; i < N; i++){
    int tmp = uni.amount(i);
    tmp -= F[i].size();
    for(auto x: B[i]){
      if(uni.root(x) == uni.root(i)){
	tmp--;
      }
    }
    tmp--;
    cout << tmp << " ";
  }
  cout << endl;
    
}


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

int main(){
	
	int n;
	cin >> n;
	
	if(n == 0) return 0;
	
	int a, b, c;
	int s1, s2, s3;
	int s1_prev, s2_prev, s3_prev;
	cin >> a >> b >> c;
	s1 = a;
	s2 = b;
	s3 = c;
	for(int i = 1; i < n; i++)
	{
		s1_prev = s1;
		s2_prev = s2;
		s3_prev = s3;
		
		cin >> a >> b >> c;
		
		s1 = max(s2_prev, s3_prev) + a;
		s2 = max(s1_prev, s3_prev) + b;
		s3 = max(s1_prev, s2_prev) + c;
	}
	cout << max(s1, max(s2, s3));
	return 0;
}


Measured memory_bytes: 3640
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;



#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: isize,
        a: isize,
        b: isize,
    }

    if b - a >= 0 {
    
        let ans = if n != 1 {(b - a) * (n - 2) + 1} else if a == b {1} else {0};
        println!("{}", ans)
    } else {
        println!("0")
    }

    println!("", );
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2200
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<long long,long long> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<long long> sta;   
    //queue<long long> que;


int main(){
	
	long long A,B,C,D,E,F,G,H,I,J,L,N,M,K,O,P,Q,R,S,T,U,V,W,X,Y,Z;
	long long ans;
	ans=0;
	string s;
    long long sum,sum1;
	sum=0;
	sum1=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work,work1,work2,work3,work4;
	work=0;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	//std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
	//std::vector<long long> v(N);
	//std::vector<long long> w(N);
    std::cin >> s;
    
    
    // 配列入力1
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	*/
	// 配列入力2
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
    
	
	//通常
	/*
    for(long long i=0; i<N; i++){
		
	}
	*/
	

	//文字列入力
	
	for(long long i=0; i<s.length()-1; i++){
		
		if(s[i]==s[i+1]){
			flg=1;
		}
	}
	

	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/


	/*
	long long a[4];
	long long value;
	value=0;
	
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
    if(flg==1){
    	//printf("%d",N);
    	//printf("%lld",N);
    	puts("Bad");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	//printf("%.12f\n",ret);
    	//cout << sum << endl;
	}
	else{
		puts("Good");
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split()))

count = [0]*n

for i in range(n):
    a = al[i]
    for _ in range(30):
        if a%2 == 0:
            a = a/2
            count[i] += 1
        else:
            break

print(min(count))


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B; cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
vector<double>a(3005);li n,n1=0,n2=0,n3=0;
double A[305][305][305];
li AA[305][305][305];
double ff(li i1,li i2,li i3){double z=1;
if(i1<0 || i2<0 || i3<0) {z=0;return(z);}
    if(i1==1 && i2==0 && i3==0){z=n;return(z);}
    if(AA[i1][i2][i3]!=-1) return(A[i1][i2][i3]);
z=n;    
double p1=i1,p2=i2,p3=i3,p4=(i1+i2+i3);p1=p1/z;p2=p2/z;p3=p3/z;p4=p4/z;z=1;  
double ans=(z+p1*ff(i1-1,i2,i3)+p2*ff(i1+1,i2-1,i3)+p3*ff(i1,i2+1,i3-1))/p4;
A[i1][i2][i3]=ans;
AA[i1][i2][i3]=1;
return(ans);}
int main(){readl(n);memset(AA,-1,sizeof(AA));li i;
for(i=0;i<n;i++) {cin>>a[i];if(a[i]==1) n1++;
else if(a[i]==2) n2++;
else if(a[i]==3) n3++;}
double ans=ff(n1,n2,n3);
printf("%.10lf",ans);    
}


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



int main (){
    int N;
    cin>>N;
    vector<int> d(N);
    int Sum=0;
    int SumDub=0;
    for(int i=0; i<N; i++){
        cin>>d.at(i);
        Sum += d.at(i);
        SumDub += d.at(i)*d.at(i);
    }
    cout<<(Sum*Sum-SumDub)/2;


}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var NTHL=(Arr.shift()).split(" ").map(Number);
var N=NTHL[0];
var T=NTHL[1];
var H=NTHL[2];
var L=NTHL[3];
var th=[];
for(var i=0;i<N;i++){
   var arr=Arr[i].split(" ").map(Number);
   th.push(arr);
}
var sum=0;
while(true){
   for(var i=0;i<N;i++){
      if(th[i][0]==0 && th[i][1]==0)return console.log(i+1);
      if(th[i][0]==0){sum+=100;th[i][1]--;}
      else{sum+=10;T++;th[i][0]--}
      if(T>L)return console.log(i+1);
      if(sum>=90){
         var ch=sum-90;
         if(T*10<ch)return console.log(i+1);
         th[i][0]+=(ch/10);
         T-=(ch/10);
         sum=0;
      }
   }
}

Measured memory_bytes: 7648
#include<stdio.h>

int main()
{
    int a,b,d,f;
    scanf("%d %d",&a,&b);
    if(a != b){

        if(a>b){
                f=0;
            for(d=1;d<=a;d++){
                if(abs(a-d) == abs(b-d)){
                    f=1;
                    break;
                }
            }
            if(f == 1){
            printf("%d",d);
            }
            else
                printf("IMPOSSIBLE");
        }
        else if(b>a){
            f=0;
            for(d=1;d<=b;d++){
                if(abs(a-d) == abs(b-d)){
                    f=1;
                    break;
                }
            }
            if(f == 1){
            printf("%d",d);
            }
            else
                printf("IMPOSSIBLE");
        }
    }

}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner() * 2
		b[i] = intScanner() * 2
	}
	sort.Ints(a)
	sort.Ints(b)
	am, bm := 0, 0
	if n%2 == 0 {
		am = (a[n/2] + a[n/2-1]) / 2
		bm = (b[n/2] + b[n/2-1]) / 2
	} else {
		am = a[n/2] / 2
		bm = b[n/2] / 2
	}
	fmt.Println(bm - am + 1)
}


Measured memory_bytes: 8352
N = int(input())
A = list(map(int,input().split()))
odd,n4 = 0,0
for i in range(N):
    if A[i]%2 == 1:
        odd += 1
    else:
        if A[i]%4 == 0:
            n4 += 1
if odd+n4==N and odd-n4==1:
    print("Yes")
else:
    print("Yes" if n4 >= odd else "No")


Measured memory_bytes: 14252
n,m = map(int,input().split())

def cmb(n,r):
    if n < 0 or r < 0 or n < r:
        return 0
    elif n == 0 or r == 0:
        return 1
    return cmb(n-1,r-1)+cmb(n-1,r)

print(cmb(n,2) + cmb(m,2))


Measured memory_bytes: 3060
# coding: utf-8
n=int(input())
"""
 N=list(map(int,input().split()))
 N.sort();
 for i in N:
    print(i)
"""
for i in range(100):
    if n-i*7>=0 and (n-i*7)%4==0 : 
        print('Yes') 
        break
    if n-i*7< 0:
       print('No')
       break


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        long min = b;
        long max = a;
        for (int i = 0; i < n-1; i++) {
            min += a;
            max += b;
        }
        long result = max - min + 1;
        if (result < 0){
            System.out.println(0);
        }else {
            System.out.println(result);
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
  if(a>=b&&b>=c){
      cout << c << " " << b << " " << a << endl;
  }
  if(a<b &&b<c){
      cout << a << " " << b << " " << c <<endl;
  }
  if(a<b&&b>=c){
     cout << a << " " << c << " " << b <<endl;
  }
  if(b<=a && a<=c){
     cout << b << " " << a << " " << c <<endl;
}
     if(b<c && c<a){
        cout << b << " " << c << " " << a <<endl; 
     }
     if(c<a && a<b){
         cout << c << " " << a << " " << b <<endl; 
     }
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    rep(i, 0, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int x,y,n,pr[200005];
vector<int>s[200005],deg[3],degp[2];
void dfs(int p,int f,int st)
{
	int v;
	degp[st].push_back(p);
	for(int i=0;i<s[p].size();i++)
	{
		v=s[p][i];
		if(v==f)continue;
		dfs(v,p,!st);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)deg[i%3].push_back(i);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		s[x].push_back(y);
		s[y].push_back(x);
	}
	dfs(1,0,0);
	if(degp[0].size()>degp[1].size())swap(degp[0],degp[1]);
	if(degp[0].size()<=deg[0].size())
	{
		for(int i=0;i<degp[0].size();i++)
		{
			x=degp[0][i];
			pr[x]=deg[0].back();
			deg[0].pop_back();
		}
		for(int i=0;i<degp[1].size();i++)
		{
			x=degp[1][i];
			if(deg[0].size()>0)
			{
				pr[x]=deg[0].back();
			deg[0].pop_back();
			}
			else
			{
				if(deg[1].size()>0)
				{
					pr[x]=deg[1].back();
			deg[1].pop_back();
				}
				else
				{
					pr[x]=deg[2].back();
			deg[2].pop_back();
				}
			}
		}
	}
	else
	{
		if(deg[1].size()<deg[2].size())swap(deg[1],deg[2]);
		for(int i=0;i<degp[0].size();i++)
		{
			x=degp[0][i];
			if(deg[1].size()>0)
			{
			pr[x]=deg[1].back();
			deg[1].pop_back();
			}
			else
			{
					pr[x]=deg[0].back();
			deg[0].pop_back();
			}
		}
		for(int i=0;i<degp[1].size();i++)
		{
			x=degp[1][i];
			if(deg[0].size()>0)
			{
				pr[x]=deg[0].back();
			deg[0].pop_back();
			}
			else
			{
					pr[x]=deg[2].back();
			deg[2].pop_back();
			}
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",pr[i]);
	return 0;	
} 

Measured memory_bytes: 19864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p[] = new int[n];

        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt() - 1;
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (p[i] == i) {
                ans++;
                i++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 49988
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int t=1,q;
	//cin>>t;
	for(q=1;q<=t;q++)
	{
		int n;
		long int W,i,j,w,x;
		long long int sum=0;
		cin>>n>>W;
		vector < pair <long int,long int> > v;   //1 stores values and 2 stores weights
		for(i=0;i<n;i++){cin>>w>>x; sum+=x; v.push_back(make_pair(x,w));}
		long long int a[sum+1]={0};
		for(i=0;i<n;i++)
		{	
			for(j=sum;j>=v[i].first;j--)
			{
				if(a[j-v[i].first]>0||j==v[i].first)
				{
					if(a[j]==0)a[j]=v[i].second+a[j-v[i].first];
					else
					{
						a[j]=min(a[j],v[i].second+a[j-v[i].first]);
					}
				}
			}
		}
		for(i=sum;i>-1;i--){if(a[i]<=W&&a[i]>0)break;}
		cout<<i<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <vector>
#include <tuple>

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<std::tuple<size_t, size_t, intmax_t>> tp;
  while (true) {
    size_t s, t;
    intmax_t e;
    scanf("%zu %zu %jd", &s, &t, &e);
    if (s == 0 && t == 0 && e == 0) break;
    --s;
    --t;
    tp.emplace_back(s, t, e);
  }

  size_t L;
  scanf("%zu", &L);

  for (size_t i = 0; i < L; ++i) {
    std::vector<intmax_t> b(M);
    for (auto& bi: b) scanf("%jd", &bi);

    std::vector<intmax_t> res(N);
    for (auto const& p: tp) {
      size_t s, t;
      intmax_t e;
      std::tie(s, t, e) = p;
      res[s] += b[t] * e;
    }
    for (size_t i = 0; i < N; ++i)
      printf("%jd%c", res[i], i+1<N? ' ':'\n');
  }
}



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

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k){
        cout << ":(";
    }else{
        cout << "Yay!";
    }
    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':

    S = list(input())
    T = list(input())

    len_s = len(S)
    len_t = len(T)

    ans = 0
    tmp = 0
    for i in range(len_s-len_t+1):
        A = S[i:i+len_t]
        for j,k in zip(A,T):
            if j == k:
                tmp+=1
        ans = max(ans,tmp)
        tmp = 0
    print(len_t-ans)

Measured memory_bytes: 9104
#include <iostream>
#include <bitset>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  vector<char> data(s.begin(), s.end());
  long long int ans = 0;
  for (long int i = 0; i < 1<<(s.size()-1); i++) {
    bitset<10> bs(i);
    string temp;
    temp.push_back(s[0]);
    for (int j = 0; j < s.size()-1; j++) {
      if (bs[j]==1) {
        ans += stoll(temp);
        temp = s[j+1];
      }
      else {
        temp.push_back(s[j+1]);
      }
    }
    ans += stoll(temp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256