akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int,int>> r(n);
    for(int i = 0; i < n; i++) {
        cin >> r[i].second >> r[i].first;
        r[i].first*=-1;
    }
    vector<pair<int,int>> b(n);
    for(int i = 0; i < n; i++) {
        cin >> b[i].first >> b[i].second;
    }
    sort(r.begin(),r.end());
    sort(b.begin(),b.end());
    for(int i = 0; i < n; i++) {
        r[i].first*=-1;
    }


    vector<bool> a(n,false);
    int cnt=0;
    for(int i = 0; i < n; i++) {
        int idx=0;
        int bx=b[i].first;
        int by=b[i].second;
        while(idx<n) {
            int ry=r[idx].first;
            int rx=r[idx].second;
            if(rx<bx && ry<by && a[idx]==false){
                a[idx]=true;
                cnt++;
                break;
            }
            idx++;
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

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

  int n=0,s=0,w=0,e=0;
  for(char c:str){
    switch(c){
      case 'N':
      n++;
      break;
      case 'S':
      s++;
      break;
      case 'W':
      w++;
      break;
      case 'E':
      e++;
      break;
    }
  }

  if((n*s==0&&n+s>0) || (w*e==0 &&w+e>0)) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        char S;
        cin >> S;
        if (S == 'Y') {
            cout << "Four" << endl;
            break;
        }
        else if (i == N - 1) {
            cout << "Three" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int d=0;
  scanf("%d", &d);
  if (d == 25) printf("Christmas");
  else if (d == 24) printf("Christmas Eve");
  else if (d == 23) printf("Christmas Eve Eve");
  else if (d == 22) printf("Christmas Eve Eve Eve");
  return 0;
}


Measured memory_bytes: 128
//unification
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int cnt=0,end=0;
	int one=0,zero=0;
	for (int i = 0; i < s.size(); ++i)
	{
		if(s[i] == '1') one ++;
		if(s[i] == '0') zero ++;
	}
	if(one > zero) cnt = one-(one-zero);
	else cnt = zero-(zero-one);
	cout<<cnt*2<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>
#include <fstream> 
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <math.h>
#include <cmath>
using namespace std;
int main(){
    char s[10];
    int i = 0;
    string str("");
    while(cin >> s[i]){
    i++;
    }
    for(int j=0;j<i;j++){
    if(s[j] == '0'){
    str += '0';	
    }else if(s[j] == '1'){
    str += '1';	
    }else {
    if(str.size() > 0){	
    str.erase(str.size() - 1);
    }	
    }
    }	
    cout << str << endl;      
    }    		 
       

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl
 
using namespace std;
using ll = long long;
 
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}
 
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}
 
 
constexpr ll MOD = (ll)1e9 + 7LL;
 
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    const int S = s.size();
    int N;
    cin >> N;
    vector<int> L(N);
    vector<int> R(N);
    vector<set<int>> Rs(S);
    for (int i = 0; i < N; i++) {
        cin >> L[i] >> R[i];
        L[i]--, R[i]--;
        if (R[i] < S / 2) {
            Rs[L[i]].insert(R[i]);
        } else if ((S - 1) / 2 < L[i]) {
            Rs[S - R[i] - 1].insert(S - L[i] - 1);
        } else if (L[i] + R[i] < S - 1) {
            Rs[L[i]].insert(S - R[i] - 2);
        } else if (L[i] + R[i] > S - 1) {
            Rs[S - R[i] - 1].insert(L[i] - 1);
        }
    }
    for (int l = 0; l < S; l++) {
        if (Rs[l].size() <= 1) {
            continue;
        }
        auto it = Rs[l].begin();
        while (true) {
            const auto prev = it;
            it++;
            if (it == Rs[l].end()) {
                break;
            } else {
                Rs[*prev + 1].insert(*it);
            }
        }
        const int r = *Rs[l].cbegin();
        Rs[l].clear();
        Rs[l].insert(r);
    }
 
    vector<int> value;
    for (int i = 0; i < S; i++) {
        value.push_back(s[i] - 'a');
    }
    show(value);
    const int size = S / 2;
    for (int i = 0; i < size; i++) {
        value[i] = (value[i] - value[S - i - 1] + 26) % 26;
    }
    show(value);
    vector<int> d(size + 1);
    d[0] = value[0];
    for (int i = 1; i < size; i++) {
        d[i] = (value[i] - value[i - 1] + 26) % 26;
    }
    d[size] = (26 - value[size - 1])%26;
    show(d);
 
    for (int l = 0; l < S; l++) {
        for (const int r : Rs[l]) {
            d[r + 1] = (d[r + 1] + d[l] + 26) % 26;
            d[l] = 0;
        }
    }
 
    for (int i = 0; i <= size; i++) {
        if (d[i] > 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
 
    return 0;
}

Measured memory_bytes: 13004
#include <stdio.h>

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

int main()
{
    int ar[100010], a, b, c, e, d, f=0;
    scanf("%d %d", &a, &b);
    for (c=0; c<a; c++)
    {
        scanf("%d %d", &d, &e);
        if(e<=b)
        {
            ar[f] = d;
            f++;
        }
    }
    if(f==0)
        printf("TLE");
    else
    {
        qsort (ar, f, sizeof(int), cmpfunc);
        printf("%d", ar[0]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n;
	cin>>n;
	vector<long long> a(n);
	for(int i=0; i<n; i++)
		cin>>a[i];
	long long max_down = LLONG_MIN;
	long long counter = 0;
	for(int i= 0; i<n-1; i++) {
		if(a[i] >= a[i+1]) {
			counter++;
		}
		else {
			max_down = max_down > counter ? max_down: counter;
			counter = 0;
		}
	}
	max_down = max_down > counter ? max_down: counter;
	cout<<max_down<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_A

int main(void){
	int i,m,f,r;

	scanf("%d %d %d",&m,&f,&r);
	while(1){
	if((m==-1)||(f==-1)||(m+f<30))
		printf("F\n");
	else if(m+f>=80)
		printf("A\n");
	else if(m+f>=65)
		printf("B\n");
	else if(m+f>=50)
		printf("C\n");
	else if(m+f>=30)
		if(r>=50)
			printf("C\n");
		else 
			printf("D\n");
	scanf("%d %d %d",&m,&f,&r);
	if((m==-1)&&(f==-1)&&(r==-1))
		break;
	}

	return 0;
}

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

using namespace std;

#define MAX_H 1010
#define MAX_W 1010

struct P{
  int x,y;
  P(int x,int y) : x(x), y(y) {}
};

bool inField(int x,int y,int H,int W){
  return (0 <= x && x < W && 0 <= y && y < H);
}

int main(){
  int H,W,arr[MAX_H][MAX_W];
  char ch;
  cin >> H >> W;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> ch;
      arr[i][j] = (ch == '.' ? -1 : ch-'0');
    }
  }
  int cnt[MAX_H][MAX_W];
  memset(cnt,0,sizeof(cnt));
  const int dx[8] = {-1,-1,-1,0,0,1,1,1};
  const int dy[8] = {-1,0,1,-1,1,-1,0,1};
  queue<P> Q;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      if(arr[i][j] == -1){ continue; }
      for(int k = 0 ; k < 8 ; k++){
        int nx = j + dx[k];
        int ny = i + dy[k];
        if(!inField(nx,ny,H,W)){ continue; }
        if(arr[ny][nx] == -1){
          cnt[i][j]++;
        }
      }
      if(arr[i][j] <= cnt[i][j]){
        Q.push(P(j,i));
      }
    }
  }
  int res = 0;
  while(!Q.empty()){
    queue<P> nQ;
    while(!Q.empty()){
      P p = Q.front(); Q.pop();
      for(int i = 0 ; i < 8 ; i++){
        int nx = p.x + dx[i];
        int ny = p.y + dy[i];
        if(!inField(nx,ny,H,W)){ continue; }
        if(arr[ny][nx] == -1){ continue; }
        if(arr[ny][nx] <= cnt[ny][nx]){ continue; }
        cnt[ny][nx]++;
        if(arr[ny][nx] <= cnt[ny][nx]){
          nQ.push(P(nx,ny));
        }
      }
    }
    Q = nQ;
    res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 9208
from heapq import heappush, heappop
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
x = sum(A)
ls = []
for i in range(1, int(x**0.5)+1):
  if x%i==0:
    ls += [i]
    if i != x//i:
      ls += [x//i]
ls.sort(reverse=True)
for i in ls:
  B =[]
  for j in A:
    heappush(B, -1*(j%i))
  y = sum(B)
  while y<0:
    u = heappop(B)
    u += i
    heappush(B,u)
    y += i
  m = 0
  for j in B:
    if j>0:
      m += j
  if m>K:
    continue
  else:
    print(i)
    break


Measured memory_bytes: 3188
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   char[] c1 = sc.next().toCharArray();
   char[] c2 = sc.next().toCharArray();
   long ans = 1;
   
   boolean skip = false;
   boolean afterskip = false;
   for(int i=0;i<N;i++)
   {
     if(skip)
     {
       skip = false;
       afterskip = true;
     }
     else
     {
       if(afterskip&&c1[i]!=c2[i])
       {
         ans*=3;
         skip = true;
         afterskip =false;
       }
       else if(afterskip)
       {
         afterskip = false;
       }
       else if(c1[i]!=c2[i])
       {
         if(i==0) ans*=6;
         else ans*=2;
         skip=true;
       }
       else
       {
         if(i==0) ans*=3;
         else ans*=2;
       }
     }
     if(ans>1000000007) ans=ans%1000000007;
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 23892
import java.util.*;
public class Main {
    public static void main(String[] args) {
        //data input
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int[] box = new int[N];

        for (int i = 0; i < N; i++) {
            box[i] = sc.nextInt();
        }

        // get sum

        long output = 0;
        for (int i = 0; i < box.length; i++) {
            for (int j = i + 1; j < box.length; j++) {
                output += (box[i] * box[j]);
            }
        }

        System.out.println(output);
    }
}

Measured memory_bytes: 21588
mod=1000000007
fact=[1 for i in range(100001)]
for i in range(1,100001):
 fact[i]=(fact[i-1]*i)%mod
s=input().split()
n=int(s[0])
m=int(s[1])
n,m=sorted((n,m))
if n==m-1:
 print((fact[n]*fact[m])%mod)
elif n==m:
 print((fact[n]*fact[m]*2)%mod)
else:
 print(0)

Measured memory_bytes: 44784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0196
{
    public class Program

    {
        class Team
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public int Win { get; set; }
            public int Lose { get; set; }
        }

        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                List<Team> teams = new List<Team>(n);
                for (int i = 0 ; i < n ; i++)
                {
                    string[] items = RStAr();

                    Team tmp = new Team();
                    tmp.ID = i;
                    tmp.Name = items[0];
                    tmp.Win = items.Skip(1).Count(x => int.Parse(x) == 0);
                    tmp.Lose = items.Skip(1).Count(x => int.Parse(x) == 1);
                    teams.Add(tmp);
                }

                foreach (var item in teams.OrderByDescending(x => x.Win).ThenBy(x => x.Lose).ThenBy(x => x.ID))
                {
                    Console.WriteLine(item.Name);
                }

            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 16236
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int n,a,b,ans;
    cin >> n >> a >> b;
    if(n*a>b){
        ans=b;
    }else{
        ans=n*a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI e[100000];
int ans, k;

int dfs(int now, int dist){
    int ma = 1;
    for (int next : e[now]){
        ma = max(ma, dfs(next, dist + 1) + 1);
    }
    if (ma == k && dist > 1){
        ans++;
        return 0;
    }
    return ma;
}

int main(){
    int n;
    cin >> n >> k;
    VI a(n);
    REP(i,n){
        scanf("%d", &a[i]);
        a[i]--;
    }

    if (a[0] != 0) ans++;
    FOR(i,1,n-1){
        e[a[i]].push_back(i);
    }

    dfs(0, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 4010;
int Y[N];

const int P = 2002;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<int> x(n),y(n);
        rep(i,n){
            scanf(" %d %d", &x[i], &y[i]);
            x[i] += P;
            y[i] += P;
        }

        int ans = 0;
        rep(i,N){

            vector<pair<pair<double,double>,int>> l;
            rep(j,n){
                int p = j, q = (j+1)%n;

                if(min(x[p],x[q])<=i && i+1<=max(x[p],x[q])){
                    double m = (double)(y[p]-y[q])/(x[p]-x[q]);
                    double b = y[p] - m*x[p];

                    double iy = m*i+b;
                    if(x[p] == i) iy = y[p];
                    if(x[q] == i) iy = y[q];

                    double iiy = m*(i+1)+b;
                    if(x[p] == i+1) iiy = y[p];
                    if(x[q] == i+1) iiy = y[q];

                    l.pb({ {min(iy, iiy), max(iy, iiy)}, j});
                }
            }

            sort(all(l));
            int L = l.size();
            assert(L%2==0);

            if(L==0) continue;

            // printf(" ---- i %d\n", i-P);
            fill(Y,Y+N,0);
            for(int j=0; j<L; j+=2){
                // lower
                int idx = l[j].se;
                int mx = x[idx]-x[(idx+1)%n], my = y[idx]-y[(idx+1)%n];
                if(mx<0){
                    mx *= -1;
                    my *= -1;
                }
                int ly = min( (my*(i-x[idx])+y[idx]*mx)/mx, (my*(i+1-x[idx])+y[idx]*mx)/mx );

                // upper
                idx = l[j+1].se;
                mx = x[idx]-x[(idx+1)%n];
                my = y[idx]-y[(idx+1)%n];
                if(mx<0){
                    mx *= -1;
                    my *= -1;
                }
                int ry = max( (my*(i-x[idx])+y[idx]*mx +mx-1)/mx, (my*(i+1-x[idx])+y[idx]*mx +mx-1)/mx );

                // printf(" %d %d\n", ly-P, ry-P);

                ++Y[ly];
                --Y[ry];
            }

            rep(j,N-1) Y[j+1] += Y[j];
            rep(j,N) ans += (Y[j]!=0);
        }
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3132
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 要素の数がわかっているパターン
    ### a b
    A, B, N = map(int, input().split())

    x = min(B-1, N)
    ans = int(A*x/B) - A * int(x/B)
        
    print(ans)



Measured memory_bytes: 27132
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if((r <= x and x <= (W - r)) and (r <= y and y <= (H - r))){
        cout << "Yes" << endl;
        
    }else{
        cout << "No" << endl;
        
    }
}

Measured memory_bytes: 1160
n, l = [int(x) for x in input().split()]

lst = [l + i - 1 for i in range(1, n+1)]

tmplst = []
for x in lst:
    if x < 0:
        tmplst.append(-x)
    else:
        tmplst.append(x)
place = tmplst.index(min(tmplst))
lst.remove(lst[place])
print(sum(lst))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll ans=m;
  REP(i,1,n) ans=ans*(m-1);
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int id[100100],p[100100];
set<int> s;
int main()
{
	int n;
	lint out=0;
	cin>>n;
	rep(i,n){
		cin>>p[i];
		id[p[i]]=i;
	}
	s.insert(-1);s.insert(n);
	for(int i=n;i>0;i--){
		s.insert(id[i]);
		if(i>=n) continue;
		set<int>::iterator it=s.lower_bound(id[i]);
		set<int>::iterator i2=it;i2++;
		if((*i2)<n){
			set<int>::iterator ix=it,iy=i2;ix--;iy++;
			out+=(lint)i*((*it)-(*ix))*((*iy)-(*i2));
		}
		i2=it;i2--;
		if((*i2)>-1){
			set<int>::iterator ix=i2,iy=it;ix--;iy++;
			out+=(lint)i*((*i2)-(*ix))*((*iy)-(*it));
		}
	}
	cout<<out<<endl;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>

using namespace std;
typedef long long ll;

ll x[3001] = {};
ll y[3001] = {};
ll ansX[3001] = {};
ll ansY[3001] = {};
ll num = 0;

int main() {
	for (int i = 1; i <= 3000; i++) {
		cin >> x[i] >> y[i];
		if (x[i] == 0 && y[i] == 0) {
			num = i - 1;
			break;
		}
		else {
			if (x[i] < y[i]) {
				ansX[i] = x[i];
				ansY[i] = y[i];
			}
			else {
				ansX[i] = y[i];
				ansY[i] = x[i];
			}
		}
	}
	for (int i = 1; i <= num; i++)cout << ansX[i] << " " << ansY[i] << endl;
	return 0;
}


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

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

    int pot = 1;
    map<int, int> cnt;
    cnt[0] = 1;
    long long ans = 0;
    int rem = 0;
    for (int i = s.length() - 1; i >= 0; i--) {
        rem += (s[i] - '0') * pot;
        rem %= 2019;
        ans += cnt[rem]++;
        pot *= 10;
        pot %= 2019;
    }

	cout << ans << "\n";


	// 42
	//  
}

Measured memory_bytes: 3784
import sys
def input():
    return sys.stdin.readline()[:-1]
h,w,k=map(int,input().split())
s = []
for i in range(h):
    str=input()
    tmp=[]
    for j in range(w):
        if str[j]=="0":
            tmp.append(0)
        else:
            tmp.append(1)
    s.append(tmp)

tdiv=2**(h-1)
#import numpy as np
#s = np.array(s)
ans = 100100100
for i in range(tdiv):
    lis=[]
    #tmp=np.zeros(w)
    #tmp+=s[0,:]
    tmp=[s[0][ii] for ii in range(w)]
    cnt = 0
    #print(tmp)
    for j in range(h-1):
        if (i>>j&1):
            #tmp+=s[j+1,:]
            tmp=[tmp[ii]+s[j+1][ii] for ii in range(w)]
        else:
            lis.append(tmp)
            #tmp=np.zeros(w)
            #tmp+=s[j+1,:]
            tmp=[s[j+1][ii] for ii in range(w)]
            cnt+=1
    lis.append(tmp)
    #lis = np.array(lis)
    #clis=np.zeros(cnt+1)
    clis=[0 for ii in range(cnt+1)]
    #print(lis,cnt)
    tmpcnt=cnt
    for ind in range(w):
        #if any(d>k for d in lis[:,ind]):
        #if lis[:,ind].max()>k:
        if max([lis[ii][ind] for ii in range(tmpcnt+1)])>k:
            cnt=10010010
            break
        clis=[lis[ii][ind]+clis[ii] for ii in range(tmpcnt+1)]
        #if clis.max()>k:
        if max(clis)>k:
            clis=[lis[ii][ind] for ii in range(tmpcnt+1)]
            cnt+=1
    #print(cnt)
    ans = min(ans,cnt)
print(ans)
#pypyを使おう!


Measured memory_bytes: 3316
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

    ans=0
    for i in range(1,n+1):
        n_min=i
        n_max=n//i*i
        ans+=(n//i)*(n_min+n_max)//2

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 9112
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main()
{
    int X;  cin >> X;
    ll A, B;
    for(ll i=0; i<=200; i++){
        for(ll j=-200; j<=200; j++){
            if(pow(i,5) - pow(j,5) == X){
              	cout << i << " " << j;
              	return 0;
            }
        }
    }
}

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

void dfs(int u, vector<vector<pair<int,int>>> &G, vector<int> &color){
  for(int i=0;i<G[u].size();i++){
    int v = G[u][i].first, w = G[u][i].second;
    if(color[v]!=-1) continue;
    
    if(w==0) color[v] = color[u];
    else color[v] = (color[u]-1)*(-1);
    dfs(v,G,color);
  }
  return;
}

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int,int>>> G(N,vector<pair<int,int>>(0));
  for(int i=0;i<N-1;i++){
    int u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].push_back(make_pair(v,w%2));
    G[v].push_back(make_pair(u,w%2));
  }
  
  vector<int> color(N,-1);
  color[0] = 0;
  dfs(0,G,color);
  
  for(int i=0;i<N;i++) cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 8960
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}

int main()
{
  ll N, L;
  cin >> N >> L;
  ll best = 0;
  ll min_taste = 1000000LL;
  for (auto i = 0; i < N; i++)
  {
    best += L + i;
    if (abs(min_taste) > abs(L+i)) min_taste = L+i;
    // cout << (L+i) << " min_taste=" << min_taste << endl;
  }

  cout << (best - min_taste) << endl;

  return 0;
}


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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    clock_t start_clock = clock();
    std::mt19937 engine(87654321);
    std::uniform_int_distribution<> type_random(1, type_num);
    std::uniform_int_distribution<> day_random(1, Day_num);
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }

    Scoring scoring(D, costs, incentives);

    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        types[day-1] = type_random(engine);
    }

    while (static_cast<double>(clock() - start_clock)/CLOCKS_PER_SEC*1000.0 < 2000.0-20.0) {
        const auto old_types = types;
        types[day_random(engine)-1] = type_random(engine);
        if (scoring.score(old_types).back() > scoring.score(types).back()) {
            types = old_types;
        }
    }

    for (long day = 1; day <= D; ++day) {
        std::cout << types[day-1] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> T(N);
  rep(i,N) std::cin >> T[i];

  int M; std::cin >> M;
  std::vector<std::pair<int,int>> d(M);
  rep(i,M) {
    int P, X; std::cin >> P >> X;
    d[i] = {P-1, X};
  }

  rep(i,M) {
    ll ans = 0;
    rep(j,N) {
      if ( d[i].first == j ) ans += d[i].second;
      else ans += T[j];
    }
    std::cout << ans << std::endl;
  }

  return 0;
}


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

#define REP(w, n) for(int w=0;w<int(n);++w)

int main() {
    string s; cin >> s;
    string res = "Yes";
    for (int i = 0; i < s.size(); ++i) {
        if ((i + 1) % 2 == 0) {
            if (s[i] == 'R') res = "No";
        } else {
            if (s[i] == 'L') res = "No";
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n,m,i,sum,dp;
	while(cin>>n)
	{	
		sum=1; 
		for(i=0;i<n;i++)
		{
			cin>>m;
			if(m%2==1)
			{
				sum*=1;
			}
			else
			sum*=2;
		}
		dp=pow(3,n)-sum;
		cout<<dp<<endl;
	}
	return 0;
}

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

int main(void){
    int N, Q, Abuf, Bbuf, Cbuf;
    vector<int> A(100000);
    long long sumA = 0LL;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A[Abuf-1]++;
        sumA += Abuf;
    }
    cin >> Q;
    for(int i=0; i<Q; i++){
        cin >> Bbuf >> Cbuf;
        sumA += (long long)(Cbuf-Bbuf)*A[Bbuf-1];
        cout << sumA << endl;
        A[Cbuf-1] += A[Bbuf-1];
        A[Bbuf-1] = 0;
    }
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define MAX 200005
                int main()
                {
                   vector<string> s;
                   int n , l;
                   scanf("%d%d",&n,&l);
                   for(int i = 0 ; i < n ; i++)
                   {
                       string a;
                       cin>>a;
                       s.push_back(a);
                   }
                   sort(s.begin(),s.end());
                   for(int i = 0 ; i < n ; i++)
                   {
                        printf("%s",s[i].c_str());
                   }
                }


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

int main ()
{
 
  std::string S;
  std::cin >> S;
  
  int size = (int)(S.length());
  int count = 0;
  
  if (size % 2 == 0)
  {
   for (int i = 0; i < size /2; i++)
   {
     if (S[i] != S[size-1-i]) count++;
   }
  }
  else
  {
    for (int i = 0; i < size /2; i++)
   {
     if (S[i] != S[size-1-i]) count++;
   }
  }
  
  std::cout << count;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int i,j,k,n,T,q;
	string s1,s2;
	char s[21];
	cin>>s;
	for(i=0;s[i]!='\0';i++){
        if(s[i]==',') s[i]=' ';
	}
	cout<<s<<endl;
}



Measured memory_bytes: 256
I = lambda:map(int, input().split())
N = int(input())
T = list(I())
M = int(input())
ans = [sum(T)]*M
for i in range(M):
    p, x = I()
    ans[i] = ans[i] - T[p-1] + x
print('\n'.join(map(str, ans)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, int> pi;
typedef long long lint;
const int MAXN = 42;

int x, y;
int main(){
	cin >> x >> y;
	if(x % y) cout << x << endl;
	else cout << -1 << endl;
}


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

inline long long read(){
	long long x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))	ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	ungetc(ch,stdin);
	return x;
}

int main(){
	long long n=read(),a=read(),b=read();
	long long cost=0,op=0,np=read();
	for(int i=1;i<n;i++){
		op=np;
		np=read();
		cost+=min(a*(np-op),b);
	}
	printf("%lld\n",cost);
	return 0;
}

Measured memory_bytes: 128
N=int(input())
p_list=list(map(int, input().split()))
p_sort = []
for i in range(N):
  p_sort.append(p_list[i])
p_sort.sort()
ans = 0



for i in range(N):
  if p_list[i] != p_sort[i]:
    ans = ans + 1
if ans <= 2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n>>a >>b;
    
    cout << min(n*a,b) <<endl;
    return 0;
}


Measured memory_bytes: 256
endday = [31] * 13
endday[2] = 28
for i in [4,6,9,11]:
    endday[i] = 30

a, b = map(int, input().split())

res = 0
done = False
for m in range(1, 13):
    if done:
        break
    for d in range(1, endday[m] + 1):
        if m == d:
            res += 1
        if m == a and d == b:
            done = True
            break

print(res)


Measured memory_bytes: 3060
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] ar = new int[n];
        int res = 0;
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
            if(ar[i] >= x){
                res++;
            }
        }
        System.out.println(res);
    }
}

class io{
    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }
}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 50064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long ans = N*(N-1)/2;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void)
{
	long int a, b, c;
	long int A;
	int i;
	long int sum;

	scanf("%ld", &a);
	scanf("%ld", &b);
	for (i = 0; i < b; i++) {
		scanf("%ld", &A);
		a = a - A;
	}
  
  sum = a;

	if (sum < 0) {
      sum = -1;
    }

	printf("%ld", sum);
	return 0;
}

Measured memory_bytes: 1728
import math
def search(a,m):
               dp=[[False for _ in range(m+1)] for _ in range(len(a)+1)]
               dp[0][0]=True
               for i in range(len(a)):
                       for j in range(m+1):
                               if a[i]<=j:
                                       dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
                               else:
                                       dp[i+1][j]=dp[i][j]
               return dp[len(a)][m]
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

for i in m:
        if search(a,i):
                print("yes")
        else:
                print("no")


Measured memory_bytes: 6016
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, a);
    IN(string, b);
    ll c = stoi(a + b);
    bool ok = false;
    REP(i, c)
    {
        ok |= i * i == c;
    }
    YES(ok);
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


int binomialmod2(ll a, ll b) {
    if ((b<0) || (b>a)) {  return 0;  }
    int ret = 1;
    while (b>0) {
        int digb = b%2, diga = a%2;
        a/=2; b/=2;
        if (digb>diga) { ret = 0; break; }
    }
    return ret;
};

int no_of_pts(vector<pair<ll,ll>>& pts, ll y_min, ll x) {  // return no of pts less or equal than x (mod 2)
  int ret = 0;
  for(auto p : pts) {
      ll x_ = p.first, y_ = p.second;
      if ((x >= x_) && (x <= x_+y_-y_min)) {
          ll a = y_-y_min, b = x-x_;
          ret += binomialmod2(a-1,b);
          ret = ret % 2;
      }
  }
  return ret;
};

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        map<ll,set<int>> a;
        forr(i,0,n) {
            readint(aa);
            a[aa].insert(i+1);
        }
        a[0].insert(0);

        map<int,ll> answer;
        auto it = a.end();
        ll tot = 0;
        int where = n;
        while (true) {
            it--;
            if (it->first==0) {break;}
            where = min(where, *it->second.begin());
            tot += it->second.size();
            answer[where] -= (prev(it)->first-it->first) * tot;
        }

        forr(i,1,n) {
            cout << answer[i] << endl;
        }

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}


Measured memory_bytes: 23936
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	ls = sum(a)
	ss = 0
	m1 = ceil(Int,ls/n)
	m2 = floor(Int,ls/n)
	for i in 1:n
		ss += a[i]^2
	end
	println(min(m1^2*n-2*m1*ls+ss, m2^2*n-2*m2*ls+ss))
end

main()


Measured memory_bytes: 110464
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
string s;
int ans;
int main(){
    cin>>s;
    int l{},r=s.size()-1;
    while(l<r){
        if(s[l]==s[r]){++l,--r;continue;}
        if(s[l]!='x'&&s[r]!='x'){
            cout<<-1<<endl;
            return 0;
        }
        if(s[l]=='x')++l,++ans;
        else --r,++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    A = []
    for i in range(N):
        a = int(input().strip())
        A.append(a)
    return N, A


def solve(N, A):
    grundy = any([a % 2 != 0 for a in A])
    if grundy:
        return "first"
    else:
        return "second"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main(){
  int i,j,k;
  
  int N;
  
  scanf("%d",&N);
  
  char str[N][11];
  
  for(i=0;i<N;i++){
    scanf("%s",str[i]);
    for(j=0;j<i;j++){
      if(strcmp(str[j],str[i])==0){
        puts("No");
        return 0;
      }
      if(j == i-1){
        if(str[j][strlen(str[j])-1] != str[i][0]){
          puts("No");
          return 0;
        }
      }
    }
  }
    puts("Yes");
    
    return 0;
  
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll n;
  string s;
  cin >> n >> s;
  ll al[26]={};
  rep(i,n){
    al[s[i]-'a']++;
  }

  ll countA=0,ans=1;
  rep(i,26){
    if(al[i]>0) {
      ans *= (al[i]+1);
      ans %= MOD;
    }
  }
  ans--;
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int x = 0;
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    int li, ri;
    cin >> li  >> ri;
    x += ri-li+1;
  }
 cout << x << endl;
}

Measured memory_bytes: 256