akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

# C - XYZ Triplets
def calc(x, y, z):
	return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


N = int(input())
ans = [0] * (N + 1)

for x in range(1, 100):
	for y in range(1, 100):
		for z in range(1, 100):
			i = calc(x, y, z)
			
			if i > N:
				break
			else:
				ans[i] += 1

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

    

Measured memory_bytes: 9304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strIn = null;
		int[]	blcnt = new int[4];
		int		len   = 0;
		int		c     = 0;

		while ((strIn = parseBlood()) != null) {
			len = strIn.length();
			c   = strIn.charAt(0);

			switch (c) {
			case 'O':
				blcnt[3]++;
				break;
			case 'B':
				blcnt[1]++;
				break;
			case 'A':
				if (len == 2) {
					blcnt[2]++;
				}
				else {
					blcnt[0]++;
				}
				break;
			}
		}

		for (int n = 0; n < blcnt.length; n++) {
			System.out.println(blcnt[n]);
		}
	}

	private static String parseBlood() {
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			strIn = strIn.split(",")[1];
		}
		
		return strIn;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

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

    int S = 0;
    int n = N;

    while (n > 0){
        S += n % 10;
        n /= 10;
    }

    if (N % S == 0){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def b_sum(self, i):
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def b_add(self, i, x):
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

fr, ba = min(a), max(a)+1

while ba - fr > 1:
	mi = (fr+ba) // 2
	bit = BIT(n+1)
	res = 0
	inv = [0]
	min_tmp = 0
	# あとで全体を-min_tmp+1だけ足さないとバグる
	for j in range(n):
		if a[j] >= mi:
			inv.append(inv[-1]+1)
		else:
			inv.append(inv[-1]-1)
			min_tmp = min(min_tmp, inv[-1])

	for j in range(n+1):
		res += bit.b_sum(inv[j] - min_tmp + 1)
		bit.b_add(inv[j] - min_tmp + 1, 1)

	if res >= (n * (n+1) / 4):
		fr = mi
	else:
		ba = mi

print(fr)

Measured memory_bytes: 123720
import sys

for s0 in sys.stdin:
  s=s0[:-1]
  d,c=s.split("=")
  a,b=d.split("+")
  f=any([e!=e[0]=="X" for e in [a,b,c]])
  N="0123456789"[f:]
  m="NA"
  s=d+"=="+c
  for e in N:
    if eval(s.replace("X",e)): m=e; break
  print m

Measured memory_bytes: 4268
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
const long long INF = 1LL << 60;

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;}

int main(){
    ll x; cin >> x;
    for(ll i=-1000;i<=1000;i++){
        for(ll j=-1000;j<1000;j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
  int n, i, x, z;
 
  	if(scanf("%d", &n)== 1);
 
  if (n <= 81)  {
  	for( i=1; i<=9; ++i ){
  		if( n%i ==0 ){
          z = n/i;
          if(z <= 9){
    	 	++x;
          }else{
            if(i*i == n){
              ++x;
            }
          }
  		}
  	}
  }

    if(x >= 1){
      printf("Yes");
    }else{
      printf("No");
    }
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    int minus = 0;
    ull sum = 0;
    ll min_n = 1000000000;
    for(int i = 0; i < N; i++){
        ll a;
        cin >> a;
        sum += abs(a);
        min_n = min(min_n, abs(a));
        if(a < 0) minus++;
    }
    if(minus % 2) cout << sum - 2 * min_n << endl;
    else cout << sum << endl;
}

Measured memory_bytes: 1024
intInput = lambda: map(int, raw_input().split())
n, m, l = intInput()
A = [intInput() for _ in xrange(n)]
B = [intInput() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(l):
        print sum([A[i][k] * B[k][j] for k in xrange(m)]),
    print

Measured memory_bytes: 4720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long max =sc.nextLong();
		long total =0;
		for (int i=0;i<N-1;i++) {
			long temp = sc.nextLong();
			if (temp<max) {
				total +=max-temp;
			} else {
				max = temp;
			}
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 59488
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
ll n,m;
vector< pair<ll,ll> > v,v1; 
char a[1005][1005];
ll tim[1005][1005];
ll visited[1005][1005];
queue< pair<ll,ll> > q;
ll posx[]={1,-1,0,0};
ll posy[]={0,0,1,-1};
ll check(ll i,ll j)
{
  if(i>=1 && i<=n && j>=1 && j<=m)
  {
     if(visited[i][j])
      return 0;
     return 1;
  }
  return 0;
}
int main()
{
  IOS
  cin>>n>>m;
  ll i,j;
  for(i=1;i<=n;i++)
  {
     string s;
     cin>>s;
     for(j=1;j<=m;j++)
     {
      a[i][j]=s[j-1];
      if(a[i][j]=='#')
       {
         visited[i][j]=1;
         tim[i][j]=0;
         q.push(mp(i,j));
       }
     }
  }
  while(!q.empty())
  {
     pair<ll,ll> t=q.front();
     q.pop();
     for(i=0;i<4;i++)
      if(check(t.ff+posx[i],t.ss+posy[i]))
      {
         visited[t.ff+posx[i]][t.ss+posy[i]]=1;
         tim[t.ff+posx[i]][t.ss+posy[i]]=tim[t.ff][t.ss]+1;
         q.push(mp(t.ff+posx[i],t.ss+posy[i]));
      }
  }
  ll maxi=0;
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
      if(tim[i][j]>maxi)
        maxi=tim[i][j];
  cout<<maxi;    

	return 0;
}

Measured memory_bytes: 33460
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        long sum = 0;
        if (n == 1) {
            System.out.println(a[0] / 2);
            return;
        }
        for (int i = 0; i < n - 1; i++) {
            long asum = a[i] + a[i + 1];
            long d = asum / 2;
            sum += d;
            a[i + 1] -= Math.max(2 * d - a[i], 0);
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 62076
from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

NN = 2020202
MOD = 10**9+7
INF = float("inf")

N = int(input())
A = [input() for i in range(N)]

count = Counter(A)
count2 = [(c, s) for s, c in count.items()]
count2.sort(key=lambda x: (-x[0], x[1]))
# print(count2)

for elem in count2:
    if elem[0] == count2[0][0]:
        print(elem[1])
    else:
        break



Measured memory_bytes: 119288
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,a[100],ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      ans=max(ans,a[i]-a[j]);
  printf("%d\n",ans);
}

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

map<ll,int>id;
int n;
ll d[101000];

#define pli pair<ll,int>
#define fi first
#define se second
priority_queue<pli>q;

int fa[101000], sz[101000]; ll sum[101000];

int main(){
    cin>>n;
    for (int i=1;i<=n;++i){
        cin>>d[i]; id[d[i]]=i;
    }
    sort(d+1,d+n+1,greater<ll>());
    for (int i=1;i<=n;++i){
        sz[i]=1;
        while (q.size()&&q.top().fi==d[i]){
            fa[q.top().se]=i;
            sz[i]+=sz[q.top().se];
            sum[i]+=sum[q.top().se]+sz[q.top().se];
            q.pop();
        }
        q.push({d[i]-(n-sz[i]*2),i});
    }
    if (q.size()!=1||sum[n]!=d[n]){
        puts("-1");
        return 0;
    }
    for (int i=1;i<n;++i)
        printf("%d %d\n",id[d[i]],id[d[fa[i]]]);
}

Measured memory_bytes: 10104
#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.second < secondElof.second;
}
bool pairCompare2(const pll firstElof, pll secondElof)
{
	return firstElof.second > secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//

int main() {
	cin >> H >> N;
	vpll AB(N);
	ll M = 0;
	for (i = 0; i < N; i++) {
		cin >> AB[i].first >> AB[i].second;
		M = max(AB[i].first, M);
	}
	vl dp(H+M+1);
	for (i = 0; i <= H+M; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (i = 1; i <= H+M; i++) {
		for (j = 0; j < N; j++) {
			ll F = AB[j].first;
			ll S = AB[j].second;
			if (i - F >= 0) {
				dp[i] = min(dp[i], dp[i - F] + S);
			}
		}
	}
	ans = INF;
	for (i = H; i <= H+M; i++) {
		ans = min(ans, dp[i]);
	}
	cout << ans;
}


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

typedef long long ll;
typedef unsigned long long ull;

enum query{
    RELATE,DIFF
};

template<unsigned long long SIZE> class unionFind{
    protected:
        long long uni[SIZE];
        long long diff_weight[SIZE];
    public:
        unionFind(){
            for(int i=0;i<SIZE;i++){
                uni[i]=-1;
                diff_weight[i]=0;
            }
        }
        unsigned long long root(unsigned long long a){
            if(a>=SIZE) throw std::range_error("与えられたインデックスが木の範囲外です");
            if(uni[a]<0) return a;
            else{
                unsigned long long r=root(uni[a]);
                diff_weight[a]+=diff_weight[uni[a]];
                return uni[a]=r;
            }
        }
        long long weight(unsigned long long a){
            root(a);
            return diff_weight[a];
        }
        long long diff(unsigned long long a, unsigned long long b){
            if(isSame(a,b)) return weight(b)-weight(a);
            else return INT64_MAX;
        }
        unsigned long long count(unsigned long long a){
            return -uni[root(a)];
        }
        bool merge(unsigned long long a, unsigned long long b, long long w=1){
            w+=weight(a);  w-=weight(b);
            a=root(a);  b=root(b);
            if(a==b) return false;
            if(uni[a]>uni[b]){
                swap(a, b);
                w=(-w);
            }
            uni[a]+=uni[b];
            uni[b]=a;
            diff_weight[b]=w;
            return true;
        }
        bool isSame(unsigned long long a,unsigned long long b){
            return root(a)==root(b);
        }
};

int main(){
    unionFind<100000> uf;
    int n,q;
    cin >> n >> q;
    for(int i=0;i<q;i++){
        int c,x,y,z;
        cin >> c;
        switch(c){
            case RELATE:
                cin >> x >> y >> z;
                uf.merge(x,y,z);
                break;
            case DIFF:
                cin >> x >> y;
                if(uf.isSame(x,y)){
                    cout << uf.diff(x,y) << endl;
                }else{
                    cout << '?' << endl;
                }
        }
    }    
    
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m;cin >> n >> m;
  vector<string> a(n); cin >> a;
  vector<string> b(m); cin >> b;
  bool f = true;
  for(int i = 0; i < n-m+1; ++i){
    for(int j = 0; j < n-m+1; ++j){
      f = true;
      for(int k = 0; k < m; ++k){
	for(int l = 0; l < m; ++l){
	  f &= a[i+k][j+l] == b[k][l];
	}
      }
      if(f){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 3632
import numpy as np

N = int(input())
Alist = []
Blist = []
sumlist = []

for i in range(N):
    a,b = map(int,input().split())
    Alist.append(a)
    Blist.append(b)
    sumlist.append(a+b)

index = np.argsort(sumlist)

sumlist = np.sort(sumlist)




counter = 0
takahasi = 0
aoki = 0

for i in range(N)[::-1]:
    if counter == 0:
        takahasi += Alist[index[i]]
        counter = 1
        continue
    if counter == 1:
        aoki += Blist[index[i]]
        counter = 0
        continue

print(takahasi-aoki)




Measured memory_bytes: 26936
#include <cstdio>
#include <cmath>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <fstream>
#include <functional>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iomanip>
#define memtst(x) (sizeof(x) / 1024. / 1024.)
#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;
const double PI = acos(-1);
const double EPS = 1e-6;
const ll MOD = 998244353;
const ll INF = 0x3F3F3F3F;
template <typename T>
inline T Abs(T x)
{
    return x < 0 ? x * -1 : x;
}
template <typename T>
inline T Max(T x, T y, T z)
{
    return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z)
{
    return std::min(std::min(x, y), z);
}
template <typename T>
inline T Ckmax(T &x, T y)
{
    return x = std::max(x, y);
}
template <typename T>
inline T Ckmin(T &x, T y)
{
    return x = std::min(x, y);
}
template <typename T>
inline T Sqr(T x)
{
    return x * x;
}
template <typename T>
inline T Pow(T x, T y)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= MOD;
        (x *= x) %= MOD;
        y /= 2;
    }
    return r % MOD;
}
template <typename T>
T Pow(T x, T y, T z)
{
    T r = 1;
    while (y > 0)
    {
        if (y % 2 > 0)
            (r *= x) %= z;
        (x *= x) %= z;
        y /= 2;
    }
    return r % z;
}
template <typename T>
inline T gcd(T x, T y)
{
    return y > 0 ? gcd(y, x % y) : x;
}
template <typename T>
inline T lcm(T x, T y)
{
    return x / gcd(x, y) * y;
}
inline void cinspu(void)
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
}
inline ll read(void)
{
    char x;
    while (x = getchar(), x != '-' && !isdigit(x))
        ;
    char flg = x == '-';
    ll num = (flg ? getchar() : x) - '0';
    while (isdigit(x = getchar()))
        (num *= 10) += x - '0';
    return flg ? -num : num;
}
const int N = 50 + 10;
const int one[6] = {0, 0, 1, 2, 3, 3};
ll a[N], p[N];
ll dfs(ll n, ll x)
{
	if (x <= 1)
		return 0;
	if (n == 1)
		return one[x];
	if (x == a[n])
		return p[n];
	ll val = 0;
	val += dfs(n - 1, std::min(x - 1, p[n] - 2));
	if (x >= p[n])
		val += 1 + dfs(n - 1, x - p[n] - (x >= a[n]));
	return val;
}
int main()
{
	cinspu();
	ll n, x;
	std::cin >> n >> x;
	p[0] = 1;
	for (int i = 1; i <= n; ++i)
		p[i] = p[i - 1] * 2 + 1;
	a[0] = 1;
	for (int i = 1; i <= n; ++i)
		a[i] = a[i - 1] * 2 + 3;
	std::cout << dfs(n, x) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

struct X{
    string str;
    ll num;
    ll id;
};

struct Y{
    ll num;
    ll id;
};

bool compstr(const X& e1, const X& e2){
  	return e1.str < e2.str;
}
bool compnum(const Y& e1, const Y& e2){
  	return e1.num > e2.num;
}

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

    ll n;
    cin >> n;
    string s;
    ll p;
    vector<X> x;
    REP(i, n){
        cin >> s >> p;
        x.push_back(X{s, p, i + 1});
    }
    sort(x.begin(), x.end(), compstr);
    vector<vector<Y>> a(n);
    ll k = 0;
    a[0].push_back(Y{x[0].num, x[0].id});
    REP(i, n - 1){
        if(x[i + 1].str != x[i].str) k++;
        a[k].push_back(Y{x[i + 1].num, x[i + 1].id});
    }
    REP(i, n){
        sort(a[i].begin(), a[i].end(), compnum);
        for(auto v : a[i]) cout << v.id << endl;
    }
    return 0;
}

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

#define int long long

int a[100100];
int b[100100];
int ans;

signed main ( ) {

    int n;
    cin >> n;

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

    int prev = 0;
    for ( int i = 0; i < n; i++ ) {
        if ( prev <= a[i] ) {
            a[i] -= prev;
            ans += prev;
        }
        else {
            ans += a[i];
            a[i] = 0;
        }
        prev = 0;
        if ( b[i] <= a[i] ) {
            ans += b[i];
            a[i] -= b[i];
        }
        else {
            prev = b[i]-a[i];
            ans += a[i];
        }
    }

    cout << ans+min(prev,a[n]) << endl;


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)
#define MOD (1000000007LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

#define vv(t) vector< vector< T > >
#define pb push_back
#define pu push
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define EQ(a,b) (abs((a)-(b))<EPS)

int n;
int a[21];

int dfs(int diff, int i){
  if(i == n) return abs(diff);
  else{
    int s = dfs(diff + a[i], i + 1);
    int t = dfs(diff - a[i], i + 1);
    return min(s, t);
  }
}

int main(void){
  ios_base::sync_with_stdio(0);
  while(cin >> n, n){
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << dfs(0, 0) << endl;
  }
  return 0; 
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,A;
  cin >> N;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    cin >> A;
    mp[A] ++;
  }

  bool all_1 = true;
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    if(itr->second != 1) all_1 = false;
  }
  if(all_1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 12892
#include<stdio.h>

#define max 10000
#define nil -1

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

node t[max];

int n, d[max], h[max];

void dep(int u, int D){
  if(u==nil)return;
  d[u]=D;
  dep(t[u].l, D+1);
  dep(t[u].r, D+1);
}

int hei(int u){
  int h1=0, h2=0;
  if(t[u].l!=nil)h1=hei(t[u].l)+1;
  if(t[u].r!=nil)h2=hei(t[u].r)+1;

  if(h1<h2)h[u]=h2;
  else h[u]=h1;
  return h[u];
}

int sib(int u){
  if(t[u].p==nil)return nil;
  if(t[t[u].p].l!=u && t[t[u].p].l!=nil)return t[t[u].p].l;
  if(t[t[u].p].r!=u && t[t[u].p].r!=nil)return t[t[u].p].r;
  return nil;
}

void Pr(int u){
  int deg=0;
  printf("node %d: ", u);
  printf("parent = %d, ", t[u].p);
  printf("sibling = %d, ", sib(u));
  if(t[u].l!=nil)deg++;
  if(t[u].r!=nil)deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", d[u]);
  printf("height = %d, ", h[u]);
  if(t[u].p==nil){
    printf("root\n");
  }else if(t[u].l==nil && t[u].r==nil){
    printf("leaf\n");
  }else {
    printf("internal node\n");
  }
}

int main(){
  int v, l, r, root=0, i;
  scanf("%d", &n);
  for(i=0 ; i<n ; i++)t[i].p=nil;
  for(i=0 ; i<n ; i++){
    scanf("%d%d%d",&v, &l, &r);
    t[v].l=l;
    t[v].r=r;
    if(l!=nil)t[l].p=v;
    if(r!=nil)t[r].p=v;
  }
  for(i=0 ; i<n ; i++)if(t[i].p==nil)root=i;
  dep(root, 0);
  hei(root);
  for(i=0 ; i<n ; i++)Pr(i);
  return 0;
}


Measured memory_bytes: 2048
//Created by Kira

#include <bits/stdc++.h>
using namespace std;

#define IOS                 \
    cin.sync_with_stdio(0); \
    cin.tie(0);             \
    cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

const int N = 5e5+10;

int n;


struct S{

    vector<bool> cnt;
    
    S() {
        cnt.assign(26, false);
    }
    S(vector<bool> cnt) : cnt(cnt){}
};


 S combine(S a, S b){
        S res;

        for(int i = 0; i < 26; i++){
            res.cnt[i] = a.cnt[i] | b.cnt[i];
        }

        return res;
}

S t[2 * N];

void build()
{
    for (int i = n - 1; i >= 0; --i)
        t[i] = combine(t[i<<1], t[i<<1 | 1]);
}

void modify(int p, S val)
{ //Set Value at position p
    for (t[p += n] = val; p > 1; p >>= 1)
        t[p >> 1] = combine(t[p],t[p ^ 1]);
}

S query(int l, int r)
{ //query on interval [l,r)

    S resL, resR;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1)
    {
        if (l & 1)
            resL  = combine(resL, t[l++]);
        if (r & 1)
            resR  = combine(resR, t[--r]);
    }
    return combine(resL, resR);
}

int main(){
    IOS
    
    cin>>n;

    string s; cin>>s;
    int q; cin>>q;

    // for(int i = 0; i < 2*n; i++){
    //     t[i].cnt.assign(26,false);
    // }


    for(int i = n; i < 2*n; i++){
        t[i].cnt[s[i-n]-'a'] = true;
    }

    build();

    for(int i = 0; i < q; ++i){
        int type; cin>>type;

        if(type == 1){
            int pos; char val;
            cin>>pos>>val; --pos;
            S nn; 
            //nn.cnt.assign(26,false);
            nn.cnt[val-'a'] = true;
            modify(pos, nn);

        }else if (type == 2){
            int L, R; cin>>L>>R; L--;

            S res = query(L, R);
            
            int fres = 0; 
            for(int i = 0; i < 26; ++i){
                if(res.cnt[i])fres++;
            }

            cout<<fres<<"\n";
        }
    }

}

ll pwr(ll a, ll b)
{
    a %= mod; //Remove mod if not required
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }

    return res;
}


Measured memory_bytes: 71444
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

int bin(vector<int> &a, int target){
    int l = 0, r = sz(a)-1;

    while (r >= l){
        int m = (l+r)/2;
        if (a[m] == target) return m;
        if (a[m] > target) r = m-1;
        else l = m+1;
    }
    return -1;
}

void solve(){
    int a, b;
    cin >> a >> b;
    if (a < 10 && b < 10) cout << a*b << '\n';
    else cout << -1 << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3660
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

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

int main() {
	int N;
	cin >> N;
	vector<int> b;
	vector<int> ret;
	for(int i=0;i<N;i++){
		int v;
		cin >> v;
		b.push_back(v);
	}
	for(int i=N;i>0;i--){
		bool ok=false;
		for(int j=i-1;j>=0;j--){
			if(b[j]==j+1)
			{
				//cerr << j+1 << endl;
				ret.push_back(j+1);
				b.erase(b.begin()+j);
				ok=true;
				break;
			}
		}
		if(!ok){
			cout << -1 << endl;
			return 0;
		}
	}
	//cerr << ret.size() << endl;
	reverse(ret.begin(),ret.end());
	for(auto v:ret)
	{
		cout << v << endl;
	}


	return 0;
}



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

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

    int L = A + B;
    int R = C + D;

    if (L > R) {
        cout << "Left" << endl;
    } else if (L == R){
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            int[] n = io.r<int>(' ');
            if (n[0] == n[1] && n[0] == 0) { break; }
            for (int i = 0; i < n[0]; i++)
            {
                for (int j = 0; j < n[1]; j++)
                {
                    io.w("#", false);
                }
                io.w("");
            }
            io.w("");
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10260
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, k) = input_tuple();
    let a_vec = input_vec();
    let mut digits = vec![0; 50];
    for a in a_vec {
        let bits: String = format!("{:b}", a);
        let mut bits: Vec<char> = bits.chars().collect();
        bits.reverse();
        // println!("{:?}", bits);
        for i in 0..bits.len() {
            if bits[i] == '1' {
                digits[i] += 1;
            }
        }
    }
    digits.reverse();
    // println!("{:?}", digits);
    let mut idx = 50u32;
    let mut x = 0;
    let mut sum = 0;
    for digit in digits {
        // println!("idx = {}: x = {}, sum = {}", idx, x, sum);
        if n - digit > digit {
            // 1にしたい
            if 2u64.pow(idx - 1) > k - x {
                //  overするから0
                sum += 2u64.pow(idx - 1) * digit;
            } else {
                // 1にする
                sum += 2u64.pow(idx - 1) * (n - digit);
                x += 2u64.pow(idx - 1);
            }
        } else {
            // 0にする
            sum += 2u64.pow(idx - 1) * digit;
        }
        idx -= 1;
    }
    // println!("{:?}", digits);
    println!("{}", sum);

}


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


int main(){

    int n;
    char s[10100];
    cin >> n >> s;
    int len = strlen(s);
    rep(i, len) {
        int x = s[i] - 'A';
        x = (x + n) % 26;
        putchar('A' + x);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int w[33];
vector<ll> a, b;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	char a;
	cin >> a;
	if (isupper(a)) cout << 'A' << endl;
	else cout << 'a' << endl;
	return 0;
}


Measured memory_bytes: 3648
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
c=gets.chomp.split.map(&:to_i)
N=gets.chomp.to_i
N.times do
  target = gets.chomp.to_i
  a[a.index(target)] = "" if a.include?(target)
  b[b.index(target)] = "" if b.include?(target)
  c[c.index(target)] = "" if c.include?(target)
end

result = "No"
i = 0
# 横揃い
result = "Yes" if a.count("") == 3
result = "Yes" if b.count("") == 3
result = "Yes" if c.count("") == 3

# 縦揃い
3.times do
  result = "Yes" if a[i] == "" && b[i] == "" && c[i] == ""
  i += 1
end

# 斜め揃い
result = "Yes" if a[0] == "" && b[1] == "" && c[2] == ""
result = "Yes" if a[2] == "" && b[1] == "" && c[0] == ""

#p a, b, c
puts result

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435
using namespace std;

void solve(){
	int t;
	cin>>t;
	map<string,int> ma;
	while(t--){
		string s;
		cin>>s;
		ma[s]++;
	}
	cout<<"AC x "<<ma["AC"]<<endl;
	cout<<"WA x "<<ma["WA"]<<endl;
	cout<<"TLE x "<<ma["TLE"]<<endl;
	cout<<"RE x "<<ma["RE"]<<endl;
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3684
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

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

    sort(A, A + N, greater<int>());

    int alice = 0;
    int bob = 0;
    for (int n = 0; n < N; n++)
        if (n % 2 == 0)
            alice += A[n];
        else
            bob += A[n];

    printf("%i\n", alice - bob);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(){
	char str[120],str2[120];
	int a=0,b=0;
	scanf("%s%s",str,str2);
	a=strlen(str);
	
	for(int i=0;i<a;i++)
	{
		b=0;
		for(int j=0;j<a;j++)
		{
			if(str[(i+j)%a]==str2[j])
			{
				b++;
			}
		}
		if(b==a)
		{
			printf("Yes");
			return 0;
		}
	}
	
	printf("No");
	}

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

using namespace std;

bool operator< (const pair<int, int> a, const pair<int, int> b){return a.first < b.first;};
//pair の1つ目の要素に従って昇順に処理したい
bool operator> (const pair<int, int> a, const pair<int, int> b){return a.first > b.first;};
//pair の2つ目の要素に従って降順に処理したい
// bool operator< (const pair<int, int> a, const pair<int, int> b){return a.second < b.second;};
// //pair の2つ目の要素に従って昇順に処理したい
// bool operator> (const pair<int, int> a, const pair<int, int> b){return a.second > b.second;};

void dijkstra(int initial, vector<bool> &visit, vector<int> &D, vector<int> &mother, vector<vector<int>> A)
{

    D[initial] = 0;
    visit[initial] = 1;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> S;

    pair<int, int> p = make_pair(D[initial], initial);

    S.push(p);

    while (!S.empty())
    {
        int w = S.top().second;

        S.pop();

        if (A[w].size() > 0)
        {
            for (int v:A[w])
            {

                if (visit[v] ==0)
                {
                  
                    visit[v] = 1;
                }

                if (D[w] + 1 < D[v])
                {

                    D[v] = D[w] + 1;

                    pair<int, int> new_pair = make_pair(D[v], v);
                    S.push(new_pair);

                    mother[v] = w;
                }
            }
        }
    }
}

int main()
{

    const int INF = 1001001001;

    int N, M;

    cin >> N >> M;

    //graph
    vector<vector<int>> A(N, vector<int>(0));

    // aint eady visit?
    vector<bool> visit(N, 0);

    // mother room of the room
    vector<int> mother(N);

    // cost array
    vector<int> D(N, INF);

    for (int i = 0; i < M; i++)
    {

        int b, c;

        cin >> b >> c;

        A[b - 1].push_back(c - 1);
        A[c - 1].push_back(b - 1);
    }
    //initialization
    dijkstra(0, visit, D, mother, A);
 

    for (int i = 0; i < N; i++)
    {
        if (visit[i] == 0)
        {
            cout <<"No"<< endl;
        }
    }
    

    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {

        cout << mother[i] + 1 << endl;
    }

    return 0;
}




// #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>;
 
// const int INF = 1001001001;
// vector<int> to[100005];
 
// int main() {
//   int n, m;
//   cin >> n >> m;
//   rep(i,m) {
//     int a, b;
//     cin >> a >> b;
//     --a; --b;
//     to[a].push_back(b);
//     to[b].push_back(a);
//   }
 
//   queue<int> q;
//   vector<int> dist(n, INF);
//   vector<int> pre(n, -1);
//   dist[0] = 0;
//   q.push(0);
//   while (!q.empty()) {
//     int v = q.front(); q.pop();
//     for (int u : to[v]) {
//       if (dist[u] != INF) continue;
//       dist[u] = dist[v]+1;
//       pre[u] = v;
//       q.push(u);
//     }
//   }
 
//   cout << "Yes" << endl;
//   rep(i,n) {
//     if (i == 0) continue;
//     int ans = pre[i];
//     ++ans;
//     cout << ans << endl;
//   }
//   return 0;
// }




Measured memory_bytes: 16940
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true){
			String x = scan.next();
			if(x.equals("0")){
				break;
			}
			int sum = 0;
			for(int i = 0; i < x.length(); i++){
				sum += Character.digit(x.charAt(i), 10);
			}
			System.out.println(sum);
		}

	}

}

Measured memory_bytes: 17292
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,W;
  cin>>N>>W;
  vector<int> w(N);
  vector<int> v(N);
  for(int i=0;i<N;i++)
    cin>>w.at(i)>>v.at(i);
  vector<vector<int64_t>> dp(W+1,vector<int64_t>(N+1,0));
  for(int i=1;i<=W;i++){
    for(int j=1;j<=N;j++){
      if(i-w.at(j-1)>=0)
        dp[i][j]=max(dp[i][j-1],dp[i-w.at(j-1)][j-1]+v.at(j-1));
      else
        dp[i][j]=dp[i][j-1];
    }
  }
  cout<<dp[W][N]<<endl;
}

Measured memory_bytes: 82304
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int abc[] = new int[3];
		int cnt = 0;

		abc[0] = a;
		abc[1] = b;
		abc[2] = c;
		Arrays.sort(abc);

		while (abc[1] != abc[2]) {
			twoPlus(abc, 0, 1);
			cnt++;
		}

		if ((abc[1] - abc[0]) % 2 == 1) {
			twoPlus(abc, 1, 2);
			cnt++;
		}

		while (abc[0] != abc[1]) {
			plusTwo(abc, 0);
			cnt++;
		}

		System.out.println(cnt);

	}

	private static void plusTwo(int[] abc, int i) {
		abc[i] += 2;
	}

	private static void twoPlus(int[] abc, int i, int j) {
		abc[i]++;
		abc[j]++;
	}

}

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

typedef long long ll;

int main() {
	ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    cin >> T[0] >> A[0];

    ll crtA=T[0], crtB=A[0];
    for(ll i=1; i<N; i++){
        cin >> T[i] >> A[i];
        ll n, nA, nB;
        if(crtA%T[i]==0) nA = crtA/T[i];
        else nA = crtA/T[i] + 1;
        if(crtB%A[i]==0) nB = crtB/A[i];
        else nB = crtB/A[i] + 1;
        n = max(nA,nB);
        crtA = n*T[i]; crtB = n*A[i];
    }
    cout << crtA+crtB << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s; // n文字
	//cout << "s.size() = " << s.size() << endl;
	vector<ll> rgb(3,0); // R , G , Bで数を入れうる
	rep(i,n){
		if(s[i] == 'R') rgb[0] ++;
		else if(s[i] == 'G') rgb[1] ++;
		else rgb[2] ++;
	}
	ll ans = rgb[0] * rgb[1] * rgb[2];
	//cout << "ans = " << ans << endl;
	rep(i,n){
		for(int j = i + 1; j < n ;j++){
			int k = j * 2 - i;
			if(i == j || i == k || j == k) continue;
			if(s[i] != s[j]){
				if(k < n){
					if( s[j] != s[k] && s[k] != s[i]){
						ans --;
						//printf("i = %d, j = %d, k = %d", i,j,k);
					}
				}
			}
		}
	}
	cout << ans << endl;
}


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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             


int main(void){
    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    
    int tmp[2];
    if( n % a == 0 ) tmp[0] = n / a * b;
    else             tmp[0] = ( n / a + 1 ) * b;
    
    if( n % c == 0 ) tmp[1] = n / c * d;
    else             tmp[1] = ( n / c + 1 ) * d;

    
    cout << min( tmp[0], tmp[1] ) << endl;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,Q,K;
int A[SIZE];

void solve() {
    cin>>N;
    REP1(n,N) {
        int max = sqrt(n)+1;
        int ans = 0;
        REP1(x,max)FOR(y,x,max)FOR(z,y,max) {
            int val = x*x + y*y + z*z + x*y + y*z + z*x;
            if (val == n) {
                if (x==y && y==z) {
                    ans += 1;
                }
                else if (x==y || y==z || z==x) {
                    ans += 3;
                }
                else {
                    ans += 6;
                }
            }
        }
        out("%lld\n",ans);
    }
}


Measured memory_bytes: 3660
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,m,v,next,cnt=0;
  cin >> n >> m;
  vector<ll> ans,len;
  string s;
  cin >> s;
  v=n;
  while(v!=0){
    next = max((ll)0,v-m);
    while(s[next]=='1'){
      next++;
    }
    if(next==v){
      cout <<"-1\n";
      return 0;
    }
    ans.push_back(v-next);
    v = next;
  }
  for(int i=ans.size()-1;i>=0;i--){
    cout << ans[i]<< " ";
  }
  cout << endl;
}


Measured memory_bytes: 1528
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N; cin >> N;
	ll a[N + 100];
	for (ll i = 0; i < N; i++)
		cin >> a[i];
	map<ll, ll>mp;
	for (ll i = 0; i < N; i++)
		mp[a[i]]++;
	ll ans = 0;
	for (auto p: mp) {
		int n = p.second;
		if(n%2==1)
          ans++;
	}
	cout << ans << endl;
	}




Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
	int R[MAX],n;
	
	cin >> n;
	for(int i=0;i<n;i++)cin >> R[i];
	
	int maxv=-2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

ll Q;
priority_queue<ll, vector<ll>, greater<ll> > topQ;
priority_queue<ll> bottomQ;

int main(){
	cin >> Q;

	ll topsum = 0;
	ll bottomsum = 0;
	ll bsum = 0;
	ll mid;
	rep(i, Q) {
		ll type;
		cin >> type;
		if(type == 1) {
			ll a, b;
			cin >> a >> b;
			bsum += b;

			if(topQ.size() == 0 || a > topQ.top()) {
				topQ.push(a);
				topsum += a;
			} else {
				bottomQ.push(a);
				bottomsum += a;
			}

			if(topQ.size() > bottomQ.size() + 1) {
				bottomQ.push(topQ.top());
				bottomsum += topQ.top();
				topsum -= topQ.top();
				topQ.pop();
			}

			if(bottomQ.size() > topQ.size() + 1) {
				topQ.push(bottomQ.top());
				topsum += bottomQ.top();
				bottomsum -= bottomQ.top();
				bottomQ.pop();
			}

			//cout << "topq " << topQ.top() << endl;
			//if(bottomQ.size() > 0) {
			//cout << "bottomq " << bottomQ.top() << endl;
			//}

			if((topQ.size() + bottomQ.size())%2 == 1) {
				if(topQ.size() > bottomQ.size()) {
					mid = topQ.top();
				} else {
					mid = bottomQ.top();
				}
			} else {
				mid = bottomQ.top();
			}
		} else {
			ll asum = topsum - topQ.size() * mid;
			asum += bottomQ.size() * mid - bottomsum;
			cout << mid << " " << asum + bsum << endl;
		}
	}
}



Measured memory_bytes: 4996
A, B, C = map(int, input().split())
cnt = 0
while True:
    if A == B == C and not (A % 2 != 0 or B % 2 != 0 or C % 2 != 0):
        print(-1)
        break
    elif A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
        print(cnt)
        break
    cnt += 1
    A, B, C = int(B/2 + C/2), int(A/2 + C/2), int(B/2 + A/2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    vector<int> a(n);
    vector<int> ans(n,0);
    for (int i = 0; i < n-1; i++) {
        cin >> a[i];
        ans[a[i]-1]++;
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4844
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int x, n, in;
	bool p[102];
	int i, j, ans;

	cin >> x >> n;
	for (i = 0; i < 102; i++) {
		p[i] = true;
	}
	for (i = 0; i < n; i++) {
		cin >> in;
		p[in] = false;
	}

	ans = 0;
	int sa = x;
	for (i = 0; i <= 101; i++) {
		if (p[i] == true && abs(i - x) < sa) {
			ans = i;
			sa = abs(i - x);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636