akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMultiplication2 solver = new BMultiplication2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultiplication2 {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = in.nextArrLong(n);
            long res = 1;
            for (int i = 0; i < n; i++)
                if (a[i] == 0) {
                    out.println("0");
                    return;
                }
            for (int i = 0; i < n; i++) {
                try {
                    res = Math.multiplyExact(res, a[i]);
                    if (res > 1_000_000_000_000_000_000L) {
                        out.println("-1");
                        return;
                    }
                } catch (Exception e) {
                    out.println("-1");
                    return;
                }
            }
            out.println(res);
            //out.print("Case #"+ testNumber + ": ");
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] nextArrLong(int n) {
            long[] a = new long[n];
            for (int i = 0; i < a.length; i++)
                a[i] = nextLong();
            return a;
        }

    }
}



Measured memory_bytes: 49100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        string s = Console.ReadLine();
        int W = int.Parse(s.Split(' ')[0]);
        int H = int.Parse(s.Split(' ')[1]);
        int x = int.Parse(s.Split(' ')[2]);
        int y = int.Parse(s.Split(' ')[3]);

        //回答の二つ目のインデックス
        string ans_2;
        if (W == 2 * x && H == 2 * y) {
            ans_2 = "1";
        } else {
            ans_2 = "0";
        }

        //出力
        Console.WriteLine(((W / 2.0f) * H).ToString() + " " + ans_2);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <stack>
#include <vector>
using namespace std;

int Solve(const string& s) {
  const int n = s.size();
  stack<char> st;
  int ret = 0;
  for (char c : s) {
    if (st.empty() || st.top() == c) {
      st.push(c);
    } else {
      st.pop();
      ret += 2;
    }
  }
  return ret;
}

int main() {
  string s;
  cin >> s;
  cout << Solve(s) << "\n";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  cin >> n >> m;
  vector<int>x(m),y(m);
  rep(i,m){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<int>num(n,1);
  vector<bool>ball(n,false);
  ball[0]=true;
  rep(i,m){
    if(ball[x[i]]&&num[x[i]]==1){
      ball[x[i]]=false;
      num[x[i]]--;
      ball[y[i]]=true;
      num[y[i]]++;
    }
    else if(ball[x[i]]&&num[x[i]]>1){
      num[x[i]]--;
      ball[y[i]]=true;
      num[y[i]]++;
    }
    else{
      num[x[i]]--;
      num[y[i]]++;
    }
  }
  int cnt=0;
  rep(i,n){
    if(ball[i])cnt++;
  }
  cout << cnt << endl;
      
}


Measured memory_bytes: 1408
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const x = parseInt(lines[0].split(' ')[0]);
  const y = parseInt(lines[0].split(' ')[1]);
  console.log(gcd(x, y));
});

function gcd (x, y) {
  var tmp;
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  
  return x;
}


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

using namespace std;

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

    vector<int> p(n);
    vector<int> q(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];

    vector<int> vt(n);
    iota(vt.begin(), vt.end(), 1);
    int a = -1;
    int b = -1;
    int index = 1;
    do {
        if (vt == p) a = index;
        if (vt == q) b = index;
        index++;
    } while (next_permutation(vt.begin(), vt.end()));

    cout << abs(a - b) << endl;
    return 0;
}


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

int main(){
  int n ; int m ; int sum=0;
	cin>>n>>m;
	vector<int>q(m);
	vector<int>d(m-1);

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

	sort(q.begin(),q.end());
	for(int i = 0  ; i < m-1 ; i++){
		d[i]=abs(q[i]-q[i+1]);
	}

	sort(d.begin(),d.end());

	

	for(int i = 0 ; i < m-1-(n-1) ; i++){
		sum=d[i]+sum;
	}

	cout<<sum;


}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    fun nextPermutation(arr: IntArray): Boolean {
        var i = arr.size - 1
        while (i > 0 && arr[i - 1] >= arr[i]) {
            i--
        }

        if (i <= 0) {
            return false
        }

        var j = arr.size - 1
        while (arr[j] <= arr[i - 1]) {
            j--
        }

        var temp = arr[i - 1]
        arr[i - 1] = arr[j]
        arr[j] = temp

        j = arr.size - 1
        while (i < j) {
            temp = arr[i]
            arr[i] = arr[j]
            arr[j] = temp
            i++
            j--
        }

        return true
    }

    val N = readLine()!!.toInt()

    val PN = readLine()!!.split(" ").map(String::toInt).toIntArray()
    val QN = readLine()!!.split(" ").map(String::toInt).toIntArray()

    val array = (1..N).toList().toIntArray()

    var index = 1
    var a = 0
    var b = 0
    do {
        if (PN.joinToString("") == array.joinToString("")) {
            a = index
        }
        if (QN.joinToString("") == array.joinToString("")) {
            b = index
        }
        index++

    } while (nextPermutation(array))

    println(Math.abs(a - b))
}



Measured memory_bytes: 53080
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

char ch[3];

void solve() {
	cin >> ch;
	sort(ch, ch + 3);
	for (int i = 0; i < 3; i++) {
		if (ch[i] == 'a' + i) continue;
		else {
			cout << "No" << endl;
			exit(0);
		}
	}
	cout << "Yes" << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
n,kk=map(int,input().split())
a=list(map(int,input().split()))
k=[]
for i in range(n-kk+1):
	x=a[i]
	y=a[i+kk-1]
	if y<=0:
		k.append(-x)
	elif x>=0:
		k.append(y)
	else:
		k.append(y-x+min(y,-x))
print(min(k))

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

int main(){
  cin >> s;
  int cnt = 0;
  for(char c:s){
    if( cnt == 0 && c == 'C' ) cnt++;
    else if( cnt == 1 && c =='F' ) cnt++;
  }
  if( cnt == 2 ) cout << "Yes" << endl;
  else cout << "No"<<endl;
}


Measured memory_bytes: 764
import sys

N = int(input())
A = [int(x) for x in input().split()]
div_times = 0

while 1:
    for a in A:
        if a % 2 != 0:
            print(div_times)
            sys.exit()
    A = list(map(lambda x: x // 2, A))
    div_times += 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int n; 
int main() {
  cin >> n;
  vector<P> time(n);
  rep(i,n) {
    int a,b; cin >> a >> b;
    if (a > b) {
      cout << "No" << endl;
      return 0;
    }
    time[i] = make_pair(b,a);
  }
  sort(time.begin(), time.end()); //(end, start)
  bool can = true;
  int end = 0;
  rep(i,n) {
    end += time[i].second;
    if (end > time[i].first) can = false;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 4840
#include <iostream>
using namespace std;
int main(void){
    int numa=0;
    int numw=0;
    int numt =0;
    int numr =0;
    int num;
    string moji;
    cin >>num;
    for(int i=0;i<num;i++){
        cin >> moji;
        if(moji =="AC"){
            numa+=1;
        }else if(moji == "WA"){
            numw+=1;
        }else if(moji == "TLE"){
            numt+=1;
        }else{
            numr+=1;
        }
    }

    cout<<"AC x " <<numa <<endl;
    cout<<"WA x " <<numw <<endl;
    cout<<"TLE x " <<numt <<endl;
    cout<<"RE x " <<numr <<endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
using namespace std;
using P = pair<int, int>;
const int inf = 2e18;
const int mod = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

struct UnionFind {
  vector<int> par;   //親
  vector<int> size;  //集合の大きさ

  UnionFind(int n) {
    par.resize(n);
    size.resize(n, 1);
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }

  //木の根を求める
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  // xとyの属する集合を併合
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (size[x] < size[y]) swap(x, y);
    par[y] = x;
    size[x] += size[y];
  }

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

signed main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    uf.unite(u, v);
  }

  int cnt = 0;
  vector<bool> visited(n, false);
  for (int i = 0; i < n; i++) {
    if (visited[uf.root(i)]) continue;
    visited[uf.root(i)] = true;
    cnt++;
  }
  cout << cnt - 1<< endl;

  return 0;
}

Measured memory_bytes: 4740
<?php
/*プログラムのイメージ
--入力-----
5
3 8 7 5 5
-----------
2*3=a+b
2*8=b+c
2*7=c+d
2*5=d+e
2*5=e+a
 
2*3=a+(2*8-c)
2*3=a+(2*8-(2*7-d))
2*3=a+(2*8-(2*7-(2*5-e)))
2*3=a+(2*8-(2*7-(2*5-(2*5-a))))
a+a=(2*3)-(2*8-(2*7-(2*5-(2*5))))
2a=(2*3)-(2*8)+(2*7)-(2*5)+(2*5)
2a=6-16+14
a=2
 
e=(2*5)-a
e=8
 
d=(2*5)-e
d=2
 
c=(2*7)-d
c=12
 
b=(2*8)-c
b=4
*/
fscanf(STDIN,"%d",$N);
$lowA = fgets(STDIN);
$arrayA = explode(" ",$lowA);
$result = [];
 
//初期値設定
for($i=0;$i<$N;$i++){
  ${"mount".$i} = 0;
}
 
//1つ目の山に降った水計算
for($i=0;$i<$N;$i++){
  if($i%2===0){
    $mount0 += $arrayA[$i];
  }else{
    $mount0 -= $arrayA[$i];
  }
}
//最後の山に降った水計算
${"mount".($N-1)} = 2*$arrayA[$N-1]-$mount0;
//上記以外の山に降った水計算
for($i=$N-2;$i>0;$i--){
  ${"mount".($i)} = 2*$arrayA[$i]-${"mount".($i+1)};
}
 
for($i=0;$i<$N;$i++){
  $result[] = ${"mount".($i)};
}
 
echo implode(" ",$result);

Measured memory_bytes: 50420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll N, NN, ans;
    cin >> N;
    NN = 2*N;
    vector<ll> v(NN);
    rep(i,NN){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ans = 0;
    rep(i,NN){
        if(i%2==0){
            ans += v[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int cnt[200020];
int main(){
    int n,i,tmp;
    scanf("%d",&n);
    for(i=0;i<n-1;i++){
        scanf("%d",&tmp);
        cnt[tmp-1]++;
    }
    for(i=0;i<n;i++){
        printf("%d\n",cnt[i]);
    }
}


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

int main(){
  int X,N,Min=100,res;
  cin >> X >> N;
  int Q[103];
  for(int i=-1;i<=101;i++){
    Q[i]=0;
  }
  for(int i=0;i<N;i++){
    int p;
    cin >> p;
    Q[p]++;
  }
  for(int i=101;i>-2;i--){
    if(Q[i]!=1){
      if(abs(i-X)<=Min){
        Min = abs(i-X);
        res = i;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3624
import math


def koch(n, p1_x, p1_y, p2_x, p2_y):
    if n == 0:
        print(f"{p1_x:.8f} {p1_y:.8f}")
        return

    # p1, p2からs, t, uを計算

    # 与えられた線分(p1, p2) を3等分点s、tを求める
    s_x = (2 * p1_x + 1 * p2_x) / 3
    s_y = (2 * p1_y + 1 * p2_y) / 3

    t_x = (p1_x + 2 * p2_x) / 3
    t_y = (p1_y + 2 * p2_y) / 3

    # 線分を3等分する2点 s,t を頂点とする正三角形 (s,u,t) を作成する
    u_x = (
        (t_x - s_x) * math.cos(math.pi / 3) - (t_y - s_y) * math.sin(math.pi / 3) + s_x
    )
    u_y = (
        (t_x - s_x) * math.sin(math.pi / 3) + (t_y - s_y) * math.cos(math.pi / 3) + s_y
    )

    # 線分 (p1,s)、線分 (s,u)、線分 (u,t)、線分 (t,p2)に対して再帰的に同じ操作を繰り返す
    koch(n - 1, p1_x, p1_y, s_x, s_y)
    koch(n - 1, s_x, s_y, u_x, u_y)
    koch(n - 1, u_x, u_y, t_x, t_y)
    koch(n - 1, t_x, t_y, p2_x, p2_y)


n = int(input())
koch(n, 0, 0, 100, 0)
print("100.00000000 0.00000000")



Measured memory_bytes: 5780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[25];
int main(){
	int n,num=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=2;i<n;i++){
		int x=max(a[i],max(a[i-1],a[i+1]));
		int y=min(a[i],min(a[i+1],a[i-1]));
		if(a[i]!=x&&a[i]!=y){
			num++;
		}
	}
	cout<<num<<endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
#include<math.h>
using namespace std;
int a[100000];
int n = 0, k = 0;
int main()
{
	
	scanf("%d", &n);
	scanf("%d", &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	int sum = 0;
	if (k == n)
		printf("1\n");
	else
	{
		while (n > 0)
		{
			n = n - k;
			if (n > 0) n++;
			sum++;
		}
		printf("%d\n", sum);
	}
	
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int dy[4] = {-1, 0, 0, 1};
int dx[4] = {0, -1, 1, 0};
int w;
int h;

void bfs(VVI table) {
    queue<PIII> que;
    que.push(make_pair(0, make_pair(1, 1)));
    table[1][1] = 1;

    while (!que.empty()) {
        PIII now = que.front();
        int score = now.first;
        int now_y = now.second.first;
        int now_x = now.second.second;
        que.pop();
        if (now_y == 2 * h - 1 && now_x == 2 * w - 1) {
            cout << score / 2 + 1 << endl;
            return;
        }
        for (int i = 0; i < 4; i++) {
            if (table[now_y + dy[i]][now_x + dx[i]] == 0) {
                que.push(make_pair(score + 1, make_pair(now_y + dy[i], now_x + dx[i])));
                table[now_y + dy[i]][now_x + dx[i]] = 1;
            }
        }
    }
    cout << 0 << endl;
    return;
}

int main(void) {
    while (true) {
        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }
        VVI table(h * 2 + 1, VI(w * 2 + 1, 1));

        for (int i = 1; i <= h * 2 - 1; i++) {
            for (int j = 1; j <= w * 2 - 1; j++) {
                table[i][j] = 0;
            }
        }

        for (int i = 1; i < h * 2; i ++) {
            if (i % 2 == 1) {
                for (int j = 2; j < w * 2; j += 2) {
                    cin >> table[i][j];
                }
            } else {
                for (int j = 1; j < w * 2; j += 2) {
                    cin >> table[i][j];
                }
            }
        }
        for (int i = 2; i < h * 2; i += 2) {
            for (int j = 2; j < w * 2; j += 2) {
                table[i][j] = 1;
            }
        }

        bfs(table);
    }
    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
static const double pi = 3.141592653589793;
static const double va = 2*pi/(60.0*12.0), vb = 2*pi/60.0;

int main() {
  double A, B;
  double H, M;
  double xa, ya, xb, yb;
  
  cin >> A >> B >> H >> M;
  
  double t = H * 60.0 + M;
  
  xa = A * cos(va * t);
  ya = A * sin(va * t);
  xb = B * cos(vb * t);
  yb = B * sin(vb * t);
  
  double dx = (xa - xb) * (xa - xb);
  double dy = (ya - yb) * (ya - yb);
  double d = sqrt(dx + dy);
  
  cout << setprecision(19) << d << endl;
}

Measured memory_bytes: 4052
k, s = gets.chomp.split.map(&:to_i)

ok = 0
0.upto(k) do |i1|
  0.upto(k) do |i2|
    if s - (i1 + i2) >= 0 && (s - (i1 + i2)) <= k
      ok += 1
    end
  end
end

puts ok

Measured memory_bytes: 1788
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#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>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    int n;
    cin >> n;

    ll ac=0,wa=0,tle=0,re=0;

    vector<string> s;
    REP(i,n){
        string ss;
        cin >> ss;
        if(ss == "AC"){
            ac++;
        }
        else if(ss == "WA"){
            wa++;
        }
        else if(ss == "TLE"){
            tle++;
        }
        else if(ss == "RE"){
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

using namespace std;
typedef long long ll;
// typedef pair<int, int> P;

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

int N, C;
int a[100000], b[100000], c[100000];
int tt[200002]; // tt[x] : 時刻xの時にやってるかどうかを累積和（いもす）で管理
int sm[200002]; // sm[y] : 時刻yの時にやっているチャンネル数

void solve() {
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 1; i <= C; i++) {
		for (int j = 0; j < 200002; j++) tt[j] = 0;	//初期化
		for (int j = 0; j < N; j++) {
			if (c[j] == i) tt[a[j] * 2 - 1]++, tt[b[j] * 2]--;	// 始まりと終了時刻のチェック
		}
		for (int j = 0; j < 200002; j++) tt[j] += tt[j - 1];	// 累積和
		for (int j = 0; j < 200002; j++) if (tt[j] > 0)sm[j]++;
	}

	int mx = 0;
	for (int j = 0; j < 200002; j++) if (mx < sm[j]) mx = sm[j];
	cout << mx << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 2944
N = int(input())
ab = []
abn = [0]*N
abw = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int,input().split()))
  ab.append([a,b])
  abw[a-1].append(b)
  abw[b-1].append(a)
  abn[a-1] += 1
  abn[b-1] += 1
c = sorted(list(map(int,input().split())))
cn = 0
d = [0]*N
s = [i for i in range(N)]
while cn <N:
  cut = []
  for i in s:
    if (abn[i] == 1 and cn<N) or len(s) == 1:
      d[i] = c[cn]
      cn += 1
      cut.append(i)
      abn[i] -=1
      s.remove(i)
  for j in cut:
    for k in abw[j]:
      abn[k-1] -= 1
print(sum(c)-max(c))
print(" ".join(map(str,d)))

Measured memory_bytes: 52056
import bisect

def nearest(x, lst):
    p = bisect.bisect_left(lst, x)
    
    if p == 0:
        return lst[p], None
    if p == len(lst):
        return lst[p - 1], None
    if lst[p] == x:
        return lst[p], None
    return lst[p - 1], lst[p]
 

def submit():
    a, b, q = map(int, input().split())

    slist = [int(input()) for _ in range(a)]
    tlist = [int(input()) for _ in range(b)]
    qlist = [int(input()) for _ in range(q)]

    near_s = {s: nearest(s, tlist) for s in slist}
    near_t = {t: nearest(t, slist) for t in tlist}

    anss = []
    for q in qlist:
        ans = float('inf')
        # 一番近いs->tの順の場合
        n = nearest(q, slist)
        for e in n:
            if not e: 
                continue
            for ee in near_s[e]:
                if not ee:
                    continue
                if ans > abs(q - e) + abs(ee - e):
                    ans = abs(q - e) + abs(ee - e)                            
        # 一番近いt->sの順の場合
        n = nearest(q, tlist)
        for e in n:
            if not e:
                continue
            for ee in near_t[e]:
                if not ee:
                    continue
                if ans > abs(q - e) + abs(ee - e):
                    ans = abs(q - e) + abs(ee - e)
        anss.append(ans)

    for ans in anss:
        print(ans)


submit()



Measured memory_bytes: 45904
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;  cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    double ave = 0;
    for (int i = 0; i < n; i++) 
        ave += a[i];

    ave /= (double)n;

    int ave_ = round(ave);
    int ans = 0;

    for (int i = 0; i < n; i++) {
        ans += (a[i]-ave_)*(a[i]-ave_);
    }

    cout << ans << endl;
    return 0;
}

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

string str,ans;
int main(){
    cin >> str;
    for(int i = 0; i < str.length(); i++){
        if(str[i] == '0'){
            ans += '0';
        }else if(str[i] == '1'){
            ans += '1';
        }else if(str[i] == 'B'){
            if(ans.length() > 0){
                ans.resize(ans.length()-1);    
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M=1e9+7,N=2e6+5;
lli fact[N];

lli binpow(lli a,lli b) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a)
{
    return binpow(a,M-2);
}

lli add(lli a, lli b)
{
	lli res = a + b;
	if(res >= M)
		return res - M;
	return res;
}
 
lli mul(lli a, lli b)
{
	lli  res = a * b;
	if(res >= M)
		return res % M;
	return res;
}
 
lli sub(lli a, lli b)
{
	return (a%M -b%M +M) %M;
}

void pre()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i] = mul(fact[i-1], i);
}

lli ncr(lli n, lli r)
{
    return mul(fact[n], inv(mul(fact[n-r], fact[r])));    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pre();
    
    lli k;
    string s;
    cin>>k>>s;
    lli i,n=s.length(),ans=binpow(26, n+k);
    
    for(i=0;i<n;i++) ans=sub(ans, mul(ncr(n+k, i), binpow(25, n+k-i)));
    cout<<ans;
    return 0;
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

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

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  解法1

  all:=A[1]+...+A[n]として
  与式を変形すると

  (答え)=(((all-A[i])*A[i])の総和)/2
  ということがわかるので，それを実装

  「2で割る」というのは「2の逆元を掛ける」ということに言い換えられるから
  mod上での逆元を求める関数(53行目，modinv)を書いて，それを最後に掛ければよい
  
  
  */

  long int n;
  scanf("%ld",&n);

  long int A[n];
  long int all=0;

  long int MOD=1e9+7;

  for(int i=0;i<n;i++){
    scanf("%ld",&A[i]);
    all+=A[i];

    //常にMODを取る！
    all%=MOD;
  }

  long int ans=0;
  for(int i=0;i<n;i++){
    /*
    allは常にMODを取っていて，all<A[i]の可能性があるので
    MODを足して正にしないといけない

    (all-A[i])>=-(1e9+7)がいえるので，足す数は1回でいいけど
    別の問題で心配だったら2,3回足しても問題ナシ
    */
    ans+=(all-A[i]+MOD)*A[i];

    //常にMODを取る！
    ans%=MOD;
  }


  //MOD上の2の逆元
  long int v=modinv(2,MOD);

  //常にMODを取る！
  printf("%ld\n",ans*v%MOD);

  return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

vector<long long> Ap, An, Az;

long long f (long long a)
{
    long long ans = 0;
    long long np = Ap.size();
    long long nn = An.size();
    long long nz = Az.size();
    long long total_p = np*(np-1)/2 + nn*(nn-1)/2;
    long long total_n = np*nn;
    long long total_z = nz*(np+nn)+nz*(nz-1)/2;
    
    if (a==0) {
        ans = total_n + total_z;
    }
    if (a>0) {
        ans += total_n + total_z;
        for (int i=0; i<np; i++) {
            long long thr = a/Ap[i];
            auto it = Ap.begin() + i;
            long long num = upper_bound(Ap.begin(), Ap.end(), thr) - it - 1;
            if (num>0) {
                ans += num;
                //cout << "num " << num << endl;
            }
        }
        for (int i=0; i<nn; i++) {
            long long thr = a/An[i];
            auto it = An.begin() +i;
            auto it_thr = lower_bound(An.begin(), An.end(), thr);
            long long num = An.end() - it_thr;
            if (it-it_thr>=0) num-=(it-it_thr+1);
            if (num>0) {
                ans += num;
                //cout << "num " << num << endl;
            }
        }
    }
    if (a<0) {
        for (int i=0; i<nn; i++) {
            long long thr = (a+1)/An[i]+1;
            long long num = Ap.end() - lower_bound(Ap.begin(), Ap.end(), thr);
            ans += num;
            //cout << "num " << num << endl;
        }
    }
    return ans;
}


int main(){
    long long N, K;
    cin >> N >> K;
    
    for (int i=0; i<N; i++) {
        long long x = 0;
        cin >> x;
        if (x>0) {
            Ap.push_back(x);
        }
        else if (x<0){
            An.push_back(x);
        }
        else {
            Az.push_back(x);
        }
    }
    
    sort(Ap.begin(), Ap.end());
    sort(An.begin(), An.end());
    
    
    long long max = 1E+18+5;
    long long min = -1E+18-5;
    long long ans = 0;
    bool flag = false;
    while (max-min>1) {
        long long temp = (max+min)/2;
        long long a = f(temp);
        //cout << max << " " << min << " " << temp << endl;
        //cout << "a=" << a << endl;
        
        if (K<a) {
            max = temp;
        }
        else if (K>a) {
            min = temp;
        }
        else if (K==a) {
            max = temp;
        }
        
    }
    
    if (max==min) {
        ans = max;
    }
    else {
        if (f(min)==K) {
            ans = min;
        }
        else {
            ans = max;
        }
    }
    //cout << f(min) << " " << f(max) << endl;
    //cout << min << " " << max << endl;
    cout << max << endl;
    //cout << f(-7) << endl;
    //cout << f(448283280358331063) << endl;
    //cout << f(448283280358331064) << endl;
    //cout << f(448283280358331065) << endl;
    
    return 0;
}


Measured memory_bytes: 2548
#include <iostream>

using namespace std;

int main()
{
	for(int b,r,g,c,s,t;cin>>b>>r>>g>>c>>s>>t,b|r|g|c|s|t;){
		int get=100+b*15+r*15+g*7+c*2;
		get+=(b*5+r*3)*15;
		int pay=(t-s)*3-(b*5+r*3);
		cout<<get-pay<<endl;
	}
	
	return 0;
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N, M, E, S, T, R;
    vector< vector<int> > G;
    vector<int> events;
    void input() {
        cin >> N >> M >> E >> S >> T >> R;
        G.clear(); G.resize(N, vector<int>(N, -1));
        for (int i = 0; i < M; i++) {
            int a, b; cin >> a >> b;
            G[a][b] = G[b][a] = 0;
        }
        events.clear(); events.resize(N, 0);
        for (int i = 0; i < E; i++) {
            int a, b, c; cin >> a >> b >> c;
            events[c] = (1 << i);
            G[a][b] = G[b][a] = (1 << i);
        }
    }

    const int MAX_E = 4;
    const int MAX_R = 100;
    const int MAX_N = 100;
    const int INF = 1<<28;

    struct State {
        int e, r, v, t;
        State(int e, int r, int v, int t) :
            e(e), r(r), v(v), t(t) {}
    };

    void solve() {
        static int D[1 << MAX_E][MAX_R + 1][MAX_N];
        for (int i = 0; i < (1 << MAX_E); i++) for (int j = 0; j <= MAX_R; j++) for (int k = 0; k < MAX_N; k++) {
            D[i][j][k] = INF;
        }
        D[0][0][S] = 0;
        queue<State> Q;
        Q.push(State(events[S], 0, S, 0));
        while (not Q.empty()) {
            State s = Q.front(); Q.pop();
            if (s.r < R) {
                for (int i = 0; i < N; i++) {
                    int x = G[s.v][i];
                    if (x < 0) continue;
                    if (x == 0 || (x & s.e)) {
                        int ne = s.e;
                        int nr = s.r + 1;
                        int nv = i;
                        int nt = s.t + 1;
                        if (events[i] > 0) ne |= events[i];
                        if (D[ne][nr][nv] > nt) {
                            D[ne][nr][nv] = nt;
                            Q.push(State(ne, nr, nv, nt));
                        }
                    }
                }
            }
            if (D[s.e][0][S] > s.t + 1) {
                D[s.e][0][S] = s.t + 1;
                Q.push(State(s.e, 0, S, s.t + 1));
            }
        }
        int ans = INF;
        for (int i = 0; i < (1 << MAX_E); i++) {
            for (int j = 0; j <= R; j++) {
                ans = min(ans, D[i][j][T]);
            }
        }
        cout << (ans == INF ? -1 : ans) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  vector<vector<int>> c(3, vector<int>(3));
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n; cin >> n;
  vector<int> b(n); rep(i, n) cin >> b[i];
  rep(i, 3) rep(j, 3) rep(k, n)
    if (a[i][j] == b[k]) c[i][j] = 1;
  rep(i, 3) {
    if (c[i][0] && c[i][1] && c[i][2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i, 3) {
    if (c[0][i] && c[1][i] && c[2][i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (c[0][0] && c[1][1] && c[2][2]) {
    cout << "Yes" << endl;
    return 0;
  }
  if (c[0][2] && c[1][1] && c[2][0]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
	"strconv"
)

func main() {
	var Length int
	fmt.Scanln(&Length)
	arr := make([]int, Length, 100)
	for i := 0; i < Length; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	for i := 0; i < len(arr); i++ {
		key := arr[i]
		j := i - 1
		for j >= 0 && arr[j] > key {
			arr[j+1] = arr[j]
			j--
		}
		arr[j+1] = key
		printbe(arr, i)
	}
}
func printbe(arr []int, ref int) {
		str := convert(arr)
		fmt.Printf("%s",str)
	//if ref < len(arr)-1 {
		fmt.Println()
	//}
}
func convert(arr []int) string {
	s :=make([]string, len(arr))
	for i:=range arr {
		s[i] = strconv.Itoa(arr[i])
	}
	return strings.Join(s," ")
}



Measured memory_bytes: 1440
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
ans = 0
n = int(input())
f = [None for _ in range(40)]
f[1] = 1
for i in range(2, 40):
    if (f[i-1]+1)*(f[i-1]+2) == 2*i:
        f[i] = f[i-1]+1
    else:
        f[i] = f[i-1]   

if n==1:
    print(0)
else:
    arr = factorization(n)
    for a,b in arr:
        ans += f[b]
    print(ans)

Measured memory_bytes: 9524
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, i, j;
	double a, rr;
	int t[3];
	
	while(scanf("%d %d %d\n", &t[0], &t[1], &t[2]) == 3) {
		if(!t[0] && !t[1] && !t[2]) break;

		for(i=0;i<2;i++) {
			for(j=i+1;j<3;j++) {
				if(t[i] > t[j]) {
					int p = t[i];
					t[i] = t[j];
					t[j] = p;
				}	
			}
		}
		
		rr = sqrt(t[0]*t[0] + t[1]*t[1])/2;

		scanf("%d\n", &n);
		for(i=0;i<n;i++) {
			scanf("%lf\n", &a);
			if(a > rr) {
				printf("OK\n");
			} else {
				printf("NA\n");
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=2e5+5;
const int mod=1e9+7;
int n,in[N],out[N],gt[N],res[N],sz[N];
vector<int>adj[N];

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n==1) return x;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

void init()
{
    gt[0]=1;
    for(int i=1;i<=n;i++) gt[i]=gt[i-1]*i%mod;
}

void dfs1(int x,int p=0)
{
    sz[x]=1;
    for(auto&u:adj[x])
    {
        if(u==p) continue;
        dfs1(u,x);
        sz[x]+=sz[u];
    }
}

void dfs2(int x,int p=0)
{
    for(auto&u:adj[x])
    {
        if(u==p) continue;
        res[u]=res[x]*sz[u]%mod;
        sz[x]=n-sz[u];
        sz[u]=n;
        res[u]=res[u]*Power(sz[x],mod-2)%mod;
        dfs2(u,x);
        sz[u]=n-sz[x];
        sz[x]=n;
    }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    init();
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1(1);
    res[1]=gt[n];
    for(int i=1;i<=n;i++) res[1]=res[1]*Power(sz[i],mod-2)%mod;
    dfs2(1);
    for(int i=1;i<=n;i++) cout<<res[i]<<'\n';
}


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

using namespace std;
#define X first
#define Y second
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl;
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
int n,m,cnt,x,y;char s[10][10];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#') cnt++;
	if(cnt!=n+m-1) return puts("Impossible"),0;
	
	x=1;y=1;
	while(!(x==n&&y==m))
	{
		if((s[x+1][y]=='#')+(s[x][y+1]=='#')!=1)
			return puts("Impossible"),0;
		if(s[x+1][y]=='#') x++;
		else y++;
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll n;
    cin>>n;
    vector<pii>v;
    v.resize(n);
    for(ll i=0;i<n;i++)
        cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end());
    pii mxy={-1,0};
    pii mny={-1,2e9};
    ll ans=0;
    for(ll i=n-1;i>=0;i--)
    {
        ll x=v[i].first,y=v[i].second;
        if(mxy.second!=0)
        {
            ans=max(ans,abs(x-mxy.first)+abs(y-mxy.second));
        }
        if(mny.second!=2e9)
        {
            ans=max(ans,abs(x-mny.first)+abs(y-mny.second));
        }
        if(mxy.second==0)
        {
            mxy=v[i];
        }
        else
        {
            if(mxy.second<v[i].second)
            {
                if(v[i].second-mxy.second-(mxy.first-v[i].first)>0)
                {
                    mxy=v[i];
                }
            }
        }
        if(mny.second==2e9)
        {
            mny=v[i];
        }
        else
        {
            if(mny.second>v[i].second)
            {
                if(abs(v[i].second-mny.second)-abs(v[i].first-mny.first)>0)
                {
                    mny=v[i];
                }
            }
        }

    }

    cout<<ans;
}


Measured memory_bytes: 6356
d=[1]+[0]*12
for i,c in enumerate(input()):
 p=[0]*13
 for j in range(13):
  for k in range(10):p[(j*10+k)%13]+=d[j]*(c>'9'or k==int(c))
 d=[t%(10**9+7)for t in p]
print(d[5])

Measured memory_bytes: 44100
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll n;
  cin>>n;
  ll a[n+1];
  rep(i,0,n+1) cin>>a[i];
  ll mi=a[n],ma=a[n];
  ll arr[n+1][2],ans;
  arr[n][0]=mi;
  arr[n][1]=ma;
  if(n==0){
    if(a[0]!=1) {
      cout<<-1;
      return ;
    }
    else{
      cout<<1;
      return;
    }
  }
  if(a[0]){
    cout<<-1;
    return;
  }
  if(log(mi)>log(2)*n){
    cout<<-1;
    return ;
  }
  repr(i,0,n)
  {
    mi=a[i]+(mi+1)/2;
    ma=a[i]+ma;
    if(log(mi)>log(2)*i){
      cout<<-1;
      return ;
    }
    if(log(ma)>log(2)*i){
      ma=pow(2,i);
    }
    arr[i][0]=mi;
    arr[i][1]=ma;
  }
  ll cur=1;
  ans=1;
  rep(i,1,n+1){
    ans+=a[i];
    if((2*cur<arr[i][0])||(cur>arr[i][1])){
      cout<<-1;
      return;
    }
    cur=min(cur*2,arr[i][1])-a[i];
    ans+=cur;
  }
  cout<<ans<<endl;
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 6500
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
#include <map>
using namespace std;
typedef pair<int, int> point;

int main(void) {
    int n, i, j, p, ans=0;
    string s;
    cin >> n >> s;
    
    for(i=0; i<n; i++) {
        int left[26]={0};
        int right[26]={0};
        int cnt=0;
        for(j=0; j<=i; j++)
            left[s[j]-'a'] = 1;
        for(j=i+1; j<n; j++)
            right[s[j]-'a'] = 1;
        
        for(p=0; p<26; p++) {
            if(left[p]==1 && right[p]==1)
                cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int p[100001];
ll sum[100002];
int main(){
    int n,m,ai,bi,ci;
    cin>>n>>m;
    rep(i,m) cin>>p[i],--p[i];
    FOR(i,1,m){
        ++sum[min(p[i-1],p[i])];
        --sum[max(p[i-1],p[i])];
    }
    rep(i,n) sum[i+1]+=sum[i];
    ll ans=0;
    rep(i,n-1){
        cin>>ai>>bi>>ci;
        ans+=min(sum[i]*ai,sum[i]*bi+ci);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  int sum = 0;
  int ans;
  int flag = 0;

  for(int i = 0; i < N; i++){
    cin >> v.at(i);
    sum += v.at(i);
  }

  if(sum % 10 != 0){
    ans = sum;
  }
  else{
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++){
      if(v.at(i) % 10 != 0){
        ans = sum - v.at(i);
        flag = 1;
        break;
      }
    }
    if(!flag){
      ans = 0;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    string s;
    cin >> s;
    ll n = s.length();
    ll dp[n][13] = {};

    if (s[n - 1] == '?') {
        rep(i, 10) { dp[0][i] = 1; }
    } else {
        int num = s[n - 1] - '0';
        dp[0][num] = 1;
    }

    ll base = 1;
    repd(i, 1, n) {
        ll index = n - i - 1;
        base = (base * 10) % 13;
        if (s[index] == '?') {
            rep(j, 10) {
                ll b = (j * base) % 13;
                rep(l0, 13) {
                    ll index_temp = (l0 - b + 13) % 13;
                    dp[i][l0] += dp[i - 1][index_temp];
                    dp[i][l0] %= mod;
                }
            }
        } else {
            ll num = s[index] - '0';
            ll b = (num * base) % 13;
            rep(l0, 13) {
                ll index_temp = (l0 - b + 13) % 13;
                dp[i][l0] += dp[i - 1][index_temp];
                dp[i][l0] %= mod;
            }
        }
    }
    cout << dp[n - 1][5] << endl;
    return 0;
}



Measured memory_bytes: 10624
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	s, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}
	q, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	t, err := nextInts(q, sc)
	if err != nil {
		panic(err)
	}
	fmt.Println(binarySearch(s, t))
}

func binarySearch(s, t []int) int {
	count := 0
	for _, v := range t {
		bottom := 0
		top := len(s) - 1
		var center int
		for {
			center = (top + bottom) / 2
			if s[center] == v {
				count++
				break
			} else {
				if top-bottom == 0 {
					break
				} else if top-bottom == 1 {
					if s[top] == v || s[bottom] == 1 {
						count++
						break
					} else {
						break
					}
				} else {
					if s[center] < v {
						bottom = center
					} else {
						top = center
					}
				}
			}
		}
	}
	return count
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	ns := make([]int, n)
	for i, _ := range ns {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		ns[i] = x
	}
	return ns, nil
}



Measured memory_bytes: 3068
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
  return *(int*)a-*(int*)b;
}

int main()
{
  int n,c,k;
  int t[100001];
  int i;
  int ans=0;
  int a=0;
  int T;
  scanf("%d%d%d",&n,&c,&k);
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
  }
  qsort(t,n,sizeof(int),compare_int);
  for(i=0;i<n;i++){
    if(a==0 || a>=c){
      ans++;
      a=1;
      T=t[i];
    }
    else if(a>0 && a<c){
      if(t[i]<=T+k){
        a++;
      }
      else{
        ans++;
        a=1;
        T=t[i];
      }
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <utility>

using namespace std;

typedef pair<int, int> P;

int n;

P p[200020];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(b, a);
  }
  
  sort(p, p+n);
  
  int time = 0;
  for (int i = 0; i < n; i++) {
    time += p[i].second;
    if (time > p[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792