akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n+1];
    for(int i = 0;i<n+1;i++){
      a[i] = sc.nextLong();
    }
    long[] b = new long[n];
    for(int i = 0;i<n;i++)b[i] = sc.nextLong();

    long max = 0l;
    for(int i = 0;i<n;i++){
      if(a[i]>=b[i]){
        max+=b[i];
      }else{
        max+=a[i];
        b[i]-=a[i];
        if(a[i+1]>=b[i]){
          max+=b[i];
          a[i+1]-=b[i];
        }else{
          max+=a[i+1];
          a[i+1]=0;
        }
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 61080
X, K, D = map(int, input().split())
X = abs(X)

a = int(X/D)

if(K-a <= 0):
    print(X-K*D)
else:
    if((K-a)%2 == 0):
        print(abs(X-a*D))
    else:
        print(abs(X-(a+1)*D))

Measured memory_bytes: 61820
//
// Created by yuu on 2019-08-04.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;


int main(void){
    int N;
    cin>>N;
    int ans=0;
    for (int i = 1; i <= N; ++i) {
        string A;
        A = to_string(i);
        if(A.length() %2 == 1){
            ans++;
        }
    }


    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}


int main(void){
    int h, w;
    cin >> h >> w;

    int y, x;
    cin >> y >> x;

    int total = h * w;

    cout << total - y * w - x * h + y * x << endl;


}



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

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramA a = new ProgramA();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {

            string s = Console.ReadLine();

            if(s[0] == s[2])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }
    }

    class ProgramB
    {
        public void main()
        {

            string s = Console.ReadLine();

            Console.WriteLine(s[0] + (s.Length - 2).ToString() +s[s.Length -1]);


        }
    }

    class ProgramC
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');

            int count4 = 0;
            int count2 = 0;

            for (int i = 0; i < n;i++)
            {
                if (long.Parse(a[i]) % 4 == 0)
                    count4++;
                else if(long.Parse(a[i]) % 2 == 0)
                    count2++;
            }


            if (count4 >= n / 2)
            {
                Console.WriteLine("Yes");
                return;
            }


            if (2 * count4 + count2 >= n)
            {
                Console.WriteLine("Yes");
                return;
            }
            

            Console.WriteLine("No");


        }
    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');

            List<int> array = new List<int>();
            int[,] ans = new int[int.Parse(s[0]), int.Parse(s[1])];

            for (int i = 0; i < n; i++)
                for (int j = 0; j < int.Parse(a[i]); j++)
                    array.Add(i + 1);

            int k = 0;
            for (int i = 0; i < int.Parse(s[0]); i++)
                for (int j = 0; j < int.Parse(s[1]); j++)
                {
                    if (i % 2 == 0)
                    {
                        ans[i, j] = array[k];
                    }
                    else
                    {
                        ans[i, int.Parse(s[1])- 1 -j] = array[k];
                    }

                    k++;
                }

            for (int i = 0; i < int.Parse(s[0]); i++)
                for (int j = 0; j < int.Parse(s[1]); j++)
                {
                    Console.Write(ans[i, j]);
                    if( j == int.Parse(s[1]) - 1)
                        Console.WriteLine("");
                    else
                        Console.Write(" ");


                }



        }
    }

}






Measured memory_bytes: 13140
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []

    for i, a in enumerate(A):
        L.append(i+a)
        R.append(i-a)
    
    Ldic = {}
    for l in L:
        if l in Ldic:
            Ldic[l] += 1
        else:
            Ldic[l] = 1
    
    Rdic = {}
    for r in R:
        if r in Rdic:
            Rdic[r] += 1
        else:
            Rdic[r] = 1
    
    total = 0

    for lkey in Ldic:
        if lkey in Rdic:
            total += Ldic[lkey] * Rdic[lkey]
    
    print(total)



if __name__ == '__main__':
    main()

Measured memory_bytes: 165760
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template <class Abel> struct BIT {
  vector<Abel> dat[2];
  Abel UNITY_SUM = 0; // to be set

  /* [1, n] */
  BIT(int n) { init(n); }
  void init(int n) {
    for (int iter = 0; iter < 2; ++iter)
      dat[iter].assign(n + 1, UNITY_SUM);
  }

  /* a, b are 1-indexed, [a, b) */
  inline void sub_add(int p, int a, Abel x) {
    for (int i = a; i < (int)dat[p].size(); i += i & -i)
      dat[p][i] = dat[p][i] + x;
  }
  inline void add(int a, int b, Abel x) {
    sub_add(0, a, x * -(a - 1));
    sub_add(1, a, x);
    sub_add(0, b, x * (b - 1));
    sub_add(1, b, x * (-1));
  }

  /* a is 1-indexed, [a, b) */
  inline Abel sub_sum(int p, int a) {
    Abel res = UNITY_SUM;
    for (int i = a; i > 0; i -= i & -i)
      res = res + dat[p][i];
    return res;
  }
  inline Abel sum(int a, int b) {
    return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) -
           sub_sum(1, a - 1) * (a - 1);
  }

  /* debug */
  void print() {
    for (int i = 1; i < (int)dat[0].size(); ++i)
      cout << sum(i, i + 1) << ",";
    cout << endl;
  }
};

int main() {
  int N;
  int Q;
  cin >> N >> Q;
  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  vector<int> lefts(Q), rights(Q), ids(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> lefts[i] >> rights[i];
    --lefts[i];
    ids[i] = i;
  }
  sort(ids.begin(), ids.end(),
       [&](int i, int j) { return rights[i] < rights[j]; });

  BIT<int> bit(N + 5);
  vector<int> prev(1100000, -1);
  vector<int> res(Q, 0);
  int r = 0;
  for (auto i : ids) {
    for (; r < rights[i]; ++r) {
      bit.add(prev[a[r]] + 2, r + 2, 1);
      prev[a[r]] = r;
    }
    int tmp = bit.sum(lefts[i] + 1, lefts[i] + 2);
    res[i] = max(res[i], tmp);
  }
  for (int i = 0; i < Q; ++i)
    cout << res[i] << endl;
}

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

using namespace std;

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

    int n;
    cin >> n;
    bool test = true;
    do
    {
        if (n % 10 == 7)
        {
            cout << "Yes";
            test = false;
        }
        
    } while (int(n /= 10) && test);
    if (test)
    {
        cout << "No";
    }
    
}

Measured memory_bytes: 3656
//#include<bits/stdc++.h>
#include<iostream>
 
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define fast() ios::base::sync_with_stdio(false); cin.tie(NULL);
typedef long long int ll;
//using ll = long long;
 
template<typename T>
inline T Abs(T a){return a < 0 ? -a : a; }
template<typename T>
inline T Max(T a, T b){return a < b ? b : a; }
template<typename T>
inline T Min(T a, T b){return a > b ? b : a; }
 
using namespace std;
 
int main(){
    //fast()
    
    string str; cin >> str;
    int length = str.length();
    for(int i = 0; i < length; i++){
        str[i] = 'x';
    }
    cout << str << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int time = 0, bis = 0;
  int A, B, T;
  std::cin >> A >> B >> T;
  range(i, T){
    time++;
    if(time%A==0) bis += B;
  }
  std::cout << bis << '\n';
  return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }

    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Bisect
{
    /* BisectRight(a, x) returns the index where to insert x in a sorted list a.
     *
     * The return value i is such that for all 0 < j < i, a[j] <= x and
     * for all j > i, a[j] > x.
     */
    public static int BisectRight<T>(T[] a, T x) where T : IComparable
    {
        int lo = 0, hi = a.Length;
        while (lo < hi)
        {
            int mid = (lo + hi) / 2;
            if (x.CompareTo(a[mid]) < 0) { hi = mid; }
            else { lo = mid + 1; }
        }
        return lo;
    }
}

class Program
{
    public static void Main()
    {
        long MAX = 1000000000000;
        int a, b, q;

        var tt = ReadIntArray();
        a = tt[0];
        b = tt[1];
        q = tt[2];

        var s = new long[a+2];
        var t = new long[b+2];
        var x = new long[q];

        s[0] = -MAX; s[a+1] = MAX;
        for (int i = 1; i <= a; i++)
        {
            s[i] = long.Parse(ReadLine());
        }

        t[0] = -MAX; t[b+1] = MAX;
        for (int i = 1; i <= b; i++)
        {
            t[i] = long.Parse(ReadLine());
        }

        for (int i = 0; i < q; i++)
        {
            x[i] = long.Parse(ReadLine());
        }

        for (int i = 0; i < q; i++)
        {
            long ans = Solve(s, t, x[i]);
            WriteLine(ans);
        }
    }

    static long Solve(long[] s, long[] t, long x)
    {
        long ans = 1000000000000;

        long sl, sr, tl, tr;

        int i = Bisect.BisectRight(s, x); sl = s[i-1]; sr = s[i];
        int j = Bisect.BisectRight(t, x); tl = t[j-1]; tr = t[j];

        ans = Math.Max(sr, tr) - x;

        long d = x - Math.Min(sl, tl);
        ans = Math.Min(ans, d);

        long d_sr = sr - x;
        long d_tl = x - tl;
        long d1 = 2 * Math.Min(d_sr, d_tl) + Math.Max(d_sr, d_tl);
        ans = Math.Min(ans, d1);

        long d_sl = x - sl;
        long d_tr = tr - x;
        long d2 = 2 * Math.Min(d_tr, d_sl) + Math.Max(d_tr, d_sl);
        ans = Math.Min(ans, d2);

        return ans;
    }
}


Measured memory_bytes: 18572
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), x = in();
    ll now = 0, ans = 0;
    REP(i, n) {
        ++ans;
        now += in();
        if (now > x) {
            cout << ans << endl;
            return 0;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;
vector<int>segx,segn;
int S;
void makeseg(){
    S=pow(2,ceil(log2(segx.size())));
    int l=S-segx.size();
    for(int i=0;i<l;i++)segx.pb(0),segn.pb(INF);
    reverse(all(segx)),reverse(all(segn));
    for(int i=1;i<segx.size();i+=2)segx.pb(max(segx[i],segx[i-1])),segn.pb(min(segn[i],segn[i-1]));
    segx.pb(0),segn.pb(0);
    reverse(all(segx)),reverse(all(segn));
}
int RMxQ(int j,int a,int b,int x,int y){
    if(y<a||b<x)return 0;
    if(a<=x&&y<=b)return segx[j];
    else return max(RMxQ(j*2,a,b,x,(x+y)/2),RMxQ(j*2+1,a,b,(x+y)/2+1,y));
}
int RMnQ(int j,int a,int b,int x,int y){
    if(y<a||b<x)return INF;
    if(a<=x&&y<=b)return segn[j];
    else return min(RMnQ(j*2,a,b,x,(x+y)/2),RMnQ(j*2+1,a,b,(x+y)/2+1,y));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,cnt=0;
    cin>>n>>k;
    vector<int>arr;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        arr.pb(x);
    }
    segx=segn=arr;
    makeseg();
    deque<ii>window;
    for(int i=0;i<k-1;i++){
        while(!window.empty()&&window.back().first>arr[i])window.pop_back();
        window.push_back(mp(arr[i],i));
    }
    bool yes=false;
    for(int i=k-1;i<n;i++){
        if(window.front().second<=i-k)window.pop_front();
        while(!window.empty()&&window.back().first>arr[i])window.pop_back();
        window.push_back(mp(arr[i],i));
        if(window.size()==k){
            yes=true;
            continue;
        }
        if(i==k-1)cnt++;
        else{
            if(RMnQ(1,i-k+1,i,0,S-1)>arr[i-k]&&RMxQ(1,i-k+1,i-1,0,S-1)<arr[i])continue;
            cnt++;
        }
  //      cout<<cnt<<"\n";
    }
    if(yes)cnt++;
    cout<<cnt;
}


Measured memory_bytes: 15816
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define INF 2e9
using namespace std;
const int N=1e6+1;
const int mod=1e9+7;
ll fastexp(ll base,ll exp){
	base%=mod;
	ll ans=1;
	while(exp>0){
		if(exp&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		exp/=2;
	}
	return ans;
}
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
ll arr[N];
int main() {
	int n,k;
	cin >> n >> k;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	sort(arr,arr+n+1);
	for(int i = 1; i <= k; i++){
		sum += arr[i];
	}
	cout << sum << endl;

	return 0;
}
   






   







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

int main() {
string o,e;
cin >> o >> e;
int n = o.size()+e.size();
string ans(n,'a');
int j = 0;
for(int i = 0; i < n; i+=2){
  ans.at(i) = o.at(j);
  j++;
}
j = 0;
for(int i = 1; i < n; i+=2){
  ans.at(i) = e.at(j);
  j++;
}
cout << ans << endl;
  }


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(--b, --a));
  }
  vsort(v);

  int rsl = 1;
  int cur = v[0].first;
  rep(i, 1, m) {
    if(cur <= v[i].second) {
      cur = v[i].first;
      ++rsl;
    }
  }
  cout << rsl << endl;
}


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

int main() {
  int n;
  cin >> n;
  int a[n][3];
  rep(i,n) rep(j,3) {
    cin >> a[i][j];
  }
  
  ll dp[n+1][3] = {0};
  
  for (int i=1; i<n+1; i++) {
    rep(j, 3)rep(k, 3) {
      if (j==k) continue;
      dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i-1][j]);
    }
  }
  ll max_s = 0;
  rep(i,3) {
    max_s = max(max_s, dp[n][i]);
  }
  cout << max_s;
  
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >>n;
	if(n==0)
	{
		cout <<0<<endl;
		return 0;
	}
	int i=0;
	string s;
	while(n!=0)
	{
		if(n%2!=0)
		{
			s+='1';
			if(i%2==0)
			--n;
			else
			++n;
		}
		else
		s+='0';
		n/=2;
		++i;
	}
	reverse(s.begin(),s.end());
	cout <<s<<endl;
	return 0;
}

Measured memory_bytes: 256
def xgcd(a, b)
  b > 0 ? q=v=w=x = 1 : a=x = 0
  y = 0
  while b > 0
    v -= q*x; w -= q*y
    q,a = a.divmod b
    return [b,v,w]  if a == 0
    x -= q*v; y -= q*w
    q,b = b.divmod a
  end
  [a,x,y]
end
N,A,B = gets.split.map &:to_i
n,s,P = 1,2,10**9+7
30.times {|i| n*=s and n%=P if N[i]>0; s*=s; s%=P}
a,b = [A,B].map{|r| N < r+r ? N-r : r}.sort
s=t=u = 1
F =->(x,y){ x.upto(y){|i| t*=N+1-i; u*=i; t%=P; u%=P}; s += t*xgcd(u,P)[1]%P }
F[1,a]; F[a+1,b]
p (n<s ? P+n-s : n-s) % P

Measured memory_bytes: 1788
import itertools
N,M = list(map(int,input().split()))
k_lis = []
for i in range(M):
    k_lis.append(list(map(int,input().split())))
P = list(map(int,input().split()))
switch_list = list(itertools.product('01',repeat = N))
ans = 0
sub = 0

for sl in range(len(switch_list)):#スイッチ全探索
    #if  '1' in  (switch_list[sl]):#スイッチが少なくとも一つ点灯
    if True:
        flag = 0
        for i in range(M):#電球１つ１つを探索していく
            counter = 0
            for j in range(1,k_lis[i][0]+1):
                if switch_list[sl][k_lis[i][j]-1] == '1' :
                    counter += 1
                    
            if counter %2 != P[i]:
                flag = 1
                break
        if flag == 0:    
            ans += 1
print(ans)


Measured memory_bytes: 8964
#include <stdio.h>


int main()
{
	int A , B;
	
	scanf("%d %d", &A, &B);
	
	( A==3&&B==2 ) ? puts("1") :puts("");
	( A==2&&B==3 ) ? puts("1") :puts("");
	( A==1&&B==2 ) ? puts("3") :puts("");
	( A==2&&B==1 ) ? puts("3") :puts("");
	( A==1&&B==3 ) ? puts("2") :puts("");
	( A==3&&B==1 ) ? puts("2") :puts("");
		
	
	return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n; cin >> n;
  if (n%1000) cout << 1000 - n%1000 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()
#define show(x) cout<<(#x)<<" is "<<(x)<<endl

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=5e5+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

ll a[N];

ll cnt[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    ll mx=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mx+=a[i];
    }
    ll q=(1ll*n*(n+1)/2);
    if(mx%q){
        cout<<"NO";
        return 0;
    }
    ll k=mx/q;
    ll s=0;
    for(int i=1;i<=n;i++){
        int nx=i+1;
        if(i==n){
            nx=1;
        }
        ll d=a[nx]-a[i];
        cnt[i]=-((d-k)/n);
        s+=cnt[i];
        if((d-k)%n || cnt[i]<0){
            cout<<"NO";
            return 0;
        }
    }
    if(s!=k){
        cout<<"NO";
        return 0;
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i,n){
    cin >> a[i].F;
    a[i].S = i+1;
  }
  sort(a.begin(),a.end());
  rep(i,n){
     cout << a[i].S <<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1536
// Problem : E - Knapsack 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int dp[105][maxn];
void solve()
{
	int n,wt;
	cin >> n >> wt;
	pp arr[n+1];
	rep(i,0,n)
	{
		int x,y;
		cin >> x >> y;
		arr[i+1]={x,y};
	}
	rep(i,0,105)
		rep(j,0,maxn)
			dp[i][j]=(int)(1e9+7);
	rep(i,0,105)
		dp[i][0]=0;
	int ans=0;
	rep(i,1,n+1)
	{
		rep(j,1,maxn)
		{
			dp[i][j]= dp[i-1][j];
			if(arr[i].ss <= j)
				dp[i][j]=min(dp[i][j],arr[i].ff+dp[i-1][j-arr[i].ss]);
			if(dp[i][j] <= wt)
				ans = j;
		}	
	}	
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 85672
import collections
from collections import Counter
n=int(input())
string_list=[input() for i in range(n)]
c = collections.Counter(string_list)
max = c.most_common()[0][1]
list = []
# print("-------")
for i in c.items():
    if i[1] == max:
        list.append(i[0])

for i in sorted(list):
    print(i)


Measured memory_bytes: 45028
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int count_right_paren(const string S, const int N) {
    vector<char> stack;
    for (int i = 0; i < N; i++) {
        char c = S[i];
        if (c == '(') {
            stack.push_back(c);
        } else {
            if (stack.size() > 0) {
                stack.pop_back();
            }
        }
    }

    return (int) stack.size();
}

int count_left_paren(const string S, const int N) {
    string T = S;
    reverse(T.begin(), T.end());
    for (int i = 0; i < N; i++) {
        if (T[i] == '(') {
            T[i] = ')';
        } else {
            T[i] = '(';
        }
    }
    return count_right_paren(T, N);
}

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;

    int cnt_lp = count_left_paren(S, N);
    int cnt_rp = count_right_paren(S, N);
    // printf("cnt_lp: %d, cnt_rp: %d\n", cnt_lp, cnt_rp);

    string ans = "";
    for (int i = 0; i < cnt_lp; i++) {
        ans.push_back('(');
    }
    ans += S;
    for (int i = 0; i < cnt_rp; i++) {
        ans.push_back(')');
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#define inf 10e8
#define rep(i,n) for(long i=0;i<n;i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> vec(n);
    for (int i=1;i<=n;i++){
        int d;
        cin >> d;
        vec[i-1]=make_pair(d,i);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
        if(i==n-1) cout << vec[i].second << endl;
        else cout << vec[i].second << " ";
    }
}



Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [ [0 for _ in range(W+1)] for _ in range(N+1) ]

for i in range(N):
    for j in range(W+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])

print(dp[N][W])

Measured memory_bytes: 171400
#include<bits/stdc++.h>
using namespace std;
int a;
int main()
{
 //freopen(".in","r",stdin);
 //freopen(".out","w",stdout);
 cin>>a;
 for(; a>0; a/=10)
 {
  if(a%10==9)
  {
   cout<<"Yes";
   return 0;	
  }
 }
 cout<<"No";
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout<<fixed<<setprecision(12);
  int d,e,i,j;
  double dis,ans;
  while(1){
    cin>>d>>e;
    if(d==0 && e==0) break;
    i=d;
    j=0;
    ans=99999999;
    while(i>=j){
      dis=sqrt(i*i+j*j);
      ans=min(ans,abs(e-dis));
      i--;
      j++;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;

int toInt(const string &s){
  stringstream ss;
  ss<<s;
  int a;
  ss>>a;
  return a;
}

int main(void){
  string s;
  while(cin>>s){
    string p,q;
    if(s.find('.')!=-1){p=s.substr(0,s.find('.'));q=s.substr(s.find('.')+1,s.size()-s.find('.'));}
    else p=s;
    while(q.size()<4)q+='0';
    int pp=toInt(p),qq=toInt(q);if(pp<0)break;
    vector<int> a,b;
    for(int i=0;i<4;++i){
      b.push_back((qq*2/10000)?1:0);
      qq=(qq*2)%10000;
    }
    if(qq)cout<<"NA"<<endl;
    else{
      for(int i=0,t=1<<7;i<8;++i){
        a.push_back((pp/t)?1:0);
        pp%=t;
        t/=2;
      }
      for(int i=0;i<8;++i)cout<<a[i];
      cout<<".";
      for(int i=0;i<4;++i)cout<<b[i];
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1252
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); ++itr)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;
#define MAXN 100005




int n, a[200005];
ll f[MAXN], invf[MAXN];
ll ipow(ll x, ll p) {
	ll ans = 1, r = x % M;
	while (p) {
		if (p & 1) ans *= r;
		r *= r;
		ans %= M;
		r %= M;
		p >>= 1;
	}
	return ans % M;
}
ll c(int x, int y) {
	if (x < y) {
		return 0;
	}
	return f[x] * (invf[y] * invf[x - y] % M) % M;
}
bool seen[100005];
int main(void)
{
	scanf("%d", &n);
	FOR(i, 0, n + 1) {
		scanf("%d", &a[i]);
	}
	f[0] = invf[0] = 1;
	FOR(i, 1, n + 2) {
		f[i] = f[i - 1] * i % M;
		invf[i] = ipow(f[i], M - 2);
	}
	int duplicate = -1;
	int x = -1;
	int y = -1;
	FOR(i, 0, n + 1) {
		if (seen[a[i]]) {
			y = i;
			break;
		}
		seen[a[i]] = true;
	}
	FOR(i, 0, n + 1) {
		if (a[i] == a[y]) {
			x = i;
			break;
		}
	}
	cout << n << endl;
	FOR(i, 2, n + 2) {
		ll ans = c(n + 1, i);
		ans -= c(n + 1 - (y - x + 1), i - 1);
		ans = (ans + M) % M;
		cout << ans << endl;
	}
	cout << endl;
}

Measured memory_bytes: 3200
//ABC097A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d){
		cout << "Yes" << endl;
		return 0;
	}else if(abs(a-b) <= d && abs(b-c) <= d){
		cout << "Yes" << endl;
		return 0;
	}else{
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
const int inf=0x3f3f3f3f;
const int m=2019;
typedef pair<int,int> P;

map<string,int>mp;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0)
            return puts("Yes"),0;
        a-=d;
        if(a<=0)
            return puts("No"),0;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 3552
#include<stdio.h>

int main(void){
	int a,b;
	int sum;
	int cnt=0;
	
	while(scanf("%d %d",&a,&b)==2){
		sum=a+b;
		while(sum>0){
			sum/=10;
			cnt++;
		}
		printf("%d\n",cnt);
		cnt=0;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){
	char s[10];
  	scanf("%4s", s);
  int i;
  for(i=0;i<3;i++){
  	if(s[i]==s[i+1]){
    	printf("Bad");
      	return 0;
    }
  }
  printf("Good");
  return 0;
}

Measured memory_bytes: 128
function main()
  
  (A,B) = map(x -> parse(Int,x), split(readline()))
  S = split(chomp(readline()),"")
  
  check = true
  
  for i in 1:A+B+1
    
    if i == A+1 && S[i] != "-"
      check = false
      break
    elseif i != A+1 && (S[i] < "0" || "9" < S[i])
      check = false
      break
    end
    
  end
  
  if check
  	println("Yes")
  else
    println("No")
  end
  
end

main()

Measured memory_bytes: 114080
#define _CRT_SECURE_NO_WARNINGS  
#include "iostream"
#include "algorithm"

#define ll long long
using namespace std;
const int MAXN = 200;
int main()
{
	int tmp=-1,cnt=0,temp;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		if (i != 0)
			tmp = temp;
		cin >> temp;
		if (i != 0 && tmp == temp) {
			cnt++;
			temp = -1;
		}
	}
	cout << cnt << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl






#define N 8
#define FREE -1
#define NOT_FREE 1
int row[N] , col[N] , dpos[2*N-1] , deng[2*N-1];
bool X[N][N];

void initialize(){
	for(int i=0;i<N;i++){row[i]=FREE;col[i]=FREE;}
	for(int i=0;i<2*N-1;i++){dpos[i]=FREE;deng[i]=FREE;}
}

void printBoard(){
	for(int i = 0; i<N; i++){
		for(int j = 0; j<N; j++){
			if(X[i][j]){
				if(row[i]!=j)return;
			}
		}
	}
	for(int i = 0; i<N; i++){
		for(int j = 0; j<N; j++){
			cout << ((row[i]==j)?"Q":".");	
		}
		cout << endl;
	}
}
void recursive(int i){
	if( i==N ){
		printBoard();
		return;
	}
	for(int j=0; j<N ; j++ ){
		if( NOT_FREE == col[j] ||
			 NOT_FREE == dpos[i+j] ||
			 NOT_FREE == deng[i-j+N-1])continue;
		row[i] = j; col[j] = dpos[i+j] = deng[i-j+N-1] = NOT_FREE;
		recursive(i+1);
		row[i] = col[j] = dpos[i+j] = deng[i-j+N-1] = FREE;
	}
}

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


	initialize();
	FOR(i,0,N){
		FOR(j,0,N){
			X[i][j] = false;
		}
	}

	int k;
	cin >> k;
	int x,y;
	FOR(i,0,k){
		cin >> x >> y;
		X[x][y] = true;		
	}
	recursive(0);
}


Measured memory_bytes: 3228
using System;
using System.Collections.Generic;
using System.Text;

namespace abc148_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var s = CIn.Read().ToCharArray();
      var t = CIn.Read().ToCharArray();

      var sb = new StringBuilder();

      for (var i = 0; i < n; i++)
      {
        sb.Append(s[i]);
        sb.Append(t[i]);
      }

      Console.WriteLine(sb.ToString());
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

Measured memory_bytes: 11220
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int yyyy,mm,dd;
    while(scanf("%d/%d/%d",&yyyy, &mm, &dd)!=EOF)
    {
        yyyy = 2018;

        printf("%d/",yyyy);

        if(mm<10)printf("0%d/",mm);
        else printf("%d/",mm);

        if(dd<10)printf("0%d\n",dd);
        else printf("%d\n",dd);

    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
int main()
{
	string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])
    cout<<"Yes";
  else
    cout<<"No";
		
	
	return 0;
} 

Measured memory_bytes: 256
while True:
    f=False
    n=input()
    if n==0:break
    L=[map(int,raw_input().split()) for i in range(n)]
    P,Q,R,C=map(int,raw_input().split())
    for i,p,q,r in L:
        c=(p+r)*4+q*9
        if p<=P and q<=Q and r<=R and c<=C:
            print i
            f=True
    if f==False:
        print "NA"

Measured memory_bytes: 4424
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;

int main(void) {
   ll N;
   cin>>N;
   vector<ll> A;
   A.resize(N);
   rep(i,0,N) A[i] = 0;
   rep(i,0,N) {
      ll a;
      cin>>a;
      if (i!=0) A[i] += A[i-1]+a;
      else A[0] = a;
   }
   ll ans = 0;
   auto itr = lower_bound(A.begin(),A.end(),(double)A[N-1]/2);
   if (itr == A.begin()) ans = (*itr)*2 - A[N-1];
   else {
      ans = (*itr)*2 - A[N-1];
      chmin(ans,A[N-1] - (*(itr-1))*2);
   }
   cout<<ans<<endl;



   return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main(){

int n;

cin >> n;

if(n <= 999){
	cout << "ABC";
} else {
	cout << "ABD";
}


return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}

int n;
double dp[305][305][305];

double solve(int ones, int twos, int threes) {
    if (!ones && !twos && !threes)
        return dp[ones][twos][threes] = 0;
    if (dp[ones][twos][threes] != -1)
        return dp[ones][twos][threes];
    double ans = (n - (ones + twos + threes));
    if (ones) ans += ones * (solve(ones - 1, twos, threes) + 1);
    if (twos) ans += twos * (solve(ones + 1, twos - 1, threes) + 1);
    if (threes) ans += threes * (solve(ones , twos + 1, threes - 1) + 1);
    ans /= (ones + twos + threes);
    return dp[ones][twos][threes] = ans;
}

int main() {
    IO;
    cin >> n;
    int num[4] = {0};
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        num[x]++;
    }
    for (int i = 0; i < 305; i++) {
        for (int j = 0; j < 305; j++) {
            for (int k = 0; k < 305; k++) {
                dp[i][j][k] = -1;
            }
        }
    }
    cout << setprecision(15) << solve(num[1], num[2], num[3]);
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

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

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  vll t(5);
  rep(i, 5) {
    cin >> t[i];
  }

  sort(all(t), [](const ll& lhs, const ll& rhs) {
    if (lhs % 10 == 0) {
      return true;
    }
    if (rhs % 10 == 0) {
      return false;
    }
    return (lhs % 10) > (rhs % 10);
  });

  ll ans = 0;
  for (int i = 0; i < 4; i++) {
    ans += ((t[i] + 9) / 10) * 10;
  }
  ans += t[4];

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


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

using namespace std;

const u_int64_t R = 1'000'000'007LL;

u_int64_t aNum[100'000];
u_int64_t abNum[100'000];
u_int64_t abcNum[100'000];

int main()
{
    string s;

    cin >> s;

    u_int64_t branch = 1;
    for (int i = 0; i < s.size(); i++)
    {
        if (i == 0)
        {
            aNum[i] = (s[i] == 'A' || s[i] == '?') ? 1 : 0;
            abNum[i] = 0;
            abcNum[i] = 0;
            branch *= s[i] == '?' ? 3 : 1;
            continue;
        }
        aNum[i] = aNum[i - 1];
        abNum[i] = abNum[i - 1];
        abcNum[i] = abcNum[i - 1];

        if (s[i] == 'A')
        {
            aNum[i] = aNum[i - 1] + branch;
        }
        if (s[i] == 'B')
        {
            abNum[i] = abNum[i - 1] + aNum[i - 1];
        }
        if (s[i] == 'C')
        {
            abcNum[i] = abcNum[i - 1] + abNum[i - 1];
        }
        if (s[i] == '?')
        {
            aNum[i] = 3 * aNum[i - 1] + branch;
            abNum[i] = 3 * abNum[i - 1] + aNum[i - 1];
            abcNum[i] = 3 * abcNum[i - 1] + abNum[i - 1];
            branch *= 3;
        }

        aNum[i] %= R;
        abNum[i] %= R;
        abcNum[i] %= R;
        branch %= R;
    }

    cout << abcNum[s.size() - 1] << endl;
    return 0;
}

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

int main(){
  int n;cin>>n;
  vector<vector<int>> cnt(n,vector<int>(26,0));
  for(int i=0;i<n;++i){
    string s;cin>>s;
    for(auto &&si: s){
      ++cnt[i][(int)(si-'a')];
    }
  }

  for(int h=0;h<26;++h){
    int mn = 1e9+1;
    for(int i=0;i<n;++i){
      mn = min(mn, cnt[i][h]);
    }
    char ch = 'a'+h;
    cout<<string(mn,ch);
  }
  cout<<endl;
}


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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
vector<pii> g[N];
int colors[N];
void dfs(int v, int p=0, int c=0){
	colors[v] = c;
	for(auto u:g[v]){
		if (u.st == p) continue;
		if (u.nd) dfs(u.st, v, c^1);
		else dfs(u.st, v, c);
	}
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=1; i<n; i++){
		int u, v, w; cin >> u >> v >> w;
		g[u].push_back({v, w&1});
		g[v].push_back({u, w&1});
	}
	dfs(1);
	for(int i=1; i<=n; i++) cout << colors[i] << endl;
	return 0;
}


Measured memory_bytes: 9216
//
// Created by TakahiroYamaji on 2020/08/02.
//
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;
int N, D;
ll x, y;
int main(){
    cin >> N >> D;
    ll res = 0;
    for (int i=0;i<N;i++){
        cin >> x >> y;
        double len = sqrt(x * x + y * y);
        if (len <= D) res++;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<array>
#include<string>
#include<set>
#include<algorithm>
#include<vector>

using namespace std;

typedef array<string,8> O;

set<O> s;

void rot(O &o,vector<int> v){
  auto t=o[v[0]];
  for(int i=0;i+1<v.size();i++){
    o[v[i]]=o[v[i+1]];
  }
  o[v.back()]=t;
}

void dfs(O o){
  if(s.insert(o).second){
    O n1=o;
    rot(n1,{0,1,2,3});
    rot(n1,{4,5,6,7});
    dfs(n1);
    O n2=o;
    rot(n2,{0,1,5,4});
    rot(n2,{3,2,6,7});
    dfs(n2);
    O n3=o;
    rot(n3,{0,3,7,4});
    rot(n3,{1,2,6,5});
    dfs(n3);
  }
}

int main(){
  for(;;){
    O o;
    for(auto &e:o){
      cin>>e;
    }
    if(!cin)break;
    s.clear();
    sort(begin(o),end(o));
    int a=0;
    do{
      if(s.count(o)==0){
	a++;
	dfs(o);
      }
    }while(next_permutation(begin(o),end(o)));
    cout<<a<<endl;
  }
}
  

Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <vector>
#include <set>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

ll N;
std::string S;
std::vector<std::set<int>> vl, vr;

int main()
{
  std::cin >> N >> S;

  std::set<int> acc;
  rep( i, N )
  {
    vl.push_back( acc );
    acc.insert( S[i]-'0' );
  }

  acc.clear();
  for( ll i = N-1; i >= 0; --i )
  {
    vr.push_back( acc );
    acc.insert( S[i]-'0' );
  }

  std::set<std::string> ans;

  rep( i, N )
  {
    for( auto it = vl[i].begin(); it != vl[i].end(); ++it ) for( auto it2 = vr[N-1-i].begin(); it2 != vr[N-1-i].end(); ++it2 )
    {
      char str[4] = {char((*it)+'0'), S[i], char((*it2)+'0'), '\0' };

      ans.insert( str );
    }
  }

  printf( "%lld\n", ll(ans.size()) );

  return 0;
}

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

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

int main()
{
  int a[3];
  int i;
  
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
 
  int min,middle,max;
  
  qsort(a,3,sizeof(int),cmp);
  
  min=a[0];
  middle=a[1];
  max=a[2];
  
  int count=0;
  
  while(1)
  {
    if(min==middle)
    {
      break;
    }
    else if(min==middle-1)
    {
      count++;
      break;
    }
    else
    {
      min+=2;
      count++;
    }
  }
  
  count+=max-min;
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 128
/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int t;

ll S;

ll dp[2001];

ll solve(ll prev_sum){
	
	
	if(prev_sum==S){
		return 1;
	}
	if(prev_sum>S){
		return 0;
	}
	if(dp[prev_sum]!=-1){
		return dp[prev_sum];
	}
	ll ans=0;
	
	for(int i=3; i<=S; i++){
		ans += (solve(prev_sum+i)+MOD)%MOD;
	}
	
	return dp[prev_sum]=(ans+MOD)%MOD;
	
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    
    cin >> S;
    memset(dp,-1,sizeof(dp));
    cout << solve(0);
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int isac[N];
  fill(isac, isac + N, 0);
  int cntwa = 0;
  while (M--) {
    int p;
    string S;
    cin >> p >> S;
    p--;
    if (isac[p] > 0) continue;
    if (S == "AC") {
      cntwa -= isac[p];
      isac[p] = 1;
    } else if (isac[p] <= 0) {
      isac[p]--;
    }
  }
  int cntac = 0;
  for (int i = 0; i < N; i++) {
    cntac += isac[i] > 0;
  }
  cout << cntac << " " << cntwa << endl;
  return 0;
}


Measured memory_bytes: 3992