akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
int a[200005] = {0};
int b[200005] = {0};
int main()
{
	int n,k;
	
	int sum = 1;
	
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int u = 0;
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		if(a[i] == a[i+1])
		{
			sum++;
		}
		else
		{
			b[u++] = sum;
		//	printf("%d\n",sum);
			ans++;
		//	printf("%d\n",ans);
			sum = 1;		
		}
	}
	sort(b,b+ans,greater<int>()); 
/*	for(int i=0;i<ans;i++)
	{
		printf("%d\n",b[i]);
	}*/
	if(ans > k)
	{
		int p = ans - k;
		//printf("%d\n",p);
		int o = 0;
		for(int i = ans - 1;i>k-1;i--)
		{
		//	printf("%d ",b[i]);
			o+=b[i];
		}
		printf("%d\n",o);
	}
	else
	{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 1792
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = [0] * n

(0..n-1).each do |i|
  ans[a[i] - 1] = i + 1
end

(0..n-1).each do |i|
  print ans[i]
  if i < n - 1
    print " "
  else
    puts ""
  end
end

Measured memory_bytes: 12548
n = int(input())
xlist = [int(i) for i in input().split()]
k = 0
dm = (100**2)*100#最大値
while k <= max(xlist):
    d = 0
    for j in range(n):
        d += (xlist[j]-k)**2
    k += 1
    if d < dm:
        dm = d
        xm = k
print(dm)

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

using namespace std;

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int ans = -1;
        for(int i=1; i<10000; ++i)
        {
            int a, b;
            a = i * 0.08;
            b = i * 0.1;
            if(n==a && m==b)
            {
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);

    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	vector<int> ans(n,0);
	int ind=0;
	rep(i,n){
		if(i+1<n && s[i]=='R' && s[i+1]=='L'){
			ind=i+1;
			continue;
		}
		if(s[i]=='L'){
			if((i-ind)%2==0) ans[ind]++;
			else ans[ind-1]++;
		}
	}
	for(int i=n-1;i>=0;i--){
		if(i-1>=0 && s[i]=='L' && s[i-1]=='R'){
			ind=i-1;
			continue;
		}
		if(s[i]=='R'){
			if((ind-i)%2==0) ans[ind]++;
			else ans[ind+1]++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1104
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;

class ModCombination
{
  private:
    int MAX = 10;
    int MOD = 10;
    vector<long long> fac;
    vector<long long> facinv;
    vector<long long> inv;
  public:
    ModCombination(int _MAX = 10, int _MOD = 10)
    {
        MAX = _MAX;
        MOD = _MOD;
        fac = vector<long long>(_MAX);
        facinv = vector<long long>(_MAX);
        inv = vector<long long>(_MAX);

        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++)
        {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            facinv[i] = facinv[i - 1] * inv[i] % MOD;
        }
    }

    long long get(int n, int k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (facinv[k] * facinv[n - k] % MOD) % MOD;
    }
};

vector<long long> mpow;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int p;
    cin >> p;
    ModCombination comb(p + 2, p);
    auto ans = vector<int>(p + 1, 0);
    // D(comb.get(2, 0));
    // D(comb.get(2, 1));
    // D(comb.get(4, 1));
    REP(k, p) {
        int ai;
        cin >> ai;
        if (ai == 0) continue;
        // 1 - (x - k) ^ (p - 1)
        long long kpow = 1;
        int pw = p - 1;
        REP(i, pw + 1)  {
            // pwCi (- k) ^ i x ^ (pw - i)
            // DD(p - 1, i);
            // D(comb.get(p - 1, i));
            long long coef = (comb.get(pw, i) * kpow) % p;
            int dim = pw - i;
            ans[dim] = (ans[dim] + p - coef) % p;
            kpow = ((p - k) * kpow) % p;
        }
        ans[0] = (ans[0] + 1) % p;
    }

    cout << ans[0];
    for (int i = 1; i <= p - 1; ++i) {
        cout << " " << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 888
//_Krenil_Bhikadiya_

#include<bits/stdc++.h>
#define MAX_SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define max(a,b) (a<b?b:a) 
#define min(a,b) (a>b?b:a) 
#define ll long long
#define ld long double
#define llu unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define umap unordered_map
#define uset unordered_set
#define rep(i,a,n) for(int i=(int)a;i<(int)n;i++)
#define rev(i,n,a) for(int i=(int)n;i>=(int)a;i--)
#define pb push_back
#define ff first
#define ss second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define endl "\n"
const int INF  = 1e9;
const llu INFM = 1e18;
const int mod  = INF+7;
using namespace std;


int gcd(int A,int B)
{
	if(A==0) return B;

	return gcd(B%A,A);
}

int lcm(int A,int B)
{
	return ( A*B / gcd(A,B) );
}

ll pwr(ll A,ll B,ll P)
{
	ll RES = 1; A %= P;

	while(B>0)
	{
		if(B&1) RES = RES * A % P;
		A = A * A % P;
		B >>= 1;
	}

	return RES;
}

ll modInv(ll A,ll M)
{
	return pwr(A,M-2,M);
}

bool isPrime(int N)
{
	if(N==1) return false;

	for(int i=2;i*i<=N;i++)
	{
		if(N%i==0) return false;
	}

	return true;
}

int a[100001],n;
int dp[100001];

int rec(int i)
{
	if(i>=n) return 0;
	if(dp[i]!=-1) return dp[i];
	int c1=INT_MAX;
	if((i+1)<=n)c1=abs(a[i]-a[i+1])+rec(i+1);
	int c2=INT_MAX;
	if((i+2)<=n)c2=abs(a[i]-a[i+2])+rec(i+2);

	return dp[i]=min(c1,c2);
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	MAX_SPEED
	
	int test=1; //cin>>test;
	while(test--)
	{
		cin>>n;

		memset(dp,-1,sizeof dp);

		rep(i,1,n+1) cin>>a[i];

		cout<<rec(1)<<endl; 
	}
}

Measured memory_bytes: 10540
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n;
   cin>>n;
   vector<int> a(100000,0);
   vector<int> b(n);
   int x=0;
   rep(i,n){
      cin>>b[i];
      if(b[i]>100000) x++;
      else a[b[i]]++;
   }
   sort(b.begin(),b.end());
   int ans=0;
   rep(i,n-x){
      if(a[b[i]]!=b[i]){
         if(a[b[i]]>b[i]){
            ans+=a[b[i]]-b[i];
            a[b[i]]=b[i];
         }
         else{
            ans+=a[b[i]];
            a[b[i]]=0;
         }
      }
   }
   ans+=x;
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3944
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdbool.h>
#include<set>
#define N 1000000007
using namespace std;
typedef long long ll;
int num[100001];
int main(void) {
	string s, t;
	cin >> s >> t;
	if (s == t)cout << "=" << endl;
	if (s < t)cout << "<" << endl;
	if (s > t)cout << ">" << endl;
	return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
aji = [L+i-1 for i in range(1,N+1)]
mini = min(aji) if 0 not in aji else 0
if mini == 0:
    print(sum(aji))
elif mini < 0:
    print(sum(aji)-max(aji))
else:
    print(sum(aji)-mini)


Measured memory_bytes: 3060
#include<stdio.h>
#include<ctype.h>
int main()
{
    char s[10];
    int len,ch=0,i,pos,upp=0;
    gets(s);
    len=strlen(s);
	if(len>=4&&len<=10)
    {
        if(s[0]!='A')
            printf("WA\n");
        else
        {
            for(i=2; i<len-1; i++)
            {
                if(s[i]=='C')
                {
                    ch++;
                    pos=i;
                }
            }
            if(ch==1)
            {
                for(i=1; i<=len-1; i++)
                {
                	if(i==pos)
						continue;
                   else if(isupper(s[i]))
                    {
                        upp++;
                        break;
                    }
                    else
                        continue;
                }
                if(upp==0)
                    printf("AC\n");
                else
                    printf("WA\n");
            }
            else
				printf("WA\n");
        }
    }
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ll long long
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,h,a,b,ans=0,cnt=0;
    cin >> n >> h;
    vector<ll> a_1,b_1;
    for(ll i=0;i<n;i++){
        cin >> a >> b;
        a_1.push_back(a);
        b_1.push_back(b);
    }
    sort(b_1.begin(),b_1.end(),greater<ll>());
    ll max = *max_element(a_1.begin(),a_1.end());
    for(ll i=0;i<h;i++){
        if(b_1[i]>=max){
            cnt+=b_1[i];
            ans++;
        }
        if(b_1[i]<max){break;}
        if(cnt>=h){
            cout << ans << endl;
            return 0;
        }
    }
    if((h-cnt)%max!=0){cout << ans+(h-cnt)/max+1 <<endl;}
    else cout << ans+(h-cnt)/max << endl;

    return 0;
}

Measured memory_bytes: 2036
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

def cnt_two(n):
  if n % 2 == 1:
    return 0
  else:
    return 1 + cnt_two(n // 2)

N = iIn()
A = iInLH()

ans = INF
for i in range(N):
  cnt = cnt_two(A[i])
  ans = min(ans, cnt)
  
print(ans)

Measured memory_bytes: 68116
n, k = map(int, input().split())
data = []
for i in range(k):
  d = int(input())
  data.append( list(map(int, input().split())) )

import collections
import itertools

# print(*data)
data = list(itertools.chain.from_iterable(data))
# print(*data)
data = list(set(data))
# print(*data)
print(n - len(data))

# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = collections.Counter(l)
# print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})

Measured memory_bytes: 9288
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  string S;
  cin >> S;
  string before = "ATGC";
  string after = "TACG";
  map <char,char> m;
  for(int i=0;i<4;i++){
    m[before[i]] = after[i];
  }
  char ans = m[S[0]];
  cout << ans << endl;
}
 


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

using namespace std;

struct csf {
    int c;
    int s;
    int f;
};

int main() {
    int n;
    cin >> n;
    vector<csf> a(n);
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i].c >> a[i].s >> a[i].f;
    }

    for (int i = 0; i < n - 1; ++i) {
        int sum = 0;
        for (int j = i; j < n - 1; ++j) {
            if (sum < a[j].s) sum = a[j].s;
            else if (sum % a[j].f == 0);
            else sum = sum + a[j].f - sum % a[j].f;
            sum += a[j].c;
        }
        cout << sum << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define repd(i,a,b) for (int i=(a);i<(b);i++)
typedef long long ll;
using namespace std;
 
int main() {
    int s;cin>>s;
    int ans = 1;
    while(1){
        if(s==1||s==2){
            cout<<4<<endl;
            return 0;
        }
        if(s%2==0)s/=2;
        else s=3*s+1;
        if(s==4){
            cout<<ans+4<<endl;
            return 0;
        }
        ans++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

const int K = 2019;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int l, r;
	cin >> l >> r;
	int ans = K;
	for (int f = l; f < l + K; f++) {
		for (int s = r - K + 1; s <= r; s++) {
			if (f < s) {
				ans = min(ans, (f * s) % K);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u == s){
        a-=1;
    }else{
        b-=1;
    }
    cout << a << " " << b << endl;
    return 0;
}

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

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

        int a,b,c,d;
        int a_sum, b_sum;

        cin >> a >> b >> c >> d;
        a_sum = a + b + c + d;
        cin >> a >> b >> c >> d;
        b_sum = a + b + c + d;

        if(a_sum == b_sum)      cout << a_sum << "\n";
        else                    cout << ((a_sum > b_sum) ? a_sum : b_sum)  << "\n";

        return 0;
}

Measured memory_bytes: 1200
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] a = new char[h][w];
        Deque<int[]> queue = new ArrayDeque<>();
        boolean[][] visited = new boolean[h][w];
        for (int i = 0; i < h; i++) {
            a[i] = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if (a[i][j] == '#') {
                    visited[i][j] = true;
                    queue.add(new int[] { i, j });
                }
            }
        }
        int cnt = -1;
        final int[][] DXDY = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
        while (!queue.isEmpty()) {
            int size = queue.size();
            cnt++;
            for (int i = 0; i < size; i++) {
                int[] p = queue.poll();
                for (int j = 0; j < DXDY.length; j++) {
                    int x = p[0] + DXDY[j][0];
                    int y = p[1] + DXDY[j][1];
                    if (x < 0 || x >= h || y < 0 || y >= w || visited[x][y]) {
                        continue;
                    }
                    visited[x][y] = true;
                    queue.add(new int[] { x, y });
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 64900
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
 
int main(){
    while(1){
        int n,d;
        cin >> n >> d;
        if(n==0) break;
 
        vector<vector<int> > c(n);
        vector<int> sum(n, 0);
        int rep=0;
        for(int i=0; i<n; i++){
            int m;
            cin >> m;
            rep += m;
            c[i].resize(m);
            for(int j=0; j<m; j++){
                cin >> c[i][j];
                sum[i] += c[i][j];
            }
        }
        
        for(; rep>0; rep--){
            int fs=0, sc=0;
            int fsidx, scidx;
            for(int i=0; i<n; i++){
                if(sc < sum[i]){
                    sc = sum[i];
                    scidx = i;
                    if(fs < sc){
                        swap(fs, sc);
                        swap(fsidx, scidx);
                    }
                }
            }
            if(fs -c[fsidx].back() +d >= sc){
                sum[fsidx] -= c[fsidx].back();
                c[fsidx].pop_back();
                continue;
            }else if(sc -c[scidx].back() +d >= fs){
                sum[scidx] -= c[scidx].back();
                c[scidx].pop_back();
                continue;
            }else{
                break;
            }
        }
        
        if(rep==0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3004
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
using namespace std;
int main(void) {
	int n,x;
	vector<int> an;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		an.push_back(x);
	}
	printf("%d",an[n - 1]);
	for (int i = n - 2; 0 <= i; i--) {
		printf(" %d", an[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2748
# include <iostream>
# include <map>
# include <algorithm>
using namespace std;

# define ll long long

bool descending(int a, int b){
  return a > b;
}

int main(){
  
  int N;
  cin >> N;
  
  int strength[3*N+5];
  for(int i=0; i<3*N; i++)
    cin >> strength[i];
  sort(strength, strength+3*N, descending);  
  
  ll ans = 0;
  for(int i=1; i<2*N; i+=2)
    ans += strength[i];
  
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 4812
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long ans = 0;
            string[] s = Console.ReadLine().Split(' ');

            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            int[][] drink = new int[N][];

            for(int i=0;i<N;i++)
            {
                drink[i] = new int[2];

                s = Console.ReadLine().Split(' ');
                drink[i][0] = int.Parse(s[0]);
                drink[i][1] = int.Parse(s[1]);
            }

            OrgComparer comp = new OrgComparer();
            Array.Sort(drink, comp);

            int count = M;

            for(int i=0;i<N;i++)
            {
                if(drink[i][1] >= count)
                {
                    ans += (long)drink[i][0] * count;
                    break;
                }

                ans += (long)drink[i][0] * drink[i][1];
                count -= drink[i][1];

            }

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

    public class OrgComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            int[] X = (int[])x;
            int[] Y = (int[])y;

            if (X[0] < Y[0])
                return -1;
            if (X[0] > Y[0])
                return 1;

            return 0;
        }
    }

}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    vector<int> x(5);
    FOR(i, 5) cin >> x[i];
    FOR(i, 5) if (x[i] == 0) cout << i+1 << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 3616
"use strict";

const isUpperCase = str => {
    return str === str.toUpperCase() ? true : false;
}

const main = (input) => {
    const spi = input.split('\n');
    const a = spi[0];

    console.log(isUpperCase(a) ? "A" : "a");
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

const int maxn = 2e5 + 10;

int N;
vector<int> adj[maxn];
vector<int> color[2];
vector<int> result;

void dfs(int u, int p, int c) {
  color[c].push_back(u);
  for (int v : adj[u]) if (v != p) {
    dfs(v, u, c ^ 1);
  }
}

void calc(int &id, int r) {
  if (color[id].size() < color[id ^ 1].size()) id ^= 1;
  for (int i = 1; i <= N; ++i) if (i % 3 == r) {
    result[color[id].back()] = i;
    color[id].pop_back();
  }
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(NULL);
  cin >> N;
  for (int i = 1; i < N; ++i) {
    int u, v; cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0, 0);
  result.assign(N + 1, 0);
  int id = 0;
  calc(id, 1);
  calc(id, 2);
  for (int i = 1; i <= N; ++i) if (i % 3 == 0) {
    int v;
    if (!color[id].empty()) {
      v = color[id].back(); color[id].pop_back();
    } else {
      v = color[id ^ 1].back(); color[id ^ 1].pop_back();
    }
    result[v] = i;  
  }
  for (int i = 1; i <= N; ++i) cout << result[i] << " ";
  return 0;
}


Measured memory_bytes: 21620
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define bit(i) (1<<(i))
#define set(mask,i) (mask |= (1<<(i)))
#define get(mask,i) (mask & (1<<(i)))
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
const ll INF64 = (ll)1e15;
const int INF32 = (int)1e9;
const int64_t md = (int64_t)((int64_t)1e9 + 7);
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll n, w;
	cin >> n >> w;
	vector<pair<ll, ll>> v(n);
	for(auto& el : v)
		cin >> el.first >> el.second;
	ll dp[n+1][w+1]; // dp[i][j] = max score we can get if we considered first i items and we have w weight left to spend;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= w; j++) {
			dp[i][j] = -INF32;
		}
	}
	for(int i = 0; i <= w; i++) dp[0][i] = 0;
	for(int i = 0; i <= n; i++) dp[i][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= w; j++) {
			dp[i][j] = dp[i-1][j];
			if((j-v[i-1].first) >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v[i-1].first]+v[i-1].second);
		}
	}
	cout << dp[n][w];

	return 0;
}

Measured memory_bytes: 82372
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int t;cin>>t;while(t--)
#define clean(x) memset(x,0,sizeof(x))
#define sz size()
const lli mod = 1000000007;
const lli maxn = 1e18;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///
void solve()
{
    int n;cin>>n;
    int lol[n];
    for(int i=0;i<n;i++)cin>>lol[i];
    lli sum=0;
    for(int i=1;i<n;i++)
    {
        lli x;
        if(lol[i]<lol[i-1])
        {
            x=(lol[i-1]-lol[i]);
            lol[i]+=x;
            sum+=x;
        }
    }
    cout<<sum<<endl;
}
int main()
{
    solve();
}


Measured memory_bytes: 4336
N = int(input())
AC, WA, TLE, RE = 0, 0, 0, 0
for i in range(N):
  S = input()
  if S == 'AC':
    AC += 1
  elif S == 'WA':
    WA += 1
  elif S == 'TLE':
    TLE += 1
  elif S == 'RE':
    RE += 1
print('AC x {}\nWA x {}\nTLE x {}\nRE x {}\n'.format(AC, WA, TLE, RE))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s; cin >> s;
  string t = "AKIHABARA";
  int p = 0;
  REP(i,s.size()){
    if(p<t.size() && s[i]==t[p]){
      p++;
    }else if(t[p]=='A'){
      p++;
      i--;
    }else{
      cout << "NO\n";
      return 0;
    }
  }
  if(p<t.size()) p++;
  cout << (p>=t.size() ? "YES\n" : "NO\n");

  return 0;
}


Measured memory_bytes: 256
import numpy as np

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


a = np.array(a)
b = np.array(b)


if np.sum(a) < np.sum(b):
    ans = -1
else:

    diff = a - b
    diff = np.sort(diff)
    if np.sum(diff<0) == 0:
        ans = 0
    else:
        for ind in range(len(diff)):
            if diff[ind] > 0:
                break

        minus = np.sum(diff[:ind])
        minus_num = ind

        yoyuu = diff[ind:][::-1]

        for ind in range(len(yoyuu)):
            minus += yoyuu[ind]
            if minus > 0:
                ans = minus_num + ind + 1
                break
            if minus == 0:
                ans = minus_num + ind
                break

print(ans)

Measured memory_bytes: 34528
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class Main implements Runnable{
	public static void main(String[] args) 
	{
		new Thread(null, new Main(), " ",Runtime.getRuntime().maxMemory()).start();
	}
	public void run(){
		solver();
	}
	
	int[] depth;
	ArrayList<Edge>[] g;
	@SuppressWarnings("unchecked")
	void solver(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		depth = new int[n];
		g = new ArrayList[n];
		for (int i = 0; i < n; ++i)
			g[i] = new ArrayList<>();
		for (int i = 0; i < n - 1; ++i) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int w = sc.nextInt();
			g[s].add(new Edge(s, t, w));
			g[t].add(new Edge(t, s, w));
		}

		dfs(0, -1);

		int d = -1;
		int v = -1;
		for (int i = 0; i < n; ++i) {
			if (d < depth[i]) {
				d = depth[i];
				v = i;
			}
		}

		Arrays.fill(depth, 0);

		dfs(v, -1);

		int ans = -1;
		for (int i = 0; i < n; ++i) {
			ans = Math.max(ans, depth[i]);
		}

		System.out.println(ans);

	}

	void dfs(int cur, int pre) {
		for (Edge e : g[cur]) {
			if (e.dst != pre) {
				depth[e.dst] = depth[e.src] + e.cost;
				dfs(e.dst, cur);
			}
		}
	}

	static class Edge {
		int src;
		int dst;
		int cost;

		public Edge(int src, int dst, int cost) {
			this.src = src;
			this.dst = dst;
			this.cost = cost;
		}
	}
}

Measured memory_bytes: 136840
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>
#include <cassert>
#include <iostream>
#include <string>
#include <map>
#include <set>
#define mkp make_pair
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
const int INF=2147483647;
int main(){
	IOS;
	string s;
	cin>>s;
	int k;
	cin>>k;
	bool flag=0;
	int pos;
	for(int i=1;i<s.length();i++){
		if(s[i]!=s[i-1]){
			pos=i;
			flag=1;
			break;
		}
	}
	if(!flag){
		cout<<(long long)s.length()*k/2<<'\n';
		return 0;
	}
	string t=s;
	long long ans=0;
	for(int i=pos+1;i!=pos;i=(i+1)%s.length()){
		if(t[i]==t[(i+s.length()-1)%s.length()]){
			t[i]=0;
			ans++;
		}
	}
	long long ans2=0;
	for(int i=1;i<pos;i++){
		if(s[i]==s[i-1]){
			s[i]=0;
			ans2++;
		}
	}
	for(int i=pos+1;i<s.length();i++){
		if(s[i]==s[i-1]){
			s[i]=0;
			ans2++;
		}
	}
	cout<<ans*(k-1)+ans2<<'\n';
	return 0;
}


Measured memory_bytes: 256
splitline()=split(readline())
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
    n = parseInt(readline())
    a = map(parseInt, split(readline()))

    ans = 0
    for i in 1:n
        while a[i]%2 == 0
            a[i] /= 2
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 134372
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
const ll MOD = 998244353;
// const ll MOD = 1e9 + 7;


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

  ll n;
  std::cin>>n;

  std::vector<ll> d(n);
  rep(i,0,n)std::cin>>d[i];

  if(n==1){
    if(d[0]==0)std::cout<<1;
    else std::cout<<0;
    return 0;
  }

  if(d[0]!=0){
    std::cout<<0;
    return 0;
  }

  std::sort(all(d));

  if(d[1]==0){
    std::cout<<0;
    return 0;
  }

  ll max=d[n-1];

  ll ans=1;

  ll cnt=1;

  rep(i,1,max+1){
    ll temp=(ll)(std::upper_bound(all(d),i)-std::lower_bound(all(d),i));
    ans=(ans*pow_mod(cnt,temp,MOD))%MOD;
    cnt=temp;
  }

  std::cout<<ans;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int A, B, M,Am,Bm;
	cin >> A >> B >> M;
	vector<int> At(A);
	Am = 1000000;
	Bm = 1000000;
	for (int i = 0; i < A; i++) {
		cin >> At.at(i);
		Am = min(Am, At.at(i));
	}
	vector<int> Bt(B);
	for (int i = 0; i < B; i++) {
		cin >> Bt.at(i);
		Bm = min(Bm, Bt.at(i));
	}
	int x, y, c,sm;
	sm = 3000000;
	rep(i, M) {
		cin >> x >> y >> c;
		sm = min(sm, At.at(x - 1) + Bt.at(y - 1) - c);
	}
	sm = min(sm, Am + Bm);
	cout << sm << endl;
	

}



Measured memory_bytes: 1024
def f():
    for i in R:
        for j in C:
            try:
                if d[(i,j)]:
                    pass
            except:
                return 1
    return 0

h,w,m=map(int,input().split())
r=[0 for i in range(h)]
c=[0 for i in range(w)]
t=[]
d={}
for i in range(m):
    x,y=map(int,input().split())
    d[(x-1,y-1)]=True
    r[x-1]+=1
    c[y-1]+=1
r_=max(r)
c_=max(c)
R=[]
C=[]
for i in range(h):
    if r[i]==r_:
        R.append(i)
for i in range(w):
    if c[i]==c_:
        C.append(i)

flag=f()
if flag:
    print(r_+c_)
else:
    print(r_+c_-1)

Measured memory_bytes: 169816
#include<iostream>
using namespace std;
int main() {
	int N, A, B;
  	cin >> N >> A >> B;
  	int sum = 0;
  	int sum1 = 0;
  	for(int j = 1; j <= N; j++){
      sum1 = 0;
  	for(int i = j; i != 0; i /= 10) {
      	sum1 += (i % 10);
    }
  	if(sum1 >= A && sum1 <= B) {
      	sum += j;
    }
    }
  	cout << sum << endl;
  	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n % 2 == 0){
			if(n / 2 >= k){
				System.out.print("YES");
			}else{
				System.out.print("NO");
			}
		}else{
			if(n / 2 + 1>= k){
				System.out.print("YES");
			}else{
				System.out.print("NO");
			}
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;

const int MOD = 2019;
int N;
string S;
vector<int> P, T;
map<int, int> M;

void input_init(void) {
	cin >> S;
	N = S.length();
	P.resize(N + 1, 0);
	T.resize(N + 1, 0);
}

void culcu(void) {
	P[1] = 1;
	for (int i = 2; i <= N; ++i)
		P[i] = (P[i - 1] * 10) % MOD;
	for (int i = 1; i <= N; ++i) {
		int k = (int)(S[N - i] - '0');
		T[i] = (k * P[i]) % MOD;
		T[i] = (T[i - 1] + T[i]) % MOD;
	}
}

ll solve(void) {
	for (int i = 0; i <= N; ++i)
		++(M[T[i]]);
	ll sum = (ll)0;
	map<int, int>::iterator itr;
	for (itr = M.begin(); itr != M.end(); ++itr) {
		int cnt = itr->second;
		if (cnt > 1)
			sum += (ll)cnt * (cnt - 1) / 2;
	}
	return sum;
}

int main(void) {
	input_init();
	culcu();
	ll ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
	int a[3],ans[2];
	char com;
	ans[0]=0;ans[1]=0;
	while(cin>>a[0]>>com>>a[1]>>com>>a[2]){
		if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1])ans[0]++;
		if(a[0]==a[1])ans[1]++;
	}
	cout<<ans[0]<<endl<<ans[1]<<endl;
	return 0;
}

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

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int N, D;
vector<int> C;
vector<vector<int>> S;

void Read(bool local = false) {
  N = 26;
  if (local) {
    D = 365;
  } else {
    cin >> D;
  }
  C.resize(N);
  for (int i = 0; i < N; i++) {
    if (local) {
      C[i] = rnd() % 100;
    } else {
      cin >> C[i];
    }
  }
  S.resize(D);
  for (int i = 0; i < D; i++) {
    S[i].resize(N);
    for (int j = 0; j < N; j++) {
      if (local) {
        S[i][j] = rnd() % 20000;
      } else {
        cin >> S[i][j];
      }
    }
  }
}

int ans_score = 0;
vector<int> ans;

void Write() {
  for (auto i : ans) {
    cout << i + 1 << "\n";
  }
}

int Arithmetic(int n) {
  return n * (n - 1) / 2;
}

vector<set<int>> Build(vector<int> a) {
  vector<set<int>> occ(N);
  for (int i = 0; i < D; i++) {
    occ[a[i]].insert(i);
  }
  for (int i = 0; i < N; i++) {
    occ[i].insert(-1);
    occ[i].insert(D);
  }
  return occ;
}

int Evaluate(vector<int> a) {
  vector<int> last(N, -1);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += S[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      score -= C[j] * (i - last[j]);
    }
  }
  return score;
}

int Evaluate(int init_score, const vector<int> &a, const vector<set<int>> &occ, int d, int q) {
  if (a[d] == q) return init_score;
  const set<int> &cur = occ[a[d]];
  auto pos = cur.lower_bound(d);
  int lst = *prev(pos);
  int nxt = *next(pos);

  int score = init_score;
  score += C[a[d]] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  pos = occ[q].upper_bound(d);
  lst = *prev(pos);
  nxt = *pos;
  score -= C[q] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  score -= S[d][a[d]];
  score += S[d][q];

  return score;
}

void Change(int &init_score, vector<int> &a, vector<set<int>> &occ, int d, int q) {
  int new_score = Evaluate(init_score, a, occ, d, q);
  init_score = new_score;
  occ[a[d]].erase(d);
  a[d] = q;
  occ[a[d]].insert(d);
}

void Solve() {
  vector<int> a(D);
  for (int i = 0; i < D; i++) {
    a[i] = i % N;
  }
  int score = Evaluate(a);
  vector<set<int>> occ = Build(a);

  // double temp = 10;
  // double cooling_rate = 0.99;
  // double absolute_zero = 0.0001;

  int rep = 2e6;
  while (rep--) {
    int d = rnd() % D;
    int q = rnd() % N;
    if (Evaluate(score, a, occ, d, q) > score) {
      Change(score, a, occ, d, q);
    }
  }
  ans = a;
}

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

  Read();
  Solve();
  Write();
  // cerr << Evaluate(ans) << "\n";
  return 0;
}


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


int main(){

 
  int N;
  cin>>N;
  
  map <string,int> mp;
  
  ll count=0;
  rep(i,N){

    string s;
    cin>>s;
    sort(s.begin(),s.end());
    count+=mp[s];
    mp[s]++;
    
  }
  
  cout<<count<<endl;
}


Measured memory_bytes: 11136
//In the name of God!
#include <bits/stdc++.h>

const int maxn = 50 + 12;
using namespace std;

int a[maxn];
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    double ans = a[0];
    for(int i = 1; i < n; i++){
        ans = (ans + a[i]) / 2;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll mul_inv(ll a, ll b) {
	ll t1 = a, t2 = b, t3;
	ll v1 = 1, v2 = 0, v3;
	while (t2 != 1) {
		ll x = t1 / t2;
		t3 = t1 - x*t2;
		v3 = v1 - x*v2;
		t1 = t2, t2 = t3;
		v1 = v2, v2 = v3;
	}
	return (v2 + b) % b;
}
ll mypow(ll a, ll b, ll m) {
	ll rv = 1;
	while (b) {
		if (b % 2) rv = rv*a%m;
		a = a*a%m;
		b /= 2;
	}
	return rv;
}

ll P[3] = { 1234577, 1234603, 1234613 };
ll Pinv[3];
ll MO[3] = { MOD, MOD + 2, MOD + 216 };
ll po[3][600050]; // po[i][j] = P[i] ** (j-300000) % MO[i]

char in[250050];

ll sum[250050][3];
int pos[250050];

int main() {
	int N, i, j;
	for (i = 0; i < 3; i++) {
		Pinv[i] = mul_inv(P[i], MO[i]);
		po[i][300000] = 1;
		for (j = 300001; j <= 600000; j++) po[i][j] = po[i][j - 1] * P[i] % MO[i];
		for (j = 299999; j >= 0; j--) po[i][j] = po[i][j + 1] * Pinv[i] % MO[i];
	}
	
	scanf("%d %s", &N, in + 1);
	pos[0] = 0;
	for (i = 1; i <= N; i++) {
		pos[i] = pos[i - 1];
		if (in[i] == '>') pos[i]++;
		if (in[i] == '<') pos[i]--;
		
		for (j = 0; j < 3; j++) {
			sum[i][j] = sum[i - 1][j];
			if (in[i] == '+') sum[i][j] = (sum[i][j] + po[j][pos[i] + 300000]) % MO[j];
			if (in[i] == '-') sum[i][j] = (sum[i][j] - po[j][pos[i] + 300000] + MO[j]) % MO[j];
		}
	}

	map <pair<ll, pll>, int> Mx;
	ll ans = 0;
	for (i = N; i >= 1; i--) {
		Mx[mp(sum[i][0], pll(sum[i][1], sum[i][2]))]++;

		ll val[3] = { 0,0,0 };
		for (j = 0; j < 3; j++) {
			val[j] = sum[N][j] * po[j][pos[i - 1] + 300000] % MO[j];
			val[j] = (val[j] + sum[i - 1][j]) % MO[j];
		}
		ans += Mx[mp(val[0], pll(val[1], val[2]))];
	}
	return !printf("%lld\n", ans);
}

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

#define m 1046527
#define L 14

char T[m][L];

int h1(long long key){
    return key%m;
}
int h2(long long key){
    return 1+key%(m-1);
}
int h(long long key, int i){
    return (h1(key)+i*h2(key))%m;
}
int charTonum(char c){
    switch(c){
        case 'A':
            return 1;
        case 'C':
            return 2;
        case 'G':
            return 3;
        case 'T':
            return 4;
        default:
            return 0;
    }
}

long long getKey(char str[]){
    int length = strlen(str);
    long long sum = 0, p = 1;
    for(int i=0;i<length;++i){
        sum += p*charTonum(str[i]);
        p *= 5;
    }
    return sum;
}
void insert(char str[]){
    long long  key, pos, i= 0;
    key = getKey(str);
    while(1){
        pos = h(key,i);
        if(strcmp(T[pos],str)==0) break;
        else if(strlen(T[pos])==0){
            strcpy(T[pos],str);
            break;
        }
        i++;
    }
}

int find(char str[]){
    long long  key, pos, i = 0;
    key = getKey(str);
    while(1){
        pos = h(key,i);
        if(strcmp(T[pos],str)==0) return 0;
        else if(strlen(T[pos])== 0) return 1;
        i++;
    }
}

int main(){
    int n,key,ret;
    /*FILE *fpRead=fopen("In9.txt","r");

    fscanf(fpRead,"%d",&n);*/
    scanf("%d",&n);
    for(int i=0;i<n;++i) T[i][0] = '\0';
    char op[7], str[L];
    for(int i=0;i<n;++i){
        //fscanf(fpRead,"%s %s",op,str);
        scanf("%s %s",op,str);
        if(op[0]=='i'){
            insert(str);
            //printf("%s %s %d\n",op,str,i);
        }
        else{
            ret = find(str);
            if(ret==0) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}



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

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

    int ans = 1000;
    for (int i = 0; i < S.length() - 2; i++) {
        string s;
        s.push_back(S[i]);
        s.push_back(S[i + 1]);
        s.push_back(S[i + 2]);
        int num = stoi(s);
        if (abs(753 - num) < ans) ans = abs(753 - num);
    }
    cout << ans << endl;
}

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

const int N = 2e5 + 10;
int64_t seg[2 * N] = {0};
int64_t dp[N] = {0};
int h[N], v[N];
int n;

void modify(int p, int64_t value) {  // set value at position p
  for (seg[p += n] = value; p > 1; p >>= 1) seg[p>>1] = max(seg[p], seg[p^1]);
  // changing the parent seg[p] left child, seg[p^1] right child and vice versa
}

int64_t query(int l, int r) {  // sum on int64_terval [l, r)
  int64_t res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res, seg[l++]);
    if (r&1) res = max(res, seg[--r]);
  }
  return res;
}

void solve() {
   for (int i = 1; i <= n; ++i) dp[h[i]] = v[i];
   for (int i = 1; i <= n; ++i) {
      int64_t mx_val = query(1, h[i]);
      dp[h[i]] = max(dp[h[i]], mx_val + v[i]);
      modify(h[i], dp[h[i]]);
   }
   cout << *max_element(begin(dp), end(dp));
}

signed main() {
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> h[i];
   for (int i = 1; i <= n; ++i) cin >> v[i];
   solve();

   return 0;
}


Measured memory_bytes: 9868
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  rep(i, n) {
    cin >> v[i];
  }
  rep(i, n) {
    cin >> c[i];
  }
  int ans;
  rep(i, n) {
    if (v[i] - c[i] >= 0) ans += v[i] - c[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, m;   cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a;  cin >> a;
        sum += a;
    }

    cout << max(n-sum, -1) << endl;

    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n;cin >> n;
    int ans=n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    vector<int> ng(a[n - 1] + 1);
    REP(i,n-1){
        if(a[i]==a[i+1]){
            ng[a[i]] = 1;
        }

    }
    REP(i,n){
        if(ng[a[i]]==1){
            ans--;
        }
        int now = a[i];
        while(now<SZ(ng)){
            ng[now] = 1;
            now += a[i];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8012