akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    for(int i=0;i<b;i++)
    {
        for(int j=0;j<w;j++)
            cout<<(j<a);
        cout<<endl;
    }
    for(int i=0;i<h-b;i++)
    {
        for(int j=0;j<w;j++)
            cout<<(j>=a);
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {
	int n;
	cin >> n;
	int a[105];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int p = 0;
	for (size_t i = 0; i < n; i++)
	{
		int m = a[i];
		int j = -1;
		for (int k = i + 1; k < n; k++)
		{
			if (m > a[k]) {
				m = a[k];
				j = k;
			}
		}
		if (0 <= j) {
			p++;
			swap(a[i], a[j]);
		}
	}
	for (size_t i = 0; i < n; i++)
	{
		if (i > 0) cout << " ";
		cout << a[i];
	}

	cout << endl;
	cout << p << endl;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



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

#define int long long

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

	int n;
	cin >> n;
	set<string> s;
	for(int i = 0; i < n; i++) {
		string a;
		cin >> a;
		s.insert(a);
	}	
	cout << s.size() << '\n';

	return 0;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int Q,H,S,D,N;
    cin >> Q >> H >> S >> D >> N;
    long long value = 0;
    long long v1 = min(Q*4,min(H*2,S));
    long long v2 = min(Q*8,min(H*4,min(S*2,D)));
    for(;N>1;N-=2,value+=v2);
    if(N==1)value += v1;
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	int n, d;
	scanf("%d %d", &n, &d);
	int **x;
	x = malloc(sizeof(int*) * n);
	for(int i = 0; i < n; i++){
		x[i] = malloc(sizeof(int) * d);
		for(int j = 0; j < d; j++)
			scanf("%d", x[i] + j);
	}
	int count = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < i; j++){
			double res = 0;
			for(int k = 0; k < d; k++)
				res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			res = sqrt(res);
			if(res - (int)res <= 1e-6)count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define fo(i,j,k) for(int i=j;i<=k;++i)
#define fd(i,j,k) for(int i=j;i>=k;--i)
#define ll long long
using namespace std;
const int N=1e5+10;
int p[N],q[N];
ll a[N],an[N];
bool vis[N];
int z[N];
int main()
{
	int n;
	scanf("%d",&n);
	fo(i,1,n) scanf("%lld",&a[i]);
	fd(i,n,1) a[i]-=a[i-1],p[i]=i;
	int m;
	ll k;
	scanf("%d %lld",&m,&k);
	while(m--){
		int x;
		scanf("%d",&x);
		swap(p[x],p[x+1]);
	}
	fo(i,1,n) if(!vis[i]){
		z[0]=0;
		for(int j=i;!vis[j];j=p[j]) z[++z[0]]=j,vis[j]=1;
		int t=1-k%z[0];
		t<=0?t+=z[0]:t;
		fo(i,1,z[0]) q[z[i]]=z[t],t=t%z[0]+1;
	}
	fo(i,1,n) an[q[i]]=a[i];
	fo(i,1,n) an[i]+=an[i-1],printf("%lld.0\n",an[i]);
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    str s, t;
    cin >> s >> t;
    fi(0, s.size()) {
    	if (s[i] != t[i]) {
    		cout << "No\n";
    		return 0;
    	}
    }
    cout << "Yes\n";
}

Measured memory_bytes: 3652
import math
import itertools

N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
Al = [0]*M
for i in range(M):
    Al[i] = i + 1
All = list(itertools.combinations_with_replacement(Al, N))

ans = 0

for A in All:
    wa = 0
    for i in range(Q):
        kari = A[b[i]-1] - A[a[i] - 1]
        if kari == c[i]:
            wa = wa + d[i]
    if ans < wa:
        ans = wa
print(ans)

Measured memory_bytes: 21448
#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
#define all(x) (x).begin(), (x).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define eb emplace_back
#define pii pair<int, int>

using namespace std;

const int mxn = 1e5 + 5;
int n, w, wv[105][2], dp[105][mxn] = {};

int recurse(int idx, int wt)
{
    if (idx == n)
        return 0;
    if (dp[wt][idx] != -1)
        return dp[wt][idx];
    int ans = 0;
    if (wv[idx][0] <= wt)
        ans = max(ans, recurse(idx + 1, wt - wv[idx][0]) + wv[idx][1]);
    ans = max(ans, recurse(idx + 1, wt));
    return dp[wt][idx] = ans;
}

void solve()
{
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
        cin >> wv[i][0] >> wv[i][1];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            if (i == 0 || j == 0)
                dp[i][j] = 0;
            else if (wv[i][0] > j)
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j - wv[i][0]] + wv[i][1], dp[i - 1][j]);
        }
    }
    cout << dp[n][w];
}

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

Measured memory_bytes: 82480
def main():
    X = [int(input()) for _ in range(5)]
    k = int(input())
    for i in range(5):
        for j in range(i+1, 5):
            if X[j] - X[i] > k:
                print(":(")
                return
    print("Yay!")


if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int nn;
	cin >> nn;
	string s;
	cin >> s;
	char n = nn + 'A';
	for(char c : s) {
		cout << (char)((c + n) % 26 + 'A');
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main()
{
   string s,s1,s2;
   cin>>s;
   s1.clear();
   s1=s1+s[0];
   int ans=1;
   for(int i=1;i<s.length();i++)
   {
       s2.clear();
       s2=s2+s[i];
       if(s1==s2)
       {
           i++;
           if(i==s.length())
            ans--;
           s2+=s[i];

       }
       s1=s2;
       ans++;
   }
   printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, K; cin >> N >> K;
    
    uint idx;
    for(uint i=1; i<=N; ++i){
        uint num; cin >> num;
        if(num==1){ idx=i; }
    }
    
    double n_before = ceil((double)(idx-1)/(double)(K-1));
    int len_filled = n_before * (K-1) + 1;
    int len_left = N - len_filled;
    
    double n_after  = ceil((double)(len_left)/(double)(K-1));
    
    cout << (int)(n_before+n_after) << endl;
    
    return 0;
}
/*
case: 4
3 3
2 1 3
>> ans == 1
*/
/*
case: 5
7 3
2 1 3 4 5 6 7
>> ans == 3
*/
/*
case: 6
8 7
2 3 4 5 6 7 8 1
>> ans == 2
*/

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	fmt.Println(strings.ToUpper(string(a[0])) + strings.ToUpper(string(b[0])) + strings.ToUpper(string(c[0])))
}


Measured memory_bytes: 640
s = input()
s_len = len(s)
if s[0] == "A":
    if s[2:s_len-1].count("C") == 1:
        dum = s.index("C")
        s = s[1:dum]+s[dum+1:s_len]
        if s == s.lower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int64_t n, l;
    cin >> n >> l;

    vector<int64_t> as(n);
    for (auto& a : as)
    {
        cin >> a;
    }

    bool success = false;
    int index = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (as[i] + as[i + 1] >= l)
        {
            success = true;
            index = i;
            break;
        }
    }
    if (!success)
    {
        cout << "Impossible" << endl;
    }
    else
    {
        cout << "Possible" << endl;
        for (int i = 0; i < index; i++)
        {
            cout << (i + 1) << endl;
        }
        for (int i = n - 2; i > index; i--)
        {
            cout << (i + 1) << endl;
        }
        cout << (index + 1) << endl;
    }
}


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

using namespace std;

int main(){
  int n, m, x;
  string s;
  string t="kogakubu10gokan";
  bool is=false;
  cin >> n >> m;
  for(int i=0; i<n; ++i){
    cin >> x >> s;
    if(is) continue;
    if(x>m){ is=true; continue; }
    t=s;
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 1208
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,ll >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define MAXN 100100
using namespace std;

ll n;
priority_queue<pii >pq;
int ok[MAXN];

int main()
{
	
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)ok[i]=INF;
	
	
	
	pq.push(mp(-1,-1));
	ok[1]=1;
	
	while (!pq.empty())
	{
		pii u=pq.top();
		pq.pop();
		u.first*=(-1);
		u.second*=(ll)(-1);
		if((u.second)%n==0)
		{
			printf("%d\n",u.first);
			return 0;
		}
		
		if(u.first+1<ok[(u.second+1)%n])
		{
			ok[(u.second+1)%n]=u.first+1;
			pq.push(mp(-(u.first+1),-((u.second+1)%n)));
		}
		if(u.first<ok[(u.second*10)%n])
		{
			ok[(u.second*10)%n]=u.first;
			pq.push(mp(-(u.first),-((u.second*10)%n)));
		}

	}
	
	

	return 0;	
} 

Measured memory_bytes: 1784
#include <stdio.h>
 
#define OVER_SIX_DIGITS 1000000
 
int sosuu_num[OVER_SIX_DIGITS];
 
void make_sosuu_num_list(void) {
    int i,j;
    for(i=0;i<OVER_SIX_DIGITS;i++)sosuu_num[i]=1;
    sosuu_num[0]=sosuu_num[1]=0;
    for(i=2;i<OVER_SIX_DIGITS;i++) {
        if(sosuu_num[i]) {
            for(j=i+i;j<OVER_SIX_DIGITS;j+=i)sosuu_num[j]=0;
        }
    }
    for(i=1;i<OVER_SIX_DIGITS;i++)sosuu_num[i]+=sosuu_num[i-1];
}
 
int main(void) {
    int n;
    make_sosuu_num_list();
    while(scanf("%d",&n)==1) {
        printf("%d\n",sosuu_num[n]);
    }
    return 0;
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
double dist(double x1, double y1, double x2, double y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}
int main() { // 問題文はしっかり読め!!!
	int x, y, h, w;
	cin >> x >> y >> h >> w;
	double radl = 30.0 * h + 0.5 * w;
	double rads = 6.0 * w;
	double x1 = x * sin(radl / 180.0 * pi);
	double y1 = x * cos(radl / 180.0 * pi);
	double x2 = y * sin(rads / 180.0 * pi);
	double y2 = y * cos(rads / 180.0 * pi);
	output(dist(x1, y1, x2, y2), 20);
	return 0;
}

Measured memory_bytes: 4164
A,B = map(int,input().split())
S = input()
mae = S[:A]
haihun = S[A]
usiro = S[(A+1):]
ans = True
if (len(mae)==A)&(haihun =="-")&(len(usiro) == B)&(len(S) == A+B+1):
    ans = True
for i in range(len(mae)):
    if mae[i] == "-":
        ans = False
for i in range(len(usiro)):
    if usiro[i] == "-":
        ans = False
if haihun != "-":
    ans = False

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

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

        String S = sc.next();
        sc.close();
        int N = S.length();
        char[] course = new char[N];
        course = S.toCharArray();
        boolean north = false;
        boolean south = false;
        boolean east = false;
        boolean west = false;
        for (int i = 0; i < N; i++) {
            if (course[i] == 'N') {
                north = true;
            }
            else if (course[i] == 'W') {
                west = true;
            }
            else if (course[i] == 'S') {
                south = true;
            }
            else {
                east = true;
            }
            if (north && south && east && west) {
                break;
            }
        }
        if (north == south && east == west) {
            out.printf("Yes\n");
        } else {
            out.printf("No\n");
        }
        out.flush();
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<cstdlib>

using Int = long long;
const Int INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; }return false;}

int main() {

	Int N, K;
	std::cin >> N >> K;

	std::vector<Int> h(N + K, 0);
	for (Int i = 0; i < N; i++)std::cin >> h[i];

	std::vector<Int> dp(N + K, INF);
	dp[0] = 0;

	for (Int i = 0; i < N; i++) {

		for (Int j = 1; j <= K; j++) {
			chmin(dp[i + j], dp[i]+std::abs(h[i] - h[i + j]));
		}
		
	}

	std::cout << dp[N - 1] << std::endl;

}

Measured memory_bytes: 1792
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner

fun main(args: Array<String>){
    val scn = Scanner(System.`in`)
    val str = scn.nextLine()
    val reverse = str!!.reversed()
    val n = str.length

    if(n % 2 == 0 || n !in 3..99){
        print("No")
        return
    }

    val regex = Regex("[a-z]*")
    if(!regex.matches(str)){
        print("No")
        return
    }



    if(str!=reverse){
        print("No")
        return
    }

    val mae = str.substring(0..(((n-1)/2)-1))
    val reverseMae = mae.reversed()

    if(mae!=reverseMae){
        print("No")
        return
    }

    val ushiro = str.substring((((n+3)/2)-1)..(n-1))
    val reverseUshiro = ushiro.reversed()

    if(ushiro!=reverseUshiro){
        print("No")
        return
    }


    print("Yes")
}

Measured memory_bytes: 29692
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int n,s[100],sum=0,a[100];
int output=0;
void fun(int i,int sum);
bool mem[110][10000];//
int main(){
	/*for(int i=0;i<100;i){
		s[i]=-1;
	}*/
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		//sum+=s[i];
	}
	//sort(s,s+n);
	/*for(int i=0;i<n;i++){
		a[i]=0;
	}*/
	fun(0,0);
	cout<<output<<endl;
	return 0;
 
}
void fun(int i,int sum){
	if(mem[i][sum])return;
	if(output<sum&&sum%10!=0) output=sum;
	if(i==n) return;
	fun(i+1,sum+s[i]);
	fun(i+1,sum);
	mem[i][sum]=true;
}

Measured memory_bytes: 1024
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define pf       push_front
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    string s;
    cin >> s;

    int q;
    cin >> q;

    deque<char> d;

    for(int i = 0; i < sz(s); i++) d.pb(s[i]);

    bool f = true;

    while(q--){

        int a;
        cin >> a;

        if(a == 1) f = !f;
        else{

            int c;
            cin >> c;

            char b;
            cin >> b;

            if(c == 1){
                if(f) d.pf(b);
                else d.pb(b);
            }
            else{
                if(f) d.pb(b);
                else d.pf(b);
            }
        }
    }

    if(f){
        while(!d.empty()){
            cout << d.front();
            d.pop_front();
        }
    }
    else{
        while(!d.empty()){
            cout << d.back();
            d.pop_back();
        }
    }
}


Measured memory_bytes: 4060
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i =0;i<n;i++){
            a[i] = sc.nextInt();
        }
        int count =0;
        while(test(a)){
            for(int i =0;i<a.length;i++){
                a[i] /= 2;
            }
            count ++;
        }
        System.out.println(count);
    }
    public static boolean test(int[] a){
        for(int i =0;i<a.length;i++){
            if(a[i]%2!=0){
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

   ll n;
   cin >> n;
   vector <ll> v(n + 1);

   for (ll i = 1; i <= 200; i++) {
      for (ll j = 1; j <= 200; j++) {
         for (ll k = 1; k <= 200; k++) {
            ll x = i * i + j * j + k * k + i * j + j * k + k * i;
            if (x <= n)
               v[x]++;
         }
      }
   }

   for (ll i = 1; i <= n; i++)
      cout << v[i] << '\n';

   return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define I ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    ll n,i,j,x=-1,ans=0;
    cin>>n;
    ll a[n],b[n],c[n-1];
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n;i++)cin>>b[i];
    for(i=0;i<n-1;i++)cin>>c[i];
    for(i=0;i<n;i++)
    {
        if(x==a[i]-1)ans+=c[a[i]-2];
        ans+=b[a[i]-1];
        x=a[i];
     //   cout<<ans<<" ";
    }
    cout<<ans;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int N,M;
  cin>>N>>M;
  cout<<(N*(N-1)/2+M*(M-1)/2)<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
dic_h = defaultdict(int)
dic_h[0] = 9999999999
dic_h[1] = 8

t = int(input())

cnt = 0
def tk(v,a,b,c,d):
    global cnt,dic_h
    if dic_h[v] != 0 :
        return dic_h[v]
    
    pas1 = v // 2
    if v == 2 :
        pas2 = 0  #無限ループ阻止のため
    else:
        pas2 = pas1 + 1 # vが2の時無限ループになる
    pam1 =  v % 2 
    pam2 = 2 - pam1
    pbs1 = v // 3
    pbs2 = pbs1 + 1
    pbm1 = v % 3 
    pbm2 = 3 -pbm1  
    pcs1 = v // 5
    pcs2 = pcs1 +  1
    pcm1 = v % 5 
    pcm2 = 5 - pcm1

    koho_a1 = tk(pas1,a,b,c,d) + pam1*d + a
    koho_b1 = tk(pbs1,a,b,c,d) + pbm1*d + b
    koho_c1 = tk(pcs1,a,b,c,d) + pcm1*d + c
    koho_a2 = tk(pas2,a,b,c,d) + pam2*d + a
    koho_b2 = tk(pbs2,a,b,c,d) + pbm2*d + b
    koho_c2 = tk(pcs2,a,b,c,d) + pcm2*d + c
    
    ret = min(v*d,koho_a1,koho_a2,koho_b1,koho_b2,koho_c1,koho_c2 ) 
    dic_h[v] = ret
    #print(v,ret)
    return ret

for i in range(t):
    n,a,b,c,d = map(int,input().split())
    #print(n,a,b,c,d)
    dic_h = defaultdict(int)
    dic_h[0] = 9999999999    
    dic_h[1] = d
    print(tk(n,a,b,c,d))


Measured memory_bytes: 96976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n;
  cin>>n;
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  int ans=0;
  int mx=0;
  int cnt=0;
  rep(i,5100){
    if(cnt==n){
      break;
    }
    cnt=0;
    rep(j,n){
      if(h[j]==0){
        cnt++;
        continue;
      }
      ans++;
      if(h[j]!=0){
        while(h[j]!=0){
          h[j]--;
          j++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

// int sousa(vector<int> a, int cnt) {
// 	bool x2 = false;
// 	REP(i, a.size()) {
// 		if(x2 || a[i]&1) a[i] = a[i]*3;
// 		else {
// 			a[i] = a[i]/2;
// 			x2 = true;
// 		}
// 	}

// 	if (!x2) return cnt;
// 	else return sousa(a, cnt+1);
// }

int x2cnt(int n, int cnt) {
	if(n&1) return cnt;
	return x2cnt(n/2, cnt+1);
}

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

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

	int cnt=0;
	REP(i,n) {
		cnt += x2cnt(a[i], 0);
	}

	cout << cnt;
}

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

int main() {
	int n,m,i,j,k,ans,cur,res;
	cin >> n >> m >> i;
	if(n+m+i<=21){
		cout << "win";
	}else{
		cout << "bust";
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct node{
	int v,id;
} a[100010];
bool cmp(node t,node b)
{
	return t.v<b.v;
}
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i].v;
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;++i)
	{
		int del=abs(a[i].id-i);
		if(del&1) ans++;
	}
	cout<<ans/2;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

    int N = sc.nextInt();

    int[] V = new int[N];
    for (int i = 0; i < N; i++) {
      V[i] = sc.nextInt();
    }
    int[] C = new int[N];
    for(int i = 0; i < N; i++){
      C[i] = sc.nextInt();
    }

    int X = 0;
    int Y = 0;

    for (int i = 0; i < N; i++) {
      if(V[i] > C[i]){
        X += V[i];
        Y += C[i];
      }
    }

    System.out.println(X - Y);

  }
}


Measured memory_bytes: 22612
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int i,sum=0,a,b,c,x,y,z;
	cin>>a>>b>>c;
	bool f=false;
	for(i=0;i<1000;i++){
	if(a%2!=0||b%2!=0||c%2!=0){
	f=true;break;}
		
		x=a;y=b;z=c;
		a=(y+z)/2;
		b=(x+z)/2;
		c=(x+z)/2;
		
	}
	if(f)
	cout<<i;
	else cout<<"-1";
}

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

int main()
{
    int n, l, ar[100];

    scanf("%d %d", &n, &l);

    for(int i=0; i<n; i++)
    {
        scanf("%d", &ar[i]);
    }

    sort(ar, ar+n);

    int sum = 0;

    for(int i=n-1; i>=(n-l); i--)
    {
        sum = sum + ar[i];
    }

    printf("%d\n", sum);

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DAnInvisibleHand solver = new DAnInvisibleHand();
    solver.solve(1, in, out);
    out.close();
  }

  static class DAnInvisibleHand {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int t = in.nextInt();
      ArrayList<Integer> al = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        al.add(in.nextInt());
      }
      al.add(0);
      int maxDif = 0;
      int tmpLow = al.get(0);
      int cnt = 0;
      int tmpDif = 0;
      for (int i = 1; i < al.size(); i++) {
        if (tmpLow > al.get(i)) {
          tmpLow = al.get(i);
          if (maxDif < tmpDif) {
            maxDif = tmpDif;
            cnt = 1;
          } else if (maxDif == tmpDif) {
            cnt++;
          }
          tmpDif = 0;
        } else {
          tmpDif = Math.max(tmpDif, al.get(i) - tmpLow);
        }
      }

      out.println(cnt);

    }

  }
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;
int dp[305][305][305];
int mn[305][4], mx[305][4];
int n, m;
bool check(int n, int R, int G, int B){
    for(int j=1;j<=3;j++){
        int cnt1 = 0, cnt2 = 0;
        if(mx[n][j] == -1) continue;
        if(R >= mx[n][j]) cnt1++;
        if(G >= mx[n][j]) cnt1++;
        if(B >= mx[n][j]) cnt1++;

        if(R >= mn[n][j]) cnt2++;
        if(G >= mn[n][j]) cnt2++;
        if(B >= mn[n][j]) cnt2++;

        if(cnt1 == j && cnt2 == j) continue;
        return 0;
    }
    return 1;
}
int dfs(int R, int G, int B){
    if(dp[R][G][B] != -1) return dp[R][G][B];
    int mx = max(R, max(G, B));
    if(mx == n) return 1;

    int ans = 0;
    if(check(mx+1, mx+1, G, B)) ans = (ans + dfs(mx+1, G, B))%mod;
    if(check(mx+1, R, mx+1, B)) ans = (ans + dfs(R, mx+1, B))%mod;
    if(check(mx+1, R, G, mx+1)) ans = (ans + dfs(R, G, mx+1))%mod;
    return dp[R][G][B] = ans;
}

int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &m);

    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++) mn[i][j] = 1e9, mx[i][j] = -1;
    }
    for(int i=1;i<=m;i++){
        int l, r, x;
        scanf("%d%d%d", &l, &r, &x);
        mn[r][x] = min(mn[r][x], l);
        mx[r][x] = max(mx[r][x], l);
    }
    printf("%d\n", dfs(0, 0, 0));
}

Measured memory_bytes: 111232
N,Y=map(int,input().split())
for i in range(N+1):
  for j in range(N-i+1):
    if Y==10000*i+5000*j+1000*(N-i-j):
      print("{} {} {}".format(i,j,N-i-j))
      exit()
print("-1 -1 -1")

Measured memory_bytes: 40684
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

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

	N = N % 10;

	if (N == 3) {
		cout << "bon" << endl;
	}
	else if (N == 0 || N == 1 || N == 6 || N == 8) {
		cout << "pon" << endl;
	}
	else cout << "hon" << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <math.h>
#include <list>
#include <cmath>
#include <queue>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

void rev(vector<ll> &x)
{
    reverse(x.begin(), x.end());
}

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

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll max(ll x, ll y)
{
    if (x > y)
    {
        return x;
    }
    else
    {
        return y;
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

void primeFactors(ll n, vector<ll> &vec)
{

    while (n % 2 == 0)
    {
        vec.push_back(2);
        n = n / 2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            vec.push_back(i);
            n = n / i;
        }
    }

    if (n > 2)
        vec.push_back(n);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

ll g(ll x)
{
    for (ll i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

void solve()
{
    ll n;
    cin >> n;
    float x = n;
    if (n == 1 || n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000)
    {
        cout << 10;
    }
    else
    {
        ll s = 0;
        while (n / 10 != 0)
        {
            s += n % 10;
            n /= 10;
        }
        s += n;
        cout << s;
    }
}
int main()
{

    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

//0 3 1 0 5 2 6
//0 0 1 2 3 5 6

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)


const int N=2e6+5;
const int mod=1e9+7;

int n,ar[N];

int main(){
      cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
      cin>>n;
      multiset<int> st;
      for(int i=1;i<=n;i++){
            cin>>ar[i];
            st.insert(ar[i]);
      }

      int ans=0;
      for(int i=1;i<=n;i++){
            vi facs;
            for(int j=1;j*j<=ar[i];j++){
               if(ar[i]%j==0) {
                     facs.push_back(j);
                     facs.push_back(ar[i]/j);
               }
            }
            st.erase(st.find(ar[i]));
            for(auto x: facs) if(st.find(x)!=st.end()){
                  ans++;
                  break;      
            }
            st.insert(ar[i]);
      }

      cout<<n-ans;
      return 0;
}

Measured memory_bytes: 13816
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define unordered_map umap
typedef long long ll;
typedef long double ld;
ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}
bool isPrime(int n){if(n<2){return false;}for(int i=2;i<sqrt(n)+1;i++){if(n%i==0) return false;}return true;}

int main(){
  int N; cin >>N;
  int f[N][10]; CINA2(f,N,10);
  ll p[N][11]; CINA2(p,N,11);
  
  int count[N];
  ll r;
  ll r_max = -pow(10,20);
  for(int i=1;i<pow(2,10);i++){
    INIT(count,N,0);
    r = 0;
    int temp = i;
    REP(j,5){
      if(temp&1){
        REP(k,N){
          count[k] += f[k][j*2];
        }
      }
      temp = temp>>1;
      if(temp&1){
        REP(k,N){
          count[k] += f[k][j*2+1];
        }
      }
      temp = temp>>1;
    }
    REP(i,N){
      r += p[i][count[i]];
    }
    if(r_max<r){r_max = r;}
    
  }
  cout << r_max << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
const int maxn=1e5+10;
char ch[maxn];
int ans;
int main(){
	cin>>ch;
	for(int i=1;i<strlen(ch);i++)
		if(ch[i]!=ch[i-1])
		 ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
import fractions
from functools import reduce
n = int(input())
t = [int(input()) for _ in range(n)]

def gcd(numbers):
  return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm(numbers):
  return reduce(lcm_base, numbers, 1)

print(lcm(t))

Measured memory_bytes: 5204
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        if (a < b) {
            ans += b;
            b--;
        } else {
            ans += a;
            a--;
        }
        if (a < b) {
            ans += b;
            b--;
        } else {
            ans += a;
            a--;
        }
        System.out.println(ans);
        sc.close();

    }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct Vertex {
    vector<lint> edge;
    bool visited;
    lint dist;
};

vector<Vertex> g;
map<lint, lint> color[100000];

lint dfs(lint node, lint from, lint prev) {
    lint c = 1;
    for(lint next : g[node].edge) {
        if(next == from)  continue;
        if(c == prev)  c++;
        color[node][next] = c;
        color[next][node] = c;
        dfs(next, node, c);
        c++;
    }
}

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

    g.resize(n);
    vector<pair<lint, lint>> edge;

    for(lint i=0; i<n-1; i++) {
        lint a, b;
        cin >> a >> b;
        a--, b--;
        edge.emplace_back(a, b);
        g[a].edge.push_back(b);
        g[b].edge.push_back(a);
    }

    dfs(0, -1, 1e18);

    vector<lint> ans;
    for(auto e : edge) {
        lint from, to;
        tie(from, to) = e;
        ans.push_back(color[from][to]);
    }

    cout << *max_element(begin(ans), end(ans)) << endl;
    for(auto& e : ans)  cout << e << endl;
}

Measured memory_bytes: 28656
#include<iostream>
#include<stdio.h>
#include<string.h>
#define LEN 100005
typedef struct pp
{
    char name[100];
    int t;

}P;
P Q[LEN];
int head,tail,n;
void enqueue(P x)
{
    Q[tail]=x;
    tail=(tail+1)%LEN;
}
P dequeue()
{
    P x=Q[head];
    head=(head+1)%LEN;
    return x;
}
int min(int a,int b){return a<b?a:b;}
int main()
{
    int elaps=0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);
    for(i=1;i<=n;i++)
    {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head=1;
    tail=n+1;
    while(head!=tail)
    {
        u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps+=c;
        if(u.t>0)enqueue(u);
        else{
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}

Measured memory_bytes: 13360
n = input()
A = list(map(int, input().split()))

def Chk(a, pos):
    cnt = 0
    tmp = 0

    for a in A:
        tmp += a

        if pos and tmp < 1:
            cnt += 1 - tmp
            tmp = 1
        elif not pos and tmp > -1:
            cnt += 1 + tmp
            tmp = -1

        pos = not pos
    return cnt

print(min(Chk(A, True), Chk(A, False)))

Measured memory_bytes: 63216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=998244353 ;
ll add(ll a,ll b){
    ll t=(a+b);
    if(t>=p)t-=p;
        return t;
}
ll sub(ll a,ll b){
    ll t=a-b+p;
    t=t%p;
    return t;
}
ll power(ll a,ll x){
    if(x<0)return 1;
    ll r=1;
    while(x!=0){
        if(x%2==1){
            r=r*a;r%=p;
        }
        a=a*a;a%=p;
        x=x/2;
    }
    return r;
}
ll mul(ll a,ll b){
    ll t=(a*b);
    if(t>=p)t%=p;
    return t;
}
map<int,int> m;
int rec(int i){
    if(i==1)return 0;
    if(m.find(i)!=m.end())return m[i];
    int x;
    if(i%2==0){
        x=1+rec(i/2);
    }
    else{
        x=1+rec(3*i+1);
    }
    m[i]=x;
    return x;
}
int getKth(int lo, int hi, int k) {
    int arr[1001];
    memset(arr,-1,sizeof(arr));
    pair<int,int> b[hi-lo+1];
    for(int i=1;i<=1000;i++){
        if(arr[i]==-1){
            rec(i);
        }
        arr[i]=m[i];
    }
    for(int i=lo;i<=hi;i++){
        b[i-lo].first=arr[i];
        b[i-lo].second=i;
    }
    sort(b,b+hi-lo+1);
    return b[k-1].second;
}
int main() {
    
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll x;ll ans=0;cin>>x;
        ans=1000*(x/500);
        x=x%500;
        ans+=(5*(x/5));
        cout<<ans;
    }   
    return 0;   
}   

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(i): $i$の根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def union(self, x, y): #union(i,j): $i$のいるグループと$j$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(i,j): $i$と$j$ が同じグループにあるならTrue，違うならFalse
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(i): $i$のいるグループの要素数を返す
        return -self.parent[self.root(x)]
#>>>>>>>>>>>>>>EhdCutHere>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

n,m = list(map(int,input().split()))
p = list(map(lambda x: int(x)-1,input().split()))

uf = UnionFind(n)
for i in range(m):
    x,y=list(map(int,input().split()))
    uf.union(x-1,y-1)

ans = 0
for i in range(n):
    if uf.issame(i,p[i]):
        ans += 1

print(ans)
#print([uf.root(i) for i in range(n)])
#print([uf.parent[i] for i in range(n)])
#print([uf.size(i) for i in range(n)])



Measured memory_bytes: 14452
#include <iostream>

using namespace std;

int max(int x, int y){
  if(x >= y) return x;
  else return y;
}

int main(){
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long p, q, r;
  p = max(a*c, a*d);
  q = max(b*c, b*d);
  r = max(p, q);
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3636
N,X  = map(int,input().split())
k = []
all = 0
moto = X
ans = 0
for i in range(N):
    k.append(int(input()))
for i in range(len(k)):
    all += k[i]
moto = moto-all
ans += len(k)
sorted(k)
if moto>0:
    ans += moto//min(k)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m), b(m), c(k), d(k);
    vector<vector<int>> friend_list(n+1);
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        friend_list[a[i]].push_back(b[i]);
        friend_list[b[i]].push_back(a[i]);
    }
    vector<vector<int>> block_list(n+1);
    for(int i = 0; i < k; i++) {
        cin >> c[i] >> d[i];
        block_list[c[i]].push_back(d[i]);
        block_list[d[i]].push_back(c[i]);
    }
    int label = 1;
    vector<int> labels(n+1, -1), label_num(n+1);
    for(int i = 1; i < n+1; i++){
        if(labels[i] == -1){
            queue<int> q;
            q.push(i);
            labels[i] = label;
            label_num[label] = 1;
            while(q.empty() != true){
                int v = q.front();
                q.pop();
                for(int x : friend_list[v]){
                    if(labels[x] == -1){
                        q.push(x);
                        labels[x] = label;
                        label_num[label]++;
                    }
                }
            }
            label++;
        }
    }
    vector<int> correction(n+1);
    for(int i = 0; i < m; i++){
        correction[a[i]]++;
        correction[b[i]]++;
    }
    for(int i = 0; i < k; i++){
        if(labels[c[i]] == labels[d[i]]){
            correction[c[i]]++;
            correction[d[i]]++;
        }
    }
    for(int i = 1; i < n+1; i++){
        cout << label_num[labels[i]] - correction[i] - 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 14584
#累積和利用ver

def max_candy(field,N):
	data = [-1]*N
	cum_0 = np.cumsum(field[0,:])
	cum_1 = np.cumsum(field[1,:])
	for i in range(N):
		# up_left + down_right
		ul = cum_0[i]
		dr = cum_1[-1] - (cum_1[i-1]  if i-1 >= 0 else 0) 
		data[i] = ul+dr
	return max(data)
  
import numpy as np
N = int(input())
field = []
for i in range(2):
	array = list(map(int,input().split()))
	field.append(array)
field = np.array(field)

print(max_candy(field,N))


Measured memory_bytes: 12504
#include<iostream>
using namespace std;
int main() {
    int h, w;
    
    while (true) {
        cin >> h >> w;
        if (w == 0 && h == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i % 2 == j % 2) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3116
//A,Elebereth,Gilthoniel mantae!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring> 
#include<map>
using namespace std;
int main()
{
	int n;cin>>n;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int a,b;cin>>a>>b;ans+=b-a+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define JN ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define mod 1000000007

#define pb push_back
#define mp make_pair

using namespace std;
typedef unsigned long long int ull;
typedef long long int          ll;

int n, W;

int w[105], value[105];

ll dp[105][100005];





int main()
{
    JN;

    cin >> n >> W;

    for(int i=1; i<=n; i++)
        cin >> w[i] >> value[i];

    for(int i=0; i<=n; i++)
    {
        for(int j=1; j<=100000; j++)
        {
            dp[i][j] = 1e13;
        }
    }

    ll ans=0;

    for(int i=1; i<=n; i++)
    {
        for(ll j=1; j<=100000; j++)
        {
            if(value[i] <= j)
                dp[i][j] = min(dp[i-1][j-value[i]]+w[i], dp[i-1][j]);
            else
                dp[i][j] = dp[i-1][j];
            //cout << dp[i][j] << endl;
            if(dp[i][j] <= W)
                ans = max(ans, j);
        }
    }


    cout << ans << "\n";
    
    
    return 0;

}

Measured memory_bytes: 80128