akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val P = na(N)
    val mx = P.max
    val S = P.sum
    val ans = S - mx / 2
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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

int main() {
    int n, m;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    cin >> m;
    vector<int> b(m);
    for (int j = 0; j < m; ++j) {
        cin >> b[j];
    }
    for (int k : b) {
        if (!binary_search(a.begin(), a.end(), k)) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}


Measured memory_bytes: 4340
#include<iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int count5 = 0;
	int count7 = 0;
	if (A == 5) {
		count5++;
	}
	else if (A == 7) {
		count7++;
	}
	if (B == 5) {
		count5++;
	}
	else if (B == 7) {
		count7++;
	}
	if (C == 5) {
		count5++;
	}
	else if (C == 7) {
		count7++;
	}

	if (count5 == 2 && count7 == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;

}

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

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

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

    int count = 0;
    long long int total = 0;
    multiset<long long int> pool;

    for(int i=0; i<n; i++){
        if(a[i] < b[i]){
            count += 1;
            total += b[i] - a[i];
        }
        if(a[i] > b[i]) pool.insert(a[i] - b[i]);
    }

    while(total > 0 && pool.empty() == false){
        total -= *prev(pool.end());
        count += 1;
        pool.erase(prev(pool.end()));
    }
    if(total > 0) cout << -1 << endl;
    else cout << count << endl;
    return 0;
}

Measured memory_bytes: 7204
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

A = {}
for i in range(1,N+1):
    A[i] = []

for a,b in data:
    A[a].append(b)
    A[b].append(a)

from collections import deque

q = deque([1])
d = [-1]*(N+1)
d[1] = 0

while q:
    n = q.pop()
    for i in A[n]:
        if d[i] != -1:
            continue
        else:
            d[i] = n
            q.appendleft(i)
print('Yes')

for i in range(2,N+1):
    print(d[i])

Measured memory_bytes: 123196
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AtCoderABC123
{
    class Pa
    {
        public long c;
        public int pos;
        public Pa(long n, int p)
        {
            c = n;
            pos = p;
        }
    }
    class Program
    {
        public static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] p = new long[5];
            p[0] = long.Parse(Console.ReadLine());
            p[1] = long.Parse(Console.ReadLine());
            p[2] = long.Parse(Console.ReadLine());
            p[3] = long.Parse(Console.ReadLine());
            p[4] = long.Parse(Console.ReadLine());
            Pa[] pp = new Pa[5];
            for (int i = 0; i < 5; i++) pp[i] = new Pa(p[i], i);
            Pa[] ppsort = pp.OrderBy(x => x.c).ToArray();
            long ftime = (N % ppsort[0].c == 0)? N / ppsort[0].c: N / ppsort[0].c + 1;
            ftime += ppsort[0].pos;
            ftime += 4 - ppsort[0].pos;
            Console.WriteLine(ftime);
        }
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    long double a, b, n; cin >> a >> b >> n;
    long double x = min(n, b-1);
    ll ans = floor(a*x/b) - a * floor(x/b);
    cout << ans << endl;
}


Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int n;
  cin >> n;

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

  int count = 0;
  for (int i = 0; i < n; i++) {
    bool isLook = true;
    for (int j = 0; j < i; j++) {
      if (h[j] > h[i]) {
        isLook = false;
        break;
      }
    }

    if (isLook) {
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
 
#define N 10000
#define Q 500
 
int main(){
 
  int n,q,i,j,c=0,temp=N;
  int S[N],T[Q];
 
  scanf("%d", &n);
 
  for(i=0 ; i<n ; i++){
    scanf("%d", &S[i]);
  }
 
   scanf("%d", &q);
 
  for(i=0 ; i<q ; i++){
    scanf("%d", &T[i]);
  }
 
  for(i=0 ; i<q ; i++){
    for(j=0 ; j<n ; j++){
      if(T[i]==S[j]) {
    if(temp!=T[i]){
    c++;
    temp=T[i];
    }
      }
    }
  }
 
  printf("%d\n",c);
 
  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define endl "\n"

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

    string a, b;
    cin >> a >> b;
    int dp[a.size() + 1][b.size() + 1];
    memset(dp, 0, sizeof dp);

    for (int i = 1; i <= a.size(); i++) {
        for (int j = 1; j <= b.size(); j++) {
            if (a[i - 1] == b[j - 1]) {
                dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j - 1]);
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    // for (int i = 0; i <= a.size(); i++) {
    //     for (int j = 0; j <= b.size(); j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    int index = dp[a.size()][b.size()];

    char lcs[index + 1];
    lcs[index] = '\0';

    int i = a.size(), j = b.size();
    while (i > 0 && j > 0) {
        if (a[i - 1] == b[j - 1]) {
            lcs[index - 1] = a[i - 1];  // Put current character in result
            i--;
            j--;
            index--;  // reduce values of i, j and index
        } else if (dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }

    cout << lcs << endl;
    return 0;
}


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

int main() {
  vector<int> x(5);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
    if (x.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}
    

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, m; cin >> n >> m;
	vector<int> h(n); rep(i, n)cin >> h[i];
	vector<bool> non(n);
	vector<vector<int>> v(n);
	rep(i, m)
	{
		int a, b; cin >> a >> b;
		--a, --b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int res = 0;
	rep(i, n)
	{
		if (non[i])continue;
		for (int x : v[i])
		{
			if (h[i] >= h[x])non[x] = true;
			if (h[i] <= h[x])
			{
				non[i] = true;
				break;
			}
		}
		if (!non[i])++res;
	}
	cout << res << endl;
}

Measured memory_bytes: 8804
#include <stdio.h>
#include <complex>
using namespace std;
typedef complex<double> P;
const double pi = atan2(0.0, -1.0);

P unit(double t) { return P(cos(t), sin(t)); }

int main() {
    P cp(0, 0);
    int cd = 90;
    for (;;) {
        int L, d;
        scanf("%d,%d", &L, &d);
        if (L == 0 && d == 0) break;
        cp += (double)L*unit(pi*cd/180);
        cd -= d;
    }
    printf("%d\n%d\n", (int)cp.real(), (int)cp.imag());
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
main(void){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if (y+r <= H && y-r >= 0 && x+r <= W && x-r >= 0){
    printf("Yes\n");
  }
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1012
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define FOR(i, a, b) for (int i = a, i##_len = (b); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS (1e-7)
#define INF (1e9)

using namespace std;

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

  string s, t;
  cin >> s >> t;
  string s2 = s + s;
  // cout << s2.find(t) << endl;
  if (s2.find(t) != string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		//0-a, 1-b, 2-c, 3-d, 4-e, 5-f
		double[] ar = new double[6] ;
		double x,y;
		String str=br.readLine();
		StringTokenizer st;

		int i=0;
		while(str!=null){
			st = new StringTokenizer(str);
			while(st.hasMoreTokens()){
				ar[i] = Double.parseDouble(st.nextToken());
				i++;
			}
			x = (ar[2]*ar[4] - ar[1]*ar[5])/(ar[0]*ar[4] - ar[1]*ar[3]);
			y = (ar[2] - (ar[0]*x))/ar[1];
			
			if(x==-0.0){
				x=0;
			}
			if(y==-0.0){
				y=0;
			}
			System.out.printf("%.3f %.3f\n",x,y);
			str = br.readLine();
			i=0;
		}

	}

}

Measured memory_bytes: 24472
N = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))

dair = {}
dbir = {}
for i in range(N):
    dair.setdefault(i, ai[N-i])
    dbir.setdefault(i, bi[N-1-i])

dair.setdefault(N, ai[0])
#print(dair)
#print(dbir)

ans = 0
for i in range(N):
    diff = dbir[i] - dair[i]
    if diff >= 0:
        ans += dair[i]
        diff2 = dair[i+1] - diff
        if diff2 >= 0:
            dair[i+1]=diff2
            ans += diff
        else:
            ans += dair[i+1]
            dair[i+1]=0
    else:
        ans += dbir[i]
    #print(ans)

print(ans)
#print(dair)
#print(dbir)

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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 




int main(int argc, char** argv) {
    fast_io
   
	
	int n;
	cin >> n;
	cout << 1LL * n * n * n << endl;
	
	

    return 0;
}























Measured memory_bytes: 3128
package main

import (
	"fmt"
)

// go run ./main.go < in

var n int

func main() {
	fmt.Scan(&n)

	var nums []int
	data := make(map[int]int)
	for i := 1; i <= n; i++ {
		data[i] = 0

		if i == n {
			break
		}
		var num int
		fmt.Scan(&num)
		nums = append(nums, num)
	}

	for _, v := range nums {
		data[v]++
	}

	for i := 1; i <= n; i++ {
		fmt.Println(data[i])
	}
}

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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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 <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec) {
        is >> x;
    }
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    vll a(n + 1), b(n);
    cin >> a;
    cin >> b;

    ll ans = 0;
    ll prev = 0;
    REP(i, n) {
        ans += min(a[i], prev);
        a[i] = max(0LL, a[i] - prev);
        ans += min(b[i], a[i]);
        prev = max(0LL, b[i] - a[i]);
        // cout << min(b[i], a[i]) << " " << prev << endl;
    }
    ans += min(prev, a[n]);

    cout << ans << endl;

    return 0;
}


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

class Binary_Indexed_Tree():
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def sum(self, i):
        ret = 0
        while i:
            ret += self.data[i]
            i &= i-1
        return ret

ans= 0
BIT = Binary_Indexed_Tree(n+1)
for i in range(n):
    BIT.add(p[i], 1)
    if BIT.sum(p[i]-1) == 0:
        ans += 1
print(ans)

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

int A,B;

int main() {
    cin>>A>>B;
    int cnt=0;
    int outlet=1;
    for (; outlet<B;) {
        outlet+=A-1;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
//next_permutation


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int n=0,i;
    cin >> s;
    for(i=0;i<4;i++)
    {
        if(s[i]=='+')
            n++;
        else
            n--;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int n,i;
string s;
map <string,int> mp;

int main() 
{
    cin>>n;
    while (n--){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"];
}

Measured memory_bytes: 3632
def main():
    n = int(input())
    x = list(map(int, input().split()))
    s = sorted(x)
    m1 = s[n // 2 - 1]
    m2 = s[n // 2]
    for i in x:
        if i < m2:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26180
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){

    int n, d, k;
    cin>>n>>d>>k;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    vector<int> c(n, 0);
    
    for(int i=0; i<n; i++){
        int day=1;
        
        while(day<=d){
            c[i]++;
            day+=a[i];
        }
    }
    
    int cnt=k;
    for(int i=0; i<n; i++){
        cnt+=c[i];   
    }
    
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	ll n ; cin >> n;
	string s; cin >> s ;
	ll  e = n-1;
	for(ll i = 1 ; i < n ; i++){
		if(s[i]=='W') e--;
	}
	ll ans = e;
	ll now = e;
	for(ll i = 1 ; i < n  ; i++){
		if(s[i-1]=='E') now--;
		else now++;
		if(s[i]=='E'&&s[i-1]=='W')now--;
		if(s[i]=='W'&&s[i-1]=='E')now++;
		ans =  min(ans,now);
		//cout<<"i: "<<i<<"now == " <<now<<endl;
	}
	if(ans<0) ans = 0;
cout<<ans<<endl;	
		

}



Measured memory_bytes: 900
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	string S;
	cin >> S;
	ll K;
	cin >> K;
	ll itr = 0;
	while (1) {
		if (S[itr] != '1') break;
		if (K - itr - 1 <= 0) break;
		if (S[itr] == '1') itr++;
	}
	cout << S[itr] << endl;
}

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

int main() {
  int n;
  int ans = 1;
  vector<int> aa;
  aa.push_back(0);

  cin >> n;
  for (int k = 0; k < n; k++) {
    int t;
    cin >> t;
    aa.push_back(t);
  }

  int t = aa[1];

  while (1) {
    if (t == 2) break;
    if (ans > n) {
      ans = -1;
      break;
    }
    t = aa[t];
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 892
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

MOD=10**9+7
n,m=map(int,input().split())
c = Counter(prime_factorize(m))
cv=list(c.values())
ans=1
for i in cv:
    for j in range(i):
        ans*=i+n-1-j
        ans%=MOD
        ans*=pow(1+j,MOD-2,MOD)
        ans%=MOD
print(ans)

Measured memory_bytes: 3316
n = gets.to_i
x = Array.new(n){gets.split}
yen=0.to_f
btc=0.to_f

x.each do |a|
  case a[1]
  when "JPY"
    yen+=a[0].to_f
  else
    btc+=a[0].to_f
  end
end

p yen+btc*380000

Measured memory_bytes: 1788
from collections import defaultdict

N, X, Y = map(int, input().split())

ctr = defaultdict(int)
for u in range(1, N):
    for v in range(u + 1, N + 1):
        d = min(v - u, abs(u - X) + 1 + abs(Y - v))
        ctr[d] += 1

for n in range(1, N):
    print(ctr[n])


Measured memory_bytes: 74572
N = int(input())
a = list(map(int, input().split()))

num2 = 0
num4 = 0
for i in range(N):
  if a[i] % 4 == 0:
    num4 += 1
  elif a[i] % 2 == 0:
    num2 += 1

if num4 >= N // 2 or num4*2 + num2 >= N:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 15956
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

int main() {
    ios::sync_with_stdio(false);

  int n;
  cin>>n;
  int ca=0,cb=0,cc=0,ans=0;
  rep(i,0,n)
  {
  	string s;
  	cin>>s;
	rep(i,0,s.length()-1)
	{
		if(s[i]=='A'&&s[i+1]=='B')
		ans++;
	}
	if(s[0]=='B'&&s[s.size()-1]=='A')
	cc++;
	else if(s[0]=='B')
	cb++;
	else if(s[s.size()-1]=='A')
	ca++;
	
  }


	   if(cc&&cb&&ca){
        cout<<ans+cc+1+min(ca-1,cb-1)<<endl;
    }
    else if(cc){
        if(ca||cb)
            cout<<ans+cc<<endl;
        else
            cout<<ans+cc-1<<endl;
    }
    else{
        cout<<ans+min(ca,cb)<<endl;
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;

const int maxn=2e5+100;
const int mo=998244353;
int a[maxn],cnt[maxn],res1[maxn],res2[maxn],r[maxn],rr[maxn];

inline int work(int k){
    int ans=0;
    while(k) {
        int cnt = 0, kk = k;
        while (kk) {
            if (kk & 1)++cnt;
            kk >>= 1;
        }
        k %= cnt;
        ++ans;
    }
    return ans;
}

int main(){
//    freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    int ct=0;
    char c=getchar();
    rep(i,1,n){
        c=getchar();
        a[i]=c-'0';
        if(a[i])++ct;
    }
    rep(i,1,n)cnt[i]=(a[i]==0)?ct+1:ct-1;

    int r1=ct-1,r2=ct+1;

    res1[n]=(r1<=1)?0:1;
    res2[n]=(r2<=1)?0:1;
    per(i,n-1,1){
        res1[i]=(r1>0)?(res1[i+1]*2)%r1:0;
        res2[i]=(res2[i+1]*2>r2)?res2[i+1]*2-r2:res2[i+1]*2;
    }

    ll ans1=0,ans2=0;
    rep(i,1,n){
        if(a[i])ans1+=res1[i],ans2+=res2[i];
    }
    rep(i,1,n){
        if(a[i]&1){
            if(ct==1)r[i]=0;
            else rr[i]=(cnt[i]<=1)?0:(ans1-res1[i]+cnt[i])%cnt[i],r[i]=1;
        }
        else rr[i]=(ans2+res2[i])%cnt[i],r[i]=1;
    }

    rep(i,1,n){
        if(rr[i]){
            r[i]+=work(rr[i]);
        }
        printf("%d\n",r[i]);
    }


    return 0;
}

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

int main()
{
  ll n, k; cin >> n >> k;
  ll ans = 0;
  for (int i=k; i<=n+1; i++) {
    ll mi = i*(i-1)/2;
    ll ma = mi+(n+1-i)*i;
    ans = (ans + ma - mi + 1) % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
import numpy as np
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return np.array(list(map(int, input().split())))

(X,N) = getVar()
p = getArray()

if (len(p) == 0):
  print(X)
else:
  subp = p - X
  i = 0
  while (True):
    if (not -i in subp):
      print(X - i)
      break
    if (not i in subp):
      print(X + i)
      break
    i += 1

Measured memory_bytes: 27224
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin  >> W >> H >> x >> y >> r;
	if (W >= x + r && H >= y + r && x > 0 && y > 0){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 3100
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    string S; cin >> S;
    int N = S.size();

    string ans;
    if (S[0]==S[N-1]) {
        ans = N % 2 == 0 ? "First" : "Second";
    } else {
        ans = N % 2 == 0 ? "Second" : "First";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
n=int(input())
L=list(map(int,input().split()))

ans=0
for i in range(n-2):
  a=L[i]
  for j in range(i+1,n-1):
    b=L[j]
    if a==b:
      continue
    else:
        for k in range(j+1,n):
          c=L[k]
          if a==c or b==c:
            continue
          else:
            if c<a+b and a<b+c and b<c+a:
                ans+=1
print(ans)


Measured memory_bytes: 9060
#define MOD 1000000007
#define PI 3.14159265358979323846
#define inf 100000000000000
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
//#define int long long
#define _ <<" "<<
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
#define int long long

int dp[1009][100009];

int h[1009];
int s[1009];
signed main() {
 
   
    
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
   // freopen("test.txt" ,"r", stdin);
    int n;cin>>n;

    ii a[n];

    forn(i,n)
    {
        int x;cin>>x;
        a[i].fi = x;
        a[i].se = i+1;
    } 
    sort(a,a+n);
    forn(i,n)cout<<a[i].se<<" ";
}

Measured memory_bytes: 1664
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	ans := calc(b) ^ calc(a-1)
	fmt.Println(ans)
}

func calc(x int) int {
	count := (x + 1) / 2
	ans := count % 2
	if x%2 == 0 {
		ans ^= x
	}
	return ans
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            int week = scan.nextInt();
            double debt = 100000;
            for (int i = 0; i < week; i++) {
                debt *= 1.05;
                if (debt % 1000 > 0) {
                    debt += 1000 - debt % 1000;
                }
            }
            System.out.println((int) debt);
        } catch (Exception e) {
            System.exit(0);
        }
    }

}

Measured memory_bytes: 26232
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int X, N; cin >> X >> N;
  vector<int> p(N); rep(i, N) cin >> p[i];
  int ans = INF;
  int tmp = INF;
  for (int i = 0; i <= 101; ++i){
    if (count(p.begin(), p.end(), i) == 0){
      if (abs(i - X) < tmp) {
        ans = i;
        tmp = abs(i - X);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
# C - HonestOrUnkind2
G = [[-1] * 15 for _ in range(15)]
N = int(input())
for i in range(N):
    Ai = int(input())
    for _ in range(Ai):
        x, y = map(int, input().split())
        G[i][x - 1] = y;
        
ans = 0
for i in range(1<<N):
    d = [0] * N
    for j in range(N):
        if (i>>j&1):  # iのjビット目が1であるかどうか 
            d[j] = 1  #  嘘つきと正直の割り当て
            
    ok = True
    for j in range(N):
        if d[j] == 1:
            for k in range(N):
                if G[j][k] == -1:
                    continue
                if G[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, bin(i).count('1'))
    
print(ans)

Measured memory_bytes: 3064
A,B,C,X,Y=map(int,input().split())

value=0
prior=A+B
if C*2 < prior :
    prior=C*2
if C*2<A :
    A=C*2
if C*2<B:
    B=C*2
 
if X>Y:
    value=Y*prior+(X-Y)*A
else:
    value=X*prior+(Y-X)*B
print(value)





Measured memory_bytes: 3060
#include<iostream>
#define MAX_NUM 2000001
typedef unsigned short ushort;

int n=0;

void counting_sort(ushort A[],ushort B[],ushort max){
    //std::cout << "ソートを開始\n";
    int count[max+1];
    for(int i=0;i<=max;i++){
        count[i] = 0;
    }
    
    for(int i=1;i<=n;i++){
        count[A[i]]++;
    }
    
    for(int i=1;i<=max;i++){
        count[i] += count[i-1];
    }
    
    for(int i=n;i>0;i--){
        B[count[A[i]]] = A[i];
        count[A[i]]--;
    }
}


int main(){
    std::cin >> n;
    ushort array[MAX_NUM] = {};
    ushort s_array[MAX_NUM] = {};
    ushort max = 0;
    for(int i=1;i<=n;i++){
        std::cin >> array[i];
        if(array[i] > max) max = array[i];
    }
    
    /*std::cout << array[1];
    for(int i=2;i<=n;i++){
        std::cout << ' ' << array[i] ;
    }
    std::cout << '\n';
     */
    
    counting_sort(array,s_array,max);
    std::cout << s_array[1];
    for(int i=2;i<=n;i++){
        std::cout << ' ' << s_array[i] ;
    }
    std::cout << '\n';
    
    return 0;
}



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

int main()
{
    int iCaseCnt = 1;
    int iNum = 0;
    
    while (cin >> iNum)
    {
        if (0 == iNum)
        {
            break;
        }
        
        cout << "Case " << iCaseCnt << ": " << iNum << endl;
        iCaseCnt++;
    }
    
    return 0;
}



Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n;
  if(n%2==0) cout<<n/2*(n/2)<<'\n';
  else cout<<n/2*(n/2+1)<<'\n';
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');

        var n = long.Parse(input[0]);
        var k = long.Parse(input[1]);

        long current = n;

        if( n > k) 
        {
            current = n % k;
        }

        var a = Math.Abs(current - k);
        var b = current;

        if (a < b)
        {
            Console.WriteLine(a);
        }
        else
        {
            Console.WriteLine(b);
        }

        Console.Read();
    }
}



Measured memory_bytes: 11220
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int q = Integer.parseInt(line);
        ArrayList<Integer> list = new ArrayList<Integer>();
        /*0:pushBack(x): 末尾にx
          1:randomAccess(p):Aの要素apの値を出力する
          2:popBack(): Aの末尾の要素を削除する
        */
        for(int i = 0; i < q; i++) {
            String line1 = sc.nextLine();
            String[] line1sp = line1.split(" ");
            int sousa = Integer.parseInt(line1sp[0]);
            if(sousa == 0) {
                int x = Integer.parseInt(line1sp[1]);
                list.add(x);
            } else if(sousa == 1) {
                int p = Integer.parseInt(line1sp[1]);
                System.out.println(list.get(p));
            } else if(sousa == 2) {
                list.remove(list.size()-1);
            }
        }
    }
 } 


Measured memory_bytes: 207520
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+2;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;

int main()
{
    IOS();

    int n,w,i,j;
    cin>>n>>w;
    vector<int> v[n+1];
    f(i,0,n-1)
    {
      int x,y;
      cin>>x>>y;
      v[x].pu(y);
      v[y].pu(x);
    }
    int ans[n+1]={0};
    f(i,0,w)
    {
      int p,x;
      cin>>p>>x;
      ans[p]+=x;
    }
    // f(i,1,n+1)
    // {
    //   cout<<ans[i]<<" ";
    // }
    queue<int> q;
    q.push(1);
    bool vis[n+1]={false};
    vis[1]=true;
    while(!q.empty())
    {
      int s=q.front();
      q.pop();
      for(auto u: v[s])
      {
        if(vis[u])
          continue;
        vis[u]=true;
        q.push(u);
        ans[u]+=ans[s];
      }
    }
    f(i,1,n+1)
    {
      cout<<ans[i]<<" ";
    }


  return 0;
}

Measured memory_bytes: 15732
#include<bits/stdc++.h>
using namespace std;
typedef long l;
typedef long long ll;
void solve(int a,int p)
{
    int res;
    res = (a*3 + p)/2;
    cout<<res;
}
int main()
{
    int a,p;
    cin>>a>>p;
    solve(a,p);
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

ll hoge(ll x){
    if(x==1) return 1;
    else{
        return 2*hoge(x/2)+1;
    }
}

int main(){
    ll H;
    cin>>H;
    cout<<hoge(H)<<endl;
    return 0;   
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<sys/time.h>
#define ck 26

unsigned long long seed;

unsigned long long xorshift(){
  seed=seed^(seed<<13);
  seed=seed^(seed>>7);
  seed=seed^(seed<<17);
  return seed;
}

int d;
int c[32];
int s[512][32];
int res[512];

int eval(){
  int i,j,lc[32],r=0;
  for(i=1;i<=ck;i++){lc[i]=-1;}
  for(i=0;i<d;i++){
    r+=s[i][res[i]];
    lc[res[i]]=i;
    for(j=1;j<=ck;j++){
      r-=c[j]*(i-lc[j]);
    }
  }
  return r;
}

int sum(int x){
  return (x*(x+1))/2;
}

int delq(int tg,int x){
  int r,i;
  int bfb=-1,bff=d,afb=-1,aff=d;
  r=s[tg][x]-s[tg][res[tg]];

  for(i=tg-1;i>=0;i--){
    if(res[i]==res[tg]){bfb=i;break;}
  }
  for(i=tg+1;i<d;i++){
    if(res[i]==res[tg]){bff=i;break;}
  }

  for(i=tg-1;i>=0;i--){
    if(res[i]==x){afb=i;break;}
  }
  for(i=tg+1;i<d;i++){
    if(res[i]==x){aff=i;break;}
  }
  
  r+=c[res[tg]]*sum((tg-bfb)-1);
  r+=c[res[tg]]*sum((bff-tg)-1);
  r-=c[res[tg]]*sum((bff-bfb)-1);

  r-=c[x]*sum((tg-afb)-1);
  r-=c[x]*sum((aff-tg)-1);
  r+=c[x]*sum((aff-afb)-1);
  return r;
}

void getperm(int n,int p[]){
  int i,tg,mem;
  for(i=0;i<n;i++){
    p[i]=i;
  }
  for(i=n-1;i>=1;i--){
    tg=(xorshift()%(i+1));
    mem=p[tg];
    p[tg]=p[i];
    p[i]=mem;
  }
}

int main(){
  long long stt,nt;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  seed=(tv.tv_sec*1000000+tv.tv_usec);
  stt=seed;
  int i,j,q,r,tg,x,p[32],dv[32];
  int tgpm[512];
  scanf("%d",&d);
  for(i=1;i<=ck;i++){scanf("%d",&c[i]);}
  for(i=0;i<d;i++){
    for(j=1;j<=ck;j++){
      scanf("%d",&s[i][j]);
    }
  }
  for(i=0;i<d;i++){
    res[i]=(i%ck)+1;
  }
  r=eval();
  q=0;
  getperm(d,tgpm);
  while(1){
    tg=tgpm[q];
    for(i=1;i<=ck;i++){dv[i]=delq(tg,i);}
    getperm(ck,p);
    for(i=0;i<ck;i++){
      if(dv[res[tg]]<=dv[p[i]+1]){res[tg]=p[i]+1;}
    }
    q++;
    if(q==d){
      getperm(d,tgpm);
      q=0;
      gettimeofday(&tv, NULL);
      nt=(tv.tv_sec*1000000+tv.tv_usec);
      if((nt-stt)>=1980000){break;}
    }
  }
  for(tg=0;tg<d;tg++){
    for(i=1;i<=ck;i++){dv[i]=delq(tg,i);}
    getperm(ck,p);
    for(i=0;i<ck;i++){
      if(dv[res[tg]]<=dv[p[i]+1]){res[tg]=p[i]+1;}
    }
  }
  for(i=0;i<d;i++){
    printf("%d\n",res[i]);
  }
  return 0;
}


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

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

int main() {
    int n; cin >> n;
    string s;
    map<string, int> m;
    bool flag = true;
    char c;
    rep(i, n){
        cin >> s;
        if(++m[s] >= 2) flag = false;
        if(i>0 && c != s[0]) flag = false;
        c = s[s.size()-1];
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int N;
        cin >> N;
        vector<ll> A(N + 1);
        vector<ll> B(N);
        for (int i = 0; i < N + 1; ++i) {
            cin >> A[i];
        }

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

        ll ans = 0;
        for (int i = 0; i < N; ++i) {
            ll dec = min(A[i], B[i]);
            ans += dec;
            A[i] -= dec;
            B[i] -= dec;

            dec = min(A[i + 1], B[i]);
            ans += dec;
            A[i + 1] -= dec;
            B[i] -= dec;

        }

        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    int x = Math.max(a+b,a-b);
    int y = Math.max(x,a*b);
    System.out.println(y);
  }
}


Measured memory_bytes: 23124
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        N: usize,
        Ds: [i64; N],
    }

    let mut ans = 0;
    for i in 0..N {
        for j in i + 1..N {
            ans += Ds[i] * Ds[j];
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
long long dp[100][100][5000];
long long n, k, x[100];
// long long x[100] means..
// long long x = [0, 0, 0 ... 0] so like...
// long long n, k = 10 is valid...
// long long n, k, x[100] is also valid
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 5000; k++) {
        if (dp[i][j][k] == 0) {
          continue;
        } else {
          dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
          dp[i + 1][j][k] += dp[i][j][k];
        }
      }
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += dp[n][i][i * k];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>

long long a[100][100];
long long b[100][100];
long long c[100][100];

int main()
{
	int n, m, l;
	scanf("%d %d %d", &n, &m, &l);
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < m; ++j)
	{
		scanf("%d", &a[i][j]);
	}
	for(int j = 0; j < m; ++j)
	for(int k = 0; k < l; ++k)
	{
		scanf("%d", &b[j][k]);
	}


	for(int i = 0; i < n; ++i)
	for(int k = 0; k < l; ++k)
	for(int j = 0; j < m; ++j)
	{
		c[i][k] += a[i][j] * b[j][k];
	}
	
	for(int i = 0; i < n; ++i)
	{
		for(int k = 0; k < l-1; ++k)
		{
			printf("%lld ", c[i][k]);
		}
		printf("%lld\n", c[i][l-1]);
	}
	return 0;
}


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

#define int long long

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

	int k;
	string s;
	cin >> k >> s;
	if(s.size() <= k) {
		cout << s << '\n';
	} else {
		for(int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...";
	}
	
	return 0;
}


Measured memory_bytes: 3640
def main():
    S = list(input())
    N = len(S)
    MOD = 10 ** 9 + 7
    dp = [[0] * 13 for _ in range(N + 5)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(13):
            if S[i] != '?':
                dp[i+1][(10 * j + int(S[i])) % 13] += dp[i][j]
                dp[i+1][(10 * j + int(S[i])) % 13] %= MOD
            else:
                for k in range(10):
                    dp[i+1][(10 * j + k) % 13] += dp[i][j]
                    dp[i+1][(10 * j + k) % 13] %= MOD
    print(dp[N][5])


if __name__ == "__main__":
    main()

Measured memory_bytes: 101420
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        if(k * 500 < x){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        sc.close();
    }
}

Measured memory_bytes: 35560
#include <iostream>
#include <algorithm>
#include <cstring>

int h[1500001], w[1500001];
int hh[1500], ww[1500];

int main() {
	int n, m;
	while (std::cin >> n >> m && (n || m)) {
		std::memset(h, 0, sizeof(h));
		std::memset(w, 0, sizeof(w));

		int max = 0;
		for (int i = 0; i < n; i++) {
			std::cin >> hh[i];
		}
		for (int i = 0; i < m; i++) {
			std::cin >> ww[i];
		}

		for (int sy = 0; sy < n; sy++) {
			for (int y = 0; y < n - sy; y++) {
				int num = 0;
				for (int i = 0; i <= sy; i++) {
					num += hh[i + y];
				}
				max = std::max(max, num);
				h[num]++;
			}
		}

		for (int sx = 0; sx < m; sx++) {
			for (int x = 0; x < m - sx; x++) {
				int num = 0;
				for (int i = 0; i <= sx; i++) {
					num += ww[i + x];
				}
				max = std::max(max, num);
				w[num]++;
			}
		}

		long long cnt = 0;
		for (int i = 0; i <= max; i++) {
			cnt += static_cast<long long>(h[i]) * w[i];
		}

		std::cout << cnt << std::endl;
	}

	return 0;
}

Measured memory_bytes: 14772
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector< vector<ll> > tree;

ll dfs(int p) {
  if (tree[p].size() == 0) {
    return 0;
  }

  vector<ll> d;
  for (auto u : tree[p]) {
    d.push_back(dfs(u));
  }
  sort(all(d));
  reverse(all(d));
  // cout << "d: ";
  // rep(i, d.size()) {
  //   cout << d[i] << " ";
  // }
  // cout << endl;

  int res = 0;
  rep(i, d.size()) {
    int c = d[i] + i + 1;
    if (res < c) {
      res = c;
    }
  }
  // cout << "res: " << res << endl;

  return res;
}

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  tree.resize(N);
  for (int i = 1; i < N; ++i) {
    ll j;
    cin >> j;
    --j; // 0-indexed
    tree[j].push_back(i);
  }

  // For Debug
  // rep(i, N) {
  //   cout << i + 1 << ": ";
  //   for (auto j : tree[i]) {
  //     cout << j + 1 << " ";
  //   }
  //   cout << endl;
  // }

  cout << dfs(0) << endl;
}


Measured memory_bytes: 13568