akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

std::vector<int> perm_inv(const std::vector<int> &p) {
  int len = p.size();
  std::vector<int> ans(len);
  for (int i = 0; i < len; ++i) {
    assert (0 <= p[i] && p[i] < len);
    ans[p[i]] = i;
  }
  return ans;
}

// q after p
std::vector<int> perm_comp(const std::vector<int> &q, const std::vector<int> &p) {
  int n = p.size();
  std::vector<int> ret(n);
  for (int i = 0; i < n; ++i) {
    ret[i] = q[p[i]];
  }
  return ret;
}


int main(void){
  int n;
  cin >> n;
  VL x(n);
  VL dx(n - 1), dy(n - 1);
  REP(i, 0, n) {
    cin >> x[i];
  }
  REP(i, 0, n - 1) {
    dx[i] = x[i + 1] - x[i];
  }
  VI perm(n - 1), sum(n - 1), cur(n - 1);
  REP(i, 0, n - 1) {
    perm[i] = i;
    sum[i] = i;
  }
  int m;
  ll k;
  cin >> m >> k;
  VI a(m);
  REP(i, 0, m) {
    cin >> a[i];
    a[i]--; // a[i] = 1, ..., n - 2
    swap(perm[a[i]], perm[a[i] - 1]);
  }
  cur = perm;
  while (k > 0) {
    if (k % 2 == 1) {
      sum = perm_comp(sum, cur);
    }
    cur = perm_comp(cur, cur);
    k /= 2;
  }
  REP(i, 0, n - 1) {
    dy[i] = dx[sum[i]];
  }
  VL y(n);
  y[0] = x[0];
  REP(i, 0, n - 1) {
    y[i + 1] = dy[i] + y[i];
  }
  REP(i, 0, n) {
    cout << y[i] << endl;
  }
}


Measured memory_bytes: 6376
using AtCoderBeginnerContest159.Questions;
using AtCoderBeginnerContest159.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest159.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();

            var subLength = (s.Length - 1) / 2;

            yield return IsKaibun(s) 
                && IsKaibun(s.Substring(0, subLength)) 
                && IsKaibun(s.Substring((s.Length + 3) / 2 - 1, subLength))
                ? "Yes" : "No";
        }

        private bool IsKaibun(string s) => s.SequenceEqual(s.Reverse());
    }
}


namespace AtCoderBeginnerContest159
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest159.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest159.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

for i,j in enumerate(permutations(range(1, n+1))):
    if j == p:
        a = i
        
    if j == q:
        b = i
        
print(abs(a-b))

Measured memory_bytes: 9172
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI 3.14159265358979323846264338327950L

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define int long long
#define Graph vector<vector<int> >
#define PII pair<int,int>
#define VI vector<int>
#define VVI vecotor<vector<int> >
#define VPII vector<pair<int,int> >

template<typename A, size_t N, typename T>

void Fill(A (&array)[N], const T &val) {
	std::fill( (T*)array, (T*)(array + N), val );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここにグローバル変数宣言
int H, W, sh, sw, gh, gw;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};//BFS関連







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数宣言
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}










//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main() {
	//入力の高速化用のコード
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int A,B;
cin>>A>>B;
if(A>=B){
	REP(i,A)cout<<B;
}
else REP(i,B)cout<<A;














return 0;

}







Measured memory_bytes: 3580
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using pii =pair<int,int>;

int n,k;
priority_queue<int> q;

void input(){
    cin>>n>>k;
    int a;
    rep(i,n){
        cin>>a;
        q.push(a);
    }
}

void src(){
    int count=0;
    rep(i,n){
        if(q.top()>=k){
            q.pop();
            ++count;
        }
    }
    cout<<count;
    return;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 892
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


const ll MOD = 1e9 + 7;

ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

pair<int, int> a[3100];

const int MAXN = 210000;
int h, w, n;

ll fc[MAXN];
ll bfc[MAXN];

ll get(int x, int y) {
	if (x < 0 || y < 0)
		return 0;
	return fc[x + y] * bfc[x] % MOD * bfc[y] % MOD;
}

ll dp[MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	fc[0] = 1;
	for (int i = 1; i < MAXN; ++i)
		fc[i] = (fc[i - 1] * i) % MOD;
	bfc[MAXN - 1] = pw(fc[MAXN - 1], MOD - 2);
	for (int i = MAXN - 2; i >= 0; --i)
		bfc[i] = (bfc[i + 1] * (i + 1)) % MOD;
	cin >> h >> w >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i].first >> a[i].second, --a[i].first, --a[i].second;
	sort(a, a + n);
	ll ans = get(h - 1, w - 1);
	for (int i = 0; i < n; ++i) {
		dp[i] = get(a[i].first, a[i].second);
		for (int j = 0; j < i; ++j) {
			dp[i] = (dp[i] - dp[j] * get(a[i].first - a[j].first, a[i].second - a[j].second)) % MOD;
		}
		if (dp[i] < 0)
			dp[i] += MOD;
		ans = (ans - dp[i] * get(h - 1 - a[i].first, w - 1 - a[i].second)) % MOD;
	}
	if (ans < 0)
		ans += MOD;
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <list>
using namespace std;

int main() {
    string s;
    int x, y, j = 0, k = 0;
    cin >> s >> x >> y;
    list<int> nums[2];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            nums[j].emplace_back(k);
            k = 0;
            j = 1 - j;
        } else {
            k++;
        }
    }
    nums[j].emplace_back(k);
    x -= nums[0].front();
    nums[0].pop_front();
    auto knapsack = [&](list<int>& nums, int target)->bool {
        int size = s.size() * 2 + 1;
        if (s.size() + target >= size) {
            return false;
        }
        vector<bool> table(size);
        auto dp = [&](int i) {
            return table[s.size() + i];
        };
        dp(0) = true;
        for (int i : nums) {
            vector<bool> next(size);
            for (int j = 0; j < size; j++) {
                if (j - i >= 0) {
                    next[j] = next[j] || table[j - i];
                }
                if (j + i < size) {
                    next[j] = next[j] || table[j + i];
                }
            }
            table = move(next);
        }
        return dp(target);
    };
    if (knapsack(nums[0], x) && knapsack(nums[1], y)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    
    if(a.equals("D")){
      if(b.equals("H")) b = "D";
      else b = "H";
    }
    System.out.println(b);
  }
}


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

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<vector<ll>> a(3, vector<ll>(n));
    rep(i, 3) {
        rep(j, n) {
            cin >> a[i][j];
        }
    }
    sort(a[0].begin(), a[0].end());
    sort(a[1].begin(), a[1].end());
    sort(a[2].begin(), a[2].end());
    rep(i, n) {
        auto und = lower_bound(a[0].begin(), a[0].end(), a[1][i]) - 1;
        auto hed = upper_bound(a[2].begin(), a[2].end(), a[1][i]);
        ans += (und - a[0].begin() + 1) * (a[2].end() - hed);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6380
N = int(input())
a = input().split()
a = list(map(int,a))
n = 0
p = N
while p == N:
  p = 0
  for i in range(N):
    if a[i]%2 == 0:
      p = p + 1
  if p == N:
    a = list(map(lambda x: x/2,a))
    n = n + 1
print(n)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vint vector<int>
int main(){
  int a;
  cin >> a;
  vint A(a);
  rep(i,a) cin >> A.at(i);
  int MIN = 100000000;
  rep(i,100){
    int sum = 0;
    rep(j,a)
      sum += pow(A.at(j) - i,2);
    MIN = min(MIN,sum);
  }
  cout << MIN << endl;
}
      
  

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

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

    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        string s = to_string(i);
        ll digit = s.length();
        if (digit % 2 != 0) {
            ans++;
        }

    }

    MSG(ans)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    if(s.size()==6&&s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);

constexpr int M = 311;
double dp[M][M][M] = {};
bool visit[M][M][M] = {};
vector<tuple<int,int,int>> top;

bool used[M][M][M] = {};
int N;
double dfs(lli i, lli j, lli k){
  double&ret = dp[i][j][k];
  if(ret)
    return ret;
  ret = 0;
  if(i==0&&j==0&&k==0)return 0;
  // dfs(i,j,k) = 1 + empty/N dfs(i,j,k)
  lli r = i + j + k;
  if(i) ret += dfs(i-1, j, k) * i;
  if(j) ret += dfs(i+1, j-1, k) * j ;
  if(k) ret += dfs(i, j+1, k-1) * k ;
  ret += N;
  ret *= 1.0/ r;
  return ret;
}
void solve(long long NN, std::vector<long long> a) {
  N = NN;
  int cnt[3] = {};
  rep(i, N)cnt[a[i]-1]++;
  printf("%.15f\n", dfs(cnt[0],cnt[1], cnt[2]));
}

signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 231680
#include <stdio.h>
 
int main(){
  int n,k,x,y;
  int total=0;
    
  scanf("%d",&n);
  scanf("%d",&k);
  scanf("%d",&x);
  scanf("%d",&y);
  
  if(n<=k){
    total=n*x;
  } else {
    total=k*x;
    total+=((n-k)*y);
  }
  
  printf("%d",total);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n, x;
	cin >> n >> x;
	vector<int>a(n);
	int ans = 0;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (sum > x) {
			break;
		}
		ans++;
	}
	if (ans == n) {
		if (x != sum) {
			ans--;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int round, house, i,range;
  scanf("%d %d", &round, &house);
  int dist[house];
  for(i = 0; i < house; i++){
    scanf("%d", &dist[i]);
  }
  
  range = dist[1] - dist[0];
  
  for(i = 1; i < house - 1; i++){
    if(range < (dist[i+1] - dist[i])){
      range = dist[i+1] - dist[i];
    }
  }
 if(range < (round - dist[house-1] + dist[0])){
   range = round - dist[house-1] + dist[0];
 }
  
  round = round - range;
  printf("%d\n",round);
  
  return 0;
}

Measured memory_bytes: 896
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def build(self, lis):
        self.value = lis
        for i, x in enumerate(lis):
            self.add(i+1, x)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)


def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    bit = FenwickTree(n)
    bit.build(a)
    
    for i in range(q):
        a, b, c = map(int, input().split())
        if a == 0:
            bit.add(b+1, c)
        else:
            print(bit.get_sum(b, c))
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 132540
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});
 
reader.on('close', () => {
  const S = lines[0];
  var ans = {A: "T", T:"A", G:"C", C:"G"}[S]
  console.log(ans);
});

Measured memory_bytes: 7500
#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>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit
int N;
vector<vector<int>> tree;

int dfs(int v = 0, int p = -1) {
    int ret = 0;
    for (auto c : tree[v]) {
        if (c != p) {
            int tmp = dfs(c, v);
            ret ^= (tmp + 1);
        }
    }

    return ret;
}

void solve() {
    cin >> N;
    tree.resize(N);
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    int g = dfs();
    if (g == 0) {
        cout << "Bob" << endl;
    } else {
        cout << "Alice" << endl;
    }


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 12788
n, m = gets.split.map(&:to_i)
A = n.times.map{gets.split.map(&:to_i)}
b = m.times.map{gets.to_i}

n.times do |i|
	_Ai = A[i]
	p m.times.map{|j| _Ai[j] * b[j]}.inject(&:+)
end

Measured memory_bytes: 8900
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, K, ans;

int main()
{
	in >> N >> K;
	std::vector<LL>x(N), plus(N + 1, 0), minus(N + 1, 0), temp;
	rep(i, N) in >> x[i];
	rep(i, N)
	{
		if (x[i] < 0) temp.push_back(x[i]);
	}
	std::sort(temp.rbegin(), temp.rend());
	LL cou1 = 1, cou2 = 1;
	rep(i, N)
	{
		if (x[i] > 0)
		{
			plus[cou1] = x[i];
			++cou1;
		}
		if (x[i] == 0) --K;
	}
	rep(i, temp.size())
	{
		if (temp[i] < 0)
		{
			minus[cou2] = -temp[i];
			++cou2;
		}
	}
	if (K == 0)
	{
		out << 0 << std::endl;
		return 0;
	}
	ans = 11234567890;
	for (int i = 0; i <= std::min<LL>(cou1 - 1, K); ++i)
	{
		if (K != i && minus[K - i] == 0) continue;
		LL res = plus[i] + minus[K - i];
		res += std::min(plus[i], minus[K - i]);
		ans = std::min(ans, res);
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3704
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextLong();
		}
		long deno = 1;
		for(long in: a) deno = lcm(in, deno);

		long num = 0;
		for(long in: a) num += deno / in;
		//System.out.println(deno);
		double ans = (double)deno / num;
		System.out.println(ans);
	
	}
	
	public static long gcd(long a, long b){
		if (a == 0) return b;
		return gcd(b % a, a);
	}
	
	public static long lcm(long a, long b){
		return a * b / gcd(a, b);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t; cin>>t; while(t--)
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend() 
const int N = 2e5+5;
const ll MAX = 1e9 +7;

int GCD(int A, int B) 
{
    if(B==0)
        return A;
    else
        return GCD(B, A % B) 	;
}
int main()
{
	bolt;
	ll ans =0;
	int a,b;
	cin>>a>>b;
	
	ll g = GCD(a,b);
	ans = a/g * b;
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
L_count = 0
R_count = 0
div = 100000
s = sum(W)
for i in range(N):
    L_count += W[i]
    R_count = s - L_count
    d = abs(L_count-R_count)
    if div > d:
        div = d
print(div)




Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

void dijkstra(int n_node, std::vector<int> &from, std::vector<int> &to, std::vector<int> &cost,
                        std::vector<long> &dist, std::vector<int> &prev, int start = 0, int end = -1){
    /**
     * Compute the minimum distance from the start point to other node(s).
     * @param[in] n_node : the number of nodes.
     * @param[in] from : the start point of each edge. (the index is the edge ID.)
     * @param[in] to : the end point of each edge.
     * @param[in] cost : the cost of each edge.
     * @param[out] dist : the minimum distance from the origin to each node.
     * @param[out] prev : the previous node of each node in the shortest path.
     * @param[in] start : the start point of search. (also reffered as "origin".)
     * @param[in] end : the destination of search. (if not specified, the min distance to each nodes is computed.)
     */
    dist.resize(n_node, -1);  // prepare for output.
    prev.resize(n_node, -1);  // prepare for output.
    dist[start] = 0;
    std::multimap<int, int> edges;  // <start node, edge index>
    for(int i = 0; i < from.size(); ++i) edges.insert(std::make_pair(from[i], i));
    std::multimap<long, int> dists;  // <provisional distance from origin node, the node>
    while(true){
        int tmp = edges.lower_bound(start)->first;
        // update the provisional minimum distance from the origin to all adjacent nodes.
        for(auto i = edges.lower_bound(start);; ++i){
            if(tmp != i->first || i == edges.end()) break;
            if(-1 == dist[to[i->second]]){
                dists.insert(std::make_pair(dist[start] + cost[i->second], i->second));
            }
        }
        if(end == start || dists.empty()) break;  // if no adjacent nodes or reach the destination, finish searching.
        // select the node nearest from the origin as the next node.
        while(true){
            if(-1 == dist[to[dists.begin()->second]]){
                prev[to[dists.begin()->second]] = from[dists.begin()->second];
                start = to[dists.begin()->second];  // move to the next node.
                dist[start] = dists.begin()->first; // fix the minimum distance from the origin to current node.
                dists.erase(dists.begin());
                break;
            }
            dists.erase(dists.begin());
            if(dists.empty()) break;  // if no adjacent nodes, finish searching.
        }
    }
    return;
}

int main(void){
    int n, m;
    std::cin >> n >> m;
    std::vector<int> from(2 * m), to(2 * m), cost(2 * m, 1), prev;
    std::vector<long> dist;
    for(int i = 0; i < m; ++i){
        std::cin >> from[i * 2] >> to[i * 2];
        --from[i * 2];
        --to[i * 2];
        from[i * 2 + 1] = to[i * 2];
        to[i * 2 + 1] = from[i * 2];
    }
    dijkstra(n, from, to, cost, dist, prev);
    std::cout << "Yes" << std::endl;
    for(int i = 1; i < n; ++i){
        std::cout << prev[i] + 1 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 39040
#include<bits/stdc++.h>
typedef long long ll;
//#define mod 1000000007
 
using namespace std;
 
bool cal(ll a, ll b) {
    cout<<a<<" "<<b<<endl;
	if (a << 1 > b) 
		return 1; 
	b >>= 1; 
	if (a << 1 > b) 
		return (b - a) & 1; 
	if (b & 1) 
		return (b - a) & 1; 
	return cal(a, b >> 1); 
}
  
 
main() {
    int n,m,q;
    cin>>n>>m>>q;
    string s[n];
    int ans=0;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<pow(2,n);i++){
        for(int j=0;j<pow(2,m);j++){
            int bl=0;
            for(int k=0;k<n;k++){
                for(int l=0;l<m;l++){
                    int c3=pow(2,k);
                    int c4=pow(2,l);
                    int c1=i&c3;
                    int c2=j&c4;
                    if(c1==0 && c2==0 && s[k][l]=='#'){
                        //cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;
                        bl++;
                    }
                }
            }
            //
            if(bl==q){
                //cout<<i<<" "<<j<<" "<<bl<<endl;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
long long n;
void solve()
{
    string a;
    cin>>a;
    long long i,k;
    cin>>k;
    for (i=0;i<a.length();i++)
        if (a[i]==a[k-1]) cout<<a[i];
        else cout<<"*";
    cout<<endl;
}
int main()
{
    while(cin>>n)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
   char a[51],b[51];
  scanf("%s %s",a,b);
  for (size_t i = 0; i < strlen(a); i++) {
    if (i < strlen(a)) {
      printf("%c",a[i]);
    }
    if (i < strlen(b)) {
      printf("%c",b[i]);
    }
  }
  printf("\n");
  return 0;
}


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

using namespace std;
# define rep(i, a, b) for(int i = a; i < (b); ++i)
# define trav(a, x) for(auto& a : x)
# define MOD 998244353
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


struct Tree {
    typedef ll T;
    static constexpr T unit = 0ll;

    T f(T a, T b) { return (a + b) % MOD; } // (any associative fn)
    vector<T> s;
    int n;

    Tree(int n = 0, T def = unit) : s(2 * n, def), n(n) {}

    void update(int pos, T val) {
        for (s[pos += n] = val; pos /= 2;)
            s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
    }

    T query(int b, int e) { // query [b, e)
        b = max(b, 0);
        e = max(e, 0);
        T ra = unit, rb = unit;
        for (b += n, e += n; b < e; b /= 2, e /= 2) {
            if (b % 2) ra = f(ra, s[b++]);
            if (e % 2) rb = f(s[--e], rb);
        }
        return f(ra, rb);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int k;
    cin >> k;
    vi l(k);
    vi r(k);
    for (int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
    }
    Tree t(n + 1);
    t.update(0, 1);
    rep(i, 1, n) {
        ll s = 0;
        rep(j, 0, k) {
            s = (s + t.query(i - r[j], i)) % MOD;
            s = (s - t.query(i - (l[j] - 1), i)) % MOD;
        }
        s = (s + MOD) % MOD;
        t.update(i, s);
    }
    cout << t.query(n - 1, n);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    double N, K;
    double sum = 0;
    double pre;
    double pre2 = log10(2);
    cin >> N >> K;
    pre = 1.0 / N;
    for(ll i = 1;i <= N;i++) {
        if(i < K) {
            double x = ceil(log10(K / i) / pre2);
            sum += pre * pow(0.5, x);
        } else {
            sum += pre;
        }
    }
    cout << setprecision(12) << fixed << sum << endl;
    return 0;
}


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

int main()
{
  int n;
  string input;

  scanf("%d", &n);
  for (int i = 0; i < n; i++){
    queue<bool> base;
    int out = 0, pt = 0;
    while (out < 3){
      cin >> input;
      if (input == "HIT"){
        base.push(true);
        if (base.size() == 4){
          pt += base.front();
          base.pop();
        }
      }
      else if (input == "HOMERUN"){
        pt += base.size() + 1;
        while (!base.empty()){ // all elements clear
          base.pop();
        }
      }
      else if (input == "OUT"){
        out++;
      }
    }
    printf("%d\n", pt);
  }

  return (0);
}

Measured memory_bytes: 1248
#include<stdio.h>
#define Max 10001
int parent(int);
int left(int);
int right(int);
int main(){
  int heap,i,A[Max];
  scanf("%d",&heap);
  for(i=1;i<=heap;i++)
    scanf("%d",&A[i]);
  for(i=1;i<=heap;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=heap)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=heap)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int x){
  return x/2;
}
int left(int x){
  return 2*x;
}
int right(int x){
  return 2*x+1;
}

Measured memory_bytes: 608
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	S := nextLine()
	ans := make([]byte, 0)
	ans = append(ans, S[0])
	index := 0
	for i := 1; i < N; i++ {
		if ans[index] != S[i] {
			ans = append(ans, S[i])
			index++
		}
	}
	fmt.Println(len(ans))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

using namespace std;

int main()
{
  string s;
  
  cin >> s;
  
  for ( size_t i = 0 ; i < s.size() ; ++i ) {
    if ( s[i] == '?' ) s[i] = 'D';
  }
  
  cout << s << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
long long i[11111111];
long long u[11111111];
long long o[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  string s;
  cin >>a>>i[0];
  u[0]=i[0];
  for(int n=1;n<a;n++) cin >>u[n],i[n]+=i[n-1]+u[n];
  o[a-1]=u[a-1];
  for(int n=a-2;n>=0;n--){
    o[n]=o[n+1]+u[n];
  }
  d=o[1]-i[0];
  if(d<0) d=-d;
  for(int n=1;n<a-1;n++){
    e=o[n+1]-i[n];
    if(e<0) e=-e;
    if(d>e) d=e;
  }
  cout <<d<<'\n';
  return (0);
}


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

int maxn;
vector<int> to[21];
int cost[21][21];
int tree[21];//その木の種類を示す //0:tree,1:leaf,2:last
bool isgo[21];


int dfs(int t,int c)
{
	int sum = 0;
	isgo[t] = true;
	bool go = false;
	for(int i=0;i<to[t].size();++i){
		int next = to[t][i];
		if(isgo[next])
			continue;
		else{
			go = true;
			int num = dfs(next,cost[t][next]);
			if(num == 0){
				tree[next] = 1;
				tree[t] = 2;
			}
			sum += num;
		}
	}
	if(go)
		return sum+c;
	else//どこにも行くところがなかった
		return 0;
}

int maxcost;

void check(int t,int sumc)//2回目のＤＦＳ・・・ムダー
{
	bool b=false;
	isgo[t] = true;
	for(int i=0;i<to[t].size();++i){
		int next = to[t][i];
		if(tree[next] == 1 || isgo[next])
			continue;
		else{
			b = true;
			check(next,cost[t][next]+sumc);
		}
	}
	if(!b){//行き先がない
		if(maxcost < sumc)
			maxcost = sumc;
	}
}

int main(void)
{
	while(1){
		cin >> maxn;
		if(maxn == 0)
			return 0;
		memset(isgo,false,sizeof(isgo));
		memset(tree,0,sizeof(tree));
		for(int i=0;i<21;++i)
		{
			to[i].clear();
		}
		memset(cost,0,sizeof(cost));
		for(int i=0;i<maxn-1;++i){
			int a,b,c;
			cin >> a >> b >> c;
			to[a].push_back(b);
			to[b].push_back(a);
			cost[a][b] = c;
			cost[b][a] = c;
		}
		int sum = dfs(1,0)*2;
		memset(isgo,false,sizeof(isgo));
		maxcost = 0;
		check(1,0);
		cout << sum - maxcost << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<pair<ll,int>> A(N,make_pair(0,0));
  for(int i=0;i<N;i++){
    cin >> A[i].first;
    A[i].second=i+1;
  }

  sort(A.begin(),A.end(),greater<pair<ll,int>>());

  vector<vector<ll>> dp(N+1,vector<ll>(N+1));

  for(int i=1;i<=N;i++){
    dp[i][0]=dp[i-1][0]+A[i-1].first*( A[i-1].second-i);
    dp[0][i]=dp[0][i-1]+A[i-1].first*(-A[i-1].second+(N-i+1));
  }

  for(int i=1;i<N;i++){
    for(int j=1;j<=N-i;j++){
      dp[i][j]=max(dp[i-1][j]+A[i+j-1].first*( A[i+j-1].second-i),
                   dp[i][j-1]+A[i+j-1].first*(-A[i+j-1].second+(N-j+1)));
    }
    /*
    for(int p=0;p<=N;p++){
      for(int q=0;q<=N;q++){
        cout << dp[p][q] << " ";
      }
      cout << endl;
    }
    cout << "-------" << endl;
    */
  }

  ll ans=0;
  for(int i=0;i<=N;i++){
    ans=max(dp[i][N-i],ans);
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  string phrase[3];
  for (int i = 0; i < 3; i++) {
  	cin >> phrase[i];
  }
  
  string abbreviation;
  for (int i = 0, size = sizeof(phrase) / sizeof(phrase[0]); i < size; i++) {
  	abbreviation += phrase[i].at(0);
  }
  
  cout << abbreviation << endl;
}


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 450555;
const int L = 21;
const int M = 1155;

void solve(){
    ll n;
    cin >> n;

    ll ans = n/500 * 1000;
    n %= 500;

    cout << ans + n/5*5;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N, int A, int B, int C, int D)
        {
            for (int i = 0; i < N - 1; ++i)
            {
                int j = N - 1 - i;
                long p1 = Math.BigMul(C, i);
                long p2 = Math.BigMul(D, i);
                long n1 = Math.BigMul(-D, j);
                long n2 = Math.BigMul(-C, j);
                if (A + p1 + n1 <= B && B <= A + p1 + n2) { return true; }
                if (A + p2 + n1 <= B && B <= A + p2 + n2) { return true; }
            }
            return false;
        }
        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], V[2], V[3], V[4]) ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> num(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> num.at(i);
    sum+=num.at(i);
  }
  //cout << sum%N << endl;
  if(sum%N==0){
    int mean=sum/N;
    int cost=0;
    for(int i=0;i<N;i++){
      cost+=pow(abs(num.at(i)-mean),2);
    }
    cout << cost << endl;
  }
  else{
    int mean1=sum/N;
    int mean2=sum/N+1;
    int cost1=0;
    int cost2=0;
    for(int i=0;i<N;i++){
      cost1+=pow(abs(num.at(i)-mean1),2);
      cost2+=pow(abs(num.at(i)-mean2),2);
    }
  	cout << min(cost1,cost2) << endl;
  }
}

Measured memory_bytes: 256
def main():
    T1, T2 = list(map(int, input().split()))
    A1, A2 = list(map(int, input().split()))
    B1, B2 = list(map(int, input().split()))
    # 青木君を基準にした高橋君の位置を追い、0に何回ぶつかるかを調べる
    V1, V2 = A1 - B1, A2 - B2
    if V1 == 0 or V2 == 0 or V1 * V2 > 0:
        print(0)
        return
    # この後は V1 * V2 < 0
    d1, d2 = V1 * T1, V2 * T2
    d12 = d1 + d2
    if d1 * d12 > 0:
        print(0)
    elif d12 == 0:  # d1 * d12 == 0
        print('infinity')
    else:  # d1 * d12 < 0
        cnt = 0
        # d1で0に達する
        cnt += abs(d1) // abs(d12)
        # d2で0に達する
        cnt += 1 + (abs(d1) - 1) // abs(d12)
        print(cnt)


if __name__ == '__main__':
    main()


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

int main(){
    int n, i, x = 0, m = 0;
    string s;
    cin >> n >> s;
    for(i=0; i<n; i++){
        if(s[i] == 'I'){
            x++;
        }else{
            x--;
        }
        m = max(m, x);
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

typedef pair<int, int> pi;

int main() {
    int n, m;

    cin>>n>>m;

    priority_queue<int> pq;

    int tmp;
    for(int i=0;i<n;i++){
        cin>>tmp;
        pq.push(tmp);
    }

    long long ans = 0;
    int res;
    while(!pq.empty())
    {
        tmp = pq.top();
        if(m > 0){
            m -= 1;
            if(tmp >= 0){
                res = tmp / 2;
                pq.pop();
                pq.push(res);
            }
            else
            {
                ans += pq.top();
                pq.pop();
            }
        }else
            break;
    }

    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }

    cout<<ans;


	return 0;
}


Measured memory_bytes: 892
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

n = ni()
s = ns()

q = deque()
for i in range(n):
    p = q.pop() if len(q) else '$'
    if not (p == '(' and s[i] == ')'):
        if p != '$':
            q.append(p)
        q.append(s[i])

ans = deque(s)
for c in q:
    if c == ')':
        ans.appendleft('(')
    else:
        ans.append(')')

print(*ans, sep="")

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

typedef long long ll;

vector < pair<ll,int> > v;
int n,V,p;
ll m,c[100005];

bool check(int index){
//	cout<<index<<endl;
	vector <pair<ll,int> > v2;
	for(int i=0;i<100005;i++) c[i]=0;
	v2=v;
	int _=v2[index].second;
	ll sum=ll(m*ll(V)); 
//	cout<<sum<<endl;
//	cout<<v2[index].second<<endl;
//	cout<<v2[index].first<<" ";
	v2[index].first+=m; sum-=m;
	int __=v2[index].first;
//	cout<<v2[index].first<<endl;
	for(int i=0;i<v2.size();i++) if(i!=index){
		if(sum<=0) break;
		if(v2[i].first>v2[index].first){
			v2[i].first+=min(sum,m);
			c[i]=min(sum,m);
			sum-=min(sum,m);
			continue;
		}
		if(v2[i].first==v2[index].first) continue;
		if(v2[i].first<v2[index].first){
		//	cout<<v2[i].first<<" "<<v2[index].first<<" "<<v2[index].second<<endl;
			ll add=min(sum,min(v2[index].first-v2[i].first,m));
			c[i]=add;
			v2[i].first+=add;
			sum-=min(sum,add);
		}
	//	cout<<sum<<endl;
	}
	for(int i=0;i<v2.size();i++) if(index!=i){
		if(sum<=0) break;
		ll add=min(sum,m-c[i]);
		sum-=add;
		v2[i].first+=add;
	}
//	cout<<v2[index].first<<" "<<v2[index].second<<endl;
	sort(v2.begin(),v2.end());
	reverse(v2.begin(),v2.end());
//	for(int i=0;i<v2.size();i++) cout<<v2[i].first<<","<<v2[i].second<<" ";
//	cout<<endl;
	for(int i=0;i<p;i++){
		if(-v2[i].second==_||v2[i].first==__) return true;
	}
	return false;
}

int main(){
	cin>>n>>m>>V>>p;
//	cout<<n<<" "<<m<<" "<<V<<" "<<p<<endl;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		v.push_back(make_pair(x,i));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
//	for(int i=0;i<v.size();i++) cout<<v[i].first<<","<<v[i].second<<" ";
//	cout<<endl;
	int low=0,high=v.size(),ans=-1;
//	cout<<check(mid)<<endl;
	while(low<high){
		int mid=(low+high)/2;
	//	cout<<mid<<endl;
	//	cout<<-v[mid].second<<" "<<check(-v[mid].second)<<endl;
		if(check(mid)){
			ans=max(ans,mid);	
			low=mid+1;
		}
		else 	
			high=mid;
	}	
	if(ans==-1) 
		printf("0\n");
	else 
		printf("%d\n",ans+1);
	return 0;
}

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

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    vector<int> w(5);
    w[0] = abs(a - (a/10)*10);
    w[1] = abs(b - (b/10)*10);
    w[2] = abs(c - (c/10)*10);
    w[3] = abs(d - (d/10)*10);
    w[4] = abs(e - (e/10)*10);
    int wmin = 11;
    int wmax = -1;
    int minid = 0;
    int maxid = 4;
    for (int i=0; i<5; i++) {
        if (wmin > w[i] && w[i] != 0) {
            minid = i;
            wmin = w[i];
        }
        if (wmax < w[i]) {
            maxid = i;
            wmax = w[i];
        }
    }

    if (minid == maxid) {
        minid = 0;
        maxid = 4;
    }
    vector<int> input{a, b, c, d, e};
    int minval = input[minid];
    int maxval = input[maxid];

    int ans = maxval;
    for (int i=0; i<5; i++) {
        if (i == maxid) {
            continue;
        } else if (i == minid) {
            continue;
        } else {
            if (ans % 10 != 0) {
                ans = (ans/10+1)*10;
                ans += input[i];
            } else {
                ans += input[i];
            }
        }
    }
    if (ans % 10 != 0) {
        ans = (ans/10+1)*10;
        ans += minval;
    } else {
        ans += minval;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256