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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int N = 5e3 + 10;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

int n, k;

LL p[N], c[N];
LL sum[N], cnt[N];
bool vis[N];

LL func(int pos)
{
    LL t = k;
    LL ret = 0;

    if (t > 10 * cnt[pos])
    {
        if (sum[pos] > 0)
        {
            LL d = t / cnt[pos];
            assert(d >= 10);
            d -= 10;
            ret += d * sum[pos];
            t -= cnt[pos] * d;
        }
        else
            t = cnt[pos];
    }

    // if (sum[pos] > 0)
    //{
    // ret += t / cnt[pos] * sum[pos];
    // t = t % cnt[pos];
    //}
    // else
    //{
    // t = t % cnt[pos];
    // if (t == 0) t = cnt[pos];
    //}

    // if (t == 0) return ret;

    int cur = pos;
    LL val = c[p[cur]];
    cur = p[cur];

    LL v = val;
    for (int i = 2; i <= t; i++)
    {
        int nxt = p[cur];
        v += c[nxt];
        val = max(val, v);
        cur = nxt;
    }
    ret += val;

    return ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; ++i) cin >> p[i];
        for (int i = 1; i <= n; ++i) cin >> c[i];

        clr(vis, false);
        for (int i = 1; i <= n; i++)
        {
            if (vis[i] == true) continue;

            set<int> st;
            LL cur = i;
            LL v = c[p[cur]];
            st.insert(p[cur]);

            cur = p[cur];

            for (int a = 2; a <= 2 * n; a++)
            {
                int nxt = p[cur];
                if (st.find(nxt) != st.end())
                {
                    break;
                }
                assert(a < n + 1);
                v += c[nxt];
                st.insert(nxt);
                cur = nxt;
            }

            for (auto idx : st)
            {
                vis[idx] = true;
                cnt[idx] = st.size();
                sum[idx] = v;
            }
        }

        LL ans = func(1);
        for (int i = 2; i <= n; i++)
        {
            LL v = func(i);
            ans = max(ans, v);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4016
A=["k","e","y","e","n","c","e"]
f=-1;p=0
S=list(map(str,input()))
if S[0:7]==A or S[len(S)-7:len(S)]==A:
  f=1
else:
  if S[0]!=A[0]:
    f=0
  else:    
    for i in range(len(S)):
      if S[i]==A[i]:
        p=p+1
      else:
        if A[0:p]+S[len(S)-(len(A)-p):len(S)]==A:
          f=1
          break
        else:
          f=0
          break
print("YES" if f==1 else "NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define maxn 300100
using namespace std;
struct data{
	int l,r,len;
	data(){}
	data(int l,int r):l(l),r(r),len(r-l+1){}
	int operator<(const data& d)const{return len<d.len;}
}d[maxn];
int tr[maxn],n,m;
void add(int x,int a){for(;x<=m;x+=x&-x)tr[x]+=a;}
int qry(int x){int ans=0;for(;x;x-=x&-x)ans+=tr[x];return ans;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&d[i].l,&d[i].r),d[i].len=d[i].r-d[i].l+1;
	sort(d+1,d+n+1);
	for(int i=1,l=1;i<=m;++i){
		while(l<=n&&d[l].len<i)
			add(d[l].l,1),add(d[l].r+1,-1),l++;
		int ans=n-l+1;
		for(int j=i;j<=m;j+=i)
			ans+=qry(j);//,printf("[%d]",qry(j));
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 4864
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    VP p(m);
    REP(i,0,m) cin >> p[i].second >> p[i].first;
    sort(all(p));
    reverse(all(p));
    int index = 0;
    REP(i,0,m) {
        REP(j,0,p[i].second) {
            if (index >= n) break;
            a[index] = max(a[index], p[i].first);
            ++index;
        }
    }
    LL ans = 0;
    REP(i,0,n) ans += a[i];
    cout << ans << endl;
    //REP(i,0,n) dump(a[i]);
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,a[N],b[N];
struct line { int l=0,r=0,v=0; } c[N];
bool check(int mid) {
    int tot=0;
    for(int i=1;i<=n;i++) b[i]=a[i]>=mid;
    for(int i=1;i<n;i++)
        if(b[i]==b[i+1]) {
            c[++tot].l=i;
            while(i<n&&b[i]==b[i+1]) i++;
            c[tot].r=i;c[tot].v=b[i];
        }
    if(!tot) return b[1];
    c[0].r=0;
    for(int i=1;i<=tot;i++) {
        int l=c[i-1].r+1,r=c[i].l-1,m=(l+r)>>1;
        if(l<=r) c[i-1].r=m,c[i].l=m+1;
    }
    int l=c[tot].r+1,r=n,m=(l+r)>>1;
    if(l<=r) c[tot].r=m;
    for(int i=1;i<=tot;i++)
        if(c[i].l<=n/2+1&&n/2+1<=c[i].r) return c[i].v;
}
int main() {
    cin>>n;n=2*n-1;
    for(int i=1;i<=n;i++) a[i]=gi();
    int l=1,r=*max_element(a+1,a+n+1),ret=0;
    while(l<=r) {
        int mid=(l+r)>>1;
        if(check(mid)) ret=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ret);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
int N;
int A[MAX],can[MAX],memo[MAX];

void BFS(){
    queue<int> Q;
    priority_queue<pair<int,int>> PQ;
    
    for(int i=0;i<N;i++){
        if(A[i]==0){
            Q.push(i);
            can[i]=INF;
        }
    }
    
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        
        if(a&&A[a-1]>0&&can[a-1]==0){
            can[a-1]=INF;
            Q.push(a-1);
        }
        if(a&&A[a-1]<0&&can[a-1]==0){
            can[a-1]=-A[a-1];
            PQ.push({-A[a-1],a-1});
        }
        
        if(a<N-1&&A[a+1]>0&&can[a+1]==0){
            can[a+1]=INF;
            Q.push(a+1);
        }
        if(a<N-1&&A[a+1]<0&&can[a+1]==0){
            can[a+1]=-A[a+1];
            PQ.push({-A[a+1],a+1});
        }
    }
    
    while(!PQ.empty()){
        int a=PQ.top().first,b=PQ.top().second;
        PQ.pop();
        
        if(can[b]!=INF&&can[b]>a) continue;
        if(memo[b]>a) continue;
        
        a--;
        
        if(a<=0) continue;
        
        if(b&&(can[b-1]<a||(can[b-1]==INF&&memo[b-1]<a))){
            int x=a;
            if(A[b-1]<0) x=min(x,-A[b-1]);
            if(can[b-1]!=INF) can[b-1]=x;
            memo[b-1]=x;
            PQ.push({x,b-1});
        }
        if(b<N-1&&(can[b+1]<a||(can[b+1]==INF&&memo[b+1]<a))){
            int x=a;
            if(A[b+1]<0) x=min(x,-A[b+1]);
            if(can[b+1]!=INF) can[b+1]=x;
            memo[b+1]=x;
            PQ.push({x,b+1});
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=0;i<N;i++) cin>>A[i];
    
    BFS();
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        if(A[i]>0){
            ans+=max(min(A[i],can[i]),0);
        }
    }
    
    cout<<ans<<endl;
    
}




Measured memory_bytes: 4684
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int dp[2][5010];
vector<int> a;

int main(){
    int N, K; cin >> N >> K;

    ll s = 0;
    for(int i = 0; i < N; i++) {
        int b;
        cin >> b;
        a.push_back(b);
        s += b;
    }
    if(s < K){
        cout << N << endl;
        return 0;
    }
    sort(a.begin(), a.end());

    int l = -1, r = N-1;
    while(r - l > 1){
        int m = (r + l) / 2;
        int b = a[m];
        int res = 0;
        if(b >= K)  res = 1;
        fill(dp[0], dp[0]+5010, 0);
        fill(dp[1], dp[1]+5010, 0);
        dp[0][0] = 1; dp[1][0] = 1;

        int x = -1;
        for(int i = 0; i < N; i++){
            if(i == m)  continue;
            x++;
            for(int j = a[i]; j < K; j++){
                dp[x%2][j] = max(dp[(x+1)%2][j], dp[(x+1)%2][j-a[i]]);
                if(j >= K-b && dp[x%2][j] == 1){
                    res = 1;
                    break;
                }
            }
            if(res == 1){
                break;
            }
        }

        if(res == 1){
            r = m;
        }
        else{
            l = m;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner jk = new Scanner(System.in);
		int a = jk.nextInt();
		int b = jk.nextInt();
		ArrayList<Integer> arr = new ArrayList<Integer>();
		arr.add(a+b);
		arr.add(a-b);
		arr.add(a*b);
		System.out.println(Collections.max(arr));
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string s; cin >> s;
    int N = s.size();
    reverse(s.begin(), s.end());
    vector<ll> v(2019, 0);
    ll prev = 0;
    ll digit = 1;
    for (int i = 0; i < N; i++)
    {
        prev = (prev + digit * (s[i] - '0'))%2019;
        v[prev]++;
        digit = (digit * 10) % 2019;
    }

    ll ans = 0;
    for (int i = 0; i < 2019; i++)
    {
        ans += v[i] * (v[i] - 1) / 2;
        if(i==0) ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL k,q,n,x,m;
LL dd[5005],d[5005];

int main() {
	ios::sync_with_stdio(false);
	cin >> k >> q;
	for(LL i = 0;i < k;i ++) cin >> dd[i];
	
	while(q --){
		LL ans = 0,sd = 0;
		cin >> n >> x >> m; x %= m;
		for(LL i = 0;i < k;i ++){
			d[i] = dd[i] % m;
			sd += d[i];
		}
		LL td = (n - 1) / k;
		ans = n - 1; ans -= (x + sd * td) / m;
		for(LL i = 0;i < k;i ++) if(!d[i]) ans -= td;
		
		x = (x + sd * td) % m;
		for(LL i = 0;i < (n - 1) % k;i ++){
			if(!d[i]) ans --;
			else{
				x += d[i];
				if(x >= m){
					x -= m;
					ans --;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include <random>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include <unordered_map>
#include<numeric>
using namespace std;
#define ios std::ios_base::sync_with_stdio(false);
#define ll  long long
#define pb push_back
#define fi(ss) freopen (ss,"r",stdin)
#define fo(ss) freopen (ss,"w",stdout)
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
#define ld long double
#define lp(i,n) for(int i = 0 ; i < n ; ++i)
typedef pair<double,double> pii;
typedef pair<pii,int> tri;
using namespace std;
map<pair<string,string>,ll> mp;
vector<pair<string,string> > v;
string s;
int main() {
	ios
	int n;
	cin >> n;
	cin >> s;
	for (int msk = 0 ; msk < (1 << (n)) ; ++msk) {
		string a = "",b = "";
		for (int i = 0 ; i < n  ; ++i) {
			if (msk & (1 << i)) {
				a += s[i];
			} else {
				b += s[i];
			}
		}
		v.pb(make_pair(a,b));
	}
	for (int msk = 0 ; msk < (1 << (n)) ; ++msk) {
		string a = "",b = "";
		for (int i = 0 ; i < n ; ++i) {
			if (msk & (1 << i)) {
				a += s[i + n];
			} else {
				b += s[i + n];
			}
		}
		string t1 = a;
		string t2 = b;
		reverse(all(t1));
		reverse(all(t2));
		mp[make_pair(t1,t2)]++;
	}
	ll ans = 0;
	REP(i,v)  {
		ans += 1LL*mp[v[i]];
	}
	cout << ans << "\n";



}


Measured memory_bytes: 91116
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = 1;
		int i = 1;
		while (m <= n) {
			m = i*i;
			i ++;
		}
		
		System.out.println((i-2) * (i-2));
	}
	
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin >> h[i];

    int ans = 0;
    while(true){
        if(*max_element(h.begin(),h.end()) == 0){
            break;
        }
        int i = 0;
        while(i<n){
            if(h[i] == 0){
                i++;
            }
            else{
                ans++;
                while(i<n && h[i]>0){
                    h[i]--;
                    i++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int GCD(int,int);

int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  if(x>=y){
    printf("%d\n",GCD(x,y)); 
  }
  else printf("%d\n",GCD(y,x));
  return 0;
}
int GCD(int x,int y){
  if(!y)return x;
  x = x%y;
  GCD(y,x);
}



Measured memory_bytes: 2144
using System;

class Program
    {
        static void Main(string[] args)
        {
            int retu = 0, gyou = 0;//?????¨???
            int[,] objA;
            int[] objB;
            int[] anslist;
            int ans = 0;
            string[] getdata = Console.ReadLine().Split();

            retu = int.Parse(getdata[0]);
            gyou = int.Parse(getdata[1]);

            objA = new int[retu, gyou];
            objB = new int[gyou];
            anslist = new int[retu];

            //??£??\??????objA
            for(int x=0; x < retu; x++)
            {
                getdata = Console.ReadLine().Split();
                for(int y = 0; y < gyou; y++)
                {
                    objA[x,y] = int.Parse(getdata[y]);
                }

            }
            //??£??\??????objB
            for(int x=0; x < gyou; x++){
                objB[x] = int.Parse(Console.ReadLine());
            }

            //?¨??????????

                for (int x = 0; x < retu; x++)
                {
                    for (int y = 0; y < gyou; y++)
                    {
                        ans += (objA[x,y] * objB[y]);
                    }
                    anslist[x] = ans;
                    ans = 0;
                }
            //????????????
            foreach(int num in anslist)
            {
                Console.WriteLine(num);
            }
        }
    }

Measured memory_bytes: 9264
import itertools

N = int(input())
A = list(int(x) for x in input().split())

mod = 10**9+7

sum_ = 0
ans = 0

for i in range(N):
    ans += sum_ * A[i]
    ans %= mod
    sum_ += A[i]
    sum_ %= mod

print(ans)


Measured memory_bytes: 31628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int D;
  cin>>D;
  cout<<"Christmas";
  while(D!=25){
    D++;
    cout<<" Eve";
  }
  cout<<endl;
}

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

char maps[100][100];
bool check[100][100];
int h,w;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int nx,ny;
int co;

void bfs(int x,int y,char sym);
int main()
{
  while(1){
    cin >> h >> w;
    co=0;
    if(!h && !w)break;
    memset(check,false,sizeof(check));
    for(int i = 0;i < h;i++){
      cin >> maps[i];
    }
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	if(check[i][j] == false){
	  co++;
	  bfs(j,i,maps[i][j]);
	}
      }
    }
    cout << co << endl;
  }
}

void bfs(int x,int y,char sym)
{
  check[y][x] = true;
  for(int i = 0;i < 4;i++){
     nx = x+dx[i];
     ny = y+dy[i];
     if(check[ny][nx] == false && maps[ny][nx] == sym && ny < h && nx < w && ny >= 0 && nx >= 0){
      bfs(nx,ny,maps[ny][nx]);
    }
  }
  return ;
}

Measured memory_bytes: 1660
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
c = LI()
lst = [v[i]-c[i] for i in range(n)]
ans = 0
for i in range(n):
    if lst[i] >= 0:
        ans += lst[i]
print(ans)

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

int b = 1'000'000'007;
int h1 = 1'100'023'409;
int h2 = 1'200'017'417;
int h3 = 1'500'026'741;

long long modpow(long long x, long long y, long long p){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1, p) % p;
    return modpow(x, y / 2, p) * modpow(x, y / 2, p) % p;
}

void set_hash(string s, vector<vector<long long>> &hash){
    for (int i = 0; i < 3; i++) hash[i][0] = 0;
    for (int i = 0; i < s.size(); i++) hash[0][i + 1] = (hash[0][i] * b + s[i]) % h1;
    for (int i = 0; i < s.size(); i++) hash[1][i + 1] = (hash[1][i] * b + s[i]) % h2;
    for (int i = 0; i < s.size(); i++) hash[2][i + 1] = (hash[2][i] * b + s[i]) % h3;
}

vector<long long> hashs(3);

void get_hash(vector<vector<long long>> &hash_t, int &x, int &x_length){
    hashs[0] = (hash_t[0][x + x_length] - hash_t[0][x] * modpow(b, x_length, h1) % h1 + h1) % h1;
    hashs[1] = (hash_t[1][x + x_length] - hash_t[1][x] * modpow(b, x_length, h2) % h2 + h2) % h2;
    hashs[2] = (hash_t[2][x + x_length] - hash_t[2][x] * modpow(b, x_length, h3) % h3 + h3) % h3;
}

vector<vector<int>> finder(5'001);

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<long long>> hash_s(3, vector<long long>(n + 1));
    set_hash(s, hash_s);
    map<vector<long long>, int> mp;
    
    int ok = 0;
    int ng = n + 1;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        bool flag = false;
        int id = 1;
        for (int i = 0; i < 5001; i++) finder[i].erase(finder[i].begin(), finder[i].end());
        mp.erase(mp.begin(), mp.end());
        for (int i = 0; i < n; i++){
            if (mid + i > n) break;
            get_hash(hash_s, i, mid);
            if (mp[hashs]) {
                if (finder[mp[hashs]].front() + mid <= i) flag = true;
                finder[mp[hashs]].push_back(i);
            }
            else {
                mp[hashs] = id;
                finder[id].push_back(i);
                id++;
            }
        }
        if (flag) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[10001][10001];

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n; i++){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    a[y1][x1]++;
    a[y2][x1]--;
    a[y1][x2]--;
    a[y2][x2]++;
  }

  int ans = 0;
  for(int i = 0; i < 1000; i++){
    for(int j = 0; j < 1000; j++){
      if(i) a[i][j] += a[i-1][j];
      if(j) a[i][j] += a[i][j-1];
      if(i && j) a[i][j] -= a[i-1][j-1];
      ans = max(ans,a[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 14940
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int a, b; char c;
	cin >> a >> c >> b;
	cout << (c == '+' ? a + b : a - b) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long n,m,res,r,a,b,d,i;
    scanf("%lld %lld",&n,&m);
    {
    	if(n>m)
	    {
	        a=m;
	        b=n;
	    }
	    else
	    {
	        a=n;
	        b=m;
	    }
        while(a!=0)
        {
            res=b%a;
            b=a;
            a=res;
        }
        printf("%lld\n",b);
    }

    return 0;
}

Measured memory_bytes: 2752
using System;

class Program
{
    static void Main(string[] args)
    {
        int x;
        int cou = 1;

        while (true)
        {
            string num = Console.ReadLine();
            x = int.Parse(num);
            if (x == 0)
            {
                break;
            }
            Console.WriteLine("Case " + cou + ": " + x);
            cou++;
        }
    }
}


Measured memory_bytes: 9348
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int d[N];
#define pii pair<int,int>
#define mkp make_pair
deque<pii> Q;
int main()
{
	int n;cin>>n;
	Q.push_back(mkp(1,1));
	while(!Q.empty()){
		pii x=Q.front(); Q.pop_front();
		int w=x.first;
		if(d[w]) continue;
		d[w]=x.second;
		Q.push_front( mkp(w*10%n,d[w]) );
		Q.push_back( mkp((w+1)%n,d[w]+1) ); 
	}
	printf("%d",d[0]);
	return 0;
}

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

using namespace std;
typedef long long ll;
#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++)
#define MOD 1000000007

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    rep2(i, 1, n) {
        cnt += (n - 1) / i;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;

typedef complex<double> P;

int n,m;
double p[50];

double cal(int a,int b,int c){

  double res;

  P s=P(cos(p[a]),sin(p[a])),t=P(cos(p[b]),sin(p[b])),u=P(cos(p[c]),sin(p[c]));

  double aa=abs(s-t),bb=abs(t-u),cc=abs(u-s);
  double ss=(aa+bb+cc)/2;

  res=sqrt(ss*(ss-aa)*(ss-bb)*(ss-cc));

  return res;
}

int main(){


  while(cin>>n>>m,n){

    for(int i=0;i<n;i++){
      cin>>p[i];
      p[i]*=2*M_PI;
    }

  double dp[50][50][50]={};
  
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=2;k<m;k++)
	for(int l=j+1;l<n;l++){
	  dp[i][l][k+1]=max(dp[i][l][k+1],dp[i][j][k]+cal(i,j,l));
	}

  double ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)ans=max(ans,dp[i][j][m]);
  
  printf("%.6f\n",ans);
  
  }


  
  return 0;
}

Measured memory_bytes: 4572
#include<bits/stdc++.h>
int main()
{
  long long sum=0;
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int k=1;k<=n;k++)
      {
        sum+=std::__gcd(i,std::__gcd(j,k));
      }
  printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 3824
from itertools import groupby, accumulate

# 入力
N, K = map(int, input().split())
S = input()

# 連続する0または1の数に関する累積和
A = list(accumulate(len(list(seq)) for _, seq in groupby(S))) + [N]
m = (
    1 if S[0] == '0' else
    0
)
# 累積和を用いて解を求める
ans = max(
    A[min(2 * K - 1, len(A) - 1)],
    A[-1] - A[max(-(2 * K), -len(A))],
    max(
        (
            a - b
            for a, b in zip(A[(2 * K + m)::2], ([0] + A)[m::2])
        ),
        default=0
    )
)

# 出力
print(ans)


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, K; cin >> N >> K;
    int A[N], P[N], lb[N]; FOR(i,0,N-1) { cin >> A[i]; P[A[i]] = i; }

    {
        set<int> s;
        RFOR(i,N-1,0){
            auto it = s.lower_bound(P[i]);
            if (it == s.begin()) lb[i] = -1;
            else lb[i] = *prev(it);
            s.insert(P[i]);
        }
    }

    bool original = false;

    int ans = 0;
    set<int> s; deque<int> dq;
    bool change = false;
    FOR(i,0,K-1){
        s.insert(A[i]);
        if (*s.rbegin() != A[i]) change = true;

        while (!dq.empty() and lb[A[dq.back()]] <= lb[A[i]]) dq.pop_back();
        dq.push_back(i);
    }
    if (lb[A[dq.front()]] <= -1) change = false, original = true;
    ans += change;
    //cout << "ans " << ans << endl;

    FOR(i,K,N-1){
        change = false;
        if (*s.begin() != A[i-K]) change = true;
        s.erase(A[i-K]);
        s.insert(A[i]);
        if (*s.rbegin() != A[i]) change = true;

        while (!dq.empty() and lb[A[dq.back()]] <= lb[A[i]]) dq.pop_back();
        dq.push_back(i);

        //cout << "i " << i << " change " << change << " : ";
        while (!dq.empty() and dq.front() <= i-K) dq.pop_front();
        //cout << " A " << A[dq.front()] << " lb " << lb[A[dq.front()]] << " : ";
        if (lb[A[dq.front()]] <= i-K) change = false, original = true;
        //cout << change << " dq " << dq.front() << "\n";


        ans += change;
    }

    ans += original;

    //FOR(i,0,N-1) { cout << lb[i] << ' '; } cout << endl;

    cout << ans << '\n';
}



Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説動画写し
const int INF=1001001001;
vector<int>to[100005];
int main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    --a;--b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> q;
  vector<int>dist(n,INF);
  vector<int>pre(n,-1);
  dist[0]=0;
  q.push(0);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int u:to[v]){
      if(dist[u]!=INF)continue;
      dist[u]=dist[v]+1;
      pre[u]=v;
      q.push(u);
    }
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(i==0)continue;
    int ans=pre[i];
    ++ans;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10484
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define lop(i,a,b) for(ll i=a;i<b;i++)
using namespace std;

void func(){
    int n,k;
    ll sum=0;
    cin>>n>>k;
    vi a(n);
    lop(i,0,n)cin>>a[i];
    sort(a.begin(),a.end());
    lop(i,0,k)sum+=a[i];
    cout<<sum<<endl;
}

int main(){
    fastio;
    int t=1;
    //cin>>t;
    while(t--){
        func();
    }
}

Measured memory_bytes: 3616
num_sum = 0
value_sum = 0
count = 0
while True:
  try:
    value, num = map(int, input().split(","))
    num_sum += num
    value_sum += value * num
    count += 1
  except EOFError:
    break

average = int(num_sum / count + 0.5) if num_sum % count else num_sum // count

print(value_sum)
print(average)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
	inline LL cal(int n) {
		// C(n,2) + n
		return 1LL*n*(n+1)/2;
	}
LL ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}


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

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

	sort(S.begin(), S.end());

	for (int i = 0; i < S.size() - 1;i++) {
		if (S[i] == S[i + 1]) {
			cout << "no" << endl;
			return 0;
		}
	}

	cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
struct Calc{
    ll p;
    string s;
    string::iterator it;
 
    Calc(ll p,string s) : p(p), s(s) {
	it = s.begin();
    }
 
    ll add(ll a,ll b){
	return (a + b) % p;
    }
 
    ll sub(ll a,ll b){
	return (a - b + p) % p;
    }
 
    ll mul(ll a,ll b){
	return (a * b) % p;
    }
 
    ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0LL){
	    d = extgcd(b,a%b,y,x);
	    y -= (a/b)*x;
	}else{
	    x = 1LL;
	    y = 0LL;
	}
	return d;
    }
 
    ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m + x % m) % m;
    }
 
    ll fact(){
	ll res = 0LL;
	if(*it == '('){
	    ++it;
	    res = exp();
	    ++it;
	}else{
	    while(isdigit(*it)){
		res *= 10LL;
		res += (*it-'0');
		++it;
	    }
	}
	return res;
    }
 
    ll term(){
	ll res = fact();
	while(*it == '*' || *it == '/'){
	    if(*it == '*'){
		++it;
		res = mul(res,fact());
	    }else if(*it == '/'){
		++it;
		ll x = fact();
		if(x == 0LL){ throw 0; }
		res = mul(res,mod_inverse(x,p));
	    }
	}
	return res;
    }
 
    ll exp(){
	ll res = term();
	while(*it == '+' || *it == '-'){
	    if(*it == '+'){
		++it;
		res = add(res,term());
	    }else if(*it == '-'){
		++it;
		res = sub(res,term());
	    }
	}
	return res;
    }
};
 
string compress(string s){
    string res;
    for(int i = 0 ; i < (int)s.size() ; i++){
	if(s[i] != ' '){ res += s[i]; }
    }
    return res;
}
 
int main(){
    ll p;
    string in;
    while(getline(cin,in),in != "0:"){
	string s;
	int i;
	in = compress(in);
	for(i = 0 ; i < (int)in.size() ; i++){
	    if(in[i] == ':'){ break; }
	    s += in[i];
	}
	stringstream ss(s);
	ss >> p;
	in = in.substr(i+1); 
	Calc c(p,in);
	try{
	    ll res = c.exp();
	    cout << in << " = " << res << " (mod " << p << ")" << endl;
	}catch(...){
	    cout << "NG" << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3312
p = int(input())
a = p // 1000
b = (p // 100) % 10
c = (p // 10) % 10
d = p % 10


if a + b + c + d == 7:
    print("{}+{}+{}+{}=7".format(a,b,c,d))
elif a + b + c - d == 7:
    print("{}+{}+{}-{}=7".format(a,b,c,d))
elif a + b - c + d == 7:
    print("{}+{}-{}+{}=7".format(a,b,c,d))
elif a + b - c - d == 7:
    print("{}+{}-{}-{}=7".format(a,b,c,d))
elif a - b + c + d == 7:
    print("{}-{}+{}+{}=7".format(a,b,c,d))
elif a - b + c - d == 7:
    print("{}-{}+{}-{}=7".format(a,b,c,d))
elif a - b - c + d == 7:
    print("{}-{}-{}+{}=7".format(a,b,c,d))
elif a - b - c - d == 7:
    print("{}-{}-{}-{}=7".format(a,b,c,d))


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n;cin>>n;
  vector<string>S(n);
  rep(i,n)cin>>S[i];
  ll count=0;
  rep(i,n){
    bool ok=true;
    rep(j,n){
      rep(k,n){
        if(S[(j+i)%n][k]!=S[(k+i)%n][j])ok=false;
      }
    }
    if(ok)count++;
  }
  cout<<count*n<<endl;
}

Measured memory_bytes: 384
//  Twitter@KonoLv1 2020年春からエンジニア見習いデビュー！
 
//  標準入出力を扱うヘッダーファイルの読み込み
#include <stdio.h>
//  "atoi" "atof"などのキャスト、"rand" 疑似乱数を発生させるヘッダーファイルの読み込み
#include <stdlib.h>
//  "strcpy" "strcat"などの文字列操作や"strlen"文字列長さ取得などを行うヘッダーファイルの読み込み
#include <string.h>
//  "sqrtl" "fmax"などの数値操作を行うヘッダーファイルの読み込み
#include <math.h>
 
int main(void){
 
    int x,y,z;
    int i,j,k;
    int n;
    unsigned long long int count = 0;
    unsigned long long int h = 0;
    unsigned long long int add = 1;
    int flg = 0;
    char s[200000] = {};
    int box[200001] = {};
    int sum = 0;
    int tmp = 0;
    

    scanf("%lld",&h);
    while(1){
        if (h == 1){
             count = count + 1;
            break;
           
        }
        add = add * 2;
        count = count + add;

        h = h / 2;

    }
   
    printf("%lld",count);
 
}

Measured memory_bytes: 128
/*
http://soj.acmm.club/show_problem.php?pid=1006&cid=2828
*/
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<deque>
using namespace std;
int a[500004],b[500004],c[500004];
deque<int> d;
int main(){
    int n;
    long long ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n;i++){
        scanf("%d", &a[i]);
    }
    sort(a, a + n);

    if(n==1||n==0){
        printf("0\n");
    }
    else if(n%2==0){
        for (int i = 0; i < n/2;i++){
            ans = ans - 2 * a[i];
        }
        for (int i = n / 2; i < n;i++){
            ans = ans + 2 * a[i];
        }
        ans = ans - a[n / 2];
        ans = ans + a[n / 2 - 1];
    }
    else{
        long long maxans = 0;
        for (int i = 0; i <= n / 2;i++){
            ans = ans - 2 * a[i];
        }
        for (int i = n / 2 + 1; i < n;i++){
            ans = ans + 2 * a[i];
        }
        ans += (a[n / 2] + a[n / 2 - 1]);
        if(ans>maxans)
            maxans = ans;


        ans = 0;
        for (int i = 0; i < n / 2;i++){
            ans = ans - 2 * a[i];
        }
        for (int i = n / 2 ; i < n;i++){
            ans = ans + 2 * a[i];
        }
        ans -= (a[n / 2] + a[n / 2 + 1]);
        if(ans>maxans)
            maxans = ans;
        ans = maxans;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2560
# https://atcoder.jp/contests/abc161/tasks/abc161_e
N, K, C = map(int, input().split())
S = input()

i = 0
left = []
while i < N and len(left) < K:
    if S[i] == 'o':
        left.append(i)
        i += (C + 1)
        continue
    i += 1

i = N - 1
right = []
while i >= 0 and len(right) < K:
    if S[i] == 'o':
        right.append(i)
        i -= (C + 1)
        continue
    i -= 1

n = len(left)
for i in range(n):
    if left[i] == right[n - i - 1]:
        print(left[i] + 1)


Measured memory_bytes: 20584
#include <iostream>
#include <vector>
using namespace std;
string s;
vector<char> hugo;
bool dfs(int n,int nw){
  if(n == 4){
    if(nw == 7){
      cout << s[0] << hugo[1] << s[1] << hugo[2] << s[2] << hugo[3] << s[3] << "=7" << endl;
      return true;
    }
    return false;
  }
  hugo.push_back('+');
  if(dfs(n+1,nw+(s[n]-'0')))return true;
  hugo.pop_back();
  hugo.push_back('-');
  if(dfs(n+1,nw-(s[n]-'0')))return true;
  hugo.pop_back();
  return false;
}
int main(){
  cin>>s;
  dfs(0,0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	ll tot=0;
	tot+= (60-m1);
	h1++;
	tot+= (h2-h1)*60;
	tot+=m2;
	cout<<tot-k;
	
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string a;
	getline(cin,a);
	for(int b=0;b<a.length();b++){
		if(a[b]>='a'&&a[b]<='z')cout<<(char)(a[b]-32);
		else if(a[b]>='A'&&a[b]<='Z')cout<<(char)(a[b]+32);
		else cout<<a[b];
		}
		cout<<endl;
}

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

int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> w(n), b;
  for (int i = 0; i < n; ++i)
    cin >> w[i];

  // int b = n;
  for (int t = 1; t < n; ++t)
  {
    int l = 0, g = 0;
    for (int i = 0; i < n; ++i)
    {
      if (i <= t)
        l += w[i];
      else
        g += w[i];
    }

    b.push_back(abs(g - l));
  }

  cout << *min_element(b.begin(), b.end()) << "\n";
  return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict
import sys
input = sys.stdin.readline

N = int(input())
s = [None] + [list(input()) for _ in range(N)]

count = defaultdict(int)

answer = 0
for i in range(1,N+1):
    c = Counter(s[i])
    c = sorted(c.items(), key=lambda x:x[0])
    # O(len(c))
    str_c = ""
    for key,item in c:
        str_c += key*item
    answer += count[str_c]
    count[str_c] += 1

print(answer)

Measured memory_bytes: 41012
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
 
typedef long long ll;
 
vector<int> ve[maxn];//vector最好定义在外面，不然可能爆栈
 
int main()
{
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>k) continue;//要有这个条件，不然下面的vector可能会成负值
		ve[k-a+1].push_back(b);//表示只能在m-a+1天或者之前做
	}
	priority_queue<int> q;
	int earn=0;
	for(int i=k;i>=1;i--)
	{
		for(int v:ve[i]) q.push(v);
		if(!q.empty())
		{
			earn+=q.top();
			q.pop();
		}
	}
	cout<<earn;
	
	
	return 0;
 } 


Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <stack>

using namespace std;

int main()
{
  int n;
  stack<int> st;
  while(1){
    cin >> n;
    if ( cin.eof() ) break;
    if(n == 0) {
      cout << st.top() << endl;
      st.pop();
    }
    else st.push(n);
  }
}

Measured memory_bytes: 1200
N, M = map(int, input().split())

islands = [list(map(int, input().split()))for _ in range(M)]
islands = sorted(islands, key=lambda x: x[1])

count = 0
current = float('inf')

for island in islands:
    if island[0] <= current < island[1]:
        continue

    count += 1
    current = island[1] - 1

print(count)


Measured memory_bytes: 29836
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[100];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int t = i;
		for (int j = i; j < n; j++) {
			if (a[t] > a[j]) t = j;
		}
		if (a[t] != a[i]) {
			swap(a[i], a[t]);
			sum++;
		}
	}
	for (int i = 0; i < n;i++)
		cout << (i == 0 ? "" : " ") << a[i];
	cout << endl << sum << endl;
}


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

int main()
{
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

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

    std::vector<int> a(n);

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<int> sorted = a;
    std::sort(sorted.begin(), sorted.end(), std::greater<int>());

    int max = sorted[0], second_max = sorted[1];

    for (auto i : a) {
        std::cout << ((i == max) ? second_max : max) << std::endl;
    }
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

string origin(string &s){
  string x;
  char t='a'-1;
  map<char,char> m;
  for(char c:s){
    if(m.count(c))x.pb(m[c]);
    else {
      t++;
      x.pb(t);
      m[c]=t;
    }
  }
  return x;
}

int main() {
  string s,t;cin >>s>>t;
  cout << (origin(s)==origin(t)?"Yes":"No");
}

Measured memory_bytes: 1168
# -*- coding:utf-8 -*-

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

    if N == 2:
        ans = max(A[0]+A[1], -A[0]+(-A[1]))
        print(ans)
        return

    # マイナスが奇数の時、好きな数字をマイナスにできる
    # マイナスが偶数の時、全てプラスにできる
    minus_num = 0
    for a in A:
        if a < 0:
            minus_num += 1
    
    ans = 0
    lowest = 10**9+1
    for a in A:
        ans += abs(a)
        if lowest >= abs(a):
            lowest = abs(a)
    
    if minus_num%2 == 0:
        print(ans)
    else:
        ans -= lowest*2
        print(ans)


if __name__ == "__main__":
    solve()


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

int main(){

string hi;
cin>>hi;
int n=0;
n=hi.size();
int i=0;
int a=0;

while(i<n){
	cin>>hi[i];
	if(hi[i]=='h'){++i;}
	else {a++;i++;}
	if(hi[i]=='i'){++i;}
	else {a++;i++;}



}

if(a==0){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}

}

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

vector<vector<pair<int, int>>> graph; //pair<to, cost>
vector<int> color;
vector<LL> length;
vector<bool> check;

void dfs(int from) {
  if (check[from]) return;
  check[from] = true;
  for (int i = 0; i < graph[from].size(); i ++) {
    int to   = graph[from][i].first;
    if (check[to]) continue;

    int cost = graph[from][i].second;
    length[to] = length[from] + cost;
    if (length[to] % 2 == 0) color[to] = 0;
    else color[to] = 1;
    dfs(to);
  }
}

int main() {
  int n; cin >> n;
  graph = vector<vector<pair<int, int>>>(n);
  for (int i = 0; i < n - 1; i ++) {
    int x, y, z;
    cin >> x >> y >> z;
    x --, y --;
    graph[x].push_back(make_pair(y, z));
    graph[y].push_back(make_pair(x, z));
  }

  color = vector<int>(n);
  length = vector<LL>(n);
  check = vector<bool>(n, false);
  color[0] = 0, length[0] = 0;
  dfs(0);

  for (int i = 0; i < n; i ++) cout << color[i] << endl;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
int d(int a,int b)
{
	if(a%b!=0) return d(b,a%b);
	else
	return b;
}
int main()
{
	long long a,b;
	cin>>a>>b;
	long long c=d(a,b);
	long long ans=a*b/c;
	cout<<ans<<endl;
	return 0;
}

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

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int h, w;
const int INF = 1001001001;
// dfs（深さ優先探索）
// https://qiita.com/drken/items/4a7869c5e304883f539b
vector<vector<int>> dist;
queue<pair<int, int>> nx;
void dfs(vector<string> &s, pair<int, int> v, int d) {
	dist[v.first][v.second] = min(dist[v.first][v.second], d);
	rep(i, 4) {
		int nh = v.first + dy[i];
		int nw = v.second + dx[i];
		if (nh < 0 || nh >= h) continue;
		if (nw < 0 || nw >= w) continue;
		if (s[nh][nw] == '#') continue;
		if(dist[nh][nw] == d) continue;
		if (dist[nh][nw] > d) nx.push({nh, nw});
		dfs(s, {nh, nw}, d);
	}
}

int main() {
	int ch, cw, dh, dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	dist.resize(h, vector<int>(w, INF));
	int d = 0;
	set<pair<int, int>> nx_dfs;
	nx_dfs.insert({ch, cw});
	
	while (!nx_dfs.empty() || !nx.empty()) {
		while (!nx_dfs.empty()) {
			int nh = (*nx_dfs.begin()).first;
			int nw = (*nx_dfs.begin()).second;
			nx.push({nh, nw});
			if (dist[nh][nw] > d) dfs(s, *nx_dfs.begin(), d);
			nx_dfs.erase(*nx_dfs.begin());
		}
		while(!nx.empty()) {
			int nx_h = nx.front().first;
			int nx_w = nx.front().second;
			nx.pop();
			for(int i = -2; i <= 2; i++) {
				for(int j = -2; j <= 2; j++) {
					int nh = nx_h + i;
					int nw = nx_w + j;
					if (nh < 0 || nh >= h) continue;
					if (nw < 0 || nw >= w) continue;
					if (s[nh][nw] == '#') continue;
					if (dist[nh][nw] <= d) continue;
					nx_dfs.insert({nh, nw});
					
				}
			}
		}
		d++;
	}
	if (dist[dh][dw] != INF) cout << dist[dh][dw] << endl;
	else cout << -1 << endl;
	
	// rep(i, h) {
	// 	rep(j, w) {
	// 		if (s[i][j] == '.') cout << dist[i][j];
	// 		else cout << '#';
	// 	}
	// 	cout << endl;
	// }
	return 0;
}

Measured memory_bytes: 9580
A,B,C,X,Y = map(int,input().split())
ans = float("inf")
for i in range(0,2*max(X,Y)+2,2):
    yen = A*max(0,X-(i//2))+C*i+B*max(0,Y-(i//2))
    ans = min(ans,yen)
print(ans)


Measured memory_bytes: 3060