akhauriyash/Code-Regression huggingface dataset:
/*input
cooooooooonteeeeeeeeeest
999993333
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int dp[maxn][2];
int main(){
    string a;
    cin>>a;
    ll as;
    cin>>as;
    if(a[a.length()-1]!=a[0]){
        ll ans=0;
        REP(i,a.length()){
            int k=i;

            while(a[i]==a[k]){
                ++i;
            }
            --i;
            ans+=(i-k+1)/2;
        }        
        cout<<ans*as;
    }
    else{
        ll ans=0;
        REP(i,a.length()){
            int k=i;
            while(a[i]==a[k] and i<a.length()){
                ++i;
            }
            --i;
            if(i==a.length()-1 and k==0){
                cout<<(a.length()*as)/2;
                return 0;

            }
        }
        int k=a.length()-1;
        while(a[k]==a.back() and k>=0){
            --k;
        }
        ++k;
        k=a.length()-k;
        int z=0;
        while(a[z]==a[0] and z<a.length()){
            z++;
        }
        ans+=(as-1)*((k+z)/2);
        ans+=(z/2)+(k/2);
        for(int i=z;i<a.length()-k;i++){
            int m=i;

            while(a[i]==a[m]){
                ++i;
            }
            --i;
            ans+=as*((i-m+1)/2);            
        }
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 998244353;
string &operator&=(string &lhs, const string &rhs) {
    for (int i = 0; i < (int)lhs.size(); ++i)
        if (rhs[i] == '0')
            lhs[i] = '0';
    return lhs;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    unordered_map<string, int> f;
    function<int(const string &)> solve = [&](const string &s) {
        if (s.empty())
            return 1;
        if (f.count(s))
            return f[s];
        int n = (int)s.length();
        int result = (s[0] - '0' + 1) * solve(s.substr(1)) % P;
        for (int len = 1; 2 * len <= n; ++len) {
            string t = s.substr(0, len);
            for (int k = 2; k * len <= n; ++k) {
                t &= s.substr((k - 1) * len, len);
                result = (result + 1LL * solve(t) * solve(s.substr(k * len))) % P;
            }
        }
        return f[s] = result;
    };
    cout << solve(s) << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int n;
int num[100005];
ll foo[100005];
int aa[100005];

ll p (ll x, ll a) {
  ll res = 1;
  while(a) {
    if(a & 1) res = res * x % mod;

    x = x * x  % mod;

    a >>= 1;
  }

  return res % mod;
}

ll r_f(ll f) {
  return p(f,mod-2);
}

ll nCr(int n, int r) {
  if(n-r < 0 || r < 0) return 0;
  return foo[n] * (r_f(foo[r]) * r_f(foo[n-r]) % mod) % mod;
}

int main() {
    cin >> n;
    int l,r;
  for(int i = 1; i <= n+1; i++) {
    cin >> aa[i];
    if(num[aa[i]]) {
      r = i; l = num[aa[i]];
    }
      else  num[aa[i]] = i;
  }
  
  foo[0] = 1;
  for(int i = 1; i <= n+1; i++) foo[i] = foo[i-1] * i % mod;
 

  for(int i = 1; i <= n+1; i++) {
    cout << (nCr(n+1,i) - nCr(l+n-r,i-1) + mod) % mod <<endl;
  }
}
  
  


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  string s;
  cin >> s;
  if(s[0]=='S') cout << "Cloudy" << endl;
  else if(s[0]=='C') cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int r, g, b, n, ans = 0;
	cin >> r >> g >> b >> n;
	for(int i = 0; i <= n; i += r)
		for(int j = 0; j + i <= n; j += g) {
			if((n - j - i) % b == 0) {
				++ans;
			}
		}
	cout << ans << endl;

}


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

#define ll long long


int main(){
	
	ios::sync_with_stdio(0) ;
	cin.tie(0) ;
	
	ll g=10000;
	int n, i;
	int ans;
	
	cin >> n;
	
	for( i=n; i<=g; ++i){
		if(i%1000==0)
		break;
	}
	
	ans = i-n;
	
	cout << ans;

	
}

Measured memory_bytes: 3648
#include <stdio.h>
 
#define N 100
 
main(){
  int i,j,v,n,A[N];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
 
  }
  printf("%d",A[n-1]);
  printf("\n");
   
  for(i=1;i<n;i++){
    v = A[i];
    j = i-1;
     
    while(j >= 0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(j=0;j<n-1;j++){
      printf("%d ",A[j]);
    }
    printf("%d", A[n-1]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1816
n,k = map(int,input().split())
mod = 10**9+7

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

max_sum = 0
min_sum = 0
ans = 0
for i in range(n+1):
    max_sum += l[n-i]
    min_sum += l[i]
    if i+1 < k:
        continue
    
    else:
        ans += (max_sum - min_sum + 1)
        ans %= mod

print(ans)

Measured memory_bytes: 78880
#include<cstdio>
int main()
{
    int n,zero,five,am;
    while(1)
    {
        scanf("%d",&n);
        if(n==0)break;
        zero=0;
        five=1;
        while(1)
        {
            five*=5;
            am=n/five;
            zero+=am;
            if(five>n)break;
        }
        printf("%d\n",zero);
    }
    return 0;
}

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

int main(){
string a;
cin >> a;
int count;
  if(a == "RRR"){ 
    cout << 3 << endl;
  }
  else if(a == "RRS" || a == "SRR"){
    cout << 2 << endl;
  }
  else if(a == "SSS"){
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll a, b, c, d;
	cin >>  a >> b >> c >> d;
	cout << min(a, b) + min(c, d);
	return 0;
}

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

int main(){
  int n, m, c; cin >> n >> m >> c;
  vector<int> b(m);
  for(int i = 0; i < m; i++){
    cin >> b.at(i);
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    int tmp = 0;
    for(int j = 0; j < m; j++){
      int a; cin >> a;
      tmp += a * b.at(j);
    }
    if(tmp + c > 0) ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int n = 0, m;
  for(int i = min(A, B); i >= 1; i--){
    if(A%i == 0 && B%i == 0){
      n++;
      m = i;
      if(n == C) break;
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();

        for (int i = 1; i < s.Length; i++)
        {
            if (s[i] == s[i - 1])
            {
                Console.WriteLine("Bad");
                return;
            }
        }

        Console.WriteLine("Good");
    }
}


Measured memory_bytes: 11092
N = int(input())

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

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

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

    return arr


f = factorization(N)
total = 0
for c in f:
    if c[0] == 1:
        continue
    target = c[1]
    cnt = 0
    for i in range(1, c[1] + 1):
        target -= i
        if target < 0:
            break
        cnt += 1
    total += cnt

print(total)

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }

  int count = 0;
  for (int i = 1; i < N - 1; i++) {
      if (p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)) {
        count++;
      } else if (p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1)) {
        count++;
      }
  }

  cout << count << endl;
}

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

int N;
int count = 0;
int S[500001];

void merge(int l, int m, int r){
    int n1 = m - l + 1;
    int n2 = r - m;
    int l_arr[n1], r_arr[n2];

    for (int i = 0; i < n1; i++){
        l_arr[i] = S[l + i];
    }

    for (int i = 0; i < n2; i++)
    {
        r_arr[i] = S[i + m + 1];
    }

    int i = 0;
    int j = 0;
    int k = l;

    while (i < n1 && j < n2)
    {
        count++;
        if (l_arr[i] <= r_arr[j])
        {
            S[k] = l_arr[i];
            i++;
        }
        else
        {
            S[k] = r_arr[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        count++;
        S[k] = l_arr[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        count++;
        S[k] = r_arr[j];
        j++;
        k++;
    }
}

void merge_sort(int l, int r){
    if (l < r){
        int mid = (l + r - 1) / 2;
        merge_sort(l, mid);
        merge_sort(mid + 1, r);
        merge(l, mid, r);
    }
}


//提出時には消す
#include <fstream>

int main()
{
    //提出時には消す
    // std::ifstream in("/home/ubuntu/procon_cpp/input.txt");
    // cin.rdbuf(in.rdbuf());

    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        cin >> S[i];
    }

    merge_sort(0, N-1);

    for (int i = 0; i < N; i++)
    {
        if(i == N -1 ) { 
            printf("%d", S[i]); 
        }else{
            printf("%d ", S[i]);
        }
    }
    printf("\n");
    printf("%d", count);
    printf("\n");

    return 0;
}


Measured memory_bytes: 7024
#include<stdio.h>
int substring(char a[],char b[]){
int i=0,j=0;
for(i=0;b[i];i++){}int len=i;i=0;
while(a[i]){j=0;while(a[i]==b[j]){i++;j++;}if(j==len){return 1;}i++;}
return 0;
}

int main()
{
    int i,j;
    char a[200],b[200],c[300];
    gets(a);
    gets(b);for(i=0;a[i];i++){}int len=i;i=0;
    for(i=0;i<len;i++){
       {c[i]=a[i];}
        }
        j=0;
        for(;i<len*2;i++){
       {c[i]=a[j];j++;}
        }
    c[i]='\0';int k=substring(c,b);
        if(k==1){printf("Yes\n");}
        else{printf("No\n");}


    return 0;
}



Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
count = 0

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            count += 1
    else:
        count += 1

if count == n:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 38256
table :: [String] -> [(Char, Char)]
table [] = []
table (x:xs) =
  let n = words x
      e = ( ((n!!0)!!0), ((n!!1)!!0) )
  in
    e:(table xs)

conv :: [(Char,Char)] -> Char -> Char
conv [] c = c
conv (t:ts) c
  | (fst t) == c = (snd t)
  | otherwise    = conv ts c

play:: [String] -> [String]
play [] = []
play ("":_) = []
play ("0":_) = []
play lines =
  let s  = read (lines!!0) :: Int
      l1 = drop 1 lines
      t  = table $ take s l1
      l2 = drop s l1
      n  = read (l2!!0) :: Int
      l3 = drop 1 l2
      i = concat $ take n l3
      o  = map (conv t) i
      l4 = drop n l3
  in
    (o:(play l4))

main = do
  c <- getContents
  let c' = filter (/='\r') c
  let o  = play $ lines c'
  mapM_ (putStrLn) o

Measured memory_bytes: 14320
#include <iostream>
 
using namespace std;
 
int main() {
string a,b,c;
 
cin>>a>>b>>c;
 
if((a[a.length()-1]==b[0]) && (b[b.length()-1]==c[0])){cout<<"YES";return 0;}
else {cout<<"NO";}
 
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>

using namespace std;

vector<vector<long long>> mem(1, vector<long long>(1, 0));
//unordered_map<pair<int, int>, long long> mem;
long long w[105];
long long v[105];
int N;
int W;

long long dp2(int i, int curWeight) {
    if (mem[i][curWeight]) {
        return mem[i][curWeight];
    }

    long long val = 0;

    if (w[i] + curWeight <= W && i < N)
        val = dp2(i + 1, curWeight + w[i]) + v[i];
    if (i < N)
        val = max(val, dp2(i + 1, curWeight));
    else
        val = 0;

    mem[i][curWeight] = val;
    return val;
}

void solve()
{
    cin >> N;
    cin >> W;

    vector<long long> dp(100005, 0);
    
    for (int i = 0; i < N; ++i)
    {
        cin >> w[i] >> v[i];
    }

    long long cw = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = W - w[i]; j >= 0; --j) {
            if (dp[j] + v[i] > dp[j + w[i]])
                dp[j + w[i]] = dp[j] + v[i];
        }
    }

    cout << dp[W] << endl;
}

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}


Measured memory_bytes: 3960
import java.util.Scanner;

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

Measured memory_bytes: 23124
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

#素因数分解
def prime_factorize(n):
    a = []
    a.append(1)
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    
    b = [[],[]]
    cnt = 1
    for i in range(len(a)+1):
        if i > 0 and i < len(a):
            if a[i] == a[i-1]:
                cnt += 1
            else:
                b[0].append(a[i-1])
                b[1].append(cnt)
                cnt = 1
        if i == len(a) and i > 0:
            b[0].append(a[i-1])
            b[1].append(cnt)
        elif i == len(a) and i == 0:
            b[0].append(a[i])
            b[1].append(cnt)
    return b

n = INT()
a = prime_factorize(n)
ans = 0
for i in range(1, len(a[0])):
    #print(a[i][1], int(sqrt(1 + 8 * a[1][i]) - 1) // 2)
    ans += int(sqrt(1 + 8 * a[1][i]) - 1) // 2
print(ans)


Measured memory_bytes: 68560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fir first
#define sec second
#define MOD 1000000007
#define vvi vector<vector<int> >
#define vvs vector<vector<string> >
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define pb push_back
#define vi vector<int>
#define test(t) int t; cin>>t; while(t--)
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vvl vector<vl>
#define loopin(i, n) for(int i = 0; i < (n); i++)
#define loopdec(i, n) for(int i = n-1; i >= 0; i--)
const int mod=1e9+7;


void solve() {
   int n;
   cin>>n;
   int a[n+1][10];
   for(int i=0;i<n;i++){
     cin>>a[i][0];
     cin>>a[i][1];
   }
   int count=0;
   for(int i=0;i<n;i++){
     if(a[i][0]==a[i][1]){
        count++;
     }else{
        count=0;
    }
    if(count>=3){
       cout<<"Yes"<<endl;
       return;
    }
  }
  cout<<"No"<<endl;



    }


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

   solve();

   

return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	int a, b;
	cin >> a >> b;
	vector<pr> s(a), g(b);
	rep(i, a) {
		cin >> s[i].first >> s[i].second;
	}
	rep(i, b) {
		cin >> g[i].first >> g[i].second;
	}
	rep(i, a) {
		int ans = 0,sub=inf;
		repd(j, b) {
			if (sub>=abs(s[i].first-g[j-1].first)+abs(s[i].second-g[j-1].second)) {
				ans = j;
				sub = abs(s[i].first - g[j - 1].first) + abs(s[i].second - g[j - 1].second);
			}
		}
		cout << ans << endl;
	}
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}

int main(){
  int n;
  cin >> n;
  vector<ll> sum(n+1,0);
  rep(i,n){
    ll a;
    cin >> a;
    sum.at(i+1)=sum.at(i)+a;
  }
  map<ll,ll> m;
  rep(i,n+1){
    if(m.count(sum.at(i)))m[sum.at(i)]++;
    else m[sum.at(i)]=1;
  }
  ll ans=0;
  for(auto i:m)
    ans+=i.second*(i.second-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
	ll n, m;
	cin >> n >> m;
	ll N = 1<<n;

	vl v(m);  // v[i] : 鍵iの空けられる宝箱の集合
	vl cost(m);  // cost[i] : 鍵iのコスト
	rep(i, m) {
		ll b;
		cin >> cost[i] >> b;
		ll s1 = 0;
		rep(j, b) {
			ll c;
			cin >> c;
			c--;
			s1 |= 1<<c;
		}
		v[i] = s1;
	}

	vvl dp(m+1, vl(N, INF));  // dp[i+1][s] : 鍵iまでで宝箱の状態をsにするときのコストの最小値
	dp[0][0] = 0;
	rep(i, m) {
		rep(s, N) {
			chmin(dp[i+1][s], dp[i][s]);
			chmin(dp[i+1][s | v[i]], dp[i][s] + cost[i]);
		}
	}

	if(dp[m][N-1] == INF) {
		out(-1);
	}
	else {
		out(dp[m][N-1]);
	}
    
	re0;
}

Measured memory_bytes: 32384
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(long long (i)=0, i_N=(n); (i)<i_N; (i)++)
using namespace std;
using ll = long long;
template<typename T> ostream& operator<< (ostream& s, vector<T> P){
    for(int i=0; i<P.size(); i++){if(i){s<<" ";} cout<<P[i];} return s;
}
int main(){
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i, N) cin>>A[i];
    sort(A.begin(), A.end());
    ll l = A[0]; 
    ll r = A[0]; 
    ll cnt = 1;
    ll i=1, j=N-1;
    ll res = 0;
    while(i<N and j>=0 and cnt<N){
        ll lcost = max(abs(A[i]-l), abs(A[i]-r));
        ll rcost = max(abs(A[j]-l), abs(A[j]-r));
        if(lcost>rcost){
            res += lcost;
            if(abs(A[i]-l) > abs(A[i]-r)) l = A[i];
            else r = A[i];
            i++;
            cnt++;
        }
        else{
            res += rcost;
            if(abs(A[j]-l) > abs(A[j]-r)) l = A[j];
            else r = A[j];
            j--;
            cnt++;
        }
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0;i < n; i++)

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    rep(i, 2){
        if(a > b){
            cnt += a;
            a--;
        }else{
            cnt += b;
            b--;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 10;
char s[N]; int c[30];
int main() {
	scanf("%s",s+1);
	for(int i=1;s[i];i++) c[s[i]-'a']++;
	LL n=strlen(s+1);
	LL tot=n*(n-1)/2;
	for(int i=0;i<26;i++){
		tot=tot-1LL*c[i]*(c[i]-1)/2;
	}
	tot++;
	cout<<tot<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    string s;
    cin>>s;
    s=s+"S";
    int cnt=0,maxi=INT_MIN;
    for (int i=0;i<s.length();i++)
    {
        if (s.at(i)=='R')
        cnt++;
        else
        {
            maxi=max(maxi,cnt);
            cnt=0;
        }
    }
    printf("%d\n",maxi);
    return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for(ll i=0;i<n;i++) cin >> s[i];
  ll ans=0;
  priority_queue<pll> mpq;
  priority_queue<pll> mmq;
  for(ll i=0;i<n;i++) {
    ll tmp=0;
    ll mi=0;
    for(ll j=0;j<s[i].size();j++) {
      if(s[i][j]=='(') tmp++;
      if(s[i][j]==')') tmp--;
      mi=min(tmp,mi);
    }
    if(mi==0) ans+=tmp;
    else if(tmp>=0) {
      mpq.push({mi,tmp});
    }
    else {
      mmq.push({tmp-mi,tmp});
    }
  }
  while(mpq.size()) {
    ll mi=mpq.top().first;
    ll tmp=mpq.top().second;
    mpq.pop();
    if(ans+mi<0) {
      cout << "No" << endl;
      return 0;
    }
    ans+=tmp;
  }
  while(mmq.size()) {
    ll tmp=mmq.top().second;
    ll mi=-mmq.top().first+tmp;
    mmq.pop();
    if(ans+mi<0) {
      cout << "No" << endl;
      return 0;
    }
    ans+=tmp;
  }
  if(ans==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 42844
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll int arr[200005];

int main(){
    ll int j ,i ,m , n , sum = 0;
    cin >> m >> n;
    if(n >= m)
    {
        while(m--) cin >> n;
        cout << 0 << endl;
        exit(0);
    }
    for(i = 0 ; i < m ; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    if(!n)
    {
        cout << sum << endl;
        exit(0);
    }
    sort(arr , arr + i);
    for(j = 0 ; j <= n ; j++ , i--) sum -= arr[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int[] A = new int[n];
   for(int i = 0;i < n;i++) A[i] = sc.nextInt();

   int p = 0;
   int r = n - 1;
   int x = A[r];
   int i = p - 1;
   int tmp,tmp2;
   for(int j = p;j < r;j++){
     if(A[j] <= x){
      i++; 
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }    
   }
   tmp2 = A[i + 1];
   A[i + 1] = A[r];
   A[r] = tmp2;
   int par = i + 1; 
   for(int j = 0;j < n;j++){
    if(j == par) System.out.print("["+A[j]+"]");
    else System.out.print(A[j]);
    if(j != n - 1) System.out.print(" ");
   }
   System.out.println();
  }
}


Measured memory_bytes: 69760
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
int c[100],a[100][100],b[100];
int main()
{
	int n,m,x;
	sc(n);sc(m);sc(x);
	rep(i,1,n){
		sc(c[i]);rep(j,1,m)sc(a[i][j]);
	}int minn=1e9;
	rep(i,1,((1<<n)-1)){
		int beg=1,u=i;
		while(u){
			b[beg++]=u%2;u/=2;
		}int biaoji=0;
		rep(j,1,m){
			int cou=0;
			rep(k,1,beg-1){
				if(b[k]==1){
					cou+=a[k][j];
				}
			}if(cou<x){
				biaoji=1;break;
			}
		}if(biaoji==1)continue;
		int count=0;
		rep(j,1,beg-1){
			if(b[j]==1){
				count+=c[j];
			}b[j]=0;
		}minn=min(minn,count);
	}if(minn==1e9){
		pf("-1\n");
	}else pf("%d\n",minn);
}


Measured memory_bytes: 3824
//package abc175;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] ip = br.readLine().split(" ");
		
		long X = Long.parseLong(ip[0]);
		long K = Long.parseLong(ip[1]);
		long D = Long.parseLong(ip[2]);
		
		long ans = 0;
		
		if(X > 0) {
			long tmp_k = Math.min(K, Math.abs(X)/D + 1);
			K -= tmp_k;
			X -= tmp_k*D;
		}else {
			long tmp_k = Math.min(K, Math.abs(X)/D + 1);
			K -= tmp_k;
			X += tmp_k*D;
		}
		ans = Math.abs(X);
		if(K > 0) {
			if(K%2 == 1) {
				if(X > 0) {
					ans = Math.abs(X-D);
				}else {
					ans = Math.abs(X+D);
				}
			}
		}
		
		System.out.println(ans);
	}
	
}


Measured memory_bytes: 32692
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])


Measured memory_bytes: 32232
id division.
  program-id. abc169c.

data division.
  working-storage section.
  77 ab   pic x(21).
  77 a    pic 9(16).
  77 b    pic 9v99   usage packed-decimal.
  77 ans  pic z(16)9.

procedure division.
  accept ab.
  unstring ab delimited by space into a b.
  compute ans = (b * 100) * a / 100.
  display ans.
  stop run.


Measured memory_bytes: 3944
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

int main(void)
{
    char s[201],t[101],i,n,ans=0;

    scanf("%s",s);
    scanf("%s",t);

    n=strlen(s);

    for ( i = 0; i < n; i++)
    {
        s[n+i]=s[i];
    }

    for ( i = 0; i < n; i++)
    {
        if(strncmp(s+i,t,n)==0) ans=1;
    }

    if(ans==1) printf("Yes");
    else printf("No");

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  string s;
  int cnt=0;
  cin >> s;

  for(int i=0; i<6; i++){
    if(s[i]=='1'){
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 764
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300;
const int MAX_M = 300;

/* typedef */

/* global variables */

int cs[MAX_N], vs[MAX_N], ds[MAX_N], ls[MAX_N];
int dp[2][MAX_M + 1];

/* subroutines */

int n_knapsak(int n, int m, int *cs, int *vs) {
  for (int i = 0; i <= m; i++) dp[0][i] = -1;
  dp[0][0] = 0;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) dp[nxt][j] = dp[cur][j];

    int ci = cs[i], c = ci;
    int vi = vs[i], v = vi;

    while (c <= m) {
      int max_j = m - c;
      for (int j = 0; j <= max_j; j++)
	if (dp[cur][j] >= 0) {
	  int d = dp[cur][j] + v;
	  if (dp[nxt][j + c] < d) dp[nxt][j + c] = d;
	}
      c += ci;
      v += vi;
    }

    cur ^= 1;
    nxt ^= 1;
  }

  int max_d = 0;
  for (int i = 0; i <= m; i++)
    if (max_d < dp[cur][i]) max_d = dp[cur][i];
  
  return max_d;
}

/* main */

int main() {
  for (;;) {
    int n, m;
    cin >> n >> m;
    if (cin.eof()) break;

    for (int i = 0; i < n; i++) {
      while (cin.get() != '\n');
      while (cin.get() != '\n');
      cin >> cs[i] >> vs[i] >> ds[i] >> ls[i];
      //printf("%d %d %d %d\n", cs[i], vs[i], ds[i], ls[i]);
    }

    int nk_v = n_knapsak(n, m, cs, vs);
    int nk_d = n_knapsak(n, m, cs, ds);
    int nk_l = n_knapsak(n, m, cs, ls);

    int max_nk = 0;
    if (max_nk < nk_v) max_nk = nk_v;
    if (max_nk < nk_d) max_nk = nk_d;
    if (max_nk < nk_l) max_nk = nk_l;

    cout << max_nk << endl;
  }

  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    cin >> A >> B;
    map<int, int> mpa, mpb;
    rep(i,N){
        mpa[A[i]]++;
        mpb[B[i]]++;
    }
    for(int i = 1; i <= N; i++){
        ll cnta = mpa[i];
        ll cntb = mpb[i];
        if(cnta + cntb > N){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    reverse(all(B));
    int idx = 0;
    rep(i,N){
        if(A[i] == B[i]){
            while(B[idx] == B[i] || A[idx] == B[i]){
                idx++;
                idx %= N;
            }
            swap(B[i], B[idx]);
        }
    }
    rep(i,N){
        cout << B[i] << " ";
    }
    cout << endl;
}


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

using namespace std;
#define ll long long
#define ld long double

#define endl '\n'
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}
//__builtin_popcount ();
struct def
{
    string h = ">";
};
int main()
{
    FAST int n;
    cin >> n;
    int arr[n];
    
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

   map<int,bool> m;
   int ans=0,dub=0;
   for(int i=0;i<n;i++)
   {
       if(!m[arr[i]])
       {
           ans++;
           m[arr[i]]=1;
       }
       else
dub++;
   }
if(dub%2==1)
cout<<ans-1<<endl;
else
cout<<ans<<endl;

        return 0;
}

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

int main() {
  int n,n1,s=0;
  cin >> n;
  n1=n;
  while(n>0){
    s += n - (n/10)*10;
    n /= 10;
  }
  if(n1 == (n1/s)*s) {
    cout << "Yes";
  }
  else{
    cout <<"No";
  }
}
  
      


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

int main(){
    int k; 
    string s;
    cin>>k;
    cin>>s;
    if(s.size()<=k)
        cout<<s<<endl;
    else{
        for(int i=0; i<k; i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}

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

using namespace std;

#define all(v)   v.begin(), v.end()
#define pb       push_back
#define sz(x)    (int) (x.size())
#define endl "\n"
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


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

    ll n; cin >> n;
    int m = n/1000 + (n%1000 != 0);
    cout << m*1000 - n;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=105;
//i_am_noob
int n,a[10],k=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i];
	sort(a,a+n);
	rep(n-1) k+=a[i];
	print1(k>a[n-1]?"Yes":"No");
	return 0;
}


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

int main() {

    int a,b,c;
    cin >> a >> b >> c;

    bool can = false;
    for(int i = 1; i < b + 1;i++){
        if(a * i % b == c) can = true;
    }
    
    if(can){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    } 

}

Measured memory_bytes: 256
a, b, x = map(int, input().split())

if x >= a**2*b/2:
    t = 2*(b*a**2-x)/(a**3)
else:
    t = (a*b**2)/(2*x)

import math
p = math.atan(t)
p = math.degrees(p)
print(p)


Measured memory_bytes: 62204
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        p: [(usize, u32); n],
    }
    let mut p = p;
    p.sort();
    let mut ans = 0;
    let mut h = std::collections::BinaryHeap::new();
    let mut i = 0;
    for j in 1..(m + 1) {
        while i < n && p[i].0 <= j {
            h.push(p[i].1);
            i += 1;
        }
        if let Some(v) = h.pop() {
            ans += v;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main() {
  int N, M, A;
  cin >> N >> M;
  int h = 0;
  for (int i = 0; i < M; i++){
    cin >> A;
    h += A;
  }
  if (N >= h)
    cout << N - h << endl;
  else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
set<int>s;
int num[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i<n;i++)
        scanf("%d",&num[i]);
    for(int i = 0;i<n;++i)
    {
        if(s.find(num[i])!=s.end())
        {
            printf("NO\n");
            return  0;
        }
        s.insert(num[i]);
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 10368
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 100005;

int n;
LL a[MaxN + 5], b[MaxN + 5];

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		LL MIN = 2, MAX = 2;
		for(int i = n; i >= 1; i--) {
			if(MIN % a[i] != 0) MIN = a[i] * (MIN / a[i] + 1);
			else MIN = a[i] * (MIN / a[i]);
			MAX = a[i] * (MAX / a[i] + 1) - 1;
		}
		if(MIN > MAX) printf("-1\n");
		else printf("%lld %lld\n", MIN, MAX);
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> res;  /* 入力番号、　誕生順 */

    vector<pair<int, int>> src[n];
    int prefe[m];
    for (int i = 0; i < m; i++) {
	int a, b;
	cin >> a >> b;
	src[a - 1].push_back(make_pair(b, i)); /* 誕生年、　入力番号 */
	prefe[i] = a;
    }

    for (int i = 0; i < n; i++)
	sort(src[i].begin(), src[i].end());
    
    for (int i = 0; i < n; i++) {
	int num = 1;
	for (int j = 0; j < src[i].size(); j++) {
	    res.push_back(make_pair(src[i][j].second, num++));
	}
    }
    
    sort(res.begin(), res.end());
	
    for (int i = 0; i < m; i++) {
	cout << setw(6) << setfill('0') << prefe[i];
	cout << setw(6) << setfill('0') << res[i].second << endl;
    }

    return 0;
}


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

int main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  vector<ll> t(200005, 0);
  rep(i, n) {
    t[a[i]]++;
  }
  ll sum = 0;
  rep(i, 200005) {
    sum += (t[i]*(t[i]-1))/2;
  }
  rep(i, n) {
    ll ans = sum - (t[a[i]]*(t[a[i]]-1))/2 + ((t[a[i]]-1)*(t[a[i]]-2))/2;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define NMAX 7003
using namespace std;
int N, Q;
string s;
pair <char, char> Que[200007];
int fall(int x) {
    if (x < 0) return -1;
    if (x >= N) return 1;
    for (int i = 0; i < Q; ++i) {
        if (s[x] == Que[i].first) {
            if (Que[i].second == 'L')
                --x;
            else ++x;
        }
        if (x < 0) return -1;
        if (x >= N) return 1;
    }
    return 0;
}
int srch(int left , int right, int type) {
    int mid, sol;
    while (left <= right) {
        mid = (left + right) / 2;
        int x = fall(mid); // -1 L 0 STAY 1 R
        if (x == 1) {
            right = mid - 1;
        }
        else if (x == -1) {
            left = mid + 1;
        }
        else {
            if (type == 1) left = mid + 1;
            else right = mid - 1;
        }
        if (type == x)
            sol = mid;
    }
    return sol;
}
int main() {
    cin >> N >> Q;
    cin >> s;
    for (int i = 0; i < Q; ++i) {
        char t, d;
        cin >> t >> d;
        Que[i] = mp(t, d);
    }
    cout << N - (srch(-1, N, -1) + 1 + N - srch(0, N, 1));
    return 0;
}


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

using namespace std;

int main()
{
    string s ;
    cin>>s ;
    stack<char>s2 ;
    for(int i = 0 ; i < s.size() ; ++i)
    {
        if(s2.size() == 0)
            s2.push(s[i]) ;
        else if(s[i] != s2.top())
            s2.pop();
        else
            s2.push(s[i]) ;
    }
    return cout<<s.size() - s2.size()<<"\n" , 0 ;
}


Measured memory_bytes: 512
#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 <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
//#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect 

const int N = 10000;

bitset<N> ask[6];
map <pi, int> numx;

void calc_dp(string s, string t, int num) {
    for (int i = 0; i < N; ++i)
        ask[num][i] = (i >= s.size());
    bool dp[s.size() + 1][t.size() + 1];
    loop(i, s.size() + 1)
        loop(j, t.size() + 1)
            dp[i][j] = (j == 0);
    loop1(i, s.size())
        loop1(j, t.size()) {
            dp[i][j] = (dp[i - 1][j - 1] && (s[i - 1] == t[j - 1] || s[i - 1] == '?' || t[j - 1] == '?'));
            if (dp[i][j] && j == t.size()) 
                ask[num][i - j] = 1;
        }
    for (int i = t.size(); i >= 0; --i)
        if (dp[s.size()][i]) 
            ask[num][s.size() - i] = 1;
}

void solve() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int ans = s[0].size() + s[1].size() + s[2].size(), cnt = 0;
    loop(a, 3)
        loop(b, 3) {
            if (a == b) continue;
            numx[{a, b}] = cnt;
            calc_dp(s[a], s[b], cnt++);
        }
    loop(a, 3)
        loop(b, 3)
            loop(c, 3) {
                if (a == b || a == c || b == c) continue;
                loop(i, s[a].size() + 1)
                    loop(j, s[a].size() + s[b].size() + 1)
                        if (ask[numx[{a, b}]][i] && ask[numx[{b, c}]][j] && ask[numx[{a, c}]][i + j])
                            ans = min(ans, 
                                max({(int)s[a].size(), (int)s[b].size() + i, (int)s[c].size() + i + j}));    
            }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (x % y == 0) return y;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x * y / GCD(x, y);}
//cout << fixed << setprecision(10);

/*
ll fac(ll x){
  if(x==0) return 1;
return x*fac(x-1);
}

ll comb(ll x,ll y){
  if(x==y) return 1;
  else if(y==0) return 1;
  else if(y==1) return x;
 else return comb(x-1,y-1)+comb(x-1,y);
}
*/

int main(){
 ll n; cin>>n;
  vector<double>v(n);
  rep(i,n) cin>>v[i];
  sort(all(v));
  double t=MMM;
  ll ans,s=v[n-1];
  rep(i,n-1){
    if(t>abs(v[n-1]/2.0-v[i])){
      t=abs(v[n-1]/2.0-v[i]); ans=v[i];
    }
    }
  
  cout<<s<<" "<<ans<<endl;
}

Measured memory_bytes: 1024