akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int max_n = 1e6;

int main(){
  ll n;  cin >> n;
  vector<ll> a(n);
  for(int i=0 ; i<n ; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  queue<ll> que;
  for(int i=0 ; i+1<n ; i++){
    if(a[i]==a[i+1]){
      que.push(a[i]);
      i++;
    }
    if(que.size() == 2){
      break;
    }
  }
  if(que.size() != 2){
    cout << 0;

  }else{
    ll x = que.front(); que.pop();
    ll y = que.front(); que.pop();
    cout << x*y << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<int> ht(n+1,0);
    for(int i=1;i<=n;i++)
        cin>>ht[i];
    vector<int> dp(n+1,0);
    dp[1] = 0;
    dp[2] = abs(ht[2]-ht[1]);
    
    for(int i=3;i<=n;i++) {
        dp[i] = min(abs(ht[i]-ht[i-1])+dp[i-1], abs(ht[i]-ht[i-2])+dp[i-2]);
    }
    cout<<dp[n];
}


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

using namespace std;

int main() {

	long long n,x;
	cin >> n >> x;
	vector<long long> a(n + 1);
	vector<long long> b(n + 1);
	for (long i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > x) {
			b[i] = x;
		}
		else {
			b[i] = a[i];
		}
	}

	for (long i = 1; i < n; i++) {

		if (b[i] + b[i + 1] > x) {
			b[i + 1] = x - b[i];
		}
	}

	long long counter = 0;
	for (long i = 1; i <= n; i++) {
		counter += a[i] - b[i];
	}
	cout << counter << endl;
}

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

//#define DEBUG
#define rep(i,n) for(int i=1;i<=n;i++)
int h,w,n;
bool c[1002][1002];
int t[1002][1002];

int main(){
  while(cin>>h>>w>>n,h){
    rep(i,h)rep(j,w)cin>>c[i][j];
    rep(i,h+1)rep(j,w+1)t[i][j]=0;
    t[1][1]=n;
    rep(i,h){
      rep(j,w){
        t[i+1][j]+=t[i][j]/2;
        t[i][j+1]+=t[i][j]/2;
        if(t[i][j]%2){
          if(c[i][j])t[i][j+1]++;
          else t[i+1][j]++;
        }
      }
    }
    #ifdef DEBUG
    rep(i,h){
      rep(j,w)cout<<c[i][j]<<" ";
      cout<<endl;
    }
    rep(i,h+1){
      rep(j,w+1)cout<<t[i][j]<<" ";
      cout<<endl;
    }
    #endif
    int i=1,j=1;
    while(i<=h&&j<=w){
      if((t[i][j]-c[i][j])%2){
        i++;
      }else{
        j++;
      }
    }
    cout<<i<<" "<<j<<endl;
  }
  return 0;
}

Measured memory_bytes: 7908
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int ice[100][100];
int n,m;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ans=0;
bool used[100][100];
void dfs(int p,int q,int num)
{
	ans=max(ans,num);
	for(int i=0;i<4;i++)
	{
		int tx=p+dx[i],ty=q+dy[i];
		if(tx<0||tx>=n||ty<0||ty>=m)continue;
		if(ice[tx][ty]==1&&!used[tx][ty])
		{
			used[tx][ty]=true;
			dfs(tx,ty,num+1);
			used[tx][ty]=false;
		}
	}
}
int main()
{
	while(1)
	{
		memset(ice,0,sizeof(ice));
		ans=0;
		cin >> m;
		cin >> n;
		if(m==0&&n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				cin >> ice[i][j];
			}
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				dfs(i,j,0);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int N;
int a[MAX];

signed main() {
	string s;
	ll K;
	cin >> s >> K;
	ll rest = K;
	rep(i, s.size()) {
		if (s[i] == 'a') continue;
		if (rest >= (int)'z' - (int)s[i] + 1) {
			rest -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
		//dump(rest);
	}
	rest %= 26;
	rep(i, rest) s.back()++;

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>


int main(){
  

  int n;
  cin>>n;
  
  vi rawdata(n);
  rep(i,n){
    int tmp;
    cin>>tmp;
    rawdata.at(i)=tmp;
  }
  
  auto sorteddata=rawdata;
  sort(sorteddata.begin(),sorteddata.end());
  
  int mymax=sorteddata.at(n-1);
  
  rep(i,n){
    if (rawdata.at(i)!=mymax){
      cout<<mymax<<endl;
    }
    
    else {
      cout<<sorteddata.at(n-2)<<endl;
    }
  }
  
  
  
  
  
  
  
  
      
 

  
}

Measured memory_bytes: 3200
n=int(input())
w=[input() for i in range(n)]
d={}
for i in range(n):
  if w[i] not in d:
    d[w[i]]=1
  else:
    print('No')
    exit()
for i in range(n-1):
  if w[i][len(w[i])-1]!=w[i+1][0]:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 3060
## 2020/01/19 Not yet
import heapq
N, M = map(int,input().split())
A = list(map(int,input().split()))

for i in range(N):
    A[i] *= -1

heapq.heapify(A)

for _ in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A, (-x//2)*(-1))  

print(-sum(A))


"""
### abswer example
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))    
 
print(-sum(a))

# 要は、M 階動的に最大値を半分にしていけばよい
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i*-1 for i in a]
heapq.heapify(a)
 
for _ in range(m):
    pop = heapq.heappop(a)
    p = -(pop*-1//2)
    # 負数の切り捨て（割り切れないとき）は絶対値が1上がるので注意
    heapq.heappush( a, p)
print(sum(list(a))*-1)
"""

Measured memory_bytes: 14380
import java.util.*;

public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        String s = sc.next();

        s = s.substring(a - 1, Math.max(c,d));

        if (s.contains("##")) {
            System.out.print("No");
        } else {
            if ((b < c && c < d) | c < b) {
                System.out.print("Yes");
            } else if(d < c){
                if (!s.contains("...")) {
                    System.out.print("No");
                } else {
                    if (s.substring(b - 2 , d + 1).contains("...")) {
                        System.out.print("Yes");
                    }else{
                        System.out.print("No");
                    }
                }
            }
        }
    }
}


//        while(!(((S.indexOf("#", A) == A+1 )&&(A+1 == B))|((S.indexOf("#", A) == A)&&(A+2 == B))) && (A != C)){
//            if((S.indexOf(".", A) == A) && (S.indexOf(".", A) == A+1)){
//                A += 2;
//            }else if((S.indexOf(".", A) == A) && !(S.indexOf(".", A) == A+1)){
//                A += 1;
//            }
////            A += (int)(Math.random()*2+1);
//        }
//
//        while(!(((S.indexOf("#", B) == B+1 )&&(B+1 == A))|((S.indexOf("#", B) == B)&&(B+2 == A))) && (B != D)){
//            if((S.indexOf(".", B) == B) && (S.indexOf(".", B) == B+1)){
//                B += 2;
//            }else if((S.indexOf(".", B) == B) && !(S.indexOf(".", B) == B+1)){
//                B += 1;
//            }
//        }
//
//        if((N == S.length()) && (A == C) && (B == D)){
//            System.out.print("Yes");
//        }else{
//            System.out.print("No");
//        }



Measured memory_bytes: 28244
N, K = map(int,input().split())
S = input()
S = [int(s) for s in S]

C = [0]
tmp = 0
car = 0
for i in range(N):
  if S[i] != car:
    C.append(tmp)
    tmp = 1
    car = S[i]
  else:
    tmp += 1
C.append(tmp)
if car == 0:
  C.append(0)

#print(C)
if len(C) <= 2*K+1:
  print(N)
else:
  tmp = sum(C[0:2*K+1])
  ans = sum(C[0:2*K+1])
  for i in range(0,len(C)-(2*K+1),2):
    tmp -= C[i]
    tmp -= C[i+1]
    tmp += C[i + 2*K+1]
    tmp += C[i + 2*K+1 + 1]
    ans = max(ans, tmp)
    #print(tmp)
  print(ans)
    
  
    
  
  

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

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

void eratos(int n, vector<bool>& isprime) {
	REP(i, n + 1) {
		isprime[i] = true;
	}
	isprime[0] = false;
	isprime[1] = false;
	int last = ((int)sqrt(n)) + 1;
	FOR(i, 2, last) {
		if (isprime[i]) {
			int j = i + i;
			while (j <= n) {
				isprime[j] = false;
				j += i;
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, d, n;
	cin >> a >> d >> n;
	vb isPrime(1000001);
	eratos(1000000, isPrime);
	while (a != 0) {
		int cur = a;
		while (n != 0) {
			if (isPrime[cur]) {
				n--;
			}
			cur += d;
		}
		cout << cur - d << endl;
		cin >> a >> d >> n;
	}
	return 0;
}



Measured memory_bytes: 3348
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

typedef long long ll;

std::vector<ll> C;
std::vector<std::vector<ll> > A;
ll N, M, X;

ll dfs(int depth, ll money, std::vector<ll> &du){
  if(depth == N){
    bool check = std::all_of(du.begin(), du.end(), [&](ll x){return x >= X;});
    if(check){
      return money;
    }else{
      return 10000000000;
    }
  }
  ll a, b;
  a = dfs(depth + 1, money, du);
  
  std::vector<ll> du_(M, 0);
  for(int i = 0 ; i < M ; i++){
    du_[i] = du[i] + A[depth][i];
  }
  b = dfs(depth + 1, money + C[depth], du_);
  return std::min(a, b);
}

int main(){
  std::cin >> N >> M >> X;
  C.assign(N, 0);
  A.assign(N, std::vector<ll> (M, 0) );
  for(int i = 0 ; i < N ; i++){
    std::cin >> C[i];
    for(int j = 0 ; j < M ; j++){
      std::cin >> A[i][j];
    }
  }
  std::vector<ll> du(M);
  ll money =  0;
  ll resa = dfs(0, money, du);
  if(resa !=  10000000000){
    std::cout << resa << std::endl;
  }else{
    std::cout << "-1" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3612
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	char c;
	cin >> c;
	if (isupper(c))
		cout << 'A';
	else
		cout << 'a';
}


Measured memory_bytes: 3620
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
e=[0 for i in range(4)]
for i in range(3):
 [x,y]=i2()
 e[x-1]+=1
 e[y-1]+=1
e.sort()
e=tuple(e)
if e==(1,1,2,2):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)




int main() {
    string yohou;
    string kekka;
    cin >> yohou;
    cin >> kekka;

    int count = 0;
    rep(i,3) {
        if (yohou[i]==kekka[i]){
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}

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

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

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

    return arr


N = int(input())

A = factorization(N)

cnt = 0

for p, e in A:
    if p == 1:
        cnt = 0
        break
    for i in range(1, 10**12):
        e -= i
        if e < 0:
            break
        else:
            cnt += 1

print(cnt)


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

int main(){
  string s;
  char c;
  int q,t,f,r=0;
  cin >> s >> q;
  deque<char>S;
  rep(i,s.size())
    S.push_back(s[i]);

  rep(i,q){
    cin >> t;
    if(t==1) ++r;
    else{
      cin >> f >> c;
      if(r%2==0){
        if(f==1)
          S.push_front(c);
        else
          S.push_back(c);
      }
      else{
        if(f==1)
          S.push_back(c);
        else
          S.push_front(c);
      }
    }
  }

  if(r%2==0)
    for(int i = 0; i < S.size();){
      cout << S.front();
      S.pop_front();
    }

  else if(r%2==1)
    for(auto i = S.begin(); i < S.end();){
      cout << S.back();
      S.pop_back();
    }

  return 0;
}

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

int main() {
  int N; cin >> N;
  if ( 100 <= N && N <= 111 ) cout << 111 << endl;
  else if ( 112 <= N && N <= 222 ) cout << 222 << endl;
  else if ( 223 <= N && N <= 333 ) cout << 333 << endl;
  else if ( 334 <= N && N <= 444 ) cout << 444 << endl;
  else if ( 445 <= N && N <= 555 ) cout << 555 << endl;
  else if ( 556 <= N && N <= 666 ) cout << 666<< endl;
  else if ( 667 <= N && N <= 777 ) cout << 777 << endl;
  else if ( 778 <= N && N <= 888 ) cout << 888 << endl;
  else if ( 889 <= N && N <= 999 ) cout << 999 << endl;

  return 0;
}


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

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100010;

vector<pii> g[N];
int out[N], dist[N];
int main (void) {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int l, r, d; scanf("%d %d %d", &l, &r, &d);
		g[l].eb(r, d);
		out[r]++;
	}
	queue <int> q;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (!out[i]) {
			q.push(i);
			cnt++;
		}
	}

	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (auto w : g[u]) {
			int v, d; tie(v, d) = w;
			out[v]--;
			if (!out[v]) {
				cnt++;
				dist[v] = dist[u] + d;
				q.push(v);
			}
		}
	}
	if (cnt != n) {
		printf("No\n");
		return 0;
	}
	for (int l = 1; l <= n; l++) {
		for (auto w : g[l]) {
			int r, d; tie(r, d) = w;
			if (dist[r] - dist[l] != d) {
				printf("No\n");
				return 0;
			}

		}
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 6784
S = input()
K = int(input())

A = []
for s in S:
    if s == 'a':
        A.append('a')
        continue
    t = ord('z') - ord(s) + 1
    if t <= K:
        K -= t
        A.append('a')
    else:
        A.append(s)

A[-1] = chr((ord(A[-1]) + K - ord('a')) % 26 + ord('a'))
print("".join(A))

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

const int MAXH = 34;
const int MAXW = 34;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int h, w, n;
char g[MAXH][MAXW];
char G[MAXH][MAXW];

int calcNum(int x, int y, int k) {
  if(G[y][x] == '.') return 0;
  int num = 1;
  for(int i = 0; i < 2; ++i) {
    for(int j = 1; ; ++j) {
      int nx = x + j*dx[k+i*2];
      int ny = y + j*dy[k+i*2];
      if(nx < 0 || nx >= w) break;
      if(ny < 0 || ny >= h) break;
      if(G[ny][nx] != G[y][x]) break;
      ++num;
    }
  }
  return num;
}

void down() {
  for(int j = 0; j < w; ++j) {
    for(int i = h-1; i >= 0; --i) {
      if(G[i][j] == '.') {
	for(int k = i-1; k >= 0; --k) {
	  if(G[k][j] != '.') {
	    swap(G[i][j], G[k][j]);
	    break;
	  }
	}
      }
    }
  }
}

bool run() {
  while(1) {
    vector<pair<int,int> > v;
    int cnt = 0;
    down();
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
	if(G[i][j] == '.') continue;
	++cnt;
	if(calcNum(j,i,0) >= n || calcNum(j,i,1) >= n) {
	  v.push_back(make_pair(j,i));
	}
      }
    }
    if(v.empty()) return cnt == 0;
    for(int i = 0; i < v.size(); ++i) {
      G[v[i].second][v[i].first] = '.';
    }
  }
}


void copy() {
  for(int i = 0; i < h; ++i) {
    for(int j = 0; j < w; ++j) {
      G[i][j] = g[i][j];
    }
  }
}

int main() {
  while(cin >> h >> w >> n) {
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
	cin >> g[i][j];
      }
    }
    bool flag = false;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j+1 < w; ++j) {
	copy();
	swap(G[i][j], G[i][j+1]);
	if(run()) {
	  flag = true;
	  i = j = 1<<28;
	}
      }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
s=input()
s=s[::-1]
n=len(s)
 
count=[0]*2019
count[0]=1
num,d=0,1
 
for i in s:
  num+=int(i)*d
  num%=2019
  d*=10
  d%=2019
  count[num]+=1
 
ans=0
for i in count:
  ans+=i*(i-1)//2
  
print(ans)

Measured memory_bytes: 9332
package main

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

var N, M, ans int

func main() {
	fmt.Scan(&N, &M)
	reader := bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)

	A := make(SortBy, N)
	BC := make(BC, M)

	for i := 0; i < N; i++ {
		reader.Scan()
		A[i], _ = strconv.Atoi(reader.Text())
	}
	for i := 0; i < M; i++ {
		reader.Scan()
		BC[i].B, _ = strconv.Atoi(reader.Text())
		reader.Scan()
		BC[i].C, _ = strconv.Atoi(reader.Text())
	}

	sort.Sort(A)
	sort.Sort(BC)

	for i := 0; i < N; i++ {

		if len(BC) != 0 && A[i] < BC[0].C {
			A[i] = BC[0].C
			BC[0].B--

			if 0 == BC[0].B {
				BC = append(BC[1:])
			}
		}
		ans += A[i]

	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type BC []struct {
	B int
	C int
}

func (a BC) Len() int      { return len(a) }
func (a BC) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a BC) Less(i, j int) bool {
	return a[i].C > a[j].C
}

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trii(x) cerr<<#x<<": ("<<x.F<<","<<x.S<<")\n";
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl
#define sz(x) (ll)(x).size()
#define all(x) x.begin(), x.end()
#define modulo 998244353ll
 

ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    ll x=power(a,b/2);
    x=(x*x)%mod;
    if(b%2)
        x=(x*a)%mod;
    return x;
}

ll inverse(ll a)
{
    return power(a,mod-2);
}

ll ncr(ll n,ll r)//r is small;
{
    ll a=1;
    for(ll r1=1;r1<=r;r1++)
    {
        a*=(n-r1+1);
        a%=mod;
        a*=inverse(r1);
        a%=mod;
    }
    return a;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;

    //ans=(2^n-1) - nCa - nCb
    ll ans=(power(2,n)+mod-1)%mod;


    ans=(ans+(mod-ncr(n,a))+(mod-ncr(n,b)))%mod;
    cout<<ans<<nl;

}


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

using namespace std;

int main()
{
    int a, b = 0;

    cin >> a >> b;

    vector<string> vec;

    for (auto i = 0 ; i < a ; i++) {
        string s;
        cin >> s;
        vec.push_back(s);
    }

    // 各文字列をソートする
    sort(vec.begin(), vec.end());
    for (auto s: vec) cout << s;
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0) break;
            int ma=-1;
            int mi=1001;
            int sum=0;
            for(int i=0;i<n;i++){
                int s=sc.nextInt();
                if(s>ma) ma=s;
                if(s<mi) mi=s;
                sum+=s;
            }
            sum-=ma+mi;
            System.out.println(sum/(n-2));
        }
    }
}


Measured memory_bytes: 29784
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




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

	vector<int> a(n);
	for (int i = 0; i < n;i++) {
		cin >> a[i];
	}
	
	int cnt = 0;
	for (int i = 1;i < n;i++) {
		if (a[i] == a[i - 1]) {
			a[i] = 10000;
			cnt++;
		}
	}

	cout << cnt << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        char[] chars = S.toCharArray();
        char[] front = new char[chars.length/2];
        for(int i=0; i<front.length; i++){
            front[i] = chars[i];
        }
        char[] back = new char[chars.length - front.length];
        int j = 0;
        for(int i=chars.length-1; front.length<=i; i--){
            back[j] = chars[i];
            j++;
        }
        // System.out.println(front[0] + " " + front[1]);
        // System.out.println(back[0] + " " + back[1]);

        int cnt = 0;
        for(int i=0; i<front.length; i++){
            if(front[i]!=back[i]){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

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

using namespace std;
using ll = long long;
const ll mod = 1000000007;


int main()
{
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    vector<ll> aida(n);
    for(int i = 0; i < n - 1; i++)aida[i] = a[i + 1] - a[i];
    aida.push_back(a[0] + (k - a[n - 1]));
    cout << k - *max_element(aida.begin(), aida.end()) << endl;
}

Measured memory_bytes: 6272
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
t = list(map(int,input().split()))
sum_num = sum(t)
for _ in range(int(input())):
    p,x = map(int,input().split())
    print(sum_num - t[p-1] + x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

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

  string s; cin >> s;
  if(s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
    int d,n;
    scanf("%d %d",&d,&n);
    if(d==0)
    {
            if(n<100)printf("%d\n",n);
            else if(n==100)printf("101\n");

    }
    else
    {
        if(d==1)
        {
            if(n!=100)printf("%d\n",n*100);
             else if(n==100)printf("10100\n");
        }
        else
        {
           if(n!=100)printf("%d\n",n*10000);
            else if(n==100)printf("1010000\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]

mincost = 0
for i in range(n):
    mincost += l[i][0]

s = []
for i in range(m+1):
    s.append(0)

flag = 0

for i in range(2 ** n):
    cost = 0
    for j in range(n):
        if ((i >> j) & 1):
            cost += l[j][0]
            for k in range(1, m+1):
                s[k] += l[j][k]
    b = 1
    for k in range(1, m+1):
        if s[k] < x:
            b = 0 
    if b == 1:
        flag = 1
        mincost = min(cost, mincost)
    for i in range(m+1):
        s[i] = 0

if flag == 1:
    print(mincost)
else:
    print(-1)


Measured memory_bytes: 9248
# N,M = map(int, input().split())
S = input()
N = len(S)

ans = 0
for i in range(N):
    if not S[i] in "ATCG":
        continue
    tmp = 0
    j = i
    while S[j] in "ATCG":
        j += 1
        tmp += 1
        if j >= N:
            break
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  copy_n(istream_iterator<int>(cin), N, P.begin());
  vector<int> M(N);
  M[0] = P[0];
  for (int i = 1; i < N; ++i) {
    M[i] = min(P[i], M[i - 1]);
  }
  int result = 0;
  for (int i = 0; i < N; ++i) {
    if (P[i] <= M[i]) ++result;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: u64,
    }

    let mut i = 1;
    let mut quot = 1;

    while i * i <= n {
        if n % i == 0 {
            quot = n / i;
        }
        i = i + 1;
    }

    let ans = quot + n / quot - 2;

    println!("{}", ans);
}


Measured memory_bytes: 4352
import math as math
while True:
    num = int(input())
    if num ==0:
        break
    point = list(map(float,input().split()))
    ave = sum(point)/len(point)
    preS = 0
    for i in range(num):
        preS = preS + (point[i]-ave)**2
    sigma = math.sqrt(preS / num)
    print('{:.8f}'.format(sigma))


Measured memory_bytes: 5776
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int k,s; cin >> k >> s;
    int ans = 0;
    REP(x,k+1){
        REP(y,k+1){
            if(x+y <= s && s-x-y<=k){
                ans ++;
            }
            
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
from bisect import bisect
import sys
input = sys.stdin.readline

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
s.sort()
t = [int(input()) for _ in range(B)]
t.sort()
for _ in range(Q):
    x = int(input())
    i = bisect(s, x)
    sl = sr = 0
    if i == 0:
        sl = -float('inf')
        sr = s[i]
    elif i == A:
        sl = s[i-1]
        sr = float('inf')
    else:
        sl = s[i-1]
        sr = s[i]
    j = bisect(t, x)
    tl = tr = 0
    if j == 0:
        tl = -float('inf')
        tr = t[j]
    elif j == B:
        tl = t[j-1]
        tr = float('inf')
    else:
        tl = t[j-1]
        tr = t[j]
    ans = min(max(sr, tr)-x, x-min(sl, tl), x+sr-2*tl, x+tr-2*sl, 2*sr-x-tl, 2*tr-x-sl)
    print(ans)


Measured memory_bytes: 111068
/* Manish Pant - insider_pants */

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#endif

#define F first
#define S second
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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


Measured memory_bytes: 3644
N, K, S = map(int, input().split())

A = [None] * N
cnt = 0
for i in range(N):
    if cnt < K:
        A[i] = S
        cnt += 1
    else:
        if S == 10 ** 9:
            A[i] = 1
        else:
            A[i] = 10 ** 9
                
# print("#", A)
print(' '.join(map(str, A)))

Measured memory_bytes: 12068
#include <stdio.h>
#include <string.h>

int main()
{
	char x[1001];
	int i,n,w,s,e;
	
	n=0;
	w=0;
	s=0;
	e=0;
	scanf("%s",&x);
	
	for(i=0;i<strlen(x);i++){
		if(x[i]=='N'){
			n=1;
		}else if(x[i]=='W'){
			w=1;
		}else if(x[i]=='S'){
			s=1;
		}else if(x[i]=='E'){
			e=1;
		}
	}
	if(((n==1&&s==1)&&((w==1&&e==1)||(w==0&&e==0)))||(n==0&&s==0&&w==1&&e==1)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
	
}


Measured memory_bytes: 128
use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut diffs = std::collections::BTreeMap::new();
    let mut cnt = 0 as i64;
    for i in 0..n {
        cnt += *diffs.get(&(a[i] - (i as i64))).unwrap_or(&0);
        *diffs.entry(-a[i] - (i as i64)).or_insert(0) += 1;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 15792
/*input
73
*/
#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;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1500+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    double n;
    cin>>n;
    cout<<fixed<<setprecision(9)<<n*2.0*PI;
}


Measured memory_bytes: 3804
def main():
    N = int(input())
    a = [int(input()) for _ in range(N)]

    ans = 0
    nxt = 1
    while True:
        if ans > N:
            print(-1)
            exit()
        elif nxt == 2:
            break
        nxt = a[nxt-1]
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7084
#include <iostream>

using namespace std;

int main()
{
int a ,b ,x;
cin>>a>>b>>x;
if(a>x) cout<<"NO";
if (a==x) cout<<"YES";
if(a<x){
if ((a+b)>=x){
    cout<<"YES";
}
else cout <<"NO";
}
return 0;
}


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

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

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

}

int partition(int array[],int left,int right){
  int i,j,pivot;
  i=left;
  j=right+1;
  pivot=left;
do{
  do{i++;}while(array[i]<array[pivot]);
  do{j--;}while(array[pivot]<array[j]);

  if(i<j){swap(&array[i],&array[j]);}
}while(i<j);

swap(&array[pivot],&array[j]);

return j;
}

void quick_sort(int array[],int left,int right){
  int pivot;

  if(left<right){
    pivot=partition(array,left,right);
    quick_sort(array,left,pivot-1);
    quick_sort(array,pivot+1,right);
  }
}

int main(){
    int n;
    int sum=0;
    scanf("%d",&n);
    int buf[n];
    int i,k;
    for(i=0;i<n;i++){
      scanf("%d",&k);
      buf[i]=k;

}
if(n==3){
  if(buf[0]<buf[1]+buf[2]&&buf[1]<buf[0]+buf[2]&&buf[2]<buf[0]+buf[1]){
    printf("1\n");
    return 0;
  }else{
    printf("0\n");
    return 0;
  }
}

    quick_sort(buf, 0, n-1);
    int l,m,j;
    for(l=n-1;l>=0;l--){
      for(m=l-1;m>=0;m--){
        int c=buf[l];
        int b=buf[m];
        int target=c-b;
        for(j=m-1;buf[j]>target;j--){
          sum++;
        }
      }
    }
    printf("%d\n",sum);
    return 0;
  }


Measured memory_bytes: 128
N, K = map(int, input().split())
S = list(map(int, list(input())))
now = 1
cnt = 0
Nums = []
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    Nums.append(cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left, right = 0, 0
tmp = 0  # sum of [left, right)
for i in range(len(Nums))[::2]:
    next_left = i
    next_right = min(i + add, len(Nums))
    while next_left > left:
        tmp -= Nums[left]
        left += 1
    while next_right > right:
        tmp += Nums[right]
        right += 1

    ans = max(tmp, ans)

print(ans)


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int x, div;
  cin >> x;
  div = gcd(360, x);
  cout << 360/div << endl;
  
return 0;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    List<Integer> iList = new ArrayList<Integer>();

    iList.add(sc.nextInt());
    iList.add(sc.nextInt());
    iList.add(sc.nextInt());

    int fCount = 0;
    int sCount = 0;
    for (int i : iList) {
      if (i == 5) {
        fCount++;
      }
      if (i == 7) {
        sCount++;
      }
    }

    if (fCount == 2 && sCount == 1) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


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

typedef pair<long,int> P;
int main(){
  int n,k;
  cin >> n >> k;
  vector<P> dt;
  for(int i = 0;i < n;i++){
    int t;long d;
    cin >> t >> d;
    dt.push_back({d,t});
  }
  sort(dt.begin(),dt.end());
  reverse(dt.begin(),dt.end());
  vector<int> kindnum(n+1);
  vector<long> sushi,result;
  long ans = 0;
  long x = 0;
  for(int i = 0;i < k;i++){
    ans += dt.at(i).first;
    kindnum.at(dt.at(i).second)++;
    if(kindnum.at(dt.at(i).second) >= 2){
      sushi.push_back(dt.at(i).first);
    }
    if(kindnum.at(dt.at(i).second) == 1){
      x++;
    }
  }
  ans += x*x;
  result.push_back(ans);
  sort(sushi.begin(),sushi.end());
  int replace = 0;
  for(int i = k;i < n;i++){
    if(replace < sushi.size() && kindnum.at(dt.at(i).second) == 0){
      ans += 2*x+1-sushi.at(replace)+dt.at(i).first;
     //cout << 2*x+1 << ' ' << sushi.at(replace) << ' ' << dt.at(i).first << ' ' << ans << endl;
      result.push_back(ans);
      replace++;
      x++;
      kindnum.at(dt.at(i).second)++;
    }
  }
  long disp = -1;
  for(int i = 0;i < result.size();i++){
    //cout << result.at(i) << endl;
    disp = max(disp,result.at(i));
  }
  cout << disp << endl;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N,W;
    cin >> N >> W;
    vector<int> wt(N),val(N);
    for(int i = 0; i < N ; ++i)
    {
        cin >> wt[i] >> val[i];
    }
    vector<vector<int>> dp(N + 1,vector<int>(W + 1));

    for(int i = 1; i <= N; ++i)
    {
        for(int j = 0; j <= W; ++j)
        {
            // not take
            dp[i][j] = dp[i - 1][j];
            // if we take the current item
            if(j - wt[i - 1] >= 0)
            dp[i][j] = max(dp[i][j],dp[i - 1][j - wt[i - 1]] + val[i - 1]);
        }
    }

    // dp[N][W]
    cout << dp[N][W];

    // O(N*W) Space
    // O(N*W) Time
}

Measured memory_bytes: 80256
from itertools import accumulate


def main():
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    ini = [0] * n
    fin = [n] * n
    for c in range(min(k, 45)):
        b = ini.copy()
        for i, ai in enumerate(a):
            b[max(i - ai, 0)] += 1
            if i + ai + 1 < n:
                b[i + ai + 1] -= 1
        a = list(accumulate(b))
    print(*a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 209388
/**
 * @Author Mehdi Maick
 * Created on 04/12/2016.
 */

import java.util.*;
import java.io.*;

import static java.lang.Math.*;

public class Main {
    public static void solve(FastReader fs, PrintWriter pw) {
        String[] a = fs.nextLine().split(" ");
        StringBuilder sb = new StringBuilder();
        for(String aa: a){
            sb.append(aa.charAt(0));
        }
        pw.println(sb);
    }

    public static void main(String[] args) throws Exception {
        FastReader fs = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        solve(fs, pw);

        fs.close();
        pw.close();
    }

    static class FastReader {

        BufferedReader reader;
        StringTokenizer st;

        FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = null;
            try {
                s = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArray(int n) {
            long[] arr = new long[n];
            int i = 0;
            while (i < n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

        int[] nextIntArrayOneBased(int n) {
            int[] arr = new int[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextInt();
            }
            return arr;
        }

        long[] nextLongArrayOneBased(int n) {
            long[] arr = new long[n + 1];
            int i = 1;
            while (i <= n) {
                arr[i++] = nextLong();
            }
            return arr;
        }

        void close() {
            try {
                reader.close();
            } catch (IOException e) {
                System.err.println("There's been an error trying closing the reader ");
                e.printStackTrace();
            }
        }
    }


}

Measured memory_bytes: 8276
#include <bits/stdc++.h>
#define rep(i,n) for (int64_t i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n),q(n);
    rep(i,n) cin>>p[i];
    int s=n/2;
    if(n%2==0){
        rep(i,n){
            q[s]=p[i];
            if(i%2==0){
                s-=(i+1);
            }
            else s+=(i+1);
        }
    }
    else{
        rep(i,n){
            q[s]=p[i];
            if(i%2==0) s+=(i+1);
            else s-=(i+1);
        }
    }
    rep(i,n){
        cout<<q[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int n, k;
    string s;

    cin >> n >> k;
    cin >> s;

    s[k - 1] = s[k - 1] + 'a' - 'A';

    cout << s << endl;

    return 0;
}



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

using namespace std;

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

	bool hasN = count(S.begin(), S.end(), 'N') != 0;
	bool hasW = count(S.begin(), S.end(), 'W') != 0;
	bool hasS = count(S.begin(), S.end(), 'S') != 0;
	bool hasE = count(S.begin(), S.end(), 'E') != 0;

	if (hasN == hasS && hasW == hasE) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
using namespace std;

int main()
{
int n;
int ans = 0;
char base[16];
scanf("%s%d", base, &n);
for(int i = 0; i < n; ++i) {
char str[16];
string strstr;
scanf("%s", str);
strstr = str;
strstr += str;
if(strstr.find(base) != string::npos)
ans += 1;
}
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int N;
    cin >> N;
    int ans;
    for(int i=0;i<N;i++){
        long long ll;
        cin >>ll;
        int cnt =0;
        while(ll%2==0){
            cnt++;
            ll /=2;
        }

        if(i==0)  ans=cnt;
        else ans = min(ans,cnt);
    }
    cout << ans <<endl;
}


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

typedef long long int lli;

string N;

bool ask(string x)
{
	cout << "? " << x << "\n"; fflush(stdout);
	char res;
	cin >> res; fflush(stdout);
	return (res == 'Y');
	//cout << "? " << x << " " << ((x > N && stoll(x) > stoll(N)) || (x <= N && stoll(x) <= stoll(N))) << "\n"; fflush(stdout);
	//return ((x > N && stoll(x) > stoll(N)) || (x <= N && stoll(x) <= stoll(N)));
}

void done(lli x)
{
	cout << "! " << x << "\n"; fflush(stdout);
	exit(0);
}

lli digs()
{
	lli v = 1ll;
	for(lli i = 1;i <= 15ll;i++)
	{
		v *= 10ll;
		if(!ask(to_string(v))) return i;
	}
	v = 1ll;
	for(lli i = 1;i <= 15ll;i++)
	{
		v *= 10ll;
		if(ask(to_string(v-1))) done(v/10ll);
	}
	return -1;
}

void solve(lli d)
{
	string q;
	for(lli i = 0;i < d;i++) q += "0";
	for(lli i = d;i > 0;i--)
	{
		lli L = 0ll, R = 9ll, ans = -1;
		while(L <= R)
		{
			lli mid = (L+R)/2ll;
			q[d-i] = char(mid+'0');
			if(ask(q+"0")) R = mid-1ll; 
			else L = mid+1ll, ans = max(ans, mid);
		}
		q[d-i] = char(ans+'0');
	}
	lli res = stoll(q)+1ll;
	done(res);
}

int main(void)
{
	//cin >> N;
	lli x = digs();
	solve(x);
}

Measured memory_bytes: 596