akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

bool visited[100002];
int steps[100002];
vector<vector<pair<ll, ll> > > edge(100002);
ll N,u,v,w;

void dfs(ll prev, ll cur, ll cnt, ll add){
    // cntを増やす
    visited[cur] = true;
    cnt += add;
    steps[cur] = cnt;
    //edgeで繋がっているかつvisitedでないノードにいく
    llrep(i,edge[cur].size()){
        ll next = edge[cur][i].first;
        if (!visited[next]){
            dfs(cur, next, cnt, edge[cur][i].second);
        }
    }
    return;
}

int main(){
    cin >> N;

    llrep(i,N-1){
        cin >> u >> v >> w;
        // edge[u][v] = edge[v][u] = w;
        edge[u].push_back( make_pair(v,w) );
        edge[v].push_back( make_pair(u,w) );
    }
    //1からなんてで行けるかを調べる
    dfs(1,1,0,0);

    llRep(i,N){
        if (steps[i]%2==0){
            cout << 0 << endl;
        }else{
            cout << 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9856
#coding:utf-8


def nC2(n):
    return n * (n-1) // 2
  
def main():
    n = int(input())
    li = list(map(int, input().split()))
    nums = [0] * n
    for num in li:
        nums[num - 1] += 1
        
    sumv = 0
    for num in nums:
        if num == 0:
            continue
        sumv += nC2(num)
    
    for num in li:
        cnt = nums[num - 1]
        v = sumv + nC2(cnt-1) - nC2(cnt)
        print(v)
        
  
if __name__ == '__main__':
    main()

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

long long p = 998244353;
long long mod_fact[300008];

void mod_fact_init(){
    mod_fact[0]=mod_fact[1]=1;
    for(int i=2;i<300008;i++){
        mod_fact[i]=(mod_fact[i-1]*i)%p;
    }
}


long long mod_pow(long long a, long long b){
    a%=p;
    if(b==0){
        return 1;
    }else if(b%2==0){
        return mod_pow(a*a, b/2)%p;
    }else{
        return (a*mod_pow(a, b-1))%p;
    }
}

long long mod_comb(long long a, long long b){
    long long c = (mod_fact[a]*mod_pow(mod_fact[a-b], p-2))%p;
    return (c*mod_pow(mod_fact[b], p-2))%p;
}

int main(void){
    long long n,a,b,k,m=0;
    cin>>n>>a>>b>>k;
    mod_fact_init();
    for(long long i=0;i<=min(k/a,n);i++){
        if((k-i*a)%b==0){
            long long j=(k-i*a)/b;
            if(j<=n)m=(m+(mod_comb(n,i)*mod_comb(n,j))%p)%p;
        }
    }
    cout<<m<<endl;
}


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

using namespace std;

int main()
{
    int N;
    char S[50];
    int K;
    cin >> N >> K;
    cin >> S;
    switch (S[K - 1]) {
    case 'A':
        S[K - 1] = 'a';
        break;
    case 'B':
        S[K - 1] = 'b';
        break;
    case 'C':
        S[K - 1] = 'c';
        break;
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//block linked list
#define Bsize 700 /*2sqrt(n)*/
typedef struct block{
	int cnt;
	ll a[Bsize+1];
	struct block*pre;
	struct block*nxt;
}block;
void Bpush(block*b,ll x){
	//リストにxを追加する
	if((*b).nxt&&(*(*b).nxt).a[0]<x){
		//次へ
		Bpush((*b).nxt,x);
		return;
	}
	int i=(*b).cnt;
	for(;i>0&&(*b).a[i-1]>x;i--)(*b).a[i]=(*b).a[i-1];
	(*b).a[i]=x;
	(*b).cnt++;
	if((*b).cnt>=Bsize){
		//分割
		block*nn=(block*)malloc(sizeof(block));
		(*nn).cnt=Bsize-Bsize/2;
		rep(i,0,Bsize-Bsize/2)(*nn).a[i]=(*b).a[i+Bsize/2];
		(*nn).pre=b;
		(*nn).nxt=(*b).nxt;
		if((*b).nxt)(*(*b).nxt).pre=nn;
		(*b).cnt=Bsize/2;
		(*b).nxt=nn;
	}
}
void con(block*p,block*q){
	//qをpにマージしてqを消す
	rep(i,0,(*q).cnt)(*p).a[(*p).cnt+i]=(*q).a[i];
	(*p).cnt+=(*q).cnt;
	(*p).nxt=(*q).nxt;
	if((*q).nxt)(*(*q).nxt).pre=p;
	free(q);
}
void Bdel(block*b,int idx){
	//idx番目を削除する(必ずidx個以上ある)
	for(;idx<(*b).cnt-1;idx++)(*b).a[idx]=(*b).a[idx+1];
	(*b).cnt--;
	
	if((*b).cnt==0&&(*b).pre)con((*b).pre,b);
	else if((*b).pre&&(*(*b).pre).cnt+(*b).cnt<Bsize/4)con((*b).pre,b);
	else if((*b).nxt&&(*(*b).nxt).cnt+(*b).cnt<Bsize/4)con(b,(*b).nxt);
}

ll Bans(block*b,int k,int flag){
	//リストのk番目を返す
	//リストにk個未満しかなければ適当に返す
	//flagがtrueなら削除する
	if((*b).cnt<=k){
		if((*b).nxt)return Bans((*b).nxt,k-(*b).cnt,flag);
		else return -1;//<-例外
	}
	ll ans=(*b).a[k];
	if(flag)Bdel(b,k);
	return ans;
}
//マージサボった
int Bfind(block*b,ll k,int flag){
	//リストにkが何個存在するか答える
	//flagがtrueなら削除する
	if((*b).cnt==0||(*b).a[(*b).cnt-1]<k){
		if((*b).nxt)return Bfind((*b).nxt,k,flag);
		else return 0;
	}
	int i=0;
	for(;(*b).a[i]<k;i++);
	int j=i;
	while(j<(*b).cnt&&(*b).a[j]==k)j++;
	if(j==(*b).cnt&&(*b).nxt){
		if(flag)(*b).cnt=i;
		return j-i+Bfind((*b).nxt,k,flag);
	}else{
		if(flag){
			for(int xxx=j;xxx<(*b).cnt;xxx++)(*b).a[xxx-j+i]=(*b).a[xxx];
			(*b).cnt-=j-i;
		}
		return j-i;
	}
}
void Bdump(block*b,ll l,ll r){
	if((*b).cnt==0){
		if((*b).nxt)Bdump((*b).nxt,l,r);
	}else if((*b).a[0]>r)return;
	else if((*b).a[(*b).cnt-1]<l){
		if((*b).nxt)Bdump((*b).nxt,l,r);
	}
	else{
		rep(i,0,(*b).cnt)if(l<=(*b).a[i]&&(*b).a[i]<=r)printf("%lld\n",(*b).a[i]);
		if((*b).a[(*b).cnt-1]<=r&&(*b).nxt)Bdump((*b).nxt,l,r);
	}
}
#undef Bsize


block*b;
int main(){
	b=calloc(1,sizeof(block));
	int q;
	scanf("%d",&q);
	int cnt=0;
	while(q--){
		int t,x;
		scanf("%d%d",&t,&x);
		if(t==0){
			Bpush(b,x);
			cnt++;
			printf("%d\n",cnt);
		}else if(t==1){
			printf("%d\n",Bfind(b,x,0));
		}else if(t==2){
			cnt-=Bfind(b,x,1);
		}else{
			int y;
			scanf("%d",&y);
			Bdump(b,x,y);
		}
	}
}


Measured memory_bytes: 4840
#include <stdio.h>

int main(){
    int p, q, r, res;
    scanf("%d %d %d", &p, &q, &r);
    if(p < 1 || p > 100 || q < 1 || q > 100 || r < 1 || r > 100){
        return -1;
    }
    res = p + q;
    if(p+r < res)
        res = p+r;
    if(q+r < res)
        res = q+r;
    
    printf("%d", res);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<vector>
#include<cstring>
#include<sstream>
#include<algorithm>
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;

#define MOD 1000000007

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

    int n;
    cin >> n;

    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];

    int ret = 0;
    for (int i = 1; i <= n; i++) {
        if (i%2 != 0 && a[i-1]%2 != 0)  ret ++;
    }

    cout << ret << endl;

    return 0;
}


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

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  
  if(c-a-b < 0)
  {
    cout << "No" << endl;
    return 0;
  }
  
  if(4*a*b < (c-a-b)*(c-a-b))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public void solve(){
		Scanner sc = new Scanner(System.in);
		
		int kaisu=1;
		int no=0;
		int n = sc.nextInt();
		
		while(n != 0){
			for(int cnt=0; cnt<n; cnt++){
				int zansu = sc.nextInt();
				
			if(zansu >= 2){
				kaisu ++;
			}else if(zansu == 1){
				no ++;
			}
			}
		
		
		if(kaisu >= 2){
			System.out.println(kaisu+no);
		}else{
			System.out.println("NA");
		}
		
		kaisu=1;
		no=0;
		n =sc.nextInt();
	}
}
public static void main(String[]args){
	Main obj = new Main();
	obj.solve();
}
}
			

Measured memory_bytes: 158428
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int r;
  cin>>r;
  cout<<setprecision(6)<<2*r*3.141592653<<endl;
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

long long PS[200001];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N;
	long long ans=0x7fffffffffffffffLL;
	cin>>N;
	for(int i=1;i<=N;i++) cin>>PS[i], PS[i]+=PS[i-1];
	for(int i=N-2;i>1;i--) {
		vector<long long> V;
		int s=1, e=i-1;
		while(s<=e) {
			int m=(s+e)>>1;
			if(abs(PS[i]-2*PS[m])<abs(PS[i]-2*PS[m+1])) e=m-1;
			else s=m+1;
		}
		V.push_back(PS[s]);
		V.push_back(PS[i]-PS[s]);
		s=i+1, e=N-1;
		while(s<=e) {
			int m=(s+e)>>1;
			if(abs(PS[N]+PS[i]-2*PS[m])<abs(PS[N]+PS[i]-2*PS[m+1])) e=m-1;
			else s=m+1;
		}
		V.push_back(PS[s]-PS[i]);
		V.push_back(PS[N]-PS[s]);
		sort(V.begin(),V.end());
		ans=min(ans,V[3]-V[0]);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 1792
package main

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

func main() {
	A, B, C := getStdinInt3()

	a_rem := A - B

	if C > a_rem {
		fmt.Printf("%d", C-a_rem)
	} else {
		fmt.Printf("%d", 0)
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2156
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(24) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b; //先に割り算をして掛けられる数を小さくして掛け算を行う
}

bool pairCompare(const pair<int, int> &firstElof, const pair<int, int> &secondElof)
{
    return firstElof.second < secondElof.second;
}

void solve()
{
    int a;
    cin >> a;
    if(a % 1000 == 0)
    {
      P(0);
      return;  
    }
    cout << ((a/1000)+1)*1000 - a << endl;
}

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


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

//#define DEBUG 1

//#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int pos[MAXN+5];

struct info
{
    int l,r,d;
};

vector<info> infos[MAXN+5];

int32_t main()
{
    #ifdef DEBUG
    //freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n,m;
    cin >> n >> m;
    for0(i,n) {
        pos[i] = -INF;
    }
    
    for0(i,m) {
        int l,r,d;
        read(l); read(r); read(d);
        l--; r--;
        infos[l].pb((info){l,r,d});
        infos[r].pb((info){l,r,d});
        
    }
    
    for (int i=0; i<n; i++) {
        if (pos[i] == -INF) {
            pos[i] = 0;
            queue<int> q;
            q.push(i);
            
            while (!q.empty()) {
                int top = q.front(); q.pop();
                iter(infos[top]) {
                    int nxt, nxt_pos;
                    if (it->l == top) {
                        nxt = it->r;
                        nxt_pos = pos[top]+it->d;
                    }
                    else {
                        nxt = it->l;
                        nxt_pos = pos[top]-it->d;
                    }
                    if (pos[nxt] == -INF) {
                        pos[nxt] = nxt_pos;
                        q.push(nxt);
                    }
                    else if (pos[nxt] != nxt_pos) {
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    printa(pos,n)
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n, d;
    cin >> n >> d;
    double x[10][10];
    rep(i, 0, n)
    {
        rep(j, 0, d)
        {
            cin >> x[i][j];
        }
    }
    int cnt = 0;
    rep(i, 0, n)
    {
        rep(j, i + 1, n)
        {
            double sum = 0;
            rep(k, 0, d)
            {
                //cout << x[i][k] << endl;
                sum += fabs(x[i][k] - x[j][k]) * fabs(x[i][k] - x[j][k]);
            }
            //cout << sum << endl;
            sum = sqrt(sum);
            //cout << sum << endl;
            if (ceil(sum) == floor(sum))
                cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long int n,m,nd;
int main(){
    cin>>n>>m;//输入
    nd=2*n;//nd是两倍n，因为一个S和两个c搭配。
    if(nd>m)cout<<m/2<<endl;//c不够就只能尽量吧c用完
    else if(nd==m)cout<<n<<endl;//刚好配对
    else{//S不够
        m-=nd;//先把能配的S配完
        m/=4;//4个c配成一组Scc
        cout<<n+m<<endl;//原本的加上组合成的
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = "Yes"
t_before = 0
x_before, y_before = 0, 0

for _ in range(N):
    ti, xi, yi = map(int, input().split())
    t_dist = abs(ti - t_before)
    x_dist = abs(xi - x_before)
    y_dist = abs(yi - y_before)
    xy_dist = x_dist + y_dist
    if xy_dist <= t_dist:
        if (t_dist % 2 == 0 and xy_dist % 2 == 0) or (t_dist % 2 == 1 and xy_dist % 2 == 1):
            t_before = ti
            x_before = xi
            y_before = yi
            continue
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int m, n;
  while (cin >> m >> n, m) {
    vector<int> a(m);
    iota(a.begin(), a.end(), 1);
    int curr = 0;
    for (int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      if (m == 1) continue;
      string ans = "";
      if (i % 3 == 0 || i % 5 == 0) {
        if (i % 3 == 0) ans += "Fizz";
        if (i % 5 == 0) ans += "Buzz";
      } else {
        ans = to_string(i);
      }
      if (s != ans) {
        a.erase(a.begin() + curr);
        curr %= (--m);
      } else {
        curr = (curr + 1) % m;
      }
    }
    for (int i = 0; i < m; i++) {
      cout << a[i] << " \n"[i + 1 == m];
    }
  }

  return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

vector<pair<int,int>> ranges;

int dp[100000]; //! dp[i] = # of max robots we can have from index i

int solve(int i) 
{
    // cout << "solve is called with " << i << endl;
    if (i == ranges.size()-1) return 1;
    int ret = dp[i];
    if (ret == 0) {
        int right = ranges[i].second;
        auto lb = lower_bound(ranges.begin()+i+1, ranges.end(), make_pair(right,0));
        if (lb == ranges.end()) {
            //! No more free robot on right side if we include robot-i
            ret = max(1, solve(i+1));
        } else {
            int c1 = 1 + solve(lb - ranges.begin());  //! include robot i
            int c2 = solve(i+1);                      //! exclude robot i
            ret = max(c1, c2);
        }
        dp[i] = ret;
    }
    // cout << "solve(" << i << ") = " << ret << endl;
    return ret;
}

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

    int N;
    cin >> N;
    ranges.resize(N);
    rep(i, N) {
        int X, L;
        cin >> X >> L;
        ranges[i].first = X-L;
        ranges[i].second = X+L;
    }
    sort(ranges.begin(), ranges.end());
 
    cout << solve(0) << endl;

    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define repB(i, z, n) for(int i = n - 1; i >= z; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<int> pq;
    rep(i, 0, N){
        int x;
        cin >> x;
        pq.push(x);
    }
    rep(i, 0, M){
        int x = pq.top();
        pq.pop();
        pq.push(x / 2);
    }
    int64_t ans = 0;
    rep(i, 0, N){
        int64_t x = pq.top();
        pq.pop();
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <cmath>

using namespace std;

int L;
int M;
int main(void) {

	cin >> L;

	int N = 1;
	int num = 1;
	for (;; N++) {
		num *= 2;
		if (num > L) { break; }
	}
	

	cout << N ;

	//==================== M
	M = 2 * (N - 1);

	int A = L - num / 2;

	while (A) {
		int j = 0;
		int m = 1;
		for (;; j++) {
			if (m <= A && A <2 * m) { break; }
			m *= 2;
		}
		//cout << "j= " << j << endl;
		M++;
		A -= pow(2, j);
	}


	cout <<" " <<M << endl;
	//=============================


	for (int i = 1; i <= N - 1; i++) {
		cout << i << " " << i + 1 << " " << 0 << endl;
	}

	int w = 1;
	for (int i = N; i >= 2; i--) {
		cout << i - 1 << " " << i << " " << w << endl;
		w *= 2;
	}
	

	 A = L - num / 2;

	while (A) {
		int j = 0;
		int m = 1;
		for (;; j++) {
			if (m <= A && A <2 * m) { break; }
			m *= 2;
		}
		//cout << "j= " << j << endl;

		cout << 1 << " " << N - j << " " << L - A << endl;

		A -= pow(2, j);
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			List<Integer> list = IntStream.range(0, 5).map(i -> {
				int number = scanner.nextInt();
				scanner.nextLine();
				return number;
			}).sorted().collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
			int k = scanner.nextInt();
			scanner.nextLine();
			if ((list.get(list.size() - 1) - list.get(0)) > k) {
				System.out.println(":(");
			} else {
				System.out.println("Yay!");
			}
		}
	}
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b; cin>>a>>b;
    int add = a+b, sub = a-b, mult=a*b;
    int ans = max(add,sub);
    ans = max(ans,mult);
    print(ans);
    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 10] * n
    for i in range(n-1):
        a[i] = min(b[i], a[i])
        a[i+1] = min(b[i], a[i+1])
    print(sum(a))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a * b) % 2 == 1) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}
	}
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<vector<pair<int, int>>> xy(n);
    rep(i, n) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            xy[i].emplace_back(x, y);
        }
    }
    int ans = 0;
    rep(bit, 1<<n) {
        bool flag = true;
        int cnt = __builtin_popcount(bit);
        
        rep(i, n) if (bit >> i & 1) {
            rep(j, sz(xy[i])) {
                int id = xy[i][j].first;
                int y = xy[i][j].second;
                if ((bit >> id & 1) != y) flag = false;
            }
        }
        
        if (flag) chmax(ans, cnt);
    }
    cout << ans << endl;
}


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

int main()
{
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   int start,finish,result;
   if(A>C)
   {
       start=A;
   }
   else
   {
       start=C;
   }
   if(B>D)
   {
      finish=D;
   }
   else
   {
       finish=B;
   }
   result=finish-start;
   if(result<0)
    result=0;
   cout<<result;

    return 0;
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

ll n,m;

ll solve(){
	ll ret = m;
	REP(i,2,n) ret *= (m-1);
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e16;
struct edge{
    int to, cost;
    edge(int to, int cost):to(to), cost(cost){}
};
const int V = 100010;
vector<edge> G[100010];
int d[100010];

void dijkstra(int s){
    fill(d, d + V, INF);//V, INF
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(d[s], s));
    while(!q.empty()){
        P p = q.top(); q.pop();
        int from = p.second;
        int cost = p.first;
        if(d[from] < cost) continue;
        rep(i, 0, G[from].size()){
            edge e = G[from][i];
            int next = e.to;
            int newCost = e.cost + cost;
            if(d[next] > newCost){
                d[next] = newCost;
                q.push(P(newCost, next));
            }
        }
    }
}

signed main(){
    int n, q, k;
    cin >> n;
    rep(i, 0, n - 1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a]. push_back({b, c});
        G[b]. push_back({a, c});        
    }
    cin >> q >> k;
    k--;
    dijkstra(k);
    rep(i, 0, q){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  PQ(P) apple;
  vi p(A),q(B),r(C);
  rep(i,A) {
    cin >> p[i];
  }
  rep(i,B) {
    cin >> q[i];
  }
  rep(i,C) {
    cin >> r[i];
  }
  sort(rng(p));
  reverse(rng(p));
  sort(rng(q));
  reverse(rng(q));
  sort(rng(r));
  reverse(rng(r));
  ll sum = 0;
  PQ(int) que; 
  rep(i,X) {
    sum += p[i];
    que.push(p[i]);
  }
  rep(i,Y) {
    sum += q[i];
    que.push(q[i]);
  }
  rep(i,C) {
    int x = que.top();
    que.pop();
    if(x > r[i]) break;
    sum -= x;
    sum += r[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2552
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		//amount of items
		int N = inputs.nextInt();
		//maximum allowed weight
		int W = inputs.nextInt();
		int[] weights = new int[N];
		int[] values = new int[N];
		for(int i=0;i<N;i++) {
			weights[i] = inputs.nextInt();
			values[i] = inputs.nextInt();
		}
		//stores if visited and totalvalue
		long[][] dp = new long[W+1][2];
		dp[0][0] = 1;
		for(int k = 0;k<N;k++) {
			for(int i = W;i>=weights[k];i--) {
				if(dp[i-weights[k]][0]==1) {
					dp[i][0] = 1;
					if(dp[i][1]==0) {
						dp[i][1] = dp[i-weights[k]][1] +values[k];
					}
					else {
						if(dp[i][1]>dp[i-weights[k]][1] +values[k])
							continue;
						else
							dp[i][1] = dp[i-weights[k]][1] +values[k];
					}
				}
			}
		}
		long ans = 0;
		for(int i =W;i>=0;i--) {
			if(dp[i][1]>ans) {
				ans = dp[i][1];
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 26708
#include <iostream>
#include <vector>
using namespace std;
int N;
vector <int> G[100005];
bool Special[100005], ok = 1;
int Grade[100005], cnt[2], ind;
int Perm[5][100005], len;
void Read()
{
    cin >> N;
    for(int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for(int i = 1; i <= N; i++)
    {
        if(G[i].size() > 1)
            Special[i] = 1;
    }
}

void buildGrade()
{
    for(int i = 1; i <= N; i++)
        for(int j = 0; j < G[i].size(); j++)
        {
            int neighb = G[i][j];
            if(Special[neighb] == 1)
                Grade[i]++;
        }
    for(int i = 1; i <= N; i++)
    {
        if(Special[i] == 0)
            continue;
        if(Grade[i] >= 3)
        {
            ok = 0;
            return;
        }
        if(Grade[i] == 1)
        {
            cnt[ind++] = i;
        }
    }
}

void findPerm(int nb, int node)
{
    int pos = 0, cr = 1, last = 0, val = 0;
    while(1)
    {
        int next = 0;
        for(int j = 0; j < G[node].size(); j++)
        {
            int neighb = G[node][j];
            if(last != neighb && Special[neighb] == 1)
            {
                next = neighb;
                break;
            }
        }
        int aux = G[node].size() - 1 - val;
        val = 1;
        for(int i = 1; i <= aux; i++)
            Perm[nb][++pos] = cr + i;
        Perm[nb][++pos] = cr;
        cr = cr + aux + 1;
        last = node;
        node = next;
        if(node == 0 || pos == N)
            break;
    }
    Perm[nb][++pos] = N;
}

void Solve()
{
    if(ind <= 1)
    {
        cout << 1 << " ";
        for(int i = 3; i < N; i++)
            cout << i << " ";
        cout << 2 << " ";
        cout << N << "\n";
        return;
    }
    int pos = 0;
    for(int i = 1; i <= N; i++)
    {
        if(Special[i] == 1 && Grade[i] == 1)
        {
            int node = i;
            for(int j = 0; j < G[i].size(); j++)
            {
                int neighb = G[i][j];
                if(Special[neighb] == 0)
                {
                    node = neighb;
                    break;
                }
            }
            ++pos;
            findPerm(pos, node);
        }
    }
    int res = 1;
    for(int i = 2; i <= pos; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            if(Perm[res][j] > Perm[i][j])
            {
                res = i;
                break;
            }
            if(Perm[res][j] < Perm[i][j])
                break;
        }
    }
    for(int i = 1; i <= N; i++)
    {
        cout << Perm[res][i] << " ";
    }
    cout << "\n";
}
int main()
{
    Read();
    buildGrade();
    if(ok == 0)
    {
        cout << "-1\n";
        return 0;
    }
    Solve();
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=2e5+5;
int n;
vi adj[mxn];
ll subans[mxn],ans[mxn],sz[mxn],fac[mxn],ifac[mxn];

ll modpow(ll a, ll b) // put b = mod-2, calc for (x!)^(mod-2) % mod only, [use x^(mod-2) when x^-1] 
{
	ll r=1;
	while(b)
	{
		if(b&1)r=(r*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return r;
}

void multi(ll &a, ll b){
	a%=MOD; b%=MOD; a*=b; a%=MOD;
}

void seive(int n){
	fac[0]=ifac[0]=1;
	for(int i=1; i<=n; i++){
		fac[i]=fac[i-1]*1LL*i%MOD;
		ifac[i]=modpow(fac[i],MOD-2);
	}
	for(int i=0; i<=n; i++)subans[i]=ans[i]=sz[i]=0;
	return;
}

int dfs1(int u, int p=-1){
	sz[u]=1;
	for(auto v:adj[u]){
		if(v==p)continue;
		sz[u]+=dfs1(v,u);
	}
	subans[u]=fac[sz[u]-1];
	for(auto v:adj[u]){
		if(v==p)continue;
		(subans[u] *= subans[v])%=MOD;
		(subans[u] *= ifac[sz[v]])%=MOD;
	}
	return sz[u];
}

void dfs2(int u, int p=-1){
	ans[u] = fac[n-1];
	for(auto v:adj[u]){
		(ans[u]*=subans[v])%=MOD;
		(ans[u]*=ifac[sz[v]])%=MOD;
	}
	for(auto v:adj[u]){
		if(v==p)continue;
		subans[u]=ans[u]%MOD;
		multi(subans[u],ifac[n-1]); 
		multi(subans[u],fac[n-1-sz[v]]);
		multi(subans[u],fac[sz[v]]);		
		multi(subans[u],modpow(subans[v],MOD-2));
		sz[u]=n-sz[v];
		dfs2(v,u);
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int u,v;
	cin >> n;
	seive(n);
	for(int i=0; i<n-1; i++){
		cin >> u >> v;
		u--; v--;
		adj[u].eb(v);
		adj[v].eb(u);
	}
	dfs1(0); dfs2(0);
	for(int i=0; i<n; i++){
		cout << ans[i] << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 21748
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = LI()
    ans = 0
    for c in range(1,n+1):
        K = (n-1)//c
        dp = 0
        S = set([0,n-1])
        for k in range(1,K+1):
            a = i = n-1-k*c
            if i in S:
                break
            b = a-c
            if b >= a or b <= 0:
                break
            S.add(i)
            j = k*c
            if j in S:
                break
            S.add(j)
            cost = s[i]+s[j]
            dp += cost
            if ans < dp:
                ans = dp
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 97620
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

A=[]
A.append(a)
A.append(b)
A.append(c)
A.append(d)
A.append(e)

A.sort()
m=A[0]
if n%m==0:
    ans = n/m + 4
else:
    ans = n/m + 4 + 1
#print(int(n/m))
print(int(ans))


Measured memory_bytes: 3064
#n=int(input())
import copy
h,w,K=map(int,input().split())
#l=list(map(int,input().split()))
l=[list(input()) for i in range(h)]
rowl=[]
coll=[]

def count_black(l2d):
    res=0
    for l in l2d:
        res+=l.count('#')
    return res

for i in range(2**h):
    temp=[]
    for k in range(h):
        if ((i >> k) & 1):#二進数iの下から数えてj桁目が1か否か
            temp.append(k)
    rowl.append(temp)
for j in range(2**w):
    temp=[]
    for k in range(w):
        if ((j >> k) & 1):
            temp.append(k)
    coll.append(temp)

count=0
# 全探索
rowall=["r" for i in range(w)]
for row in rowl:
    for col in coll:
        test=copy.deepcopy(l)
        for i in row:
            test[i]=rowall
        for j in col:
            for i in range(h):
                test[i][j]='r'
        if count_black(test)==K:
            count+=1

print(count)


Measured memory_bytes: 9248
#include<stdio.h>
int main()
{
    int N,i,j,k,l,cnt;
    while (scanf("%d",&N)!=EOF) {
        cnt = 0;
        for (i = 0; i <= 9; i++) {
            for (j = 0; j <= 9; j++) {
                for (k = 0; k <= 9; k++) {
                    for (l = 0; l <= 9; l++) {
                        if (i + j + k + l == N) {
                            cnt++;
                        }
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	string str = s;
	reverse(str.begin(), str.end());
	bool ok = s == str;
	int n = s.size();
	str = s.substr(0, (n - 1) / 2);
	reverse(str.begin(), str.end());
	if(ok)
		ok = str == s.substr(0, (n - 1) / 2);
	str = s.substr((n + 3) / 2 - 1);
	reverse(str.begin(), str.end());
	if(ok)
		ok = str == s.substr((n + 3) / 2 - 1);
	cout << (ok ? "Yes" : "No");
}


Measured memory_bytes: 3560
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as BSC8
main :: IO ()
main = do
  s <- BSC8.getLine
  BSC8.putStrLn $ solve s (BSC8.length s)
solve :: BSC8.ByteString -> Int -> BSC8.ByteString
solve bs n = if a == b then "Yes" else "No"
  where
    a = BSC8.take m       bs
    b = BSC8.drop (m + 1) bs
    m = n `div` 2

Measured memory_bytes: 3732
import itertools
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in itertools.product([0, 1], repeat=h):
    for wi in itertools.product([0, 1], repeat=w):
        cnt = 0
        for i, j in itertools.product(range(h), range(w)):
            if hi[i] and wi[j]:
                if s[i][j] == "#":
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Measured memory_bytes: 9208
let a = readLine()!
let b = a.index(a.endIndex, offsetBy: -1)
let c = a[b]
 
if c == "2" || c == "4" || c == "5" || c == "7" || c == "9" {
    print("hon")
} else if c == "0" || c == "1" || c == "6" || c == "8" {
    print("pon")
} else {
    print("bon")
}

Measured memory_bytes: 7744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  int sum;
  
  if(A>=K){
	sum = K;
  }else if(A+B >= K){
  	sum = A;
  }else {
  	sum = A - (K-A-B);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

#define  each(i,c) for(typeof(c.begin()) i=c.begin();i!=c.end();++i)

#define pb push_back
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) range(i,0,n)

#define dump(x) cerr << #x << " = " <<  (x) << endl;


const int inf=1<<29;

int n,m;

struct node{int to,cost; };

vector<node> graph[410];

inline void add_edge(int a,int b,int c){
	node in; in.to=b; in.cost=c;
	graph[a].pb(in);
	return ;
}

struct state{
		int to,cost;
		bool operator < (state a) const { return cost < a.cost;}
		bool operator > (state a) const { return cost > a.cost;}
};

int dist[410];

int dijkstra(){
	state init;
	init.to=n-1;init.cost=0;
	priority_queue<state,vector<state>,greater<state> > q;
	q.push(init);
	while(!q.empty()){
		state cur=q.top();q.pop();
		rep(i,graph[cur.to].size()){
			state next=cur;
			next.to=graph[cur.to][i].to;
			next.cost+=graph[cur.to][i].cost;
			if(next.cost > dist[next.to]){
				dist[next.to]=next.cost;
				q.push(next);
			}

		}

	}
	return dist[0];
}


int main(void){
	cin >> n >> m;

	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		add_edge(b,a,c);
	}

	cout << dijkstra() << endl;
	return 0;
}

Measured memory_bytes: 1244
#include<map>
#include<cstdio>
#include<iostream>
using namespace std;
int a[100005];
int n,ans;
map<int,int> ma;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	  ma[a[i]]++;
	for(int i=1;i<=n;i++)
	  ans=max(ans,ma[a[i]]+ma[a[i]-1]+ma[a[i]+1]);
	printf("%d",ans);
	return 0;
}

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

int l, r;
string s,t;

int main()
{
	cin >> s;
	t = " ";
	while (!s.empty())
	{
		if ((t.back() == 'T') && (s.back() == 'S'))
		{
			t.pop_back();
		}
		else
		{
			t.push_back(s.back());
		}
		s.pop_back();
		
	}
	cout << t.size() - 1 << endl;
}

Measured memory_bytes: 1020
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    
    int n, m; cin >> n >> m;
    priority_queue<ll> que;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        que.push(a);
        ans += a;
    }
    
    for (int i = 0; i < m; i++)
    {
        ll a = que.top();
        ans = ans - (a+1)/2;
        que.pop();
        que.push(a/2);
    }
    cout << ans << endl;
    
    return 0;
}

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

int main() 
{
int a;
  cin >> a;
  float sum = a * 2 * 3.141592;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    long long int all=0,x=0,min=1000000000000000000,temp;
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
        all+=a[i];
    }
    for(int i=0;i<n-1;i++){
        x+=a[i];
        temp=all-2*x;
        temp=temp>0?temp:-temp;
        min=min>temp?temp:min;
    }
    printf("%lld\n",min);
    return 0;
}


Measured memory_bytes: 896
from collections import Counter

# print('input >>')

N = int(input())
Ss = []
for _ in range(N):
    Ss.append(input())

Ss_cnt = Counter(Ss)
common = Ss_cnt.most_common()
most = common[0][1]
cand = []
for e in common:
    if e[1] == most:
        cand.append(e[0])
    else:
        break

cand.sort()

# print('-----output-----')
for c in cand:
    print(c)

Measured memory_bytes: 47804