akhauriyash/Code-Regression huggingface dataset:
from math import factorial as fact
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(n,r))

def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def factorization(n):
	tmp=n
	count=0
	for i in range(2,int(n**0.5)+2):
		if tmp%i==0:
			cnt=0
			while tmp%i==0:
				cnt+=1
				tmp//=i
			count+=1
	if tmp!=1:
		count+=1

	return count
			




a,b,c,d=input2()

for i in range(1,10000):
	if i%2==1:
		c-=b
		if c<=0:
			print("Yes")
			break
	else:
		a-=d
		if a<=0:
			print("No")
			break

	







Measured memory_bytes: 27164
#include<bits/stdc++.h>
using namespace std;
int mod(int a , int b){
   if(a>b){
	return a-b;
   }
   else{
   	return b-a;
   }
}
int mincost( vector<int> &h , int n , int k){
int dp[n];
for(int i=0;i<n;i++)
{
	dp[i]=INT_MAX;
}
dp[0]=0;
dp[1]=mod(h[0],h[1]);


for(int i=2;i<n;i++)
{
	for(int j=1;j<=k;j++)
	 {
	 	if(i-j>=0)
	 	 dp[i]=min(dp[i], dp[i-j]+mod(h[i],h[i-j]));
	 	else
	 	 break;	
	 }
}
                
return dp[n-1];


}


int main(){
int  n,k;
cin>>n>>k;
vector<int> h;
int x;
for(int i=0;i<n;i++)
{
	cin>>x; 
	h.push_back(x);
}



cout<<mincost(h,n,k);

	return 0;
}

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

const ULL M = 1000000007;

ULL powm(ULL a, ULL i) {
    if (!i) return 1;
    if (i & 1) return powm(a * a % M, i >> 1) * a % M;
    return powm(a * a % M, i >> 1);
}

ULL F[10001], I[10001], iF[10001];

ULL C(ULL n, ULL r) { return F[n] * iF[r] % M * iF[n - r] % M; }
ULL P(ULL n, ULL r) { return F[n] * iF[n - r] % M; }
ULL H(ULL n, ULL r) { return C(r + n - 1, n - 1); }

struct Problem {

    void Solve() {
        F[0] = 1; for (UL i = 1; i <= 10000; i++) F[i] = F[i - 1] * i % M;
        I[1] = 1; for (UL i = 2; i <= 10000; i++) I[i] = M - M / i * I[M % i] % M;
        iF[0] = 1; for (UL i = 1; i <= 10000; i++) iF[i] = iF[i - 1] * I[i] % M;
        ULL N, K; cin >> N >> K;
        if (N > K) { cout << 0 << endl; return; }
        cout << C(K, N) << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;


pair<int64_t, int64_t> solve(int64_t x) {
    map<int64_t, int64_t> f;
    for (int64_t a = 0; ; ++ a) {
        f[a * a * a * a * a] = a;
        f[- a * a * a * a * a] = - a;
        if (a * a * a * a * a >= 1e15) break;
    }
    for (auto [b5, b] : f) {
        auto it = f.find(x + b5);
        if (it != f.end()) {
            return {it->second, b};
        }
    }
    assert (false);
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t X;
    cin >> X;
    auto [A, B] = solve(X);
    cout << A << ' ' << B << endl;
    return 0;
}


Measured memory_bytes: 3772
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
DEBUG = 'ONLINE_JUDGE' not in sys.argv

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)

def main():
    print(Yes if sum(map(int, input()))%9==0 else No)








main()



Measured memory_bytes: 10076
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

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

int main()
{
	ll N,M,Q;
	cin >> N >> M >> Q;
	vector< vector <int> > cnt(N, vector<int>(N,0)), ans(N, vector<int>(N,0));//cnt[r][l]
	for(int i=0; i<M; i++){
		int l,r;
		cin >> l >> r;
		l--;r--;
		cnt[r][l]++;
	}

	for(int i=0; i<N; i++) ans[i][i]=cnt[i][i];
	for(int r=1; r<N; r++){
		for(int l=r-1; l>=0; l--){
			ans[r][l]=ans[r][l+1]+ans[r-1][l]-ans[r-1][l+1]+cnt[r][l];
		}
	}
	

	for(int q=0; q<Q; q++){
		int l,r;
		cin >> l >> r;
		l--;r--;
		cout << ans[r][l] << endl;
	}

	

    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a,sum=0;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d",&a);
		sum=sum+a;
	}
	if(sum<=n)
		printf("%d\n",n-sum);
	else
		printf("-1\n");
	return 0;
}

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

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

    if (n < 1000)
        cout << "ABC" << endl;
    else
        cout << "ABD" << endl;
    return 0;
}


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


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

int main(void){
  int r1, r2;
  cin >> r1 >> r2;
  cout << setprecision(9);
  cout << 1.0/(1.0/r1 + 1.0/r2) << endl;
  return 0;
}



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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x; cin >> x;
    int ans = 0;
    while(ans * (ans+1) < 2* x) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define pb push_back
#define ll long long int
#define vi vector<int>
#define floop(i,n) for(int i = 0; i < n; ++i)
#define maxi 1000000000000000000

int main(){
		int a,b;
  cin>>a>>b;
  cout<<a*b;


	return 0;
	
}

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

import sys
import os
import math


n, m = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

def sum_len(A):
    all_sum = 0
    previous_sum = 0
    for i in range(1, len(A)):
        now_sum = previous_sum + i * (A[i] - A[i-1])
        all_sum += now_sum
        previous_sum = now_sum
    return all_sum

a = 10**9 + 7
xl = sum_len(X)
yl = sum_len(Y)
#print(xl)
#print(yl)
print(xl * yl % a)

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

#define sz 100005
#define ff first
#define ss second
#define nl printf("\n");
#define ll long long int

char f,g;
bool flag;
pair < int ,int > pi;
map < int , int > mp;
vector < pair < int , pair < int, int > > > v,va,vb;
vector < pair < int , pair < int, int > > > vp;
//vector < pair < int, int > > vp;
int arr[sz],brr[sz],crr[sz];

int digitof(int x){
    int cnt=0;
    while(x){
        x/=10;
        cnt++;
    }
    return cnt;
}

int main(){

    int n,m, i,j,k, x=0,y=0,z=0, a,b,c;

    cin>>n>>m;
    for(i=0; i<m; i++){
        cin>>a>>b;
        v.push_back({b,{a,i}});
        ///cout<<v[i].ff<<' '<<v[i].ss.ff<<' '<<v[i].ss.ss<<endl;
    }
    sort(v.begin(),v.end());

    for(i=0; i<m; i++){

       a=v[i].ss.ff;///num
       b=v[i].ss.ss;///index
       //cout<<a<<' '<<b<<
       mp[a]++;
       vp.push_back({b,{a,mp[a]}});
    }
    sort(vp.begin(),vp.end());

    for(i=0; i<m; i++){

        x=vp[i].ss.ff;
        y=6-digitof(x);

        while(y--)cout<<0;
        cout<<x;

        x=vp[i].ss.ss;
        y=6-digitof(x);

        while(y--)cout<<0;
        cout<<x<<endl;
    }

    return 0;

}


Measured memory_bytes: 8564
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

long long solve(long long R, long long C, int K, const std::vector<long long> &r, const std::vector<long long> &c,
                const std::vector<long long> &v) {
  vector<vector<ll>> s(R, vl(C, 0));
  REP(i, K) { s[r[i]][c[i]] = v[i]; }

  vector<vector<vl>> dp(R, vector<vl>(C, vl(4, 0)));
  dp[0][0][1] = s[0][0];
  REP(i, R) {
    REP(j, C) {
      REP(k, 4) {
        if (k == 0) {
          if (i > 0) {
            REP(l, 4) {
              chmax(dp[i][j][k], dp[i - 1][j][l]);
              chmax(dp[i][j][1], dp[i - 1][j][l] + s[i][j]);
            }
          }
          if (j > 0) {
            chmax(dp[i][j][k], dp[i][j - 1][k]);
          }
        } else {
          if (j > 0) {
            chmax(dp[i][j][k], dp[i][j - 1][k]);
            chmax(dp[i][j][k], dp[i][j - 1][k - 1] + s[i][j]);
          }
        }
      }
    }
  }
  ll ans = 0;
  REP(k, 4) { chmax(ans, dp[R - 1][C - 1][k]); }
  return ans;
}

// generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
  int R, C;
  int K;
  std::cin >> R >> C >> K;
  std::vector<long long> r(K), c(K), v(K);
  for (int i = 0; i < K; ++i) {
    std::cin >> r[i] >> c[i] >> v[i];
    r[i]--;
    c[i]--;
  }
  auto ans = solve(R, C, K, r, c, v);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 711376
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>

#define rep(i,n)  for (int i = 0; i < (int)(n); i++)
#define INF 9999999999
#define PI 3.14159265359
using namespace std;

int main()
{
	int ans;
	cin >> ans;
	ans=ans+ans*ans+ans*ans*ans;
	cout << ans << endl;
	return 0;
}


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

int K;
unsigned int gcd_bc[200][200];

unsigned int euclidean_gcd(unsigned int a, unsigned int b){
    if(a < b) return euclidean_gcd(b, a);
    unsigned r;
    while (r=a%b) {
        a = b;
        b = r;
    }
    return b;
}

int main(){
    cin >> K;
    for(int b=1; b<=K; ++b){
        for(int c=b; c<=K; ++c){
            unsigned int res = euclidean_gcd(b, c);
            gcd_bc[b][c] = res;
            gcd_bc[c][b] = res;
        }
    }
    unsigned int sum =0;
    for(int a=1; a<=K; ++a){
        for(int b=1; b<=K; ++b){
            for(int c=1; c<=K; ++c){
                sum += euclidean_gcd(a, gcd_bc[b][c]);
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 3756
m,n = gets.split.map(&:to_i)
mat = []

for i in 1..m
temp = gets.split.map(&:to_i)
temp.push(temp.inject(:+))
mat.push(temp)
puts temp.join(" ")
end

temp = []
for i in 0..n

sum = 0
for j in 0..(m-1)
sum += mat[j][i]
end

temp.push(sum)

end

puts temp.join(" ")




Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	vector<int> H(N);
	for(int i=0;i<N;i++)cin >> H[i];
	int cur = 0;
	int ans = 0;
	while(cur!=N){
		int t = 0;
		while(cur!=N-1 && H[cur]>=H[cur+1]){
			t++;
			cur++;
		}
		ans = max(ans,t);
		cur++;
	}
	cout << ans << endl;
}

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

typedef long long ll;

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
		
	ll n, l, r;

	cin>>n;

	ll ans = 0;

	while(n--) {
		cin>>l>>r;
		ans += r-l+1;
	}
	cout<<ans<<endl;
	
}

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

int main()
{
    int h, w, cnt=0;
    cin >> h >> w;
    char a;
    for(int i=0; i<h*w; i++){
        cin >> a;
        if(a=='.') cnt++;
    }
    if (cnt==(h-1)*(w-1)) cout << "Possible\n";
    else cout << "Impossible\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>

using namespace std;

using ull = unsigned long long;

int main(int argc, char** argv)
{
    ull N;
    std::vector<ull> A;
    unordered_set<ull> exists;
    map<ull, bool> furui;
    unordered_map<ull, ull> appearCount;
    ull maxV = 0;
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i];
        maxV = std::max(A[i], maxV);
        furui[A[i]] = true;
        appearCount[A[i]]++;
    }

    if (N == 1)
    {
        cout << "1" << endl;
        return 0;
    }

    if (furui.size() == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    ull count = 0;
    for (auto furuiIt = furui.begin(); furuiIt != furui.end(); ++furuiIt)
    {
        if (furuiIt->second == false)
        {
            continue;
        }
        if (appearCount[furuiIt->first] <= 1)
        {
            count++;
        }
        auto v = furuiIt->first;
        for (ull value = v; value <= maxV; value += v)
        {
            auto nextIt = furui.find(value);
            if (nextIt != furui.end())
            {
                nextIt->second = false;
            }
        }
    }
    //for (size_t i = 0; i < N; ++i)
    //{
    //    if (furui[A[i]] == false)
    //    {
    //        // Not divisable
    //        count++;
    //    }

    //    for (ull v = A[i]; v <= maxV; v += A[i])
    //    {
    //        furui[v] = true;
    //    }
    //}

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 25676
#include<stdio.h>
#define N 100

int m[101][101], p[101], n;

void matrixChain()
{
   int i, j, k, l;

   for (i=1; i<=n; i++)
      m[i][i] = 0;

   for (l=2; l<=n; l++){
      for (i=1; i<=n-l+1; i++){
         j = i+l-1;
         m[i][j] = 100000000; 
         for (k=i; k<j; k++){
            if (m[i][j] > m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
               m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
         }
      }
   }
}


int main()
{
   int i;

   scanf("%d", &n);
   for (i=1; i<=n; i++){
      scanf("%d %d", &p[i-1], &p[i]);
   }

   matrixChain();

   printf("%d\n", m[1][n]);

   return 0;
}

Measured memory_bytes: 1856
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(1,n-1):
  if p[i] > p[i-1] and p[i] < p[i+1]:
    ans += 1
  elif p[i] < p[i-1] and p[i] > p[i+1]:
    ans += 1

print(ans)


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

ll N;



int main(){
	cin >> N;
	
	vector<ll> A(N);
	for ( int i = 0; i < N; i++ )
		cin >> A[i];
	
	vector<ll> acc(N*3+1); // 累積和  a0 - a1 + a2 - a3 + a4 - a5 ....
	acc[0] = 0;
	ll sgn = 1;
	for ( int i = 0; i < 3*N; i++ ){
		acc[i+1] = acc[i] + A[i%N] * sgn;
		sgn = -sgn;
	}
	
	for ( int i = 0; i < N; i++ ){
		if ( i % 2 == 0 )
			cout << (acc[i+N]-acc[i]) << " ";
		else
			cout << (acc[i+2*N]-acc[i+N]) << " ";
	}
	cout << endl;
	
	
	return 0;
}



Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n;
int a[51];
int f[51][2501];
//int f[101][101];
int32_t main()
{
    cin>>n>>t;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int res=0;
    int sum=0;
    f[0][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=i;j>0;j--)
            {
                //cerr<<j<<endl;
                for(int k=2500;k>=a[i];k--)
                {
                    f[j][k]+=f[j-1][k-a[i]];
                }
            }
    for(int i=1;i<=n;i++)
    {
        res+=f[i][t*i];
    }
    cout<<res;
}


Measured memory_bytes: 1280
from sys import stdout

s = input()
q = int(input())
pref = ''
suff = ''
order = 1
for i in range (q):
  e = input().split()
  if e[0] == '1':
    order *= (-1)
  else:
    if order == 1:
      if e[1] == '1':
        pref = e[2] + pref
      else:
        suff += e[2]
    else:
      if e[1] == '2':
        pref = e[2] + pref
      else:
        suff += e[2]
if order == 1:
    stdout.write(pref)
    stdout.write(s)
    stdout.write(suff)
else:
    stdout.write(suff[::-1])
    stdout.write(s[::-1])
    stdout.write(pref[::-1])


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

map<long long, long long> dp;
long long N, A, B, C, D;

long long solve(long long N) {
    if (dp.count(N))    return dp[N];

    long long ans = 1e18;
    if (N <= ans/D)     ans = min(ans, N*D);

    if (N%2==0)         ans = min(ans, solve(N/2)+A);
    else {
        ans = min(ans, solve(N/2)+A+D);
        if (N > 1) ans = min(ans, solve(N/2+1)+A+D);
    }

    if (N%3==0)         ans = min(ans, solve(N/3)+B);
    else if (N%3==1)    ans = min(ans, solve(N/3)+B+D);
    else                ans = min(ans, solve(N/3+1)+B+D);

    if (N%5==0)         ans = min(ans, solve(N/5)+C);
    else if (N%5==1)    ans = min(ans, solve(N/5)+C+D);
    else if (N%5==2)    ans = min(ans, solve(N/5)+C+D+D);
    else if (N%5==3)    ans = min(ans, solve(N/5+1)+C+D+D);
    else                ans = min(ans, solve(N/5+1)+C+D);

    return dp[N] = ans;
}

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

    int t;
    cin>>t;

    while (t--) {
        cin>>N>>A>>B>>C>>D;

        dp.clear();
        dp[0] = 0;

        cout<<solve(N)<<endl;
    }
}


Measured memory_bytes: 4416
#include <iostream>
#include <cstring>
using namespace std;
#define int long long

main(){
  int n;
  cin>>n;
  int a[n][n];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  int ans=0;
  bool used[n];
  memset(used,0,sizeof(used));
  used[0]=1;
  int cost[n];
  for(int i=0;i<n;i++) cost[i]=a[0][i];
  while(1){
    int v=-1;
    for(int i=0;i<n;i++){
      if(used[i]||cost[i]<0) continue;
      if(v<0||cost[i]<cost[v]) v=i;
    }
    if(v<0) break;
    used[v]=1;
    ans+=cost[v];
    for(int i=0;i<n;i++){
      if(a[v][i]<0) continue;
      if(cost[i]<0||a[v][i]<cost[i]) cost[i]=a[v][i];
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3120
#include<stdio.h>

int main(){
	int a, b, m, n, temp, amari;
	while(scanf("%d %d", &a, &b) != EOF){
		if(a < b){
			temp = a;
			a = b;
			b = temp;
		}
		m = a;
		n = b;
		amari = m % n;
		while(amari != 0){
			m = n;
			n = amari;
			amari = m % n;
		}
		printf("%d %d\n", n, a * (b / n));
	}
	return 0;
}

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

double heron(double a,double b,double c){
  double s = (a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
  double a,l,x;

  while(cin >> a >> l >> x){
    double t = (l+x)/2;

    printf("%.10f\n", heron(a,l,l)+heron(t,t,l)*2);
  }

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long smaller_factor_sum(long long x){
  long long ans = 0;
  for (int i = 1; i * i <= x; i++){
    if (x % i == 0){
      if (x != 1){
        ans += i;
      }
      if (i * i < x && i != 1){
        ans += (x / i);
      }
    }
  }
  return ans % MOD;
}
long long modsub(long long a, long long b){
	a %= MOD;
	b %= MOD;
	if (a >= b){
		return (a - b) % MOD;
	} else {
		return MOD - (b - a) % MOD;
	}
}
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> M(K);
  for (int i = 1; i <= K; i++){
    M[i - 1] = i;
    for (int j = 1; j * j <= i; j++){
      if (i % j == 0){
        if (i != 1){
          M[i - 1] = modsub(M[i - 1], M[j - 1]);
          if (j * j < i && j != 1){
            M[i - 1] = modsub(M[i - 1], M[i / j - 1]);
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= K; i++){
    long long A = modpow((K / i), N);
    long long B = M[i - 1];
    ans = (ans + A * B % MOD) % MOD;
  }
  cout << ans;
}

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

using ll = long long;

int main()
{
    vector<int> x(5, -1);

    for (int i = 0; i < 5; i++) {
        cin >> x[i];
    }

    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) {
            cout << (i + 1) << endl;
            return 0;
        }
    }

    return 1;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 2e3 + 10;
const int M = (int) 700;
const ll LINF = (ll) 1e18;
const int mod = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
const double PI =  3.14159265359;


int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    ll n, l, r;
    cin >> n >> l >> r;
    if (n == 1 && l != r) {
        cout << 0;
        return 0;
    }
    ll min_sum = (n - 1) * l + r, max_sum = (n - 1) * r + l;
    cout << max(0ll, max_sum - min_sum + 1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    bool ok = 0;
    ll win = 0;
    rep(i,n-2){
        if (s[i] != s[i+2]) ok = 1;
    }
    rep(i,2,n-2){
        if (s[i-2] == s[i+1] && s[i-1] == s[i+2]) win++;
    }
    if (n > 3 && s[0] == s[3]) win++;
    if (n > 3 && s[n-4] == s[n-1]) win++;
    if (!ok){
        PRINT("Second");
    }
    else{
        ll m = n;
        if (s[0] == s[n-1]) m += 1;
        if ((m-2)%2 || win == 1) PRINT("First");
        else PRINT("Second");
    }
}


Measured memory_bytes: 512
N, MOD = int(input()), 10**9 + 7


def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


DP = [{} for i in range(N+1)]
for i in range(0, N+1):
    # 1-origin
    if i == 0:
        DP[i]['TTT'] = 1
    else:
        for c in 'AGCT':
            for last3, count in DP[i-1].items():
                if ok(last3+c):
                    ret = count % MOD
                    if last3[1:]+c in DP[i]:
                        DP[i][last3[1:]+c] += ret
                    else:
                        DP[i][last3[1:]+c] = ret
print(sum(DP[i].values()) % MOD)

Measured memory_bytes: 3820
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
double n,k,a=0,b,cnt=1;
cin>>n>>k;
double z,first;
for(int i=1;i<=n;i++){
  z=i;
  while(z<k){
    z*=2;
    cnt*=2;
  }
  if(i==1){
    b=cnt;
  }
  a+=b/cnt;
  cnt=1;
}
b*=n;
cout<<setprecision(18)<<a/b<<endl;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Maybe

solve :: VU.Vector Int -> Int -> IO ()
solve xs n = VU.forM_ (VU.fromList [0..n-1]) $ \i -> print $ max (l VU.! i) (r VU.! (i+1))
    where
        l = VU.scanl max 0 xs
        r = VU.scanr max 0 xs

main = do
    n <- readLn :: IO Int
    xs <- VU.replicateM n (fst . fromJust . B.readInt <$> B.getLine)
    solve xs n

Measured memory_bytes: 8572
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;

int main(){
    int k,x;
    s(k) s(x)
    p(x-k+1)
    for(int i = x-k+2; i < x+k; i ++){
        pk p(i)
    }
    pn


    return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
    }

    map<int, ll> G;
    rep(i, N) {
        G[A[i]]++;
    }

    ll tmp = 0;
    bool ok = true;
    switch (G.size()) {
        case 1:
            for (auto x : G) {
                if (x.first != 0) {
                    ok = false;
                }
            }

            break;
        case 2:
            for (auto x : G) {
                if (x.first == 0) {
                    if (x.second != (N / 3)) {
                        ok = false;
                        break;
                    }
                } else {
                    if (x.second != (2 * N / 3)) {
                        ok = false;
                        break;
                    }
                }
            }

            break;
        case 3:
            for (auto x : G) {
                tmp ^= x.first;
                if (x.second != (N / 3)) {
                    ok = false;
                    break;
                }
            }
            if (tmp != 0) {
                ok = false;
            }

            break;
        default:
            ok = false;
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 8804
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c,x,y;
    T=1;
    while(T --> 0)
    {
        cin>>n>>x>>y;
        int A[n+1][n+1];
        int B[n+1]={0};
        for(i=1;i<=n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                B[ min(abs(j-i), abs(x-i) + abs(y-j) +1  ) ]++;
            }
        }
        for(i=1;i<n;i++)
        cout<<B[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		D052 d = new D052();
		d.main();
		
	}
}

class D052 {
	
	int N;
	long A;
	long B;
	long[] X;
	
	D052() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextInt();
		this.A = cin.nextInt();
		this.B = cin.nextInt();
		this.X = new long[N];
		for (int i = 0; i < N; i++) {
			X[i] = cin.nextInt();
		}
	}
	
	void main() {
		
		long fati = 0;
		for (int i = 0; i < N - 1; i++) {
			long dist = X[i + 1] - X[i];
			long tmp = Math.min(dist*A, B);
			fati += tmp;
		}
		System.out.println(fati);
	}
	
}

Measured memory_bytes: 47184
using System;
using System.Linq;
namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var cnt = 1;
            int ans;
            while (true)
            {
                if(input[0] <= cnt * input[1])
                {
                    ans = cnt * input[2];
                    break;
                }
                cnt++;
            }
            System.Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string b;
  cin >>b;
  
  if(b =="A"){
    cout<<"T"<<endl;
  }
  else if(b=="T"){
    cout<<"A"<<endl;
  }
  else if(b=="G"){
    cout<<"C"<<endl;
  }
  else{
    cout<<"G"<<endl;
  }
}

Measured memory_bytes: 256
//ABC111B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=n;i<2000;i++){
		int a = i/100;
		int b = (i-100*a)/10;
		int c = i-100*a-10*b;
		if(a == b && b == c){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
# D - Maze Master
from collections import deque


def bfs(start: int):
    queue = deque([start])
    dist = {start: 0}
    while queue:
        x = queue.popleft()
        for nx in (x + 1, x - 1, x + W, x - W):
            if maze[nx] and nx not in dist:
                dist[nx] = dist[x] + 1
                queue.append(nx)
    return max(dist.values())


def main():
    global W, maze
    H, W, *S = open(0).read().split()
    H, W = int(H) + 2, int(W) + 2
    maze = [False] * W  # flatten S and put sentinels
    for s in S:
        maze += [False] + [c == "." for c in s] + [False]
    maze += [False] * W
    ans = max(bfs(i) for i, x in enumerate(maze) if x)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <stdio.h>
#define INFTY 2000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[100][100];

int prim(){
  int u,i,j,k,min,sum=0,d[100],p[100],color[100];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    min=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=BLACK){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)
      break;
    color[u]=BLACK;
    for(k=0;k<n;k++){
      if(color[k]!=BLACK && A[u][k]!=INFTY){
	if(d[k]>A[u][k]){
	  d[k]=A[u][k];
	  p[k]=u;
	  color[k]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)
      sum+=A[i][p[i]];
  }
  return sum;
}



int main(){
  int i,j,a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a);
      A[i][j]=a;
      if(a==-1)
	A[i][j]=INFTY;
    }
  }
  printf("%d\n",prim());
}



Measured memory_bytes: 1992
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

ll N;
ll A[200001];
ll sum[200001];
map<ll,ll> m;

int main(){
    cin>>N;
    repn(i,N) cin>>A[i];

    repn(i,N){
        sum[i]=sum[i-1]+A[i];
    }

    for(int i=0;i<=N;i++){
        m[sum[i]]++;
    }

    ll ans=0;
    repr(e,m){
        ans+=e.second*(e.second-1)/2;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

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

int main()
{
    vector<int> v = {1,
                     1,
                     1,
                     2,
                     1,
                     2,
                     1,
                     5,
                     2,
                     2,
                     1,
                     5,
                     1,
                     2,
                     1,
                     14,
                     1,
                     5,
                     1,
                     5,
                     2,
                     2,
                     1,
                     15,
                     2,
                     2,
                     5,
                     4,
                     1,
                     4,
                     1,
                     51};
    int k;
    cin >> k;
    cout << v[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  string S;
  cin>>S;
  N=S.size();
  int ans=0;
  for(int i=0;i<N;i++){
  if(S.at(i)=='1')
    ans++;
    else
      ans--;
  
  }ans=abs(ans);
  ans=N-ans;
  cout<<ans<<endl;

return 0;
}

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

#define ll long long
using namespace std;

int main() {
    ll a,b,k;
    cin >> a >> b >> k;

    if(k<=a)
        cout<< a-k << ' ' << b << endl;
    else if(k<=a+b)
        cout<< 0 << ' ' << b- (k-a) <<endl;
    else
        cout<< 0 << ' ' << 0 <<endl;
    return 0;
}

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

int main()
{
    int l=0,Ascore=0,Bscore=0;
    char ch;
    while((ch=getchar())!='\n')
    {
        if(ch=='p')
            Ascore++;
        l++;
    }
    Bscore=l>>1;
    printf("%d\n",Bscore-Ascore);
    return 0;
}


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


int main()
{
	int a,b;
	cin>>a>>b;
	if(a*b==15) cout<<"*";
	if(a+b==15) cout<<"+";
	if(a+b!=15&&a*b!=15) cout<<"x";
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int N;
vector<vector<int>> G;
vector<int> mx;

void dfs(int v){
  mx[v] = 0;
  vector<int> suzu;
  for(int nv: G[v]){
    dfs(nv);
    suzu.emplace_back(mx[nv]);
  }
  sort(suzu.rbegin(),suzu.rend());
  for(int i=0; i<suzu.size(); i++){
    chmax(mx[v],i + suzu[i]+1);
  }
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  G.resize(N);
  for(int i=1; i<N; i++){
    int p;
    cin >> p;
    p--;
    G[p].emplace_back(i);
  }
  mx.resize(N);
  dfs(0);
  cout << mx[0] << "\n";
  return 0;
}

Measured memory_bytes: 19960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int N,M,C;cin>>N>>M>>C;
  vi B(M);
  rep(i,M)cin>>B[i];

  int A;
  int cnt = 0;
  rep(i,N){
    int ans = C;
    rep(i,M){
      cin>>A;
      ans += A*B[i];
    }
    if(ans>0)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,d,ans=0;
    cin >>n>>d;
    for(long long i=0;i<n;i++){
        long long x,y;
        cin >>x >>y;
        if(x*x+y*y<=d*d) ans++;
    }
    
    cout <<ans;
}


Measured memory_bytes: 3620
#include <iostream>                                  
using namespace std;                                 
                                                     
int main() {                                         
  int S;                                             
  cin >> S;                                          
  int h = S/3600;                                    
  int m = S%3600/60;                                 
  int s = S%3600%60;                                 
  cout << h << ":" << m << ":" << s << endl;         
  return 0;                                          
}                                                    
                

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

int D;

int dist(int a, int b){
	return min( abs(a-b) , abs(D-abs(a-b)) );
}

int search(vector<int>& v, int k){
	int low = 0, high = v.size();
	while( high - low > 1 ){
		int mid = (low + high) / 2;
		if( v[mid] > k ){
			high = mid;
		}else{
			low = mid;
		} 
	}
	return min( abs(v[low]-k) , abs(v[high]-k) );
}

int main(){
	int N, M;
	while( cin >> D , D){
		cin >> N >> M;
	
		vector<int> d(N+1), k(M);
		d[0] = 0;
		d[N] = D;
		for(int i=1 ; i < N ; i++ ){
			cin >> d[i];
		}
		for(int i=0 ; i < M ; i++ ){
			cin >> k[i];
		}
		sort( d.begin() , d.end() );
		sort( k.begin() , k.end() );
		int ans=0;
		for(int i=0 ; i < M ; i++ ){
			ans += search( d , k[i] );
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1528
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    if (a[0] == '7' || a[1] == '7' || a[2] == '7')
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

int main() {
   int N, C_money;
   cin >> N >> C_money;
   vector<int> v(N);

   for(int i=0; i<N; i++) {
       cin >> v[i];
       C_money -= v[i];
   }

   sort(v.begin(), v.end());

   N += C_money / v[0];
    cout << N << endl;
}


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

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > v( n , vector<int> (3,0));
    vector<vector<int> > values( n , vector<int> (3,0));
     
    for(int  i = 0; i < n; i++){
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }
    
    for(int i = 0; i < 3; i++){
        values[0][i] = v[0][i];
    }
    
    for(int i = 1; i <n; i++){
        for(int j = 0; j < 3; j++){
            values[i][j] = INT_MIN;
            for(int k = 0; k < 3; k++){
                if(k != j) values[i][j] = max(values[i][j], v[i][j] + values[i - 1][k]);
            }
        }
    }
    
    int maximum = *max_element(values[n-1].begin(), values[n - 1].end());
    cout<<maximum;
    return 0;
}


Measured memory_bytes: 13988
m = []
for i in range(3):
  l = list(map(int, input().split()))
  for x in l:
    m.append(x)
                
n = int(input())

for i in range(n):
  a = int(input())
  if a in m:
    m[m.index(a)] = 0
    
if ((m[0] + m[1] + m[2]) == 0) or ((m[3] + m[4] + m[5]) == 0) or ((m[6] + m[7] + m[8]) == 0) or ((m[0] + m[3] + m[6]) == 0) or ((m[1] + m[4] + m[7]) == 0) or ((m[2] + m[5] + m[8]) == 0) or ((m[0] + m[4] + m[8]) == 0) or ((m[2] + m[4] + m[6]) == 0):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main()
{
    int n, d[110];
    map<int, int> mp;

    cin >> n;

    int res = 0;
    REP(i, n)
    {
        cin >> d[i];
        if (mp[d[i]] == 0)
            res++;
        mp[d[i]] = 1;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if ((a <= c && b >= c) || (b <= c && a >= c)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
// finish date: 2018/03/16

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


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


    return 0;
}

Measured memory_bytes: 256
def sol():
    n=int(input())
    AC=WA=TLE=RE=0
    for i in range(n):
        p=input()
        if(p=="AC"):
            AC+=1
        elif(p=="WA"):
            WA+=1
        elif(p=="TLE"):
            TLE+=1
        elif(p=="RE"):
            RE+=1
    print("AC x "+str(AC))
    print("WA x "+str(WA))
    print("TLE x "+str(TLE))
    print("RE x "+str(RE))
if(__name__=='__main__'):
    sol()


Measured memory_bytes: 8960
#include<stdio.h>

int main(){

int n,m,a;

while(1){

scanf("%d%d%d",&n,&m,&a);if(n==0&&m==0&&a==0)break;

int N[1003][102]={};
for(int i=0;i<m;i++){
	int h,p,q;
scanf("%d%d%d",&h,&p,&q);

N[h][p]=1;
N[h][q]=2;
}

for(int i=1000;i>=0;i--)
{if(N[i][a]==1)a++;
else if(N[i][a]==2)a--;
}
printf("%d\n",a);
}
return 0;
}

Measured memory_bytes: 1432