akhauriyash/Code-Regression huggingface dataset:
import copy

s = input()

def value(s, adding_list):
    insert_index = []
    for index in range(len(adding_list)):
        if adding_list[index]:
            insert_index.append(index)

    if len(insert_index) == 0:
        return int(s)

    value_list = []

    for index in range(len(insert_index)):
        if index == 0:
            value_list.append(s[0:insert_index[index]+1])
        if index < len(insert_index)-1:
            value_list.append(s[(insert_index[index]+1) : insert_index[index+1]+1])

        if index == len(insert_index)-1:
            value_list.append(s[insert_index[index]+1:])

    ret_val = 0
    for value in value_list:
        ret_val += int(value)

    return ret_val

def dfs(adding_list, changing_index):
    sum = 0
    if changing_index == len(s)-2:
        return value(s, adding_list)
    else:
        changing_index += 1
        new_adding_list = copy.copy(adding_list)
        sum += dfs(new_adding_list, changing_index)

        new_adding_list = copy.copy(adding_list)
        new_adding_list[changing_index] = True
        sum += dfs(new_adding_list, changing_index)
        return sum

def main():
    if len(s) > 1:
        ret_val = 0
        plus_list = [False for _ in range(len(s)-1)]
        ret_val += dfs(plus_list, 0)

        plus_list = [False for _ in range(len(s)-1)]
        plus_list[0] = True
        ret_val += dfs(plus_list, 0)
        print(ret_val)
    else:
        print(s)

main()

Measured memory_bytes: 41712
S=gets.chomp
a=[1]
(1 ... S.size).each{|i|
    if S[i]==S[i-1]
        a[-1]+=1
    else
        a<<1
    end
}
#warn a.inspect
l=0
r=a.size-1
ls=a[0]
rs=a[-1]
while l+1<r
    if ls+a[l+1]<rs+a[r-1]
        l+=1
        ls+=a[l]
    else
        r-=1
        rs+=a[r]
    end
end
warn [ls,rs].inspect
puts [ls,rs].max


Measured memory_bytes: 15188
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
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;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	
	int x,a,b;
	cin>>x>>a>>b;
	int arest=x-a;
	cout<<arest%b<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;
const int Max_N(100050);

inline void GG()
{
	puts("No"), exit(0);
}

int N, K, Head[Max_N], Total, To[Max_N << 1], Next[Max_N << 1], L[2][Max_N], R[2][Max_N], Ans[Max_N];

inline void Add_Edge(int s, int t)
{
	++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}

void dfs(int u, int fa)
{
	for (int i = Head[u], v;i;i = Next[i])
		if ((v = To[i]) != fa)
		{
			dfs(v, u);
			for (int c = 0;c <= 1;++c)
				L[c][u] = max(L[c][u], L[c ^ 1][v] - 1), R[c][u] = min(R[c][u], R[c ^ 1][v] + 1);
		}
	if (L[0][u] > R[0][u] && L[1][u] > R[1][u])
		GG();
}

/*
只考虑一个点的子树，该点能填的数一定是一段连续的奇数和一段连续的偶数的并。可以归纳证明 
*/

void printAns(int u, int fa)
{
	for (int i = Head[u], v;i;i = Next[i])
		if ((v = To[i]) != fa)
		{
			if (L[(Ans[u] & 1) ^ 1][v] <= Ans[u] - 1 && Ans[u] - 1 <= R[(Ans[u] & 1) ^ 1][v])
				Ans[v] = Ans[u] - 1;
			else
				Ans[v] = Ans[u] + 1;
			printAns(v, u);
		}
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		L[0][i] = 0, R[0][i] = 1000000, L[1][i] = 1, R[1][i] = 1000001;
	for (int i = 1, u, v;i != N;++i)
		scanf("%d%d", &u, &v), Add_Edge(u, v), Add_Edge(v, u);
	scanf("%d", &K);
	for (int v, p;K--;)
		scanf("%d%d", &v, &p), L[p & 1][v] = R[p & 1][v] = p, L[(p & 1) ^ 1][v] = 100000, R[(p & 1) ^ 1][v] = 0;
	dfs(1, -1);
	puts("Yes");
	Ans[1] = (L[0][1] <= R[0][1] ? L[0][1] : L[1][1]), printAns(1, -1);
	for (int i = 1;i <= N;++i)
		printf("%d\n", Ans[i]);
	return 0;
}

Measured memory_bytes: 9472
<?php
$nums = explode(' ', trim(fgets(STDIN)));
// print_r($nums);
$ans = 0;
foreach($nums as $num){
$ans += $num;
}
// echo $ans;
if($ans >= 22){
echo 'bust';
}elseif($ans <= 21){
echo 'win';
}
?>

Measured memory_bytes: 3828
#include<stdio.h>
int main()
{
	char a[22];
	while(scanf("%c",&a[0])!=EOF)
	{
		for(int i=1;i<=19;i++)
			scanf("%c",&a[i]);
		for(int i=0;i<=4;i++)
			printf("%c",a[i]);
		printf(" ");
		for(int i=6;i<=12;i++)
			printf("%c",a[i]);
		printf(" ");
		for(int i=14;i<=18;i++)
			printf("%c",a[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main()
{
	int flag = 0, k, x, i;
	cin >> k >> x;
	for(int i=x-k+1; i<x+k; i++)
		cout << i << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
before_value = gets.to_i
unless before_value.zero?
  puts -1
  exit
end
count = 0
(n-1).times do
  value = gets.to_i
  diff = value - before_value
  case (value <=> before_value + 1)
  when 1
    puts -1
    exit
  when 0
    count = count + 1
  when -1
    count = count + value
  end
  before_value = value
end
puts count

Measured memory_bytes: 3836
n = int(input())
s = input()

mod = 10**9 + 7

dp = [[0] * n for _ in range(n)]

for more in range(n):
    dp[0][more] = 1

for i in range(n-1):
    if s[i] == "<":
        cum = 0
        for more in reversed(range(n-1-i)):
            cum += dp[i][more+1]
            cum %= mod
            dp[i + 1][more] += cum
            dp[i + 1][more] %= mod
    else:
        cum = 0
        for more in range(n-1-i):
            cum += dp[i][more]
            cum %= mod
            dp[i+1][more] += cum
            dp[i+1][more] %= mod

print(dp[n-1][0])


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

int gcd(int x, int y) {
    if (x%y == 0) {
        return y;
    }
    return gcd(y, x%y);
}

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

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

    vector<int> l(n), r(n);
    l[0] = a[0];
    for (int i = 0; i < n-1; i++) {
        l[i+1] = gcd(l[i], a[i+1]);
    }
    r[n-1] = a[n-1];
    for (int i = n-1; i > 0; i--) {
        r[i-1] = gcd(r[i], a[i-1]);
    }


    int ans = 1;
    rep(i, n) {
        if (i == 0) {
            ans = max(r[1], ans);
            continue;
        }
        if (i == n-1) {
            ans = max(l[n-2], ans);
            continue;
        }
        ans = max(gcd(l[i-1], r[i+1]), ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4488
import java.util.*;
import java.lang.*;
import java.math.*;

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

        int n = sc.nextInt();
        int[] HappinessSelectA = new int[n];
        int[] HappinessSelectB = new int[n];
        int[] HappinessSelectC = new int[n];

        for (int i = 0; i < n; i++) {
            HappinessSelectA[i] = sc.nextInt();
            HappinessSelectB[i] = sc.nextInt();
            HappinessSelectC[i] = sc.nextInt();
        }
        int[][] HappinessSum = new int[3][n];
        HappinessSum[0][0] = HappinessSelectA[0];
        HappinessSum[1][0] = HappinessSelectB[0];
        HappinessSum[2][0] = HappinessSelectC[0];
        for (int i = 1; i < n; i++) {
            HappinessSum[0][i] = Math.max(HappinessSum[1][i-1], HappinessSum[2][i-1])
                                    + HappinessSelectA[i];
            HappinessSum[1][i] = Math.max(HappinessSum[0][i-1], HappinessSum[2][i-1])
                                    + HappinessSelectB[i];
            HappinessSum[2][i] = Math.max(HappinessSum[1][i-1], HappinessSum[0][i-1])
                                    + HappinessSelectC[i];
        }

        int MaxHappiness = HappinessSum[0][n-1];
        if (HappinessSum[1][n-1] > MaxHappiness) {
            MaxHappiness = HappinessSum[1][n-1];
        }
        if (HappinessSum[2][n-1] > MaxHappiness) {
            MaxHappiness = HappinessSum[2][n-1];
        }

        System.out.println(MaxHappiness);

        sc.close();
    }
}


Measured memory_bytes: 95744
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007LL;

int N, M;
int A[1111], B[1111];

int main(){
	scanf("%d %d", &N, &M);
	for(int i = 0; i < N; i++) scanf("%d", &A[i]);
	for(int i = 0; i < M; i++) scanf("%d", &B[i]);
	
	sort(A, A + N);
	sort(B, B + M);
	ll res = 1LL;
	for(int i = N * M; i >= 1; i--){
		int cnt;
		bool flag = true;
		if(upper_bound(A, A + N, i) - lower_bound(A, A + N, i) > 1){
			printf("0\n");
			return 0;
		}
		if(upper_bound(B, B + M, i) - lower_bound(B, B + M, i) > 1){
			printf("0\n");
			return 0;
		}
		if(binary_search(A, A + N, i) && binary_search(B, B + M, i)) cnt = 1;
		else if(binary_search(A, A + N, i)) cnt = M - (lower_bound(B, B + M, i) - B);
		else if(binary_search(B, B + M, i)) cnt = N - (lower_bound(A, A + N, i) - A);
		else{
			cnt = (M - (lower_bound(B, B + M, i) - B)) * (N - (lower_bound(A, A + N, i) - A));
			flag = false;
		}
		if(!flag && cnt < (M * N - i)){
			printf("0\n");
			return 0;
		}
		if(flag) res *= (ll)cnt;
		else res *= (ll)(cnt - (M * N - i));
		res %= MOD;
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 128
import numpy as np
 
N = int(input())
 
A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(N)]
 
for i in range(N):
    A[i], B[i] = map(int, input().split())
    C[i] = A[i] + B[i]
 
C.sort(reverse=True)
 
ans = 0
 
for i in range(N):
    if i % 2 == 0:
        ans += C[i]
 
print(ans - sum(B))

Measured memory_bytes: 24552
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x; cin>>x;
	if (x<1200) cout<<"ABC";
	else cout<<"ARC"<<endl;
	return 0;
}

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

int main(){
    int n,k;cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];

    vector<int> dp(k+1,0);

    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(v[j]<=i){
                if(dp[i-v[j]]==0){
                    dp[i]=1;
                    break;
                }
            }
        }
    }
    //for(int i=0;i<=k;i++)cout<<dp[i]<<" ";
    if(dp[k]==1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

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

typedef long long ll;

vector<ll> a,p;

ll f(ll n, ll x){
	if(n==0){
		if(x<=0) return 0;
		else return 1;
	}
	else if(x<=1+a[n-1]) return f(n-1, x-1);
	else return p[n-1] + 1 + f(n-1, x-2-a[n-1]);
}
 
int main(int argc, char const *argv[])
{
	ll n,x;
	cin >> n >> x;
	a.resize(n);
	p.resize(n);
	a[0] = 1;
	p[0] = 1;
	for(ll i=1; i<n; i++){
		a[i] = 2 * a[i-1] + 3;
		p[i] = 2 * p[i-1] + 1;
	}
	cout << f(n,x) << endl;
	return 0;
}

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

int main() {
  int n, k, d, x;
  cin >> n >> k;

  map<int, int> p;

  for (int i = 0; i < k; i++) {
    cin >> d;
    vector<int> a(d);
    for (int j = 0; j < d; j++) {
      cin >> a[j];
      p[a[j]]++;
    }
  }

  cout << n - p.size() << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <vector>
#include <string>

class rect {
public:
    int H;
    int W;
    rect(int H_, int W_)
        : H(H_)
        , W(W_)
    {
    }
};

void printRect(int height, int width) {
    bool isOddRow = true;
    bool isBlack = true;

    for(int h = 0; h < height; h++){
        isBlack = isOddRow;
        for(int w = 0; w < width; w++){
            if(isBlack){
                printf("#");
            }else{
                printf(".");
            }
            isBlack = !isBlack;
        }
        printf("\n");
        isOddRow = !isOddRow;
    }
    printf("\n");
}

int main(int argc, char* argv[]){
    std::vector<rect> list;
    int H, W;
    while(true) {
       scanf("%d %d", &H, &W);
       if(H == 0 && W == 0) break;
       list.push_back(rect(H,W));
    }

    for(auto each: list) {
        printRect(each.H, each.W);
    }
}


Measured memory_bytes: 2600
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string str;
  bool c = false;
  bool f = false;
  
  cin >> str;
  
  int j;
  
  for(int i = 0 ; i < str.length() ; i++){
    if(str[i] == 'C'){
      for(j = i+1 ; j < str.length() ; j++){
        if(str[j] == 'F'){
          f = true;
          break;
        }
      }
      if(j != str.length()){
        c = true;
        break;
      }
    }
  }
  
  if(c && f) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;

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

  string a, b;
  cin >> a >> b;

  if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) cout << "YES" << "\n";
  else cout << "NO" << "\n";
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100+10;
int a[maxn][maxn];
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=100;++i)
		for(int j=1;j<=50;++j){
			a[i][j]=1;		
		}
	--n;--m;
	int x=1,y=1;
	while(n){
		a[x][y]=0;
		x+=2;
		if(x>100){
			x=1;
			y+=2;
		}
		--n;
	}
	x=1,y=100;
	while(m){
		a[x][y]=1;
		x+=2;
		if(x>100){
			x=1;
			y-=2;
		}
		--m;
	}
	cout<<100<<" "<<100<<endl;
	for(int i=1;i<=100;++i,cout<<endl)
		for(int j=1;j<=100;++j){
			if(a[i][j]) printf("#");
			else printf(".");
		}
	return 0;
}


Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library

#pragma endregion library

int main(){
    ll a;long double b; cin >> a >> b;
    ll ans=a*b;
    cout << ans << '\n';
    
}

Measured memory_bytes: 3748
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int f(int x){
	if(x%4==0)return x;
	if(x%4==1)return 1;
	if(x%4==2)return x+1;
	if(x%4==3)return 0;
}

int a,b;

main(){
	cin>>a>>b;
	dump(f(b)^f(a-1));
}

/*for(;;){
	cin>>a>>b;
	for(int i=a+1;i<=b;i++){
		a^=i;
	}
	dump(a);
	}*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
ll f[N],ans;
int main(){
	ll n,V;
	cin>>n>>V;
	ll w,v;
	memset(f,0x3f3f3f3f,sizeof(f));

	f[0]=0ll;
	for(int i=1;i<=n;i++){
		cin>>w>>v;
		for(int j=1e5;j>=v;j--){
			f[j]=min(f[j],f[j-v]+w);
			if(f[j]<=V) ans=max(ans,1ll*(j));
		}
	}
	cout<<ans;

}





Measured memory_bytes: 2560
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = list(input())

def ok(s):
    if S[0] != 'A':
        return False
    if S[-1] == 'C' or S[1] == 'C':
        return False

    if len(list(filter(lambda x : x == 'C', S[2:]))) != 1:
        return False


    if list(map(lambda x: x.lower() if x not in ['A', 'C'] else x, s)) != s:
        return False

    return True

print("AC" if ok(S) else "WA")

Measured memory_bytes: 3572
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k, q = LI()
A = LI()


def list_split(arr, x):
    ret = []
    d = []
    for v in arr:
        if v >= x:
            d += [v]
        elif d:
            ret += [d]
            d = []
    else:
        ret += [d]
    return ret


ans = INF
for e in set(A):
    y = []
    for arr in list_split(A, e):
        l = len(arr)
        if l >= k:
            y += sorted(arr)[:min(l - k + 1, q)]
    if len(y) >= q:
        ans = min(ans, sorted(y)[q - 1] - e)



print(ans)




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

def Solve():
    ans = 0
    for i in range(n):
        if V[i]:
            continue
        cur = i
        S, an = 0, 0
        m = VMAX
        while True:
            V[cur] = True
            an += 1
            v = A[cur]
            m = min(m, v)
            S += v
            cur = T[v]
            if V[cur]:
                break
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans

MAX = 1000
VMAX = 10000

n = int(input())
A = [int(x) for x in input().split()]
s = min(A)
B = sorted(A)
T = [0] * (VMAX + 1)
for i, b in enumerate(B):
    T[b] = i
V =[False] * MAX
ans = Solve()
print(ans)


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

int main()
{
	int N;
	cin >> N;
	bool ok = false;
	for (int i = 0; i * 4 <= N; i++) {
		ok |= (N - (i << 2)) % 7 == 0;
	}
	puts(ok ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b, c=0,k;
    cin>>a>>b>>k;
    lli ans=min(a, b);
    while(true){ 
        if(a%ans==0&&b%ans==0){ 
            c++;
        }
        if(c==k){ 
            break;
        }
        ans--;
    }

    out(ans);
}

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

void call(int n) {
    int i = 1;
    while (true) {
        int x = i;
        if (x % 3 == 0) {
            cout << ' ' << i;
        } else {
            while (true) {
                if (x % 10 == 3) {
                    cout << ' ' << i;
                    break;
                }
                x /= 10;
                if (!x) break;
            }
        }
        if (++i > n) break;
    }

    cout << endl;
}

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

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


int main(){
  ll n,k; cin >> n >> k;
  ll r,s,p; cin >> r >> s >> p;
  string t; cin >> t;
  ll ans = 0;
  for(ll i=0; i<n; i++){
    if(t.at(i)=='r')ans += p;
    else if(t.at(i)=='s')ans += r;
    else ans += s;
  }
  //cout << ans << endl;
  for(ll i=0; i<k; i++){
    char pre = t.at(i);
    ll next = i+k;
    //cout << ' ' << i << endl;
    while(next<n){
      //if(n<next)break;
      if(pre==t.at(next)){
        //cout << next << ' ' << t.at(next) << endl;
        if(pre=='r')ans -= p;
        else if(pre=='s')ans -= r;
        else ans -= s;
        if(n<=next+k)break;
        pre = t.at(next+k);
        next += 2*k;
      }else{//cout << "hoge";
            pre = t.at(next);next += k;
           //cout << "hage";
      }
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{

	int a,b;
	scanf( "%d%d", &a, &b);
	
	if( a < b)
	printf( "a < b\n");
	else if( a > b )
	printf( "a > b\n" );
	else
	printf( "a == b\n");
	
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

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

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

	int b[200001];
	for(int i=1;i<=n;i++) b[i] = 0;

	int m = 0;
	for(int i=n;i>=1;i--){
		int cnt = 0;
		for(int j=i*2;j<=n;j+=i) cnt += (b[j]==1 ? 1 : 0);
		b[i] += (cnt%2==a[i] ? 0 : 1);
		m += (cnt%2==a[i] ? 0 : 1);
	}
	cout << m << endl;
	for (int i = 1; i <= n; i++){
		if(b[i]) cout << i << " ";
	}
	if(m > 0)cout << endl;


		return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		int j = sc.nextInt();
		int k = sc.nextInt();
		int c[] = new int[k];
		int n = 0;
		for (int x = 1; x <= k; x++) {
			if (k % x == 0) {
				c[n++] = x;
			}
		}
		int m = 0;
		for (m = 0; m < n; m++)
			if (c[m] >= i) {
				break;
			}
		int l;
		for (l = n - 1; l >= 0; l--)
			if (c[l] <= j) {
				break;
			}
		System.out.printf("%d\n", l - m + 1);
		sc.close();
	}
}

Measured memory_bytes: 26444
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll=long long;

int main(){
	int n,a[100100],sum,ans=0;

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

	for(int i=0;i<n;i++)ans+=a[i]-1;
	cout<<ans;
}

		

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    cout<<fixed<<setprecision(10);

    int n;cin>>n;

    vector<double>v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(v.begin(),v.end());

    rep2(i,1,n){
        v[i]=(v[i-1]+v[i])*0.5;
    }
    cout<<v[n-1]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;cin>>A>>B>>C>>D;
  int count=0;
  for(int i=0;i<=100;i++){
    if(A<=i && i<=B && C<=i && i<=D)count++;
  }
  if(count>0)count--;
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

typedef long long int ll;
using namespace std;
   
ll GreatestCommonDivisor(ll p, ll q)
{
  while ( true )
  {
    ll yo = p % q;
    if ( yo == 0 ) return q;
    p = q;
    q = yo;
  }
  return q;
}
 
//最小公倍数
ll LeastCommonMultiple(ll a, ll b)
{
  return a / GreatestCommonDivisor(a,b) * b;
}
 
 
ll f(ll a)
{
  ll num = 0;
  while ( a > 0 )
  {
    if ( a % 2 == 1) return num;
    ++num;
    a = a / 2;
  }
  return num;
}
 

int main()
{
  ll n, m;
  cin >> n >> m;
  
  vector<ll> a(n);
  for ( auto& ai : a) {
    cin >> ai;
    ai /= 2;
  }
 
  //ai に 含まれる2の数を計算（同じでないと半公倍数は存在せず）
  ll c = f( a[0] );
  for ( int i = 1; i < n; ++i )
  {
    if ( c != f(a[i])) { 
      cout << 0;
      return 0;
    }
  }
 
  //a の最小公倍数を計算
  ll lcm = a[0], x = a[0];
  for ( ll i = 1; i < n; ++i )
  {
    lcm = LeastCommonMultiple(a[i], lcm);
    if ( lcm > m ) {
      cout << 0;
      return 0;
    }
  }

  cout << (m -lcm) / 2 / lcm + 1; 
  return 0;
}
 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	cout<<(n*n*n)<<endl;































	
}

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

int main(){
  int res;
  char c;
  cin >> res;
  while(cin >> c,c != '='){
    int tmp;
    cin >> tmp;
    if(c == '+'){
      res += tmp;
    }
    else if(c == '-'){
      res -= tmp;
    }
    else if(c == '*'){
      res *= tmp;
    }
    else if(c == '/'){
      res /= tmp;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1160
////////////////////////////////////////////////
//  ********  *      *    *******    * *      //                 :
//  *         *      *   *       *   *   *    //     64 BITS     C     64 BITS
//  *****     *      *  *         *  *     *  //                 +
//  *         *      *  ***********  *     *  //:  13 - 6 - 2020 +   13 - 6 - 2020 :
//  *         *      *  *         *  *   *    //                 1
//  *         ********  *         *  * *      //     64 BITS     7     64 BITS
////////////////////////////////////////////////                 :
#define ll long long
#define ui unsigned int
#define ud unsigned double
#define mp make_pair
#define pii pair<int, int>
#define pb push_back
#define pi acos(-1.0)
#define eps 1e-12
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <array>
#include <errno.h>
#include <stdlib.h>
#include <queue>
using namespace std;
int main()
{
    char c[4];
    scanf("%s", &c);
    if (c[0] == '7' || c[1] == '7' || c[2] == '7'){
        puts("Yes\n");
    }
    else{
        puts("No\n");
    }
    return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int h;
int w;
char field[20][21];
int cost[20][21];
int INF=100000;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
typedef pair<int,int> P;

void solve();
int bfs(int x,int y);
int main(){
  scanf("%d",&h);
  scanf("%d",&w);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf(" %c",&field[i][j]);
      cost[i][j]=INF;
    }
  }
  solve();
  return 0;
}

void solve(){
  int max_dist=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int distance = bfs(i,j);
      if(distance>max_dist){
        max_dist=distance;
      }
    }
  }
  printf("%d\n",max_dist);
}

int bfs(int x,int y){
  if(field[x][y]=='#'){
    return 0;
  }
  queue<P> que;
  que.push(P(x,y));
  int max_cost=0;
  cost[x][y]=0;
  while(que.size()){
    P p1 = que.front();que.pop();
    int sx = p1.first;
    int sy = p1.second;

    for(int i=0;i<4;i++){
      int nx = sx + dx[i];
      int ny = sy + dy[i];
      if(field[nx][ny]=='.' && 0<= nx && nx <h && 0<= ny && ny <w){
        if(cost[nx][ny]==INF){
          cost[nx][ny]=cost[sx][sy]+1;
          if(cost[nx][ny]>max_cost){
            max_cost=cost[nx][ny];
          }
          que.push(P(nx,ny));
        }
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cost[i][j]=INF;
    }
  }
  return max_cost;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<stack>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

struct task {
    string name;
    int time;
    task(string name, int time):name(name), time(time) {}
};

int main() {
    int n, q;
    queue<task> qu;
    cin >> n >> q;
    string name;
    int time;
    rep(i, n) {
        cin >> name >> time;
        qu.push(task(name, time));
    }
    int now = 0;
    while(!qu.empty()) {
        task t = qu.front();
        qu.pop();
        if(t.time > q) {
            now += q;
            t.time -= q;
            qu.push(t);
        }
        else {
            now += t.time;
            printf("%s %d\n", t.name.c_str(), now);
        }
    }

    return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  int count,i,h;
  count=0;
  for ( i=1 ; i<=N ; i++)
  {
    cin >> h;
    if (h>=K)
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    e[a].append(b)

q = defaultdict(int)
for i in range(Q):
    p, x = map(int, input().split())
    q[p] += x

seen = [False] * (N + 1)
ans = [0] * (N + 1)


def dfs(e, v, x):
    seen[v] = True
    ans[v] += x
    for next_v in e[v]:
        if seen[next_v]:
            continue
        else:
            dfs(e, next_v, x + q[next_v])


dfs(e, 1, q[1])
print(*ans[1:])


Measured memory_bytes: 257280
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		sc = null;
		int i;
		int cnt=0;
		int max=0;
		for(i=0; i<s.length(); i++) {
			if(s.charAt(i) == 'A'||
				s.charAt(i) == 'C'||
				s.charAt(i) == 'G'||
				s.charAt(i) == 'T') {
				cnt++;
			} else {
				cnt=0;
			}
			max=max(max,cnt);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
#define int long long
typedef pair<int,int> pii;
signed main(){
    int n; cin>>n;
    vector<vector<pii>>edge(n,vector<pii>());
    rep(i,n-1){
        int a,b,c; cin>>a>>b>>c;
        --a,--b;
        edge[a].push_back(pii(b,c));
        edge[b].push_back(pii(a,c));
    }
    int Q,k;
    cin>>Q>>k;
    priority_queue<pii,vector<pii>,greater<pii>>que;
    que.push(pii(0,--k));
    vector<int>d(n,LLONG_MAX/10);
    d[k]=0;
    while(!que.empty()){
        pii now=que.top(); que.pop();
        if(d[now.second]<now.first)continue;
        rep(i,edge[now.second].size()){
            pii next=edge[now.second][i];
            if(d[next.first]<now.first+next.second)continue;
            d[next.first]=now.first+next.second;
            que.push(pii(d[next.first],next.first));
        }
    }
    rep(i,Q){
        int s,e; cin>>s>>e;
        --s,--e;
        cout<<d[s]+d[e]<<endl;
    }
}

Measured memory_bytes: 11120
n, m = gets.split.map &:to_i
coins = gets.split.map &:to_i
t = Array.new(n+1, Float::INFINITY)
t[0] = 0
coins.each do |c|
  (c..n).each do |j|
    t[j] = [ t[j], t[j-c] + 1 ].min
  end
end
puts t[n]

Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
         while(true){
         int H = sc.nextInt();
         int W = sc.nextInt();
         if(H == 0 && W == 0){
             break;
         }
         for(int i = 0; i < H; i++){
             for(int j= 0; j < W; j++){
                 if(i == 0 || i == H - 1 || j == 0 || j == W - 1){
                 System.out.print("#");
                 }else{
                     System.out.print(".");
                 }
             }
             System.out.println("");
             }
             System.out.println("");
         }
}
}

Measured memory_bytes: 34364
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],sum[n];
    ll sum1=(n*(n+1))/2;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0)
        {
            sum[i]=a[i];
        }
        else
        {
            sum[i]=min(sum[i-1],a[i]);
        }
    }
    ll ans=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]==sum[i])
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}









Measured memory_bytes: 1792
import java.util.*;
    public class Main{
     	public static void main(String args[]){
        	Scanner s = new Scanner(System.in);
         	int n = s.nextInt();
          	int [] h = new int[n];
          for(int i =0;i<n;i++){
          	h[i]=s.nextInt();
          }
          int [] dp = new int [n+1];
          
          Arrays.fill(dp,Integer.MAX_VALUE);
          dp[1]=0;
                  
          for(int i =2;i<=n;i++){
            dp[i]=Math.min(dp[i-1]+Math.abs(h[i-1]-h[i-2]),dp[i]);
              if(i>=3)
            dp[i]=Math.min(dp[i-2]+Math.abs(h[i-1]-h[i-3]),dp[i]);               
        }
                   System.out.println( dp[n]);
     
     }  
    }

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int a, b;

	cin >> a >> b;


	if(a <= 5){
		cout << 0 << endl; return 0;
	}

	if(a <= 12){
		cout << b / 2 << endl; return 0;
	}


	cout << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort( a , a + 3 );
	cout << a[1] - a[0] + a[2] - a[1];
}


Measured memory_bytes: 3664
n = int(input())
mod = 10**9 + 7
acgt = ["A", "C", "G", "T"]
dp = {acgt[i]+acgt[j]+acgt[k]: 1 for i in range(4) for j in range(4) for k in range(4)}
dp["AGC"] = 0
dp["ACG"] = 0
dp["GAC"] = 0

for i in range(n-3):
    next_dp = {key: 0 for key in dp.keys()}
    for key, val in dp.items():
        for item in acgt:
            next_key = key + item
            if next_key[1:] == "AGC" or next_key[1:] == "ACG" or next_key[1:] == "GAC":
                continue
            elif next_key[0] + next_key[2:] == "AGC" or next_key[:2] + next_key[3] == "AGC":
                continue
            else:
                next_dp[next_key[1:]] = (next_dp[next_key[1:]] + val) % mod
    dp = next_dp
print(sum(dp.values()) % mod)

Measured memory_bytes: 40176
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

llint n;
string s[1000005];
int lb[1000005], add[1000005];
vector<P> pvec[1000005], nvec[1000005];
bool used[1000005];

bool calc(vector<P> vec[])
{
	priority_queue<P> Q;
	llint h = 0, pre = 0;
	for(int i = 0; i < vec[0].size(); i++) Q.push(vec[0][i]);
	
	while(Q.size() > 0){
		llint id = Q.top().second;
		Q.pop();
		if(lb[id] > h) return false;
		used[id] = true;
		h += add[id];
		if(pre < h){
			for(int i = pre+1; i <= h; i++){
				for(int j = 0; j < vec[i].size(); j++) Q.push(vec[i][j]);
			}
			pre = h;
		}
	}
	return true;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s[i];
	
	llint sum = 0;
	for(int i = 1; i <= n; i++){
		llint h = 0, mn = 0;
		for(int j = 0; j < s[i].size(); j++){
			if(s[i][j] == '(') h++;
			else h--;
			mn = min(mn, h);
		}
		sum += h;
		
		if(h >= 0){
			lb[i] = -mn, add[i] = h;
			pvec[lb[i]].push_back(P(add[i], i));
		}
		else{
			mn -= h;
			lb[i] = -mn, add[i] = -h;
			nvec[lb[i]].push_back(P(add[i], i));
		}
	}
	if(sum != 0){
		cout << "No" << endl;
		return 0;
	}
	
	if(!calc(pvec) || !calc(nvec)){
		cout << "No" << endl;
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		if(!used[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 121764
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const ll INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
    ll n;
    cin>>n;
    map<string,ll> mp;
    rep(i,n){
        string str;
        cin>>str;
        mp[str]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3632
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left >= n && right >= n) return;
    if (left < n && arr[left] > arr[i]) largest = left;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110712
N = int(input())
W = []
for i in range(N):
    X = input()
    W.append(X)
    if i >= 1:
        if W[i-1][len(W[i-1])-1] != W[i][0]:
            print("No")
            exit()
    for j in range(i):
        if W[i] == W[j]:
            print("No")
            exit()
else:
    print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> gr[100005];
vector<int> path;
set<int> br;
int co;
int fi(int x,int co,int xx){
  //cout << x << endl;
  if(x==0){
    path.push_back(x);
    return 1;
  }
  for(int i=0;i<gr[x].size();i++){
    if(gr[x][i]==xx)continue;
    int p=fi(gr[x][i],co+1,x);
    if(p==1){
      path.push_back(x);
      return 1;
    }
  }
  return 0;
}
void cobr(int x,int bre,int xx){
  // cout << x << endl;
  if(x==bre)return;
  if(br.count(x)==0){
    co++;
    br.insert(x);
    //cout << x << endl;
    
  }
  else return;
  for(int i=0;i<gr[x].size();i++){
    if(gr[x][i]==xx)continue;
    cobr(gr[x][i],bre,x);
    
  }
}


      
int main(){
  cin >> n;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  fi(n-1,0,-1);
  int cango=path.size()/2+path.size()%2;
  //
  // for(int i=0;i<path.size();i++){
  // cout << path[i] << "path"<< endl;
  //}
  //
  //cout << path[cango] << "cantgo"<< endl;
  cobr(0,path[cango],-1);
  //cout << co << endl;
  if(co*2>n)cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 13176
io = STDIN
n=io.gets.to_i
if n<=9
  puts n
elsif n<=99
  puts 9
elsif n<999
  puts n-99+9
elsif n<=9999
  puts 999-99+9
elsif n<=99999
  puts n-9999+999-99+9
else
  puts 99999-9999+999-99+9
end


Measured memory_bytes: 1788
n,k=map(int, input().split()) 
r,s,p=map(int, input().split()) 
T = str(input())
box = ["e" for i in range(len(T))]

for i in range(len(T)):
    if T[i] == "r":
        if box[i-k] != "p":
            box[i] = "p"
        else:
            box[i]="e"
    elif T[i]=="s":
        if box[i-k] != "r":
            box[i] = "r"
        else:
            box[i]="e"
    else:
        if box[i-k] != "s":
            box[i] = "s"
        else:
            box[i]="e"
for i in range(len(T)):
    if box[i] == "r":
        box[i]=r
    elif box[i]=="s":
        box[i]=s
    elif box[i]=="p":
        box[i]=p
    else:
        box[i]=0
print(sum(box))


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

void solve() {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}



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

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  for(ll i=0;i<s.size();i++) {
    if('z'-s[i]<k&&s[i]!='a') {
      k-='z'-s[i]+1;
      s[i]='a';
    }
  }
  k%=26;
  if(k>0) {
    s[s.size()-1]=char(s[s.size()-1]+k);
    k=0;
  }
  cout << s << endl;
}

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

#define mp make_pair
#define pb push_back 
#define pf push_front 
#define pbp pop_back
#define pfp pop_front 
#define sz(x) x.size()
#define all(x) x.begin(),x.end() 
#define ios_base ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define open(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9+7;
const int N = 1e5+123;
const int inf = 1e9+123;
const long long INF = 1e18;
const double eps = 1e-5;
                 
ll a, b, c;
ll ans;
int main () {        
	ios_base       
	cin >> a >> b >> c;
	ans = ((a-a/2)*b*c) -(a/2*b*c);
	ans = min(ans, min( ((b-b/2)*a*c) -(b/2*a*c), ((c-c/2)*b*a) -(c/2*b*a) ) );
	cout << ans;
	return 0; 
}
 


Measured memory_bytes: 256