akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

vector<int> v;
vector<vector<int>> g;

pair<bool, pair<int, int>> dfs(int x, int c) {
    if (v[x] != -1) {
        if (v[x] != c) {
            return {false, {0, 0}};
        } else {
            return {true, {0, 0}};
        }
    }
    v[x] = c;
    pair<bool, pair<int, int>> res = {true, {c == 0, c == 1}};
    for (int y : g[x]) {
        auto p = dfs(y, 1 - c);
        res.first &= p.first;
        res.second.first += p.second.first;
        res.second.second += p.second.second;
    }
    return res;
}

int main() {
    std::ios::sync_with_stdio(false);

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

    g.resize(n);
    v.assign(n, -1);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    long res = 0;

    for (int i = 0; i < n; i++) {
        if (v[i] == -1) {
            auto p = dfs(i, 0);
            if (p.first) {
                res += 1L * p.second.first * p.second.second;
            } else {
                long s = p.second.first + p.second.second;
                res += s * (s - 1) / 2;
            }
        }
    }

    cout << res - m << "\n";

    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
	ll a,b,c;
	
	scanf("%lld%lld%lld",&a,&b,&c);
	
	if(a%2 == 0 || b%2 == 0 || c%2 == 0) printf("0\n");
	else{
		if(a>c) swap(a,c);
		if(b>c) swap(b,c);
		printf("%lld\n",a*b);
	}
	
	return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


const ll INF = (ll)1e15;

ll arr[302][302];


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=n;j++)
    		cin>>arr[i][j];


    ll ans = 0;
    for(int i=1;i<=n;i++)
    	for(int j=i+1;j<=n;j++){
    		bool needed = true;
    		for(int k=1;k<=n;k++){
    			if(k == i || k == j)	continue;
    			if(arr[i][k]+arr[k][j] < arr[i][j]){
    				cout<<"-1";
    				return 0;
    			}
    			if(arr[i][k]+arr[k][j] == arr[i][j]){
    				needed = false;
    			}
    			if(arr[j][k]+arr[k][i] < arr[i][j]){
    				cout<<"-1";
    				return 0;
    			}
    			if(arr[j][k]+arr[k][i] == arr[i][j]){
    				needed = false;
    			}
    		}
    		if(needed)	ans += arr[i][j];
    	}

    cout<<ans;
    return 0;
}







 




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
const int M=1e5+5;
int a[M];
vi v;
int ans;
int mark[M];
int32_t main()
{
	CS;
	int n; cin>>n;
	int t=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(!mark[a[i]]) ans++;
		if(mark[a[i]]>0) t++;
		mark[a[i]]++;
	}
	if(t&1) ans--;
	return cout<<ans<<endl,0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int d = getInt(sc);
		int x = getInt(sc);

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = getInt(sc);
		}

		int chocolate = x;
		for (int i = 0; i < n; i++) {
			int day = 1;
			while (day <= d) {
				chocolate++;
				day += a[i];
			}
		}

		System.out.println(chocolate);

	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll q,h,s,d,n;cin>>q>>h>>s>>d>>n;){
		n*=4;
		ll res=0;
		if(n>=8){
			res+=n/8*min({q*8,h*4,s*2,d});
			n%=8;
		}
		if(n>=4){
			res+=n/4*min({q*4,h*2,s});
			n%=4;
		}
		if(n>=2){
			res+=n/2*min({q*2,h});
			n%=2;
		}
		if(n>=1){
			res+=q;
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 256
/* ファイル名：ITP1_11_A.c	*/
/* 内容：サイコロを転がすシミュレーションを行う	*/
/*		 １行目に各面の整数が、図に示すラベルの順番に空白区切りで与えられる	*/
/*		 ２行目に命令を表す１つの文字列が与えられる							*/
/*		 文字列の文字の意味													*/
/*		 N：前に1つ転がす													*/
/*		 S：後ろに1つ転がす													*/
/*		 W：左に1つ転がす													*/
/*		 E：右に1つ転がす													*/
/*		 すべての命令を実行した後のサイコロの上面の数を１行に出力する		*/

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/


/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:すべての命令を実行した後のサイコロの上面の数を１行に出力する	*/
int main( void )
{
	/* 内部変数定義	*/
	/* 入力・出力	*/
	int dice[6];	/* サイコロの各面の数字	*/
	char com[100];	/* 命令を表す文字列		*/
	
	/* 処理	*/
	int i;			/* ループ用変数			*/
	
	/* サイコロの各面の数字を入力	*/
	for(i = 0; i < 6; i++){
		scanf("%d",&dice[i]);
	}
	
	/* 命令を表す文字列を入力	*/
	scanf("%s",com);
	
	/* サイコロを転がす関数を呼び出す	*/
	dice_roll(dice, com);
	
	/* 結果(サイコロの上の面)を出力	*/
	printf("%d\n",dice[0]);
	
	return 0;
}
/* 関数名:dice_roll	*/
/* 引数：int *d    サイコロのポインタ	*/
/*		 char *c   命令のポインタ		*/
/* 処理内容:サイコロを転がすシミュレーションを行う	*/
void dice_roll(int *d, char *c){
	/* 内部変数定義	*/
	/* 処理	*/
	int i;			/* ループ用変数			*/
	int x;			/* 入れ替え用変数		*/
	
	/*命令を表す文字列の最後までループ	*/
	for(i = 0; c[i] != '\0'; i++){
		switch(c[i]){
			/* 命令を表す文字が'E'の場合	*/
			case 'E':
				/* 右に1つ転がす	*/
				x = d[0];
				d[0] = d[3];
				d[3] = d[5];
				d[5] = d[2];
				d[2] = x;
				break;
			/* 命令を表す文字が'N'の場合	*/
			case 'N':
				/* 前に1つ転がす	*/
				x = d[0];
				d[0] = d[1];
				d[1] = d[5];
				d[5] = d[4];
				d[4] = x;
				break;
			/* 命令を表す文字が'S'の場合	*/
			case 'S':
				/* 後ろに1つ転がす	*/
				x = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = x;
				break;
			/* 命令を表す文字が'W'の場合	*/
			case 'W':
				/* 左に1つ転がす	*/
				x = d[0];
				d[0] = d[2];
				d[2] = d[5];
				d[5] = d[3];
				d[3] = x;
				break;
		}
	}
	
}


Measured memory_bytes: 2112
N,M = map(int,input().split())
D = []
for i in range(N):
    D.append(tuple(map(int, input().split())))
D.sort()

drinks=M
cost = 0
for i in D:
    if drinks > i[1]:
        drinks -= i[1]
        cost += i[1] * i[0]
    else:
        cost += (drinks * i[0])
        break

print(cost)


Measured memory_bytes: 22704
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define Author std::ios_base::sync_with_stdio(0);
#define ABHISHEK_SHARMA cout.tie(0);
#define IIIT_ALLAHABAD cin.tie(0);

int main(){
    //Booster
    Author
        ABHISHEK_SHARMA
        IIIT_ALLAHABAD
    //Driver Code here
    ll n, i, t, k, count=0, j;
    cin>>n;
    for(i=1; i<=3500; i++){
        for(j=1; j<=3500; j++){
            if((4*i*j-n*i-n*j)>0){
                if((n*i*j)%(4*i*j-n*i-n*j)==0){
                k=(n*i*j)/(4*i*j-n*i-n*j);
                cout<<i<<" "<<j<<" "<<k;
                return 0;
                }
            }
        }
    }
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edge(n);
    int s, t;
    for (int i = 0; i < m; i++){
        cin >> s >> t;
        s--; t--;
        edge[s].push_back(t);
    }
    vector<double> dp(n);
    dp[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--){
        double tmp = 0;
        for (int j = 0; j < edge[i].size(); j++) tmp += dp[edge[i][j]];
        dp[i] = tmp / edge[i].size() + 1;
    }
    double ans = dp[0];
    for (int k = n - 2; k >= 0; k--){
        if (edge[k].size() == 1) continue;
        vector<double> n_dp = dp;
        double tmp = 0; double max_num = 0;
        for (int j = 0; j < edge[k].size(); j++){
            tmp += dp[edge[k][j]];
            max_num = max(max_num, dp[edge[k][j]]);
        }
        tmp -= max_num;
        n_dp[k] = tmp / (edge[k].size() - 1) + 1;
        for (int i = k - 1; i >= 0; i--){
            double tmp = 0;
            for (int j = 0; j < edge[i].size(); j++) tmp += n_dp[edge[i][j]];
            n_dp[i] = tmp / edge[i].size() + 1;
        }
        ans = min(ans, n_dp[0]);
    }
    cout << setprecision(15) << ans << endl;
}


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

const int maxn = 105;

int a[maxn], n, m, K;

int main()
{
	#ifdef MPS
		freopen("a.in","r",stdin);
		freopen("a.out","w",stdout);
	#endif
		char a;
		cin >> a;
		cout << (char)(a + 1);
	return 0;
}

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

int main(){
    int n;
    long long x[100000],dp[100000],a,b;
    scanf("%d%lld%lld",&n,&a,&b);
    for(int i=0;i<n;i++){
        scanf("%lld",&x[i]);
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=dp[i-1]+min(a*(x[i]-x[i-1]),b);
    }
    printf("%lld\n",dp[n-1]);
}

Measured memory_bytes: 1664
int main(int argc, const char * argv[]) {
    int i=1,x;
    while(1){
        scanf("%d",&x);
        if(1<=x&&x<=10000){
            if(i<=10000){
                printf("Case %d: %d\n",i,x);
                i++;
            }
        }if(x==0){
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	int n,m,a,b;
	while(cin>>n,n){
		map<int,int> M;
		rep(i,n){
			cin>>m>>a>>b;
			M[a]+=m; M[b]-=m;
		}
		int ans=0,cur=0;
		fr(i,M){
			cur+=i->second;
			ans=max(ans,cur);
		}
		cout<<(ans>150?"NG":"OK")<<endl;
	}
	return 0;
}

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

int gcd(int a, int b)
{
	int r = a % b;
	while(r > 0){
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

int main()
{
	int N,M;
	cin >> N >> M;
	string S, T;
	cin >> S >> T;

	long long L = lcm(N,M);
	int g = gcd(N,M);

	for(int i = 0; i < g; i++){
		if(S[N / g * i] != T[M / g * i]){
			cout << -1 << "\n";
			return 0;
		}
	}

	cout << L << "\n";

	return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	template<typename T> inline int ts(T *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 200007 , mo = 1000000007;

int n,m,s[_];
lint f[_]={0};

int main()
{
	n=ty(),m=ty(),ts(s+1);
	for(int i=m;i>=1;i--)s[i]=s[i]==s[1];

	lint ans=0;
	while(m && s[m])m--;
	if(m<=0)ans=1;
	
	int lim=n;
	for(int l=1,r=1;l<=m;l=r+1)
	{
		while(l<=m && !s[l])l++;
		if(l>m)break;
		r=l;
		while(r<m && s[r+1])r++;
		int len=r-l+1;
		if(l==1)lim=min(lim,len+(1-len%2));
		if(len&1)lim=min(lim,len);
	}

	if(lim>=n)
	{
		f[0]=1;
		for(int i=1,x=0;i<=n;i++)f[i]=x,x=(x+f[i-1])%mo;
		for(int i=2;i<=n;i++)ans=(ans+f[n-i]*i%mo)%mo;
	}
	else
	{
		f[0]=1;
		for(int i=2,x=f[0];i<=n;i+=2)
		{
			f[i]=x,x=(x+f[i])%mo;
			if(i>lim)x=(x-f[i-lim-1]+mo)%mo;	
		}
		for(int i=2;i<=lim+1;i+=2)ans=(ans+f[n-i]*i%mo)%mo;
	}
	printf("%lld\n",ans);

	return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

int N,M,A[25][25],B[25],C;

int main(){
  cin >> N >> M >> C;
  for(int i=0;i<M;i++) cin >> B[i];

  int ans[25],rec=0;
  for(int i=0;i<25;++i) ans[i] = 0;

  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin >> A[i][j];
      ans[i]+=A[i][j]*B[j];
    }
    if(ans[i]+C>0) rec++;
  }
  cout << rec <<endl;
  return 0;
}


Measured memory_bytes: 256
from math import ceil
from collections import deque

N, D, H = map(int, input().split())
Monsters = sorted([list(map(int, input().split())) for i in range(N)])
Monsters = [[x, ceil(h/H)] for x, h in Monsters]

ans = 0
acc = 0
deq = deque([])

for x, h in Monsters:
  while deq and x>deq[0][0]:
    lim, dam = deq.popleft()
    acc -= dam
  c = max(0, h-acc)
  ans += c
  acc += c
  if c:
    deq += [(x+2*D, c)]
    
print(ans)

Measured memory_bytes: 132824
# Problem - 三角形

import math

# input
a, b, C = map(int, input().split())
C_radians = math.radians(C)

# calc
area_S = a * b * math.sin(C_radians) / 2
c = math.sqrt(a*a + b*b - 2*a*b*math.cos(C_radians))
length_L = a + b + c
height_h = 2 * area_S / a

# output
print(area_S)
print(length_L)
print(height_h)



Measured memory_bytes: 5708
N, A, B = map(int,input().split())
 
ans = 0
for i in range(0, N+1):
    tmp=i
    sum=0
    while(tmp>0):
        sum += tmp%10
        tmp = int(tmp/10)

    if A<=sum and sum<=B:
        ans+=i
 
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define sz  200010
using namespace std;


ll num[sz];

int main()
{

    ll n,k,i,j,a,b,x,c=0,d;

    d=1;

    cin>>n;

    while(n>0)
    {
       c+=d;
       n=n/2;
       d=d*2;
    }

    cout<<c<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    int count=0;
    cin>>n>>x;
    int a[100]={};
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(a[i]>x)break;
        if(i==n-1 && a[i]<x)break;
        x-=a[i];
        count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

i64 N, X, D;
vector<i64> cnt, weight;

int main() {
  cin >> N >> X >> D;
  cnt.resize(N, 1);
  weight.resize(N);

  vector<i64> p(N, -1);
  vector<i64> limit(N, D);
  limit[0] = 1e18;
  cin >> weight[0];
  rep(i,1,N) {
    cin >> weight[i] >> p[i];
    p[i]--;
  }

  for(i64 i = N;i --> 1;) {
    cnt[p[i]] += cnt[i];
    weight[p[i]] += weight[i];
  }

  vector<i64> vec(N);
  rep(i,0,N) vec[i] = i;
  sort(all(vec), [&](i64 i, i64 j) { return 1.0 * cnt[i] / weight[i] > 1.0 * cnt[j] / weight[j];  });


  i64 M = 50 * 50 * 50 + 20;
  vector<vector<i64>> dp(N + 1, vector<i64>(M + 1, 1e18));
  vector<vector<i64>> f(N + 1, vector<i64>(M + 1, 0));
  dp[N][0] = 0;

  for(i64 i = N; i --> 0;) {
    for(i64 j = 0; j <= M; j++) {
      for(i64 k = 0;k <= std::min(limit[i], 50ll) && j + cnt[i] * k <= M; k++ ) {
        if(dp[i][j + cnt[i] * k] > dp[i + 1][j] + weight[i] * k) {
          dp[i][j + cnt[i] * k] = std::min(dp[i][j + cnt[i] * k], dp[i + 1][j] + weight[i] * k);
          f[i][j + cnt[i] * k] = k;
        }
      }
    }
  }

  i64 MAX = 0;
  for(i64 j = 0;j <= M;j++) {
    if(dp[0][j] == 1e18) continue;
    if(dp[0][j] > X) continue;
    vector<i64> remain(N);
    i64 now = j;
    for(i64 i = 0;i < N;i++) {
      remain[i] = limit[i] - std::min(limit[i], 50ll);
      now = now - f[i][now] * cnt[i];
    }
    i64 ans = j;
    i64 we = dp[0][j];
    for(auto i: vec) {
      i64 a = (X - we) / weight[i];
      a = std::min(remain[i], a);
      ans = ans + cnt[i] * a;
      we = we + weight[i] * a;
    }
    MAX = std::max(MAX, ans);
  }
  cout << MAX << endl;
}


Measured memory_bytes: 103084
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] h =new int[N];
   for(int i=0;i<N;i++) h[i] = sc.nextInt();
   
   int tmpmin=h[0];
   int tmpmax;
   boolean up= true;
   int ans =h[0];
   for(int i=1;i<N;i++)
   {
     if(up)
     {
       if(h[i-1]>h[i]) 
       {
         up=false;
         tmpmax=h[i-1];
         ans+=tmpmax-tmpmin;
       }
     }
     else
     {
       if(h[i-1]<h[i])
       {
         up=true;
         tmpmin=h[i-1];
       }
     }
   }
   if(up) ans+= h[N-1]-tmpmin;
   
   System.out.println(ans);
 }
}

Measured memory_bytes: 22868
N = int(input())
A = list(map(int, input().split()))

x = [0]*N
tmp = 0
for i in range(N):
    if i % 2 == 0:
        tmp += A[i]
    else:
        tmp -= A[i]
x[0] = tmp
for i in range(1, N):
    x[i] = int(2 * (A[i - 1] - x[i - 1] / 2))

output = ""
for i in range(N):
    output += str(x[i]) + " "
print(output)


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int MOD = (int)1e9 + 7;
int h, w, grid[1000][1000];
ll ans[1001][1001];



int main()
{
	cin >> h >> w;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			char temp;
			cin >> temp;
			if(temp == '#') grid[i][j] = 1;
		}
	}
	ans[1][1] = 1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(i == 1 && j == 1) continue;
			if(grid[i-1][j-1]) continue;
			ans[i][j] += ans[i][j-1] + ans[i-1][j];
			ans[i][j] %= MOD;
		}
	}
	cout << ans[h][w] << "\n";
	return 0;
}

Measured memory_bytes: 12032
#include<stdio.h>

int main(){
	int x,y;
	int ansx,ansy,ansv;
	char str[20];
	int vector[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
	while(1){
		ansx=0,ansy=0,ansv=0;
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		while(1){
			char cmd[20];
			int b,c=0;
			int value=0;
			
			while(b=getchar()){
				if(b=='\n'){
					break;
				}
				str[c]=(char)b;
				c++;
			}
			str[c]='\0';
			
			if(strcmp("STOP",str)==0){
				break;
			}
			else if(strcmp("RIGHT",str)==0){
				ansv=(ansv+1)%4;
			}
			else if(strcmp("LEFT",str)==0){
				ansv=(ansv+3)%4;
			}
			else{
				sscanf(str,"%s %d",cmd,&value);
				if(strcmp("FORWARD",cmd)==0){
					//printf("F v=%d\n",value);
					ansx+=vector[ansv][0]*value;
					ansy+=vector[ansv][1]*value;
					if(ansx<0)ansx=0;
					if(ansx>x-1)ansx=x-1;
					if(ansy<0)ansy=0;
					if(ansy>y-1)ansy=y-1;
				}
				else if(strcmp("BACKWARD",cmd)==0){
					//printf("B v=%d\n",value);
					ansx-=vector[ansv][0]*value;
					ansy-=vector[ansv][1]*value;
					
					if(ansx<0)ansx=0;
					if(ansx>x-1)ansx=x-1;
					if(ansy<0)ansy=0;
					if(ansy>y-1)ansy=y-1;
				}
			}
		}
		printf("%d %d\n",ansx+1,ansy+1);
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int tbl[2001][2001];

int main(int argc, char const *argv[]) {
  ll n, ret = 0;

  cin >> n;
  vector<ll> ls(n);
  for (int i = 0; i < n; i++) {
    cin >> ls[i];
  }
  sort(ls.begin(), ls.end());
  int k;
  for (int i = 1; i < n; i++) {
    k = 0;
    // cerr << i << '\t';
    for (int j = 0; j <= 2000; j++) {
      while (ls[k] + ls[i] <= j && k < i) {
        k++;
      }
      if (k >= i)
        break;
      tbl[i][j] = tbl[i - 1][j] + i - k;
      //  cerr << tbl[i][j] << ',' << k << '\t';
    }
    // cerr << endl;
  }
  /*
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 20; j++) {

      cerr << tbl[i][j] << '\t';
    }
    cerr << endl;
  }
  */

  for (int i = 2; i < n; i++) {
    ret += tbl[i - 1][ls[i]];
  }

  cout << ret << endl;

  return 0;
}


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

int main( void )
{
    int n, m;
    while ( cin >> n >> m && n && m ) {
        vector <int> p(n);
        for ( int i = 0; i < n; i++ ) {
            cin >> p[i];
        }

        int answer = 0;
        sort( p.rbegin(), p.rend() );
        for ( int i = 0, j = 1; i < n; i++, j++ ) {
            if ( j < m ) {
                answer += p[i];
            } else {
                j = 0;
            }
        }

        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 0
package main

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

var sc *bufio.Scanner

func init() {
        // 100MB
        bufsize := 100 * 1024 * 1024
        sc = bufio.NewScanner(os.Stdin)
        sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
        sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
        s := readStringArray(n)
        a := make([]int, n)
        for i := range a {
                a[i], _ = strconv.Atoi(s[i])
        }
        return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
        a := make([]string, n)
        for i := 0; i < n; i++ {
                sc.Scan()
                a[i] = sc.Text()
        }
        return a
}

func main() {
        n := readInt()
        hs := readIntArray(n)

        dp := make([]int, n)

        dp[0] = 0
        dp[1] = abs(hs[1] - hs[0])

        for i := range dp {
                if i <= 1 {
                        continue
                }
                onestep := abs(hs[i]-hs[i-1]) + dp[i-1]
                twostep := abs(hs[i]-hs[i-2]) + dp[i-2]
                if onestep < twostep {
                        dp[i] = onestep
                } else {
                        dp[i] = twostep
                }
        }

        fmt.Println(dp[n-1])

}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include<bitset>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart;
#define setTime tStart = clock();
#define time0 (double)(clock() - tStart)/CLOCKS_PER_SEC
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
#define NMAX 30
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;

int main(){
        int a, b;
        cin >> a >> b;
        if(a <= 8 && b <= 8){
            cout << "Yay!" << endl;
        } else {
            cout << ":(";
        }
}


Measured memory_bytes: 256
import collections
n = int(input())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
max_x = [-1, -1]
for k, v in count.items():
  temp_num = v
  if k-1 in count.keys():
    temp_num += count[k-1]
  if k+1 in count.keys():
    temp_num += count[k+1]
  if temp_num > max_x[1]:
    max_x[0] = k
    max_x[1] = temp_num
print(max_x[1])

Measured memory_bytes: 14564
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {
      int a = in.nextInt();
      int b = in.nextInt();
      int c = in.nextInt();
      if (a < b && b < c) {
        out.println("Yes");
      } else {
        out.println("No");
      }
    }
  }

  public static void main(String[] args) throws IOException {
//    ??????
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    
    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }
   
    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }
    
    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken()); 
    }
    
    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }
    
    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }
    
  }
  
}

Measured memory_bytes: 24512
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
(function Main(input) {
  var money = input.split(/\s+/);
  for(var i = 0; i < money.length; i++) {
  money[i] = parseInt(money[i], 10);
  }
  var max = Math.max(money[0], money[1], money[2]);
  var min = Math.min(money[0], money[1], money[2]);
  var average = (money[0] + money[1] + money[2]) - max - min;
  console.log('%d', min + average);
})(input);


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

using namespace std;

namespace mylib {
template<int mod>
struct ModInt {
	using ll = long long;
	int x;
	const static int M = mod;
	ModInt(ll x_) {
		x = x_ % mod;
		if (x < 0) x += mod;
	}
	ModInt() : ModInt(0) {}
	inline ModInt& operator+=(const ModInt rhs) {
		x += rhs.x;
		x %= mod;
		return (*this);
	}
	inline ModInt& operator-=(const ModInt rhs) {
		x += -rhs;
		return *this;
	}
	inline ModInt& operator*=(const ModInt rhs) {
		x = ((ll) x * rhs.x) % mod;
		return *this;
	}
	inline ModInt& operator/=(ModInt rhs) {
		return *this *= rhs.power(mod - 2);
	}
	inline ModInt power(ll p) {
		if (p == 0) return 1;
		if (p % 2 == 1) return (*this) * power(p - 1);
		ModInt t = power(p / 2);
		return t * t;
	}
	inline ModInt& operator=(const ModInt& rhs) {
		this->x = rhs.x;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const {
		return this->x == rhs.x;
	}
	inline int operator!=(const ModInt& rhs) const {
		return !(*this != rhs);
	}
	inline ModInt operator++(signed unused) {
		ModInt res(*this);
		++(*this);
		return res;
	}
	inline ModInt& operator++() {
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(signed unused) {
		ModInt res(*this);
		--(*this);
		return res;
	}
	inline ModInt& operator--() {
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const {
		return (*this);
	}
	inline ModInt operator-() const {
		return (*this).x ? ModInt(mod - (*this).x) : ModInt(0);
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
	operator int() const { return x;}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs) {
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs) {
		long long t;
		lhs >> t;
		rhs = ModInt(t);
		return lhs;
	}
};
using modint = ModInt<1000000007>;
//using modint = ModInt<998244353>;
modint operator"" _mi(unsigned long long lit) {
	return modint(lit % modint::M);
}
}; // mylib
using namespace mylib;

modint solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	if (N % 2) {
		for (int i = 0; i < N; i++) {
			if (A[i] != (i + 1) / 2 * 2) return 0;
		}
	} else {
		for (int i = 0; i < N; i++) {
			if (A[i] != i / 2 * 2 + 1) return 0;
		}
	}
	modint res = 1;
	for (int i = 0; i < N / 2; i++) {
		res *= 2_mi;
	}
	return res;
}

int main() {
	cout << solve() << endl;
}



Measured memory_bytes: 640
n=int(input())
s=list(input())
change="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA"
change2=""
for i in range(26):
  change2+=change[i+n] 
for i in range(len(s)):
	s[i]=change2[change.find(s[i])]
print("".join(s))    

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  ll n;
  sl(n);
  std::vector<ll> a,b,c;
  ll x;
  for(ll i=0;i<n;i++){
    sl(x);
    a.push_back(x);
  }
  for(ll i=0;i<n;i++){
    sl(x);
    b.push_back(x);
  }
  for(ll i=0;i<n;i++){
    sl(x);
    c.push_back(x);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll ans=0;
  for(ll i=0;i<n;i++){
    vector<ll> :: iterator C  = upper_bound(c.begin(),c.end(),b[i]);
    vector<ll> :: iterator A  = lower_bound(a.begin(),a.end(),b[i]);
    ans = ans+(A-a.begin())*(c.end()-C);
  }
  pl(ans);
  printf("\n");
  return 0;
}


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> x(n);
	int xcnt = 0;
	int c = mod - n + 1;
	rep(i, n) {
		cin >> x[i];
		if (x[i] < 0) x[i] += mod;
		xcnt += c * x[i]; xcnt %= mod;
		c += 2; c %= mod;
	}
	vector<int> y(m);
	int ycnt = 0;
	c = mod - m + 1;
	rep(i, m) {
		cin >> y[i];
		if (y[i] < 0) y[i] += mod;
		ycnt += c * y[i]; ycnt %= mod;
		c += 2; c %= mod;
	}
	cout << xcnt * ycnt%mod << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N >> H;
	ll A = 0;
	vl B(N);
	for (i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		A = max(a, A);
		B[i] = b;
	}
	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	for (i = 0; i < N; i++) {
		if (B[i] > A) {
			H -= B[i];
			ans++;
			if (H <= 0) {
				cout << ans;
				exit(0);
			}
		}
	}
	ans += (H - 1) / A + 1;
	cout << ans;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> mp;
  int a, b;
  REP(i, m) {
    cin >> a >> b;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }
  string ans = "IMPOSSIBLE";
  REP(i, mp[1].size()) {
    int sec = mp[1][i];
    REP(j, mp[sec].size()) {
      if(mp[sec][j] == n) {
        ans = "POSSIBLE";
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 7;

vector <int> g[MAXN];
int a[MAXN];
bool used[MAXN];
set <int> ms1, ms2;

void jfs(int u) {
    ms1.insert(u);
    ms2.insert(a[u]);
    used[u] = true;
    for (int v : g[u]) {
        if (!used[v]) jfs(v);
    }
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i]; --a[i];
    }

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u - 1].push_back(v - 1);
        g[v - 1].push_back(u - 1);        
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            ms1.clear();
            ms2.clear();
            jfs(i);
            for (int j : ms1) ans += (ms2.find(j) != ms2.end());
        }
    }

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

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

using ll = long long;
using ld = long double;

int main()
{
    int n,now=0,ans=0;
    cin >> n;

    vector<int> a(n);
    vector<bool> b(n);

    for(int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        a.at(i)--;
    }
    
    while(true){
        if(b.at(now)) break;
        b.at(now)=true;
        now=a.at(now);
        ans++;
        if(now==1)
        {
            cout << ans<<endl;
            return 0;
        }
    }
    cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#define LENGTH 100005

using namespace std;

typedef struct{
    string name;
    int time;
} Queue;

Queue Q[LENGTH];
int head, tail, n;

Queue dequeue(){
    Queue x = Q[head];
    if(head + 1 == LENGTH) head = 0;
    else head++;
    return x;
}

void enqueue(Queue x){
    Q[tail] = x;
    if(tail + 1 == LENGTH) tail = 0;
    else tail++;
}

int main(){
    int q, finish_time = 0;
    cin >> n >> q;
    for(int i = 0; i < n; i++) cin >> Q[i].name >> Q[i].time;
    head = 0;
    tail = n;
    while(head != tail){
        Queue x = dequeue();
        finish_time += min(q, x.time);
        x.time -= min(q, x.time);
        if(x.time > 0) enqueue(x);
        else cout << x.name << " " << finish_time << endl;
    }
    return 0;
}


Measured memory_bytes: 6924
#include<bits/stdc++.h>
using namespace std;
int main() {
  char a[1000];
  cin>>a;
  int n = strlen(a);
  for (int i = 0; i < n; i++) if (a[i] == '7') {
    printf("Yes");
    return 0;
	}
   printf("No");
   return 0;
}

Measured memory_bytes: 3764
import sys
input = sys.stdin.readline
import heapq
def solve():
  n,m = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = []
  for i in range(n):
    heapq.heappush(query,-1*a[i])
  for i in range(m):
    nexta = -1 * heapq.heappop(query)
    nexta //= 2
    heapq.heappush(query,-1 * nexta)

  print(-1*sum(query))
solve()

Measured memory_bytes: 14168
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    int N;
    cin >> N;
    int ans = N / 2 + N % 2;
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main()
{
	int l,r;
	int minn=2019;
	scanf("%d%d",&l,&r);
	for(int i=l;i<=r;i++)
		for(int j=i+1;j<=r;j++)
		{
			if(i%2019==0||j%2019==0)
			{
				printf("0");
				return 0;
			}
			else
				minn=min(minn,(int)(((long long)i*j)%2019));
		}
	printf("%d",minn);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef complex<double> C;

namespace std {
    bool operator < (const C& a, const C& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}

struct L : public vector<C> {
    L(const C &a, const C &b) {
        push_back(a); push_back(b);
    }
};

//??????
double cross(const C& a, const C& b) {
    return imag(conj(a)*b);
}

//??´???????????????????????????
C crosspoint(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    //????????´????????¨???
    // if(abs(A) < EPS && abs(B) < EPS){
    //     return m[0];
    // }
    return m[0] + B / A * (m[1] - m[0]);
}

int main()
{
	int q;
	cin >> q;
	rep(i,q){
		int a,b,c,d,e,f,g,h;
		cin >> a >> b >> c >> d >> e >> f >> g >> h;
		C res = crosspoint(L(C(a,b),C(c,d)),L(C(e,f),C(g,h)));
		printf("%.10f %.10f\n",real(res),imag(res));
	}
	return 0;
}

Measured memory_bytes: 3212
import math
a=list(map(int,input().split()))
ans=0
if max(a)-min(a)>=2:
    print(0)
else:
    if a[0]==a[1]:
        ans=math.factorial(max(a))
        ans=(ans%1000000007)*(ans%1000000007)*2
    else:
        ans=math.factorial(max(a))
        ans1 = math.factorial(min(a))
        ans=(ans%1000000007)*((ans1)%1000000007)
    print(int(ans%1000000007 ))

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m; cin >> n >> m;
	int l=0, r=n;
	for(int i=0;i<m;i++){
		int li,ri; cin >> li >> ri;
		if(l<li)	l = li;
		if(ri<r)	r = ri;
		if(l>r){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << r-l+1 << endl;
	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;
}

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

int sg, mult;
int v[100010];

int main()
{
    int maxim(0), minim(1e9);
    int n;
    cin >> n;

    for (int i(0); i < n; i++) {
        cin >> v[i];
        maxim = max(maxim, v[i]);
        minim = min(minim, v[i]);
    }

    if (maxim > 1 + minim) {
        cout << "No";
        return 0;
    }
    if (maxim == minim) {
        if (maxim == n - 1 || 2 * maxim <= n) {
            cout << "Yes\n";
            return 0;
        }
        cout << "No";
        return 0;
    }

    for (int i(0); i < n; i++) {
        if (v[i] == maxim)
            mult++;
        else
            sg++;
    }

    maxim -= sg;
     /// maxim -> nr de grupe ramase din cei >= 2

    if (2 * maxim <= mult && maxim > 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        byte[] daikeihen = new byte[3];
        for(byte i = 0;i <= 2; i++){
      	daikeihen[i] = sc.nextByte();
        }System.out.println((daikeihen[0] + daikeihen[1]) * daikeihen[2] / 2);
    }
}

Measured memory_bytes: 23508
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;

int H, W, K;
char A[10][10];
char B[10][10];
void solve() {
	cin >> H >> W >> K;
	REP(i, H) {
		REP(j, W) {
			cin >> A[i][j];
		}
	}
	int ans = 0;
	REP(b1, 1 << H) {
		REP(b2, 1 << W) {
			REP(i, H)REP(j, W)B[i][j] = A[i][j];
			REP(i, H) {
				if (b1&(1 << i)) {
					REP(j, W) {
						B[i][j] = '1';
					}
				}
			}
			REP(j, W) {
				if (b2&(1 << j)) {
					REP(i, H) {
						B[i][j] = '1';
					}
				}
			}
			int cnt = 0;
			REP(i, H)REP(j, W) {
				if (B[i][j] == '#')cnt++;
			}
			if (cnt == K)ans++;
		}

	}
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt(),b=sc.nextInt();
		String str =sc.next();
		int judge=0;

		for(int i=0; i<(a+b+1); i++) {
			String s=str.substring(i,i+1);
			if(i==a) {
				if(s.equals("-")) {
					judge+=1;
				}
			}else {
				if(s.matches("[0-9]")) {
					judge+=1;
				}
			}
		}
		if(judge==(a+b+1)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

using namespace std;

int main() {
    string n; cin >> n;
    int ans = 0, oth = 0;
    for (int i = 0; i < (int)n.size(); ++i) {
        ans += (i == 0 ? n[i] - '1' : 9);
        oth += n[i] - '0';
    }
    cout << max(ans, oth) << endl;

    return 0;
}


Measured memory_bytes: 256