akhauriyash/Code-Regression huggingface dataset:
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Solve() {
  S := NextLine()
  var Q int
  NextInt(&Q)
  T := make([]int, len(S) + 2 * Q)
  for i := range T {
    T[i] = -1
  }
  for i, s := range S {
    T[Q + i] = int(s) - int('a')
  }
  l, r := Q - 1, Q + len(S)
  d := 1
  for i := 0; i < Q; i++ {
    q := strings.Split(NextLine(), " ")
    t, _ := strconv.Atoi(q[0])
    if t == 1 {
      d *= -1
    } else {
      f, _ := strconv.Atoi(q[1])
      f = 2 * f - 3
      c := int(q[2][0]) - int('a')
      if d * f < 0 {
        T[l] = c
        l--
      } else {
        T[r] = c
        r++
      }
    }
  }
  ans := make([]rune, r - l - 1)
  if 0 < d {
    for i := range ans {
      ans[i] = rune(T[l + 1 + i] + int('a'))
    }
  } else {
    for i := range ans {
      ans[i] = rune(T[r - 1 - i] + int('a'))
    }
  }
  Write(string(ans))
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> vec; // int型の配列変数vecを宣言
  int N; 
  cin >> N; 
  vec = { 0, 0, 0, 0, 0 }; 
  for (int i = 0; i < N; ++i) {
  string S;
  cin >> S;     
  if(S.at(0) == 'M') vec.at(0)++;
  if(S.at(0) == 'A') vec.at(1)++;
  if(S.at(0) == 'R') vec.at(2)++;
  if(S.at(0) == 'C') vec.at(3)++;
  if(S.at(0) == 'H') vec.at(4)++;
  } 
long long int a, b, c, d, e; 
  a = vec.at(0), b = vec.at(1), c = vec.at(2), d = vec.at(3), e = vec.at(4); 
long long int X; 
  X = a*b*c+a*b*d+a*b*e+a*c*d+a*c*e+a*d*e+b*c*d+b*c*e+b*d*e+c*d*e; 
cout << X << endl; 
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = (1LL << 50);

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;









ll e[300][300];
ll r[300];
ll d[300][300];

void floyd(int N) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}

ll vis[300];
ll minval = inf;

void dfs(int from, int val, int cnt, int R) {
	
	if (cnt == R) {

		minval = min(minval, val);
		return;
	}


	for (int j = 0; j < R; j++) {
		if (vis[r[j]] == 0) {
			vis[r[j]] = 1;
			dfs(r[j], val + d[from][r[j]], cnt + 1, R);
			vis[r[j]] = 0;
		}

	}



}





int main() {

	ll N, M, R;
	ll A, B, C;
	cin >> N >> M >> R;


	rep(i, 300) {
		rep(j, 300) {
			e[i][j] = 0;
			d[i][j] = inf;
			if (i == j)
				d[i][j] = 0;
		}
	}

	rep(i, R)
		cin >> r[i];


	rep(i, M) {
		cin >> A >> B >> C;
		e[B][A] = e[A][B] = C;
		
		d[B][A] = d[A][B] = C;

	}
		

	floyd(N);



	for (int j = 0; j < R; j++) {
		vis[r[j]] = 1;
		dfs(r[j], 0, 1, R);
		vis[r[j]] = 0;
	}

	cout << minval << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int total = 0;
  for (int i = 0; i < N; i++){
      int X1;
      int X2;
      cin >> X1 >> X2;
      total = total + X2 - X1 + 1;

  }
  cout << total;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
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;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color, D; vll path;
//***********//
void dfs(ll now, ll C) {
	stack<ll> S;
	S.push(now);
	color[now] = C;
	while (!S.empty()) {
		ll u = S.top();
		S.pop();
		for (ll i = 0; i < path[u].size(); i++) {
			ll v = path[u][i];
			if (color[v] == 0) {
				dfs(v, C);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	path.resize(N);
	color.resize(N);

	for (i = 0; i < M; i++) {
		ll x, y;
		cin >> x >> y;
		path[x].push_back(y);
		path[y].push_back(x);
	}
	ll C = 1;
	for (i = 0; i < N; i++) {
		if (color[i] == 0) {
			dfs(i, C);
			C++;
		}
	}
	vpll L(N);
	for (i = 0; i < N; i++) {
		L[i] = make_pair(A[i], i);
	}
	sort(L.begin(), L.end());
	vll P(C);
	for (i = 0; i < N; i++) {
		P[color[L[i].second]].push_back(L[i].first);
	}
	ll need = (C - 2) * 2;
	if (C == 2) {
		cout << 0;
	}
	else {
		for (i = 1; i <= C - 1; i++) {
			ans += P[i][0];
			need--;
		}
		vl Q;
		for (i = 1; i <= C - 1; i++) {
			for (j = 1; j < P[i].size(); j++) {
				Q.push_back(P[i][j]);
			}
		}
		sort(Q.begin(), Q.end());
		if (need > Q.size()) {
			cout << "Impossible";
			exit(0);
		}
		else {
			for (i = 0; i < need; i++) {
				ans += Q[i];
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 11896
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

template <class T> T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}


#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n, k;
	::std::cin >> n >> k;
	::std::vector<u64> a(n), b(n), c;
	for (const auto i : rep<>(0, n)) {
		::std::cin >> a[i];
		for (const auto j : rep<>(0, i)) {
			b[j] += a[i];
			c.push_back(b[j]);
		}
		b[i] = a[i];
		c.push_back(b[i]);
	}

	u64 ans = 0;
	for (const auto p : revrep<>(0, 40)) {
		ans |= u64(1) << p;
		usize cnt = 0;
		for (const auto e : c) {
			if ((e&ans) == ans)++cnt;
		}
		if (k > cnt)ans ^= u64(1) << p;
	}

	::std::cout << ans << ::std::endl;

	return 0;
}


Measured memory_bytes: 6580
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int dp[100005],n,k;
vector<int> v;
int solve(int i){
  if(i>=n-1)return 0;
  if(dp[i]!=-1)return dp[i];
  int ans=1e18;
  rep(j,1,k+1){
    if(i+j>=n)break;
    ans=min(ans,llabs(v[i]-v[i+j])+solve(i+j));
  }
  dp[i]=ans;
  //cout<<ans<<" "<<i<<"\n";
  return ans;
}
int32_t main(){
  clr(dp,-1);
  cin>>n>>k;
  rep(i,0,n){
    int t; cin>>t;
    v.pub(t);
  }
  cout<<solve(0)<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 11068
L=[]
def make_list(n,m,p,l):
  if n==0:
    L.append(l)
  else:
    for i in range(p,m+1):
      make_list(n-1,m,i,l+[i])
  
N,M,Q = map(int,input().split())
T=[tuple(map(int,input().split())) for _ in range(Q)]
ans=0
make_list(N,M,1,[])
for l in L:
  tmp=0
  for a,b,c,d in T:
    if l[b-1]-l[a-1]==c:
      tmp+=d
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 23040
from collections import defaultdict
from bisect import *
def solve():
    mod = 10**9+7
    d = defaultdict(lambda: [])
    N = int(input())
    for i in range(N):
        a = int(input())
        d[a].append(i)
    selist = []
    ends = [-1]
    for l in d.values():
        for i in range(len(l)-1):
            if l[i+1]-1>l[i]:
                selist.append([l[i],l[i+1]])
                ends.append(l[i+1])
    selist = [[-1,-1]]+sorted(selist,key=lambda x:x[1])
    # s_ind = {}
    # for i,(s,e) in enumerate(selist):
        # e_ind[e] = i
    # ends = list(e_ind.keys())
    ends.sort()
    dp = [0]*(len(selist))
    for i in range(1,len(selist)):
        dp[i] = dp[i-1]+1
        ind = bisect_right(ends,selist[i][0])
        dp[i] += dp[ind-1]
    ans = dp[-1]+1
    ans %= mod
    return ans
print(solve())

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


int main () {

 string s;
 cin >> s;
 
 if(s[0] == s[1]  && s[1] == s[2])
 {
	  cout<< "No";
 }
 else
 {
	 cout << "Yes";
 }
 
	return 0;
}


Measured memory_bytes: 3112
# 異なる数 -> 大きいほうが左右両端につく 1通り*それぞれの階乗をかけたもの(順列)
# 同じ数 -> 左右が異なるので2通り*それぞれのre
# ぜんぶ整数の掛け算なので都度割っても変わらない

n, m = gets.chomp.split.map(&:to_i)
d = 10**9+7
ans = 1
if n==m
  n.downto(1) do |i|
    # mのぶんもついでにやる
    ans*=i
    ans%=d
    ans*=i
    ans%=d
  end
  puts 2*ans%d
elsif (n-m).abs==1
  # なるべく一緒に処理する
  1.upto([n, m].max) do |i|
    if i<=n
      ans*=i
      ans%=d
    end
    if i<=m
      ans*=i
      ans%=d
    end
  end
  puts ans
else
  puts 0  
end

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;
int main(){
  int K,X;
  cin >> K >> X;
  for(int i=-K+1;i<=K-1;i++){
    cout << X+i << " ";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

ll dp[50];

ll fib(ll k){
    if(dp[k] != -1){
        return dp[k];
    }else if(k == 0){
        dp[k] = 1;
        return dp[k];
    }else if(k == 1){
        dp[k] = 1;
        return dp[k];
    }else{
        dp[k] = fib(k - 1) + fib(k - 2);
        return dp[k];
    }
}


signed main(){
    REP(i, 50){
        dp[i] = -1;
    }
    ll n;
    cin >> n;
    cout << fib(n) << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>

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

using namespace std;

int main(void)
{
  int N;
  int remain;
  int Linput;
  vector<int> L;

  cin >> N;

  rep(N)
  {
    cin >> Linput;
    L.push_back(Linput);
  }

  int MaxIndex, MaxSize;

  vector<int>::iterator iter = max_element(L.begin(), L.end());

  MaxIndex = (int)distance(L.begin(), iter);
  MaxSize = L[MaxIndex];

  remain = 0;

  rep(N)
  {
    if(i != MaxIndex)
      remain += L[i];
  }

  if(MaxSize < remain)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

#define  __  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define  int  long long
#define  endl  '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
//______________________



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

  long double a[n], ans = 0.0;

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

  ans = a[0];

  for(int i = 1; i < n; i++)
    ans = (ans + 1.0*a[i]) / 2;

  cout << fixed << setprecision(10) << ans;
  
 return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for comb in combinations_with_replacement(range(1,M+1), N):
    score = 0
    for a, b, c, d in abcd:
        if comb[b-1] - comb[a-1] == c:
            score += d
    ans = max(ans, score)

print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std ; 
int main()
{
    int n ; 
    cin>>n ; 
    vector<int> v(n) ; 
    for(int i =0 ;i<n;i++)
        cin>>v[i] ; 
    sort(v.begin() , v.end()) ; 
    long long  ans = 0 ; 
    for(int i =0 ;i<n;i++)
    {
        for(int j = i+1 ; j<n;j++)
        {
            int temp = v[i] + v[j] ;
            
            auto  l = lower_bound(v.begin() , v.end() , temp)  ; 
             l-- ; 
            
            ans += (l-v.begin() - j) ;  
            
            
        }
    }
    cout <<ans ;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

vector<vector<int>> mp(501, vector<int>(501,0));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W,0));
    vector<int> x, xd, y, yd;
    REP(i, H){
        REP(j, W){
            cin >> a[i][j];
        }
    }
    REP(i, H){
        if(i%2==0){
            for(int j = 0; j < W; j++){
                if(i == H-1 && j == W-1){
                    break;
                }
                if(a[i][j] %2 == 1){
                    a[i][j]--;
                    if(j == W - 1){
//                        cout << i << " " << j << " " << i+1 << " " << j << endl;
                        x.push_back(i+1);
                        xd.push_back(i+2);
                        y.push_back(j+1);
                        yd.push_back(j+1);
                        a[i+1][j]++;
                    }else{
//                        cout << i << " " << j << " " << i << " " << j+1 << endl;
                        x.push_back(i+1);
                        xd.push_back(i+1);
                        y.push_back(j+1);
                        yd.push_back(j+2);
                        a[i][j+1]++;
                    }
                }
            }
        }else{
            for(int j = W-1; j >= 0; j--){
                if(i == H-1 && j == 0){
                    break;
                }
                if(a[i][j] %2 == 1){
                    a[i][j]--;
                    if(j == 0){
//                        cout << i << " " << j << " " << i+1 << " " << j << endl;
                        x.push_back(i+1);
                        xd.push_back(i+2);
                        y.push_back(j+1);
                        yd.push_back(j+1);
                        a[i+1][j]++;
                    }else{
//                        cout << i << " " << j << " " << i << " " << j-1 << endl;
                        x.push_back(i+1);
                        xd.push_back(i+1);
                        y.push_back(j+1);
                        yd.push_back(j);
                        a[i][j-1]++;
                    }
                }
            }

        }
    }
    cout << x.size() << endl;
    REP(i, x.size()){
        cout << x[i] << " " << y[i] << " " << xd[i] << " " << yd[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 6244
N, M = map(int, input().split())

A = []
B = []

for i in range(N):
    A.append(input())

for i in range(M):
    B.append(input())
ans = True

for i in range(M):
    if B[i] not in A[i]:
        ans = False
        break

print('Yes' if ans == True else 'No')

Measured memory_bytes: 3064
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 A = nal(N)

    def simulate(cnt: Long): Long = {
      val s = A.map(_ / N).sum
      REP(N) { i =>
        A(i) -= (N + 1) * (A(i) / N)
        A(i) += s
      }

      if (s == 0) {
       cnt
      } else {
        simulate(cnt + s)
      }
    }

    val ans = simulate(0)
    out.println(ans)
  }


  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  def debug(num: Long): Unit = {
    System.err.println(num)
  }

  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[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


Measured memory_bytes: 35012
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,k;
    cin >>  n >> k;
    vector<int>data(n,0);
    rep(i,n){
        int a;
        cin >> a;
        data[a-1]++;
    }
    sort(all(data));
    reverse(all(data));
    int ans = 0;
    for(int i = k;i<n;i++){
        ans+=data[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace _0593
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] hiyou = new int[x[0]];
            int[] kekka = new int[x[0]];
            for (int i = 0; i < x[0]; i++)
            {
                hiyou[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < x[1]; i++)
            {
                int sinsa = int.Parse(Console.ReadLine());
                int j = 0;
                while (true)
                {
                    if (sinsa >= hiyou[j])
                    {
                        kekka[j]++;
                        break;
                    }
                    j++;
                }
            }
            int a = x[1];
            bool b = true;
            while (b)
            {
                for (int j = 0; j < x[0]; j++)
                {
                    if (a == kekka[j])
                    {
                        Console.WriteLine(j + 1);
                        b = false;
                        break;
                    }
                }
                a--;
            }
        }
    }
}

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

int main( ) {
  int A, B, K;
  cin >> A >> B >> K;
  
  for(int i = min(A,B); i >= 1; i--){
    if(A % i == 0 && B % i == 0){
      K--;
      if(K == 0){
        cout << i << endl;
        return 0;
      }
    }
  }
  assert(false);
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
int main()
{
    int count1=0,count2=0;
    char s[N];
    gets(s);
    char *p=s;
    for(;*p!='\0';p+=2)
    {
       if(*p=='0')count1++;
    }
    for(p=&s[1];*p!='\0';p+=2)
    {
        if(*p=='1')count1++;
    }
    p=s;
    for(;*p!='\0';p+=2)
    {
       if(*p=='1')count2++;
    }
    for(p=&s[1];*p!='\0';p+=2)
    {
       if(*p=='0')count2++;
    }
    if(count1<count2)
        printf("%d",count1);
    else
        printf("%d",count2);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	while(true){
		int a, b, n, t1, t2;
		scanf("%d %d", &a, &b);
		if(a == 0 && b == 0) return 0;
		scanf("%d", &n);

		vector< vector<int> > ucs;

		vector< vector<int> > crosses;

		for(int i = 0;i < b;++i){
			vector<int> row(a, 0);
			crosses.push_back(row);

			vector<int> ucrow(a, 0);
			ucs.push_back(ucrow);
		}

		for(int i = 0;i < n;++i){
			scanf("%d %d", &t1, &t2);
			ucs[t2-1][t1-1] = 1;
		}

		crosses[0][0] = 1;
		for(int i = 0;i < b;++i){
			for(int j = 0;j < a;++j){
				if(i != 0 || j != 0){
					if(i == 0){
						crosses[i][j] += crosses[i][j-1];
					}else if(j == 0){
						crosses[i][j] += crosses[i-1][j];
					}else{
						crosses[i][j] += crosses[i-1][j] + crosses[i][j-1];
					}


					if(ucs[i][j] == 1) crosses[i][j] = 0;
				}
			}
		}

		printf("%d\n", crosses[b-1][a-1]);
	}
}


Measured memory_bytes: 2760
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = (int)1e5 + 10;
int a[maxN];
int t;
bool used[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> t;
    int best = 1e9 + 10;
    int val = -1e9;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        val = max(val, a[i] - best);
        best = min(best, a[i]);
    }
    pair < int, int > bb = make_pair(1e9 + 10, -1);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] - bb.first == val) {
            assert(bb.second != -1 && !used[i] && !used[bb.second]);
            used[i] = used[bb.second] = true;
            ans++;
        }
        bb = min(bb, make_pair(a[i], i));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 768
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(sum([i if (i%3 != 0 and i%5 != 0) else 0 for i in range(1,N+1)]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 33716
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
int main() {
	int hp; int mahp;
	while (cin >> hp >> mahp, hp) {
		int r, c; cin >> r >> c;
		char fie[100][100];
		rep(i, r) {
			string s; cin >> s;
			rep(j, c) {
				fie[i][j] = s[j];
			}
		}
		int t; cin >> t;
		int dam[26] = {};
		rep(i, t) {
			char x; int cost; cin >> x >> cost; dam[x - 'A'] = cost;
		}
		int s; cin >> s;
		pair<char, int> move[1000];
		int sum = 0;
		rep(i, s) {
			char x; int count; cin >> x >> count; move[i] = { x,count }; sum += count;
		}
		int p; cin >> p;
		int por[12];
		rep(i, p) {
			cin >> por[i];
		}
		int dp[1001][1<<12];
		rep(i, 1001) {
			rep(j, (1 << 12)) {
				dp[i][j] = -1;
			}
		}
		dp[0][(1 << p)-1] = hp;
		P now = { 0,0 };
		int godam[1000]; int cnt = 0;
		rep(i, s) {
			rep(j, move[i].second) {
				char x = move[i].first;
				if (x == 'U') {
					now.first--;
				}
				else if (x == 'D') {
					now.first++;
				}
				else if (x == 'L') {
					now.second--;
				}
				else if (x == 'R') {
					now.second++;
				}
				godam[cnt] = dam[fie[now.first][now.second] - 'A'];
				cnt++;
			}
		}
		rep(i, sum) {
			per(j, (1 << p)) {
				if (dp[i][j] <= 0)continue;
				dp[i + 1][j] = dp[i][j] - godam[i];
				rep(k, p) {
					if ((1 << k)&j) {
						dp[i][j ^ (1 << k)] = min(dp[i][j] + por[k], mahp);
					}
				}
			}
		}
		bool f = false;
		rep(j, (1 << p)) {
			if (dp[sum][j] > 0) {
				f = true;
			}
		}
		if (f) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
	init();

	ll N, M; cin >> N >> M;
    int a = N, b = M;
    if (abs(N - M) > 1) {
        cout << 0 << "\n";
        return 0;
    }
    ll Nf = 1, Mf = 1;
    while (N > 0) {
        Nf *= N;
        Nf %= mod;
        --N;
    }
    while (M > 0) {
        Mf *= M;
        Mf %= mod;
        --M;
    }
    ll ans = (Nf * Mf) % mod;
    if (a == b) {
        ans *= 2;
        ans %= mod;
    }
    cout << ans << "\n";





	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	long A,B;cin>>A>>B;
	if((A+B)%2==0) cout<<(A+B)/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
# AOJ 0517: Longest Steps
# Python3 2018.6.30 bal4u

while True:
	n, k = map(int, input().split())
	if n == 0: break
	c = [0]*(n+2)
	f = 0;
	for i in range(k):
		a = int(input())
		if a == 0: f = 1
		else: c[a] = 1
	ans = w0 = w = 0
	for i in range(1, n+1):
		if c[i]: w += 1
		elif w > 0:
			if w0 + w + f > ans: ans = w0 + w + f
			w0 = w if f and c[i+1] else 0
			w = 0
	if w0 + w + f > ans: ans = w0 + w + f
	print(ans)


Measured memory_bytes: 6240
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b,c;
    int i=0,sum=0;
    //char a,b='.';
    cin>>a;
    if(a<1200) cout<<"ABC";
    else if(a<2800) cout<<"ARC";
    else cout<<"AGC";
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A [] = new int[N];
        long Num [] = new long[N+1];
        long Comb[][] = new long[N+1][2];
        long sum = 0;
        Arrays.fill(Num,0);
        for(int i=0;i<N+1;i++)Arrays.fill(Comb[i],0);
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
            Num[A[i]]++;
        }
        for(int i=1;i<=N;i++){
            if(Num[i]!=0) {
                Comb[i][0] = (Num[i] * (Num[i] - 1)) / 2;
                Comb[i][1] = ((Num[i] - 1) * (Num[i] - 2)) / 2;
                sum += Comb[i][0];
            }
        }
        for(int i=0;i<N;i++) {
            long opt = sum-Comb[A[i]][0]+Comb[A[i]][1];
            System.out.println(opt);
        }
    }
}

Measured memory_bytes: 109040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
 
const int ALPHABET_SIZE = 26; 
  
// trie node 


int main() 
{ 
ll int T;T=1;
while(T--)
{ll int n,i,j;
  cin>>n;
  string s;
  cin>>s;
  ll int countb[n]={0},countg[n]={0},countr[n]={0},ans=0;
  if(s[n-1]=='B')countb[n-1]++;
  if(s[n-1]=='G')countg[n-1]++;
  if(s[n-1]=='R')countr[n-1]++;
  for(i=n-2;i>=0;i--)
  {
    countb[i]=countb[i+1];
     countr[i]=countr[i+1];
      countg[i]=countg[i+1];
    if(s[i]=='B')countb[i]++;
    if(s[i]=='G')countg[i]++;

    if(s[i]=='R')countr[i]++;

  }
  for(i=0;i<n;i++)
  {
    if(s[i]=='R')
    {
      for(j=i+1;j<n;j++)
      {
        if(s[j]=='G')
        {
          ans+=countb[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='B')ans--;
        }
        if(s[j]=='B')
        {
          ans+=countg[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='G')ans--;
        }
      

      }
    }
  }
    for(i=0;i<n;i++)
  {
    if(s[i]=='G')
    {
      for(j=i+1;j<n;j++)
      {
        if(s[j]=='R')
        {
          ans+=countb[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='B')ans--;
        }
        if(s[j]=='B')
        {
          ans+=countr[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='R')ans--;
        }
      

      }
    }
  }
    for(i=0;i<n;i++)
  {
    if(s[i]=='B')
    {
      for(j=i+1;j<n;j++)
      {
        if(s[j]=='G')
        {
          ans+=countr[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='R')ans--;
        }
        if(s[j]=='R')
        {
          ans+=countg[j];
            if(i+2*(j-i)<n&&s[i+2*(j-i)]=='G')ans--;
        }
      

      }
    }
  }
  cout<<ans<<endl;
}


       
    return 0; 
} 


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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

/***** Union-Find *****/

const int MAX_N = 10000;
int Par[MAX_N];
int Rank[MAX_N];

void union_find_init(int n){
	for(int i=0; i<n; ++i){
		Par[i] = i;
		Rank[i] = 0;
	}
}

int find(int x){
	if(Par[x] == x){
		return x;
	}else {
		return Par[x] = find(Par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);

	if(x == y)
		return ;

	if(Rank[x] < Rank[y]){
		Par[x] = y;
	} else{
		Par[y] = x;
		if(Rank[x] == Rank[y]){
			++Rank[x];
		}
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

/***** /Union-Find *****/

/***** Kruskal *****/

struct edge {
	int from,
		to,
		cost;
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

const int MAX_E = 10000;
edge es[MAX_E];
int V, E;

int kruskal(void){
	sort(es, es + E, comp);
	union_find_init(V);

	int res = 0;
	for(int i=0; i<E; ++i){
		edge e = es[i];
		if(!same(e.from, e.to)){
			unite(e.from, e.to);
			res += e.cost;
		}
	}

	return res;
}

/***** /Kruskal *****/

int main(void) {
	while (cin >> V >> E, V) {
		E *= 2;
		for (int i = 0; i < E / 2; i++) {
			int a, b, cost;
			cin >> a >> b >> cost;
			es[i * 2].from = a;
			es[i * 2].to = b;
			es[i * 2].cost = cost;
			es[i * 2 + 1].from = b;
			es[i * 2 + 1].to = a;
			es[i * 2 + 1].cost = cost;
		}

		int res = kruskal();

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,a,b,c,d;
  cin>>N;
  a=N/1000;
  b=(N-a*1000)/100;
  c=(N-a*1000-b*100)/10;
  d=N-a*1000-b*100-c*10;
  if (a==b && b==c){
  cout<< "Yes" <<endl;
  }
  else if (b==c && c==d){
  cout << "Yes" <<endl;
  }
  else {
  cout<< "No" <<endl;
  }
}

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

#define println(msg) cout << msg << endl
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend()) // greater<int>()

int main() {
  // 入力
  int N;
  cin >> N;

  vector<int> a(3 * N);
  for (int i = 0; i < (3 * N); i++) {
    cin >> a.at(i);
  }
  
  // 計算
  sort_vec(a);

  // 小さい側のN個は、それぞれのチームの最弱に配置するので、使わない
  vector<int> b;
  for (int i = 0; i < (2 * N); i++) {
    b.push_back(a.at(i + N));
  }
  
  // 点数を最大化したいが、チームで一番強い人がもったいない
  // チームごとの1, 2位の差を最小化すれば、全体では最大になるはずという発想
  long sum = 0L;
  for (int i = 0; i < (2 * N); i+=2) {
    sum += b.at(i);
  }  
  
  // 出力
  println(sum);
}


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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(0); cin.tie(0) ; cout.tie(0);
#define err(x) cerr << #x << " is : " << x << endl
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v)       v.begin() , v.end()
#define pb           push_back
#define ff           first
#define ss           second

bool palin(string p)
{
      int i = 0 , j = p.size() - 1;
      while(i <= j)
      {
            if(p[i] != p[j])
                  return false;
            i++ , j--;
      }
      return true;
}
int32_t main()
{
      tie();
      string s;
      cin >> s;
      int n = s.size();
      bool cond = palin(s);
      s = '.' + s;
      string x = s.substr(1 , ((n - 1) / 2));
      string p = s.substr((n + 3) / 2);
      cond &= palin(x);
      cond &= palin(p);
      if(cond)
            cout << "Yes" << endl;
      else
            cout << "No" << endl;
      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{  
   int n,m,s=0;
  cin>>n>>m;
  while(m--)
  {
     int x;
    cin>>x;
    s+=x;
  }
  if(s>n)cout<<-1;
  else cout<<n-s;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;

#define bit(k) (1LL<<(k))

typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

/*------------------------------------*/
int A[10][10];
int N;
bool c[10][10];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    rep(i,3)rep(j,3){
        cin>>A[i][j];
        c[i][j] = false;
    }
    cin>>N;
    rep(i,N){
        int b;
        cin>>b;
        rep(i,3)rep(j,3){
            if(b == A[i][j])c[i][j] = true;
        }
    }

    bool ans = false;
    //行について
    rep(i,3){
        bool ALL = true;
        rep(j,3){
            if(!c[i][j])ALL = false;
        }
        if(ALL){
            ans = true;
        }
    }
    //列について
    rep(j,3){
        bool ALL = true;
        rep(i,3){
            if(!c[i][j])ALL = false;
        }
        if(ALL){
            ans = true;
        }
    }
    //斜めについて
    if(c[0][0] && c[1][1] && c[2][2])ans = true;
    if(c[0][2] && c[1][1] && c[2][0])ans = true;
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

int main() {
  int a;
  int b;
  1<= a <=100;
  1<= b <=100;
  cin >> a >> b;
  double x;
  x = 1 + ( a + b - 1) / 2;
  cout << x << endl;
    
}

Measured memory_bytes: 256
/**************erik****************/
#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  int ll;
typedef unsigned long long int ull;
//map<ll,ll> mp1;
//set<int> s1;
//set<int>::iterator it;
#define maxm(a,b,c)  max(a,max(c,b))
#define minm(a,b,c)  min(a,min(c,b))
#define f(i,n)  for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;i--)

// int solve(int dp[], int x,int n,int l){
//     if(x>=n){
//         return 0;
//     }
  	
//   int zz,yy;
//   if(l==0){
//   	zz = solve(dp,x+1,n,1) + a[x][0];
//     yy = solve(dp,x+1,n,2) + a[x][0];
//   } else if(l==1){
//   	 zz = solve(dp,x+1,n,0) + a[x][1];
//     yy = solve(dp,x+1,n,2) + a[x][1];
//   } else {
//   	 zz = solve(dp,x+1,n,1) + a[x][2];
//     yy = solve(dp,x+1,n,0) + a[x][2];
//   }

//   return dp[x] = max(zz,yy);
// }
int main()
{
  int n;
 cin>>n;
  int a[n][3];
 for(int i=0;i<n;i++){
     for(int j=0;j<3;j++){
     	cin>>a[i][j];
     }
 }
 int dp[n][3];
 for(int i=0;i<n;i++){
   if(!i){
   	dp[i][0]=a[i][0];
    dp[i][1]=a[i][1];
    dp[i][2]=a[i][2];
   } else {
   	dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
   }
 }
 cout<<maxm(dp[n-1][0],dp[n-1][1],dp[n-1][2])<<endl;
 return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll 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;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0;
vl flag, color; vll path;
//***********//
ll Npow(ll x, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return Npow(x * x % MOD, n / 2);
	else return x * Npow(x, n - 1) % MOD;
}
vl divisor(ll n) {
	vl ret;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i != 1 && i * i != n) ret.push_back(n / i);
		}
	}
	//ret.push_back(n);
	return ret;
}
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
int main() {
	cin >> N >> K;
	vl V(K + 1);
	ll c = 0;
	for (ll x = K; x >= 1; x--) {
		ll z = (((Npow(K/x, N)- V[x]) % MOD)+MOD)%MOD;
		c = (c + z) % MOD;
		ans = (ans + z*x + MOD) % MOD;
		vl D = divisor(x);
		//debug(z);
		for (i = 0; i < D.size(); i++) V[D[i]] += z;
		//debug(x,y,z, ans);
	}
	cout << ans;
}


Measured memory_bytes: 4048
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] job = new int[N][2];
		for (int i = 0; i < N; i++) {
			job[i][0] = sc.nextInt();
			job[i][1] = sc.nextInt();
		}
		Arrays.sort(job, (a, b) -> a[0] != b[0] ? a[0] - b[0] : b[1] - a[1]);
		int ans = 0;
		PriorityQueue<Integer> q = new PriorityQueue<>();
		for (int i = M, j = 0; i >= 0; i--) {
			while (j < N && job[j][0] + i <= M) {
				q.offer(-job[j++][1]);
			}
			if (!q.isEmpty())
				ans -= q.poll();
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 89300