akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;
const int MAXK = 3;
const ll INF = 1e18;

int n;
int a[MAXN];
int sign[MAXN];

int read_sign() {
	char c;
	while (1) {
		c = getchar();
		if  (c == '-') {
			return -1;
		}
		if  (c == '+') {
			return +1;
		}
	}
	assert(0);
}

bool read() {
	if  (scanf("%d\n", &n) < 1) {
		return 0;
	}
	scanf("%d", &a[0]);
	sign[0] = 1;
	for (int i = 1; i < n; ++i) {
		sign[i] = read_sign();
		scanf("%d", &a[i]);
	}
	return 1;
}

int get_sign(int x) {
	return (x & 1) ? -1 : +1;
}

ll dp[MAXN][MAXK];

ll solve() {
	forn(i, n + 1) {
		forn(k, MAXK) {
			dp[i][k] = -INF;
		}
	}

	dp[0][0] = 0;

	// forn(i, n) {
	// 	printf("%d ", sign[i] * a[i]);
	// }
	// puts("");

	forn(i, n) forn(k, MAXK) {
		ll cur_dp = dp[i][k];
		if  (cur_dp <= -INF) {
			continue;
		}
		// printf("dp[%d][%d] = %lld\n", i, k, cur_dp);
		dp[i + 1][k] = max(dp[i + 1][k], cur_dp + sign[i] * get_sign(k) * a[i]);
		if  (k > 0) {
			dp[i + 1][k - 1] = max(dp[i + 1][k - 1], cur_dp + sign[i] * get_sign(k) * a[i]);
		}
		if  (sign[i] == -1 && k + 1 < MAXK) {
			dp[i + 1][k + 1] = max(dp[i + 1][k + 1], cur_dp + sign[i] * get_sign(k) * a[i]);
		}
	}

	ll ans = -INF;
	forn(k, MAXK) {
		ans = max(ans, dp[n][k]);
	}

	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		cout << solve() << endl;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 3328
s = list(input())
ans = 0
a = []
if s[0] == "R":
  ans += 1
else:
  a += [ans]
  ans = 0
if s[1] == "R":
  ans += 1
else:
  a += [ans]
  ans = 0
if s[2] == "R":
  ans += 1
else:
  a += [ans]
  ans = 0
a += [ans]
print(max(a))

Measured memory_bytes: 61660
#include<bits/stdc++.h>
using namespace std;
int n,m,mx=1;
bool check(int x)
{
	int a=m/x;
	return a>=n;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i*i<=m;i++)
	{
		if(m%i==0)
		{
			int j=m/i;
			if(check(i))
			{
				mx=max(mx,i);
			}
			if(check(j))
			{
				mx=max(mx,j);
			}
		}
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 256
def get_primes(n):
    if n < 10: return [2,3,5,7]
    x = [0,0]+[i for i in range(2,n+1)]
    for e in get_primes(int(n**0.5+1)):
        for j in range(e*2, n+1,e):
            x[j] = 0
    return filter(None, x)

PRIMES = get_primes(10000)
n = int(input())
c = 0
for i in range(n):
    p = int(input())
    f = 1
    for e in PRIMES:
        if e >= p:
            break
        if p % e == 0:
            f = 0
            break
    c += f
print c

Measured memory_bytes: 4904
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = pow(10,9) + 7;

ll modpow(ll a, ll b, ll mod = MOD) {
   ll res = 1;
   for (a %= mod; b; a = a * a % mod, b >>= 1)
     if (b & 1) res = res * a % mod;
   return res;
 }

//E
int main()
{
    ll N,K;
    ll sum=0;
    cin >> N >> K;
    vector<ll> res(K,1);

    for(int n=K; n>0; --n){
        int a=K/n;
        res[n-1]=modpow(a,N);
        for(int j=2; j<=K/n; ++j){
            res[n-1] -= res[j*n-1];
        }
    }
    
    rep(i,K){
        ( sum += res[i]*(i+1) );
    }

    cout << sum%MOD << endl;
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <typename T>
std::vector<std::pair<T, T> > factorint(T n) {
        std::vector<std::pair<T, T> > res;
        for (T i = 2; i*i <= n; ++i) {
                T counter = 0;
                while (n % i == 0) {
                        n /= i;
                        ++counter;
                }
                if (counter != 0) {
                        res.push_back(std::make_pair(i, counter));
                }
        }
        if (n != 1) {
                res.push_back(std::make_pair(n, 1));
        }
        return res;
}

int main()
{
        ll X;
        cin >> X;

        if (X <= 3) {
                cout << 1 << endl;
                return 0;
        }

        ll ans = 2;
        rep(i, 4, X+1) {
                auto f = factorint(i);
                bool flg = true;
                ll std = f[0].second;
                for (auto x : f) {
                        if (x.second != std or x.second == 1) flg = false;
                }
                if (flg) ans = i;
        } 
        cout << ans << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B; cin >> A >> B;
  string res = A*B%2==0 ? res = "No" : res = "Yes";
  cout << res << endl;
}


Measured memory_bytes: 256
n,k,c = map(int,input().split())
s = input()

l_used = [False]*(n+1)
r_used = [False]*(n+1)
idx = 0
cnt = 0
while idx < n:
    if s[idx] == 'o':
        l_used[idx] = True
        cnt += 1
        idx += c+1
    else:
        idx += 1
idx = n-1
while idx >= 0:
    if s[idx] == 'o':
        r_used[idx] = True
        idx -= c+1
    else:
        idx -= 1

if cnt == k:
    ans = [] 
    for i in range(n):
        if l_used[i] and r_used[i]:
            ans.append(i+1)
    for i in ans:
        print(i)

Measured memory_bytes: 15876
s = list(str(input()))

arr = list(map(int, s))

ref1 = [0] * len(s)
for i in range(len(ref1)):
    if i % 2 == 0:
        ref1[i] = 1

ref2 = [0] * len(s)
for i in range(len(ref2)):
    if i % 2 == 1:
        ref2[i] = 1

score1 = 0
for i in range(len(s)):
    if ref1[i] != arr[i]:
        score1 += 1


score2 = 0
for i in range(len(s)):
    if ref2[i] != arr[i]:
        score2 += 1
    
print(min(score1,score2))


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

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 0
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 31064
x = gets.to_i
def prime?(n)
  return true if n == 2 || n == 3
  return false if n < 2 || n % 2 == 0 || n % 3 == 0
  step_flag = true
  current = 5
  while current <= Math.sqrt(n).to_i
    return false if n % current == 0
    current += step_flag ? 2 : 4
    step_flag = !step_flag
  end

  return true
end

loop do
  if prime?(x)
    puts x
    break
  end
  x += 1
end

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

int main(void) {
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> grid[i][j];
        }
    }
    
    int a[h], b[w];
    int x;
    for (int i=0; i<h; i++) {
        x = 0;
        for (int j=0; j<w; j++) {
            if (grid[i][j] == '.') x++;
        }
        if (x == w) a[i] = 0;
        else a[i] = 1;
    }
    
    for (int i=0; i<w; i++) {
        x = 0;
        for (int j=0; j<h; j++) {
            if (grid[j][i] == '.') x++;
        }
        if (x == h) b[i] = 0;
        else b[i] = 1;
    }
    
    for (int i=0; i<h; i++) {
        if (a[i]) {
            for (int j=0; j<w; j++) {
                if (b[j]) {
                    cout << grid[i][j];
                }
            }
            cout << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3600
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1127

from decimal import Decimal, getcontext
from itertools import combinations
from heapq import *


getcontext().prec = 30

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

while True:
    N = int(input())
    if N ==0:
        exit()

    tree = UnionFind(N)

    pos = dict()
    for i in range(N):
        pos[i] = tuple(map(Decimal, input().split()))

    data = []

    for a,b in combinations(range(N), 2):
        x1,x2,x3,xr = pos[a]
        y1,y2,y3,yr = pos[b]
        cost = max(((x1-y1)**2 + (x2-y2)**2 + (x3-y3)**2).sqrt() -xr -yr, 0)
        data.append((a, b, cost))

    res = 0
    data.sort(key=lambda x: x[2])

    for a, b, cost in data:
        if tree.union(a,b):
            res += cost
    print("{:.03f}".format(res))


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=1,flg=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1])count++;
  }
  cout<<count<<"\n";
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
char s[51];
int main(void)
{
	int len,i;
	scanf("%s",s);
	FOR(i,0,strlen(s)-8) putchar(s[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int[] sums = new int[(int) Math.pow(2,n)];
        for (int j = 0; j < Math.pow(2,n); j++) {
            int sum = 0;
            for (int k = 0; k < n; k++) {

                if ((j >> k & 1) == 1) {
                    sum += a[k];
                }
            }
            sums[j] = sum;
        }
        int q = scanner.nextInt();
        for (int i = 0; i < q; i++) {
            int m = scanner.nextInt();
            boolean flag = false;
            LOOP: for (int j = 0; j < Math.pow(2,n); j++) {
                if (sums[j] == m) {
                    flag = true;
                    System.out.println("yes");
                    break LOOP;
                }
            }
            if (!flag) System.out.println("no");
        }
    }
}



Measured memory_bytes: 31784
/* サーチプログラム */
#include<stdio.h>
//all 1

/* マクロの定義 */
#define N 10000
#define Q 500
//all 2

/* プロトタイプ宣言 */
int Linear_Search(int *, int);
//all 1

/* グローバル変数宣言 */
int n=0;
int q=0;
//all 2


main() 
{
  int i=0;
  int S[N];
  int T[Q];
  int val=0;

  /* n個を決定 */
  scanf("%d",&n);

  /* Sの要素 */
  for(i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  /* q個を決定 */
  scanf("%d", &q);

  /* Tの要素*/
  for(i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }

  /*  */
  for(i = 0; i < q; i++) {
  val +=  Linear_Search(S, T[i]);
  }

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

  return 0;
}


/* Linear_Search関数 */
int Linear_Search(int *A, int key) 
{

  /*
  static int cnt = 0;

  while(A[n] != key){
  //  for(i = 0; i < n; i++) {
    //if(A[i] == key) {
      cnt++;
      //   printf("%d",cnt);
  return cnt;
  //   }
  }*/
  int i;
  for(i=0;i<n;i++)
    {
      if(A[i]==key)
	return 1;
    }
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int sum = 0;
    rep(i,N) if(A[A[i]-1] == i+1) sum++;
    cout << sum / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int sum = 0;
	char ch;

	while(true)
	{
		while((ch = getchar()) != '\n'){
			sum += ch - '0';
		}
		if(sum == 0)
			break;
		else{
			printf("%d\n",sum);
			sum = 0;
		}
	}
}


Measured memory_bytes: 2696
def solve(C,N):
    W,R = [],[]
    for i in range(N):
        if C[i] == "W":
            W.append(i)
        else:
            R.append(i)

    W.sort(reverse = True)
    cnt = 0

    while True:
        if len(W) > 0 and len(R) > 0:
            if W[-1] < R[-1]:
                cnt += 1
                W.pop()
                R.pop()
            else:
                break
        else:
            break

    return cnt

def main():
    N = int(input())
    C = input()

    ans = solve(C,N)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 17268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

i64 iabs(i64 x) {
    return x >= 0 ? x : -x;
}
i64 dp[2001][2001];
int main() {
    i64 n;
    cin >> n;
    vector<i64> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    using P = pair<i64, i64>;
    vector<P> p(n);
    for (int i = 0; i < n; ++i) p[i] = {a[i], i};

    sort(begin(p), end(p), greater<>());
    for (int l = 0; l <= n; ++l) {
        for (int r = 0; l + r <= n; ++r) {
            i64 i = l + r - 1, j;
            if (i < 0) continue;
            i64 a;
            tie(a, j) = p[i];
            if (l > 0) {
                dp[l][r] = max(dp[l][r], dp[l - 1][r] + iabs(j - (l - 1)) * a);
            }
            if (r > 0) {
                dp[l][r] = max(dp[l][r], dp[l][r - 1] + iabs(j - (n - r)) * a);
            }
        }
    }
    
    i64 ans = 0;
    for (int l = 0; l <= n; ++l) {
        int r = n - l;
        ans = max(ans, dp[l][r]);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string A[8];
  for (int i = 0; i < H; i++) cin >> A[i];
  int pass = 0;
  for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (A[i][j] == '#') pass++;
  if (pass == H + W - 1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            int a = ReadInt();
            string s = ReadString();

            if (a >= 3200)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine("red");
            }
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;
  double t,a;
  cin >>n >>t >>a;
  vec<double> h(n);
  REP(i,n) cin >>h[i];
  REP(i,n) h[i] = a-(t-h[i]*0.006);

  int answer=1;
  REP(i,n) if(h[i] < 0) h[i] = -h[i];
  double mintemp=h[0];
  REP(i,n){
    if(h[i] < mintemp){
      mintemp = h[i];
      answer = i+1;
    }
  }

  cout <<answer <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
#define vsort(v) sort(v.begin(), v.end())
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	vsort(s);
	vsort_r(t);
	if(t > s) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int id;
    double h,w,bmi;
    
    while (scanf("%d,%lf,%lf", &id, &w,&h)!=EOF){
        bmi = w / h/h;
   //     printf("%f\n",bmi);
        if (bmi>=25.0) printf("%d\n",id);
    }
    
    return 0;
}

Measured memory_bytes: 1056
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    cout << min({ A*X + B*Y,max(X,Y) * 2 * C,(X < Y) ? 2 * X*C + (Y - X)*B : 2 * Y*C + (X - Y)*A }) << endl;

    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

m = [(e + 1) / 2 for e in p]

t = sum(m[0:K])
result = t
for i in range(N - K):
    t -= m[i]
    t += m[i + K]
    if t > result:
        result = t
print(result)

Measured memory_bytes: 24804
//============================================================================
// Name        : aoj0076.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <utility>
#include <cmath>
#define sqr(x) (x) * (x)
using namespace std;

int main() {
	int n;
	pair<double,double> l, v, w;
	while(true){
		cin >> n;
		if(n == -1){
			break;
		}
		l = make_pair(1,1); // 現在の位置
		v = make_pair(1,0);
		w = make_pair(0,1);
		for(int i = 0;i < n - 2;i++){
			v = make_pair(v.first + w.first,v.second + w.second);
			w = make_pair(-v.second,v.first);
			w = make_pair(w.first / sqrt(sqr(w.first) + sqr(w.second)),w.second / sqrt(sqr(w.first) + sqr(w.second)));
			l = make_pair(l.first + w.first,l.second + w.second);

		}
		cout << l.first << endl << l.second << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
using namespace std;
int main()
{int n;
 cin>>n;
 int a[1000000]={ 0 };
       for (int i=0;i<n;i++)
         cin>>a[i];
      int k=0;
       int max=0;
       
     for (int i=0;i<n-1;i++)
       { if (a[i]>=a[i+1])
          k++;
       else 
       { if (max<k)
           max=k;
         
        k=0;
       }
       }

if (k>0 && max<k)
       max=k;
     
 
  if (max>=1)
       cout<<max;
   else 
       cout<<0;
       
       









return 0;


}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    ll n, y; cin >> n >> y;
    int n10000 = -1, n5000 = -1, n1000 = -1;

    rep(i,y/10000 +1){
        for(int j=0; 5000*j + 10000*i <= y  && i+j <=n; j++){
            for(int k = 0; 1000*k + 5000*j + 10000*i <= y && i+j+k <=n; k++){
                if(1000*k + 5000*j + 10000*i == y && i+j+k ==n){
                    n10000 = i;
                    n5000 = j;
                    n1000 = k;
                    break;
                }
            }
        }

    }

    cout << n10000 << " " << n5000 << " " << n1000 << endl;

}
    

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    string s;
    int start, gool;
    cin >> s;
    
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            start = i;
            break;
        }
    }
    
    for(int j = s.size()-1; j >= 0; j--){
        if(s[j] == 'Z'){
            gool = j;
            break;
        }
    }
    
    cout << gool - start + 1 << endl;
}

Measured memory_bytes: 640
import math

S = input().split()
A=float(S[0])
B=float(S[1])
H=float(S[2])
M=float(S[3])
siita=(H*60+M)/2-M*6;
if(siita>180):
    siita=360-siita
ans=math.sqrt(A*A+B*B-2*A*B*math.cos(siita*3.1415926535897932/180))
print(ans)

Measured memory_bytes: 9384
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = 0

for i in range(n):

	ans += b[a[i]-1]

	if i > 0 and a[i] == a[i-1] + 1:
		ans += c[a[i-1]-1]
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int p_b[10][3], q_b[10][3];  //括弧の配列
int indent_p[10], indent_q[10];
int n;

typedef struct bracket{ int r, c, s; }bra_t;
typedef struct bracket_st{ bra_t b[8000]; }bst_t;

void  Check_b(char st[10][90], int in, int pq[10][3]) {
  int numr = 0, numc = 0, nums = 0, piriod;
  int i, j;

  for(i = 0; i < in; ++i){
    piriod = 0;
    pq[i][0] = numr; pq[i][1] = numc; pq[i][2] = nums;
    for(j = 0; st[i][j] != '\0'; ++j){
      switch (st[i][j]) {
        case '(':
          numr++;
          break;
        case '{':
          numc++;
          break;
        case '[':
          nums++;
          break;
        case ')':
          numr--;
          break;
        case '}':
          numc--;
          break;
        case ']':
          nums--;
          break;
        case '.':
          if(!j){
            for(; st[i][j] == '.'; ++j)
              piriod++;
            --j;
          }
          break;
      }
    }
    indent_p[i] = piriod++;
  }
}

bst_t Indent_check(int pq[10][3], int indent[10], bst_t *bst, int in){
  bst_t oks;
  int res, f, k = 0;

  for(int i = 0; i < 8000; ++i){
    f = 1;
    for(int j = 0; j < in; ++j){
      res = (pq[j][0] * bst->b[i].r) + (pq[j][1] * bst->b[i].c) + (pq[j][2] * bst->b[i].s);
      if(res != indent[j]){
        f = 0;
        break;
      }
    }
    if(f){
      oks.b[k] = bst->b[i];
      n++;
      k++;
    }
  }
  return oks;
}

void Indent(int q[10][3], bst_t *oks, int in){
  int temp, res, f;

  for(int i = 0; i < in; i++){
    f = 1;
    for(int j = 0; j < n; j++){
      if(j != 0)
        temp = res;
      res = q[i][0] * oks->b[j].r + q[i][1] * oks->b[j].c + q[i][2] * oks->b[j].s;
      if(n == 1)
        indent_q[i] = res;
      else if(j != 0 && temp != res){
        indent_q[i] = -1;
        f = 0;
        break;
      }
    }
    if(f)
      indent_q[i] = res;
  }
}

void Allset(bst_t *bst){
  bra_t bra;
  int l = 0;

  for(int i = 1; i <= 20; ++i){
    for(int j = 1; j <= 20; ++j){
      for(int k = 1; k <= 20; ++k){
        bra.r = i; bra.c = j; bra.s = k;
        bst->b[l] = bra;
        l++;
      }
    }
  }
}

int main (){
  char p[10][90], q[10][90], st[90];  //入力文字列
  bst_t all, oks;
  int ans[10];
  int i, j;
  int pin, qin;  //行数

  Allset(&all);
  while (1) {
    scanf("%d%d", &pin, &qin);
    if(pin == 0 && qin == 0)
      return 0;
    n = 0;
    for( i = 0; i < pin; i++){
      scanf("%s", st);
      for( j = 0; st[j] != '\0'; j++)
        p[i][j] = st[j];
      p[i][j] = '\0';
    }
    Check_b(p, pin, p_b);
    oks = Indent_check(p_b, indent_p, &all, pin);
    for( i = 0; i < qin; i++){
      scanf("%s", st);
      for( j = 0; st[j] != '\0'; j++)
        q[i][j] = st[j];
      q[i][j] = '\0';
    }
    Check_b(q, qin, q_b);
    Indent(q_b, &oks, qin);
    for( i = 0; i < qin - 1; i++)
      printf("%d ", indent_q[i]);
    printf("%d\n", indent_q[i]);
  }
}



Measured memory_bytes: 2124
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int a, b, k, i;

	scanf("%d%d%d", &k, &a, &b);
	for (i = a; i <= b; i++) {
		if (i % k == 0) {
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");

	return 0;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>

#define unless(c) if (!(c))
#define each(i, c) for (auto& i: c)

using namespace std;

int main(void)
{
  const int N = 300;
  string s;
  while (cin >> s) {
    sort(s.begin(), s.end());
    int cnt[N];
    fill(cnt, cnt + N, 0);
    for (int i = 0; i < s.size(); ++i) {
      ++cnt[s[i]];
    }
    string t;
    while (true) {
      const string u = t;
      for (int i = 0; i < N; ++i) {
	if (cnt[i]) {
	  string add = "";
	  int k = i;
	  for (int j = i; j < N && cnt[j]; ++j) {
	    add += j;
	    k = j;
	  }
	  if (add.size() <= 2) {
	    t += add;
	  } else {
	    t += i;
	    t += '-';
	    t += k;
	  }
	  for (int k = 0; k < add.size(); ++k) {
	    --cnt[add[k]];
	  }
	  break;
	}
      }
      if (u == t) break;
    }
    sort(s.begin(), s.end());
    // cout << s << endl;
    // cout << t << endl;
    cout << t.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//6,9,36,81,216,729,1296,6561,7776,59049,46656
int main(){
	ll n,dp[100000],a[12]={1,6,9,36,81,216,729,1296,6561,7776,59049,46656};
	cin>>n;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		dp[i]=100000;
	}
	for(ll i=1;i<=n;i++){
		for(ll j=0;j<12;j++){
			if(i-a[j]>=0)dp[i]=min(dp[i],dp[i-a[j]]+1);
		}
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define MAX_MEMBER 500000

typedef struct {
  int left;
  int right;
} Direction;

typedef enum {
  Left,
  Right,
} LR;

Direction left[MAX_MEMBER];
Direction right[MAX_MEMBER];
LR member[MAX_MEMBER];

int nmember;

int main()
{
  char lf;
  int nleft = 0;
  int nright = 0;

  scanf("%d%c", &nmember, &lf);
  for(int i = 0; i < nmember; i++) {
    char ch = getchar();
    switch(ch) {
      case 'W':
        member[i] = Left;
        break;
      case 'E':
        member[i] = Right;
        break;
      default:
        fprintf(stderr, "Unknown char: '%c'\n", ch);
        exit(1);
    }
  }

  nleft = 0;
  nright = 0;
  for(int i = 0; i < nmember; i++) {
    left[i].left = nleft;
    left[i].right = nright;
    switch(member[i]) {
      case Left:
        nleft++;
        break;
      case Right:
        nright++;
        break;
      default:
        fputs("While initializing left[].\n", stderr);
        fprintf(stderr, "Unknown member: %d\n", member[i]);
        exit(1);
    }
  }

  nleft = 0;
  nright = 0;
  for(int i = nmember-1; 0 <= i; i--) {
    right[i].left = nleft;
    right[i].right = nright;
    switch(member[i]) {
      case Left:
        nleft++;
        break;
      case Right:
        nright++;
        break;
      default:
        fputs("While initializing right[].\n", stderr);
        fprintf(stderr, "Unknown member: %d\n", member[i]);
        exit(1);
    }
  }

  int result = INT_MAX;
  for(int i = 0; i < nmember; i++) {
    result = min(result, left[i].left + right[i].right);
  }
  printf("%d\n", result);
  return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define N 11111116
#define next nxt

int n,k,dx[N],dy[N],x[N],y[N],next[N],p[N],h[N],ans;

struct flag{int x,y,z;}a[N];
bool cmp_x(flag a,flag b){return a.x<b.x;}
bool cmp_y(flag a,flag b){return a.y<b.y;}
bool cmp_z(flag a,flag b){return a.z<b.z;}

void add(int a,int b){
	x[++k]=a;y[k]=b;next[k]=p[x[k]];p[x[k]]=k;
	x[++k]=b^1;y[++k]=a^1;next[k]=p[x[k]];p[x[k]]=k;
}

void build(int l,int r){
	int t=(l+r)|(l<r);
	if (l==r) add(2*(n+t),2*dx[l]+1),add(2*(3*n+t),2*dy[l]);
	else {
		int mid=(l+r)/2,
			lc=(l+mid)|(l<mid),
			rc=(mid+1+r)|(mid+1<r);
		add(2*(n+t),2*(n+lc));
		add(2*(n+t),2*(n+rc));
		add(2*(3*n+t),2*(3*n+lc));
		add(2*(3*n+t),2*(3*n+rc));
		build(l,mid);build(mid+1,r);
	}
}

void insert(int k,int l,int r,int x,int y,int z){
	int t=(l+r)|(l<r);
	if (x<=l&&y>=r) add(z,2*(k+t));
	else {
		int mid=(l+r)/2;
		if (x<=mid) insert(k,l,mid,x,y,z);
		if (y>=mid+1) insert(k,mid+1,r,x,y,z);
	}
}

bool travel(int x,int c1,int c2){
	h[x]=c2;
	if (h[x]&&h[x^1]) return false;
	for (int t=p[x];t;t=next[t])
		if (h[y[t]]==c1){
			if (!travel(y[t],c1,c2))
			return false;
		}
	return true;
}

bool check(int d){
	fill(p+1,p+10*n+1,0);
	fill(h+1,h+10*n+1,0);
	k=0;build(1,n);
	for (int i=1,l=1,r=0;i<=n;i++){
		while (l<=n&&a[dx[l]].x<=a[dx[i]].x-d) l++;
		while (r<n&&a[dx[r+1]].x<a[dx[i]].x+d) r++;
		if (l>r) continue;
		if (i<l||i>r) insert(n,1,n,l,r,2*dx[i]);
		else {
			if (l<i) insert(n,1,n,l,i-1,2*dx[i]);
			if (i<r) insert(n,1,n,i+1,r,2*dx[i]);
		}
	}
	for (int i=1,l=1,r=0;i<=n;i++){
		while (l<=n&&a[dy[l]].y<=a[dx[i]].x-d) l++;
		while (r<n&&a[dy[r+1]].y<a[dx[i]].x+d) r++;
		if (l>r) continue;
		insert(3*n,1,n,l,r,2*dx[i]);
	}
	for (int i=1,l=1,r=0;i<=n;i++){
		while (l<=n&&a[dx[l]].x<=a[dy[i]].y-d) l++;
		while (r<n&&a[dx[r+1]].x<a[dy[i]].y+d) r++;
		if (l>r) continue;
		insert(n,1,n,l,r,2*dy[i]+1);
	}
	for (int i=1,l=1,r=0;i<=n;i++){
		while (l<=n&&a[dy[l]].y<=a[dy[i]].y-d) l++;
		while (r<n&&a[dy[r+1]].y<a[dy[i]].y+d) r++;
		if (l>r) continue;
		if (i<l||i>r) insert(3*n,1,n,l,r,2*dy[i]+1);
		else {
			if (l<i) insert(3*n,1,n,l,i-1,2*dy[i]+1);
			if (i<r) insert(3*n,1,n,i+1,r,2*dy[i]+1);
		}
	}
	for (int i=1;i<=5*n;i++)
		if (!h[2*i]&&!h[2*i+1]){
			if (travel(2*i,0,2)) {travel(2*i,2,1);continue;}
			travel(2*i,2,0);
			if (travel(2*i+1,0,2)) {travel(2*i+1,2,1);continue;};
			return false;
		}
	return true;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++){
		a[i].x=read();
		a[i].y=read();
		a[i].z=i;
	}
	sort(a+1,a+n+1,cmp_x);
	for (int i=1;i<=n;i++) dx[i]=a[i].z;
	sort(a+1,a+n+1,cmp_y);
	for (int i=1;i<=n;i++) dy[i]=a[i].z;
	sort(a+1,a+n+1,cmp_z);
	for (int k=1<<29;k;k/=2)
		if (check(ans+k)) ans+=k;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 43520
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li2 = []
for i in range(len(li)):
    s = li.pop(0)
    li2.append(s)
    li2.sort()
    ans = li2+li
    print(' '.join(map(str, ans)))


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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int k = in();
  int candle_posis[n];
  REP(i,n) {
    cin >> candle_posis[i];
  }
  int ans = 1000000000;

  // 左端からk個選ぶ。そのグループを右にずらしていく
  REP(i,n-k+1) {
    int left = candle_posis[i]; // グループ左端
    int right = candle_posis[i+k-1];  // グループ右端

    // 選んだ値全てが0以上
    if(left >= 0) {
      ans = min(ans, right);
      continue;
    }
    // 選んだ値全てが0以下
    if(right <= 0) {
      ans = min(ans, abs(left));
      continue;
    }

    // 一度どちらかの端に行って折り返す必要があるケース
    int tmp_ans = min(abs(left), right) * 2 + max(abs(left), right);
    ans = min(ans, tmp_ans);
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
 	int n;
	cin>>n;
	vector<pair<int,int> > vec;
	for(int i = 0; i < n; ++i){
        	int a, b;
		cin>>a>>b;
		vec.push_back(make_pair(a, b));
	}
	
	sort(vec.begin(), vec.end());
	int x = vec[n - 1].first;
	int y = vec[n - 1].second;
	cout<<x + y<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < 6){
        cout << "0";
    } else if (a >= 6 && a <= 12){
        cout << b / 2;
    } else {
        cout << b;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;
int n,m;
vvint adj;
vector <bool> vis;

void dfs(int s){
	vis[s] = 1;
	for(int u : adj[s]){
		if(!vis[u]) dfs(u);
	}
	return;
}

void solve(){
	cin >> n >> m;
	adj = vvint(n);
	vis = vector <bool> (n,0);
	for(int i = 0;i < m;++i){
		int x,y,z;
		cin >> x >> y >> z;
		--x,--y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int ans = 0;
	for(int i = 0;i < n;++i){
		if(!vis[i]){
			dfs(i);
			++ans;
		}
	}
	cout << ans << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 11824
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=1;
    while((x*2)<=y){
        x*=2;
        ans++;
    }
    cout<<ans<<endl;
}

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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int n;
int a;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (~scanf("%d", &a))
    {
        int ans = a * a * a + a * a + a;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>
#define MAX 25

int Sibling(int);
int Degree(int);
int Depth(int);
int Height(int);

struct node
{
  int p;
  int l, r;
} typedef node;

node N[MAX];

int main()
{
    int i, j;
    int n, id;

    scanf("%d", &n);
    
    for(i = 0; i < n; i++)
    {
        N[i].p = -1;
    }
    
    for(i = 0; i < n; i++)
    {
        scanf("%d", &id);
        scanf("%d %d", &N[id].l, &N[id].r);
        if(N[id].l != -1) N[N[id].l].p = id;
        if(N[id].r != -1) N[N[id].r].p = id;
    }
    
    for(i = 0; i < n; i++)
    {
        printf("node %d: ", i);
        printf("parent = %d, ", N[i].p);
        printf("sibling = %d, ", Sibling(i));
        printf("degree = %d, ", Degree(i));
        printf("depth = %d, ", Depth(i));
        printf("height = %d, ", Height(i));

        if(N[i].p == -1) printf("root\n");
        else if(N[i].l == -1 && N[i].r == -1) printf("leaf\n");
        else printf("internal node\n");
    }
    
    return 0;
}

int Sibling(int id)
{
	if(N[id].p == -1) return -1;
	
	if(N[N[id].p].l != id) return N[N[id].p].l;
	else return N[N[id].p].r;
}

int Degree(int id)
{
	int count = 0;
	
	if(N[id].l != -1) count++;
	if(N[id].r != -1) count++;
	
	return count;
}

int Depth(int id)
{
	int count = 0;

    while(N[id].p != -1)
    {
        count++;
        id = N[id].p;
    }
    
    return count;
}

int Height(int id)
{
	int lc, rc;
	
	if(id == -1) return -1;
	
	lc = Height(N[id].l);
	rc = Height(N[id].r);
	
	if(lc > rc) return lc + 1;
	else return rc + 1;
}

Measured memory_bytes: 612
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
// long long C(int a,int b){
// 	if(a<b||b<0)return 0;
// 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
// }
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int mag[]={mod,2,5,5,4,5,6,3,7,6};
int p[10];
int dp[11000];
int rev[11000];
int calc(int a){
	if(~dp[a])return dp[a];
	if(a==0)return 0;
	int to=0;
	int val=-99999999;
	for(int i=9;i>0;i--){
		if(!p[i])continue;
		if(mag[i]>a)continue;
		int tmp=calc(a-mag[i]);
		if(tmp>val){
			to=i;
			val=tmp;
		}
	}

	rev[a]=to;
	return dp[a]=val+1;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int s;scanf("%d",&s);
		p[s]=1;
	}
	for(int i=0;i<=a;i++)dp[i]=-1;
	calc(a);
	int at=a;
	while(at){
		printf("%d",rev[at]);
		at-=mag[rev[at]];
	}
	printf("\n");
}

Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iterator>
#include<queue>
#include<algorithm>
#include<functional>

typedef long long ll;
typedef std::map<char, int> string_type;
typedef std::unordered_map<int, int> type_occurences;
typedef std::set<int> type_set_int;
using t_map_rate_n = std::map<int, int>;
using vint = std::vector<int>;


struct abc_178_b {
	ll run(ll a, ll b, ll c, ll d) {
#if 0
正同士のとき
最大同士の積

双方負の範囲を含むとき
正x正 と 負x負 の大きい方

正と負のとき、絶対値の小さい2つ

0以上と0以下のとき、0
#endif
		std::vector<ll> as, cs;
		ll max = a*c;

		as.push_back(a);
		as.push_back(b);
		if(a <= 0 && 0 <= b) {
			as.push_back(0);
		}

		cs.push_back(c);
		cs.push_back(d);
		if(c <= 0 && 0 <= d) {
			cs.push_back(0);
		}

		for(auto ita = as.begin(); ita != as.end(); ++ita) {
			for(auto itc = cs.begin(); itc != cs.end(); ++itc) {
				max = std::max(max, (*ita)*(*itc));
			}
		}

		return max;
	}
};

int main(void) {
	abc_178_b solver;
	ll a, b, c, d;

	std::cin >> a >> b >> c >> d;

	std::cout << solver.run(a, b, c, d) << std::endl;

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()

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

int main()
{
	int n; cin >> n;
	int a, res; cin >> res;
	rep(i, 2, n)
	{
		cin >> a;
		res = gcd(res, a);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
from math import ceil, sqrt
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

D = set()
for x in A[:2]:
  for i in range(1, ceil(sqrt(x))+2):
    if x % i == 0:
      D.add(i)
      D.add(x//i)

D = list(D)
D.sort(reverse=True)
for d in D:
  count = 0
  for a in A:
    if a % d != 0:
      count += 1
    if count >= 2:
      break
  else:
    print(d)
    break


Measured memory_bytes: 16156
#include<iostream>
using namespace std;
int main()
{
    long long N,A,B;
    cin >> N >> A >> B;

    long long ans;

    if((B-A)%2==0){
        ans = (B-A)/2;
    }else{
        ans = min((A+B-1)/2,N+1-(A+B+1)/2);
    }



    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string a[51],b[51];
ll n,m;
ll f(ll x,ll y)
{
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
{

    if(a[x+i][y+j]!=b[i][j])return 0;
}

return 1;
}
int main()
{

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

for(int i=0;i<=n-m;i++)
for(int j=0;j<=n-m;j++)
if(f(i,j))return 0&puts("Yes");
puts("No");


}

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

int main() {
  char s[5];
  cin >> s;
  
  if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])){
    cout << "Yes" << endl; 
  }else{
    cout << "No" << endl;
  }
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

ll N, K;
ll A[200010], F[200010];

bool f(ll x){
    ll k = 0;
    REP(i, N){
        if(F[i] * A[i] <= x) continue;
        k += A[i] - x / F[i];
    }
    return (k <= K);
}

signed main(){
    cin >> N >> K;
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> F[i];
    sort(F, F + N, greater<ll>());
    sort(A, A + N);
    ll x = 0, l = 0, r = 0;
    REP(i, N) r = max(r, F[i] * A[i]);
    if(f(0)){
        PRINT("0");
        return 0;
    }
    while(l < r){
        if(l + 1 == r){
            x = r;
            break;
        }
        x = (l + r + 1) / 2;
        if(f(x)) r = x;
        else l = x;
    }
    PRINT(x);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
  int tmp,i;
  long N,ans=0;cin>>N;
  string strN=to_string(N);
  for(tmp=0;tmp<(1<<(strN.size()-1));tmp++){
    bitset<9> s(tmp);
    long L=0,copyN=N;
    int w=1;
    for(i=0;i<strN.size()-1;i++){
      w*=10;
      if(s[i]){L+=copyN%w;copyN/=w;w=1;}
    }
    ans+=L+copyN;
  }
  if(ans==0)ans+=N;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 1

#include <queue>
#include <cstdio>
#include <limits>

int main()
{
	int n, MAX = std::numeric_limits<int>::min();

	std::queue<int> R;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		int temp;

		scanf("%d", &temp);

		R.push(temp);

		if (MAX < R.back() - R.front() && R.size() > 1)
		{
			MAX = R.back() - R.front();
		}

		if (R.back() < R.front())
		{
			while (R.size() > 1)
			{
				R.pop();
			}
		}
	}

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

	return 0;
}

// Time : O( 2n )

Measured memory_bytes: 1800