akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF 1000000001
int v,e,r,cnt=0;
vector<pair<int,int> >edge[100000]; 
int d[100000];
bool check[100000];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >vrt;
int main(void){
   cin>>v>>e>>r;
   for(int i=0;i<v;i++){
       d[i]=INF;
       check[i]=false;
   }
   d[r]=0;
   check[r]=true;
   for(int i=0;i<e;i++){
       int s,t,c;
       cin>>s>>t>>c;
       edge[s].push_back(make_pair(t,c));
   }
   vrt.push(make_pair(0,r));
   while(cnt<v){
       while(!vrt.empty()&&d[vrt.top().second]!=vrt.top().first)vrt.pop();
       int n=vrt.top().second;
       check[n]=true;
       vrt.pop();
       for(int i=0;i<edge[n].size();i++){
           int s=edge[n][i].first,cn=edge[n][i].second;
           if(!check[s]&&d[n]+cn<d[s]){
               d[s]=d[n]+cn;
               vrt.push(make_pair(d[s],s));
           }
       }
       cnt++;
   }
   for(int i=0;i<v;i++){
       if(d[i]==INF)cout<<"INF\n";
       else cout<<d[i]<<endl;
   }
}

Measured memory_bytes: 13120
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	const LL INF = 1LL << 60;
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1, m, v, p;
		cin >> n >> m >> v >> p;
		if (n < 1) return 0;
		vector<LL> a(n), sum(n + 1);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		sort(a.begin(), a.end());
		for (int i = 0; i < n; ++i) {
			sum[i + 1] = sum[i] + a[i];
		}
		int left = -1, right = n;
		while (right - left > 1) {
			int mid = (right + left) / 2;
			bool ok = true;
			if (mid >= n - p) {
				;
			} else if (a[mid] + m < a[n - p]) {
				ok = false;
			} else {
				if (mid == 1) {
					LL aa = 1;
					++aa;
				}
				LL votes = max(0LL, (v - (p - 1)- mid)) * m;
				LL r = (a[mid] + m) * (n - p + 1 - mid) - (sum[n - p + 1] - sum[mid]);
				ok = r >= votes;
			}
			if (ok) {
				right = mid;
			} else {
				left = mid;
			}
		}
		int ans = n - left - 1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1920
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 line = br.readLine();

		String[] ana = new String[3];
		ana = line.split(" ");
		int jal[] = new int[3];
		int t = 0;
		for (int i = 0; i < ana.length; i++)
			jal[i] = Integer.parseInt(ana[i]);
		t=jal[0]+jal[1];
		if(t<10)
			System.out.println(t);
		else
			System.out.println("error");
	}
}


Measured memory_bytes: 21204
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
  if(l[i]!=(i+1)):
    ind=l.index(i+1)
    l[i],l[ind]=l[ind],l[i]
    break
count=0
#print(l)
for i in range(n):
  if(l[i]!=(i+1)):
    break
  count+=1
if(count==n):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

void work() {
   int n, dr; cin>>n>>dr;
    if (n >= 10) {
        cout << dr;
    } else {
        cout << dr + 100 * (10 - n);
    }
    cout << endl;
}

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll i,n,k;
      ll ans=0;
      cin>>n>>k;
      vector<ll>p(n);
      for(i=0;i<n;i++) cin>>p[i];
        sort(all(p));
      for(i=0;i<k;i++) ans+=p[i];
        cout<<ans;
    }
    return 0;
   }

Measured memory_bytes: 14140
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

ll gcd(ll a,ll b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> v(N);
  int high=0;
  rep(i,N){
    cin >> v[i];
    if(high<v[i]) high=v[i];
  }
  ll GCD=v[0];
  for(int i=0;i<N;i++){
    GCD=gcd(GCD,v[i]);
  }
  if(high>=K&&(high-K)%GCD==0){
    cout << "POSSIBLE" << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
using namespace std;

int main()
{
   int n, ans = 0;
   string s;
   cin >> n >> s;

   for(int i = 0; i < n - 2;i ++)
   {
       if(s.substr(i, 3) == "ABC") ans++;
   }

   cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long X;
    cin >> X;
    long long Y = 100;
    for(int i=1; i<=1000000; i++){
        Y *= 1.01;
        if(Y >= X){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for (int k = 0; k < K; ++k) {
        ans += p[k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3668
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int q = sc.nextInt();
		boolean reversflag = false;
		List<String> prelist = new ArrayList<String>();
		List<String> aftlist = new ArrayList<String>();
		for (int i = 0; i < q; ++i) {
			int t = sc.nextInt();
			if (t == 1)
				reversflag = !reversflag;
			else {
				int f = sc.nextInt();
				String c = sc.next();
				if (reversflag) {
					if (f == 1)
						f = 2;
					else
						f = 1;
				}
				if (f == 1)
					prelist.add(c);
				else
					aftlist.add(c);
			}
		}
		int len = prelist.size();
		StringBuffer ans = new StringBuffer();
		for (int i = len - 1; i >= 0; --i)
			ans.append(prelist.get(i));
		ans.append(s);
		for (String t : aftlist)
			ans.append(t);
		if (reversflag)
			ans.reverse();
		System.out.println(ans.toString());
		sc.close();
	}
}


Measured memory_bytes: 153996
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll N, x;
	ll a[100000];
	
	cin >> N >> x;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	ll sumTwo[100000];
	for(int i = 0; i < N-1; i++){
		sumTwo[i] = a[i] + a[i+1];
	}
	
	// まず、隣接する3つの箱の２ペアの総和が多い場合を処理する
	ll count = 0;
	for(int i = 0; i < N-2; i++){
		if(sumTwo[i] > x && sumTwo[i+1] > x){
			ll eat = min(sumTwo[i] - x, sumTwo[i+1] - x);
			eat = min(eat, a[i+1]); // 減らす対象の箱のキャンディの数が0未満になってはいけない
			count += eat;
			a[i+1] -= eat;
			sumTwo[i] -= eat;
			sumTwo[i+1] -= eat;
		}
	}
	// 残ったペアを処理する場合は、どちらの箱を処理しても同じ
	for(int i = 0; i < N-1; i++){
		if(sumTwo[i] > x){
			count += sumTwo[i] - x;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using v=vector<int>;

int main() {
    int N;cin>>N;
    v x(N);
    v y(N);
    for (int i = 0; i < N; i++){
        int X,Y;cin>>X>>Y;
        x[i]=X+Y;
        y[i]=X-Y;
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    cout<<max(x[N-1]-x[0],y[N-1]-y[0])<<endl;
}

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

ll dis(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);

    rep(i, h){
        cin >> s[i];
    }

    ll dx[] = {-1, 0, 1, 0};
    ll dy[] = {0, 1, 0, -1};

    rep(i, h){
        rep(j, w){
            if (s[i][j] == '.'){
                continue;
            }
            bool flg = true;
            rep(k, 4){
                ll y = i+dy[k];
                ll x = j+dx[k];
                if (x < 0 || x >= w || y < 0 || y >= h){
                    continue;
                }
                if (s[y][x] == '#'){
                    flg = false;
                    break;
                }
            }
            if (flg){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3572
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    INF = 10**10  # INF+INFを計算してもオーバーフローしない範囲で大きく

    # dpテーブル
    N = int(input())
    # dp[i]:= frogがiへと移動するための最小コスト
    dp = [INF]*N
    h = list(map(int, input().split()))
    """
    初期化の値は，
        最小化問題：INF, 
        最大化問題：-INF（0以上の値しか取らないなら-1, あるいは0でもいいかも)
        数え上げ問題：0
        確率問題：0
        Yes/No判定問題:False
    """

    # 初期条件
    dp[0] = 0

    # ループ
    for i in range(1, N):
        dp[i] = min(dp[i], dp[i-1]+abs(h[i-1]-h[i]))
        if i >= 2:
            dp[i] = min(dp[i], dp[i-2]+abs(h[i-2]-h[i]))

    # 出力
    print(dp[N - 1])


resolve()

Measured memory_bytes: 65844
import sys
H, W = list(map(int, input().split()))
s = [list(input()) for _ in range(H)]

flag = True
for h in range(H):
    for w in range(W):
        if s[h][w] == "#" and not (h != 0 and s[h - 1][w] == "#" or
                h != H - 1 and s[h + 1][w] == "#" or
                w != 0 and s[h][w - 1] == "#" or
                w != W - 1 and s[h][w + 1] == "#"):
            print("No")
            sys.exit()
print("Yes")


Measured memory_bytes: 3064
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int n,k,l, cnt[N];

class dsu {
public:
    vector<int> p;
    int n;
    
    dsu(int _n) : n(_n) {
        p.resize(n+1);
        iota(p.begin(), p.end(), 0);
    }
    
    inline void re_init(){
        iota(p.begin(), p.end(), 0);
    }
    
    inline int findset(int x) {
        return (x == p[x] ? x : (p[x] = findset(p[x])));
    }
    
    inline bool unite(int x, int y) {
        x = findset(x);
        y = findset(y);
        if (x != y) {
            int smal = min(x,y);
            int lar = max(x,y);
            p[lar] = smal;
            return true;
        }
        return false;
    }
    inline int num_of_componet(){
        int ans = 0;
        for (int i = 1; i <= n; i++){
            if(i == findset(i)) ans++;
        }
        return ans;
    }
};



int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    
    dsu road(n), rail(n);
    for (int i = 0; i < k; i++){
        int u,v;
        cin>>u>>v;
        road.unite(u,v);
    }
    
    for (int i = 0; i < l; i++){
        int u,v;
        cin>>u>>v;
        rail.unite(u, v);
    }
    
    map<pair<int, int>, int>E;
    for (int i = 1; i <= n; i++){
        E[make_pair(road.findset(i), rail.findset(i))] ++;
    }
  
    for (int i = 1; i <= n; i++){
        cout<<E[make_pair(road.findset(i), rail.findset(i))]<<" \n"[i==n];
    }
    
    
    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h> 
using namespace std; 
#define int long long 
#define UNIQUE(v) v.erase(unique(all(v)), v.end()); 
#define ZIP(v) sort(all(v)),UNIQUE(v) 
#define ADD(a, b) a = (a + b) % mod 
#define MUL(a, b) a = (a * b) % mod 
#define repi(i,m,n) for(int i = m;i < n;i++) 
#define drep(i,n,m) for(int i = n;i >= m;i--) 
#define rep(i,n) repi(i,0,n) 
#define rrep(i,n) repi(i,1,n+1) 
#define chmin(x,y) x = min(x,y) 
#define chmax(x,y) x = max(x,y) 
#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(), v.rend() 
#define pb(x) push_back(x) 
#define fi first 
#define se second 
typedef pair<int,int> P; 
typedef pair<int, P> PP; 
typedef vector<int> vi; 
const int inf = 1e9+7; 
const int INF = 1e18+7; 
const int mod = 1e9+7; 
//26 

signed main(){
int a, b;
scanf("%lld%lld", &a, &b);
if(a <= 8 and b <= 8)printf("Yay!\n");
else printf(":(\n");
return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
using namespace std;
string s,t;
int p;
map<char,int>m;
void convert(string &s){
    r(i,s.size()){
        if(i&&s[i]==' '){
            if(s[i-1]==')'&&s[i+1]=='(')s[i]='*';
            else if(isalpha(s[i-1])&&isalpha(s[i+1]))s[i]='*';
            else if(s[i-1]==')'&&isalpha(s[i+1]))s[i]='*';
            else if(isalpha(s[i-1])&&s[i+1]=='(')s[i]='*';
            else if(s[i-1]==')'&&isdigit(s[i+1]))s[i]='*';
            else if(isdigit(s[i-1])&&s[i+1]=='(')s[i]='*';
            else if(isdigit(s[i-1])&&isalpha(s[i+1]))s[i]='*';
            else if(isalpha(s[i-1])&&isdigit(s[i+1]))s[i]='*';
            else if(isdigit(s[i-1])&&isdigit(s[i+1]))s[i]='*';
            else s.erase(s.begin()+i--);
        }
        if(isdigit(s[i])&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(isalpha(s[i])&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(isalpha(s[i])&&isdigit(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i]==')'&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i]==')'&&isdigit(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&isalpha(s[i]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&isdigit(s[i]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&s[i]==')')s.insert(s.begin()+i+1,'*');
    }
}
int Sbnf1(string &s);
int get_S(string &s){
    int res=0;
    if(s[p]=='(')p++,res=Sbnf1(s),p++;
    else if(isdigit(s[p])){
        while(isdigit(s[p])){
            res=res*10+(s[p++]-'0');
        }
    }
    else res=m[s[p++]];
    return res%mod;
}
int Sbnf3(string &s){
    int res=get_S(s);
    while(s[p]=='^'){
        p++;
        int ret=get_S(s),kit=res;
        r(i,ret-1){
            res*=kit;
            res=res%mod;
        }
    }
    return res%mod;
}
int Sbnf2(string &s){
    int res=Sbnf3(s);
    while(s[p]=='*'){
        p++;
        res*=Sbnf3(s);
        res=res%mod;
    }
    return res%mod;
}
int Sbnf1(string &s){
    int res=Sbnf2(s);
    while(s[p]=='+'||s[p]=='-'){
        int pp=p++;
        if(s[pp]=='+')res+=Sbnf2(s);
        if(s[pp]=='-')res-=Sbnf2(s);
        while(res<0)res+=mod;
        res=res%mod;
    }
    return res%mod;
}
main(){
    while(getline(cin,t)){
        if(t==".")break;
        convert(t);
        while(getline(cin,s)){
            if(s=="."){
                cout<<'.'<<endl;
                break;
            }
            int flag = 0;
            convert(s);
            r(i,7){
                r(j,26)m[j+'a']=rand()%mod;
                p=0;
                int y=Sbnf1(t)%mod;
                p=0;
                int x=Sbnf1(s)%mod;
                if(y!=x)flag++;
            }
            cout<<(flag?"no":"yes")<<endl;
        }
    }
}

Measured memory_bytes: 2992
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define endl      '\n'
#define all(v)    v.begin(), v.end()
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int32_t main(){
	kehsihba();
	ll k,x;cin>>k>>x;
	set<ll>s;
	s.insert(x);
	for(int i=1;i<k;i++){
		s.insert(x+i);
		s.insert(x-i);
	}
	for(auto i:s){
		cout<<i<<" ";
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int p = 1;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int j = 0; j < N; j++) {
    p = vec.at(p - 1);
    if(p == 2) {
      break;
    }
    else {
      count += 1;
    }
  }
  
  if (count == N) {
    cout << -1 << endl;
  }
  else {
    cout << count + 1 << endl;
  }
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	const int p = 31;
	vector<long long> p_pow(sz(s));
	p_pow[0] = 1;
	for (int i = 1; i < sz(p_pow); i++)
		p_pow[i] = p_pow[i - 1] * p;
	vector<long long> h(sz(s));
	for (int i = 0; i < sz(s); i++)
	{
		h[i] = (s[i] - 'a' + 1LL) * p_pow[i];
		if (i)
			h[i] += h[i - 1];
	}

	int res = 0;

	for (int l = 1; l <= sz(s) / 2; l++)
	{
		map<long long, int> cnt;
		bool found = false;
		for (int i = 0; i + l <= sz(s); i++)
		{
			long long cur_h = h[i + l - 1];
			if (i)
				cur_h -= h[i - 1];
			long long curhash = cur_h * p_pow[sz(s) - l - i];
			if (cnt.find(curhash) == cnt.end())
			{
				cnt[curhash] = i;
			}
			else
			{
				if (cnt[curhash] + l <= i)
				{
					res = l;
					found = true;
					break;
				}
			}
		}
		if (!found)
			break;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(200005)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = na()
    g[a-1].append(b-1<<32|i)
    g[b-1].append(a-1<<32|i)
    # g[a-1].append((b-1, i))
    # g[b-1].append((a-1, i))


def dfs(cur, pre, prec, g, colors):
    gen = 1
    for e in g[cur]:
        if e>>32 != pre:
            if gen == prec:
                gen += 1
            colors[e&(1<<32)-1] = gen
            dfs(e>>32, cur, gen, g, colors)
            gen += 1

colors = [0] * (n-1)
dfs(0, -1, 0, g, colors)

print(max(colors))
for v in colors:
    print(v)


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

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  
  int A;
  A = 100*a + 10*b + c;
  
  if ( A % 4 == 0 ) {
    cout << "YES" << endl;
  }
  
    if (!( A % 4 == 0 )) {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
using ll = long long;
using namespace std;

int main()
{
    string s;
    cin >> s;
    int m = 999999;
    for (int i = 0; i < s.size() - 2; i++)
    {
        int x = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        //cout << x << endl;
        m = min(m, abs(x - 753));
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> c(3, vector<int> (3));
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int a2, a3, b2, b3;
  a2 = c.at(0).at(0) - c.at(0).at(1);
  a3 = c.at(0).at(0) - c.at(0).at(2);
  b2 = c.at(0).at(0) - c.at(1).at(0);
  b3 = c.at(0).at(0) - c.at(2).at(0);
  //cout << a2 << " " << a3 << " " << b2 << " " << b3 << endl;
  bool judge = false;
  for(int i = 0; i < 3; i++) {
    int x = c.at(i).at(0) - c.at(i).at(1), y = c.at(i).at(0) - c.at(i).at(2),
     z = c.at(0).at(i) - c.at(1).at(i), w = c.at(0).at(i) - c.at(2).at(i);
    //cout << x << "/" << y << "/" << z << "/" << w << endl;
    if(x != a2 || y != a3 || z != b2 || w != b3) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N,K;
    cin >> N >> K;
    
    ll s = 0, t = 0;
    ll ss = 0, tt = N;
    
    rep(i,K-1){
        s += ss;
        t += tt;
        ss++;
        tt--;
    }
    
    
    ll ans = 0;
    
    reps(i,K,N+2){
        s += ss;
        t += tt;
        ss++;
        tt--;

        ans += (t-s+1)%mod;
        ans %= mod;
        
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, m;
  cin >> n;
  map<string, int> blue;
  rep (i, n) {
    string s;
    cin >> s;
    auto itr = blue.find(s);
    if (itr != blue.end()) blue[s]++;
    else blue[s] = 1;
  }

  cin >> m;
  map<string, int> red;
  rep (i, m) {
    string s;
    cin >> s;
    auto itr = red.find(s);
    if (itr != red.end()) red[s]++;
    else red[s] = 1;
  }

  int ans = 0;
  for (auto itr = blue.begin(); itr != blue.end(); itr++) {
    int plus = itr->second;
    auto itrR = red.find(itr->first);
    if (itrR != red.end()) {
      if (red[itr->first] < plus)  ans = max(ans, plus - red[itr->first]);
    } else {
      ans = max(ans, plus);
    }
  }
  P(ans);

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <utility>
#include <map>
 
int main()
{
  	std::map<int, int> ref;
  	int n;
  	int tmp;
  	for(int i=0;i<9;i++)
    {
      std::cin >> tmp;
      ref[tmp] = i;
    }
  	std::cin >> n;
  	bool check[9];
  	for(int i=0;i<9;i++)
    {
      	check[i] = false;
    }
  	for(int i=0;i<n;i++)
    {
      	std::cin >> tmp;
      	auto it = ref.find(tmp);
      	if(it != ref.end())
        {
			check[ref[tmp]] = true;
        }
    }
  	bool ans = false;
  	for(int i=0;i<3;i++)
    {
      	ans = (ans || (check[i*3] && check[i*3+1] && check[i*3+2]));
      	ans = (ans || (check[i] && check[i+3] && check[i+6]));
      	if(ans) break;
    }
  	ans = (ans || (check[0] && check[4] && check[8]));
  	ans = (ans || (check[2] && check[4] && check[6]));
  	if(ans)
      	std::cout << "Yes";
  	else
      	std::cout << "No";
  	std::cout << "\n";
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
#define EPS 1e-15
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;cin>>q;
  ll op = 0,cl = 0;
  for(int i=0;i<q;i++){
    ll p,n;
    char c;
    cin>>p>>c>>n;
    if(c=='(')op+=n;
    else cl+=n;
    if(op == cl)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3216
N = int(input())
ary1 = list(map(int,input().split()))
ary2 = ary1
ans = 0
#i=0の場合はここに書く。
def f_state(k):
  state1 = 1 if k>0 else 0
  return(state1)

for i in range(10000):
#  num_switch = 0
  state1 = f_state(ary2[0])
  ary2[0] = max([0,ary2[0]-1])
  if state1 ==1:
    ans +=1
  for i in range(1,N):
    if f_state(ary2[i]) == 1 and state1 ==0:
      ans +=1
    state1 = f_state(ary2[i])
    ary2[i] = max([0,ary2[i]-1])
  if sum(ary2)==0:
    break

print(ans)


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

#define boost ios::sync_with_stdio(); cin.tie(); cout.tie();
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define vt vector 
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 

const int INF = 1e9 + 10;
const int mod = 1e9 + 7;
const ll LLINF = 1e18 + 10;
const int mxn = 100 + 10;
bool was[mxn];
void solve() 
{
	int x,n,curr;
	cin >> x >> n;
	for(int i =0;i < n;i++){
		cin >> curr;
		was[curr] = true;
	}
	int a = x-1;
	int b = x+1;
	if(was[x] == false){
		cout << x;
		return;
	}
	while(was[a] == true && was[b] == true){
		a--;
		b++;
	}
	//cout << was[a] << " " << was[b] << "\n";
	if(was[a] == true && was[b] == false){
		cout << b;
	}
	else if(was[a] == false && was[b] == true){
		cout << a;
	}
	else{
		if(abs(x-a) <= abs(x-b)){
			cout << a;
		}
		else{
			cout << b;
		}
	}
	return;
}
int main()
{
    boost
    //int t; read(t); while(t--)
    solve();
}


Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

#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;
using ll = long long;
const ll inf = 10000000000;
typedef tree<int, null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> new_data;

int main()
{
   ll H,N;
   cin>>H>>N;
   vector<ll>A(N),B(N);
   for(int i=0;i<N;i++)
   {
       cin>>A[i]>>B[i];
   }
   vector<ll>dp(H+4,inf);
   dp[0]=0ll;
   for(ll i=0;i<H;i++)
   {
       for(ll j=0;j<N;j++)
       {
           dp[min(i+A[j],H)]=min(dp[min(i+A[j],H)],dp[i]+B[j]);
       }
   }
   cout<<dp[H]<<endl;
}


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc .nextInt();
        int M = sc.nextInt();
        int wa[] = new int[N+1];
        int correct=0,penalties=0;
        while (M-- > 0){
            int p = sc.nextInt();
            String s = sc.next();
            if(wa[p]==-1){
                continue;
            }
            if(s.equals("WA")){
                wa[p]++;
            }
            else {
                correct++;
                penalties += wa[p];
                wa[p] = -1;
            }
        }

        System.out.println(correct+" "+penalties);
    }
}


Measured memory_bytes: 62956
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>

using namespace std;

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

map<int,bool> board;
int N;

int main(){

    cin>>N;

    int count=0;
    for(int i=0;i<N;i++){
        int Ax;
        cin>>Ax;
        if(!board[Ax]){
            count++;
            board[Ax]=true;
        } else {
            count--;
            board[Ax]=false;
        }
    }

    cout<<count;
}


Measured memory_bytes: 4864
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int arr[] = new int[n];
		for(int i=0;i<n;i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int sum = 0;
		for(int i=0;i<k;i++) {
			sum+=arr[i];
		}
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 38968
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 ll n;
 cin>>n;
 ll ans=1e15;
 for(ll i=1;i<=1e7;i++)
 {
           ll a=n/i;
           if(a*i==n) ans=min(ans,i-1+a-1);
           
 }
 cout<<ans;
 
    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

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

toBit(x,r)=Bool[(x>>(r-i))%2==1 for i in 1:r]
function fromBit(a::Array{Bool,1},r)
	x = 0
	for i in 1:r
		x += a[i]*(2^(r-i))
	end
	x
end

function main()
	n,k = readline() |> split |> parseMap
	a = zeros(Int,n,2)
	for i in 1:n
		a[i,:] = readline() |> split |> parseMap
	end
	r = 0
	while 2^r<=k
		r += 1
	end
	m = 0
	bk = toBit(k,r)
	for i in 1:r+1
		ck = copy(bk)
		if i<=r
			ck[i]=false
			for j in i+1:r
				ck[j]=true
			end
		end
		c = fromBit(ck,r)
		if c<=k
			z = 0
			for j in 1:n
				if c|a[j,1]<=c
					z += a[j,2]
				end
			end
			m = max(m,z)
		end
	end
	println(m)
end

main()

Measured memory_bytes: 157012
H,W,K = map(int,input().split())
c = [input() for _ in range(H)]
ans =0
for i in range(1<<H):
    for j in range(1<<W):
        count = 0
        for k in range(H):
            for l in range(W):
                if c[k][l]=="#" and (i>>k)&1 and (j>>l)&1:
                    count +=1
        if count == K: ans +=1
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<string>

using namespace std;

const int MAX = 100001;
int alltime = 0;

class pro
{
public:
	string name;
	int time;
	void input(string, int);
	void print();
	pro& operator=(const pro);
};

void pro::input(string name, int time)
{
	pro::name = name;
	pro::time = time;
}

void pro::print()
{
	cout << name << " " << alltime << endl;
}

pro& pro::operator=(const pro pro)
{
	name = pro.name;
	time = pro.time;
	return *this;
}

class queue
{
private:
	pro s[MAX];
	int head;
	int tail;
public:
	queue();
	void initialize();
	bool empty();
	bool full();
	void enqueue(pro);
	pro dequeue();
	void rein(int);
};

queue::queue()
{
	head = tail = 0;
}

void queue::initialize()
{
	head = tail = 0;
}

bool queue::empty()
{
	return head == tail;
}

bool queue::full()
{
	if (tail + 1 == MAX)return head == 0;
	else return head == tail + 1;
}

void queue::enqueue(pro x)
{
	if (full())return;
	s[tail] = x;
	tail++;
	if (tail == MAX)tail = 0;
}

pro queue::dequeue()
{
	if (empty()){pro a;a.input("a",0);return a;}
	pro v = s[head];
	head++;
	if (head == MAX)head = 0;
	return v;
}

void queue::rein(int q)
{
	int a;
	if (tail == 0)a = MAX - 1;
	else a = tail - 1;
	s[a].time -= q;
}

int main()
{
	queue queue;
	pro now;
	int n, q, i, time;
	string str;
	cin >> n >> q;
	for (i = 0; i < n; i++)
	{
		cin >> str >> time;
		now.input(str, time);
		queue.enqueue(now);
	}
	while (!queue.empty())
	{
		now = queue.dequeue();
		if (now.time <= q)
		{
			alltime += now.time;
			now.print();
		}
		else
		{
			alltime += q;
			queue.enqueue(now);
			queue.rein(q);
		}
	}
    return 0;
}



Measured memory_bytes: 7036
/**
>>> In The Name Of GOD
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define bs binary_search
#define smin(x,y) (x) = min((x) ,(y))
#define smax(x,y) (x) = max((x) ,(y))
#define sz(x) (int)(x).size()
#define ssz(x) (int)(x).length()
#define all(x) (x).begin(),(x).end()

//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

///ifstream fin("input.txt");
///ofstream fout("output.txt");


bool cmp_pair_F_2(pair <int,int> x, pair <int,int> y)
{
    return x.F>y.F;
}
bool cmp_pair_S_2(pair <int,int> x, pair <int,int> y)
{
    return x.S>y.S;
}
bool cmp_pair_S_1(pair <int,int> x, pair <int,int> y)
{
    return x.S<y.S;
}

bool cmp(int x, int y)
{
	return x>y;
}



int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //int i,j;
    ll w,h;
    cin >> w >> h;
    int x,y;
    cin >> x >> y;
    double s=(w*h);
    s/=2.0;
    cout.precision(10);
    cout << fixed << s << ' ';
    if (w%2==0 && h%2==0 && (x==w/2 && y==h/2))
        cout << 1;
    else
        cout << 0;
    return 0;
}


Measured memory_bytes: 256
package main

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

type bc struct {
	num int
	value int
}

type bcs []bc

func (b bcs) Len() int {
	return len(b)
}

func (b bcs) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

func (b bcs) Less(i, j int) bool {
	return b[i].value < b[j].value
}


var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	sort.Ints(a)
	b := make([]bc, m)
	for i := 0; i < m; i++ {
		b[i].num = nextInt()
		b[i].value = nextInt()
	}
	sort.Sort(sort.Reverse(bcs(b)))

	//fmt.Printf("%v\n", a)
	//fmt.Printf("%v\n", b)

	sum := 0
	idx := 0
	idx2 := 0
	for i:=0 ; i < n; i++ {
		x := a[i]
		y := 0
		if idx < m {
			y = b[idx].value
			idx2++
			if idx2 == b[idx].num {
				idx2 = 0
				idx++
			}
		}
		if x < y {
			sum += y
		} else {
			sum += x
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", sum)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


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

int main(){
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a){
        for (int b = 0; b + a <= N; ++b){
            int c = N - a - b;
            int total = 10000*a + 5000*b + 1000*c;
            if(total == Y ){
                res10000 = a;
                res5000  = b;
                res1000  = c;
            }
        }
    } 

    cout << res10000 << " " << res5000 << " " << res1000 << endl;

}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/04/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    cnt[a]++;
  }
  int ans = 0;
  for (int i = 1; i <= 1e5; i++) {
    int c = cnt[i-1]+cnt[i]+cnt[i+1];
    ans = max(ans, c);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int main (){
	long long int a;
	cin >>a ;
  	long long int b = a;
	int asum=0;
	while(a!=0){
		asum = asum+ a%10;
		a = (a-a%10)/10;
	}
	if(b%asum == 0){
		cout << "Yes";
	}
	else {
		cout << "No";	
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
/********************************************//**
 ****** Author: Shivam Kejriwal *****************
 ****** Handle: techno_phyle    *****************
 ***********************************************/

#include<bits/stdc++.h>
using namespace std;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;

#define mod 1000000007
#define N 100010
#define M 100010
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto it:a) cout << it << " "; cout << endl
#define adbp(a) for(auto it:a) cout << it.first << " " << it.second << endl
#define pb push_back

//greater<pair<int,int> , greater<int>>
const ll INF = 1e18L + 5;
//int dp[N][3];
int main(){
	fastIO;
    //#ifndef ONLINE_JUDGE
    //    freopen("../input.txt", "r", stdin);
    //    freopen("../output.txt","w",stdout);
    //#endif
	ll n,w;
    cin >> n >> w;
    ll weigh[n+1];
    ll val[n+1];
    for(int i=0;i<n;i++)
    	cin >> weigh[i] >> val[i];
    ll sum_v = 0;
    for(int i=0;i<n;i++) sum_v += val[i];
    vector<ll> dp(sum_v+1 , INF);
	dp[0] = 0;
    for(int i=0;i<n;i++){
    	for (int j = sum_v - val[i]; j >=0;j--){
    		dp[j + val[i]] = min(dp[j+val[i]] ,dp[j] + weigh[i]); 
    	}
    }
    ll ans = 0;
    for(ll i=0;i<=sum_v;i++)
    {
    	if(dp[i]<=w){
    		ans = max(ans, i);
    	}
    }
    cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int dp[110][10];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    dp[0][0] = 1;
    rep(i, H) {
        rep(bit, (1 << (W - 1))) {
            bool right = true;
            rep(j, W - 1) {
                if ((bit & (1 << j)) && (bit & (1 << (j + 1)))) right = false;
            }
            //cout << bitset<8>(bit) << " " << right << endl;
            if (!right) continue;
            rep(j, W) {
                if (j + 1 < W && (bit & (1 << j)))
                    dp[i + 1][j] += dp[i][j + 1];
                if (j - 1 >= 0 && (bit & (1 << (j - 1)))) {
                    dp[i + 1][j] += dp[i][j - 1];
                }
                int tmp = dp[i][j];
                if (j - 1 >= 0) tmp *= !(bit & (1 << (j - 1)));
                dp[i + 1][j] += !(bit & (1 << j)) * tmp;
                dp[i + 1][j] %= mod;
                /*
                rep(s, H + 1) {
                    rep(t, W) {
                        cout << dp[s][t] << " ";
                    }
                    cout << endl;
                }
                */
            }
        }
    }
    cout << dp[H][K - 1] << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  string S; cin >> S;
  string s1 = "", s2 = "";
  vector<char> pat{'0', '1'};
  for (int i = 0; i < S.size(); i++) {
    s1.PB(pat[i%2]);
    s2.PB(pat[(i+1)%2]);
  }
  SHOWX(s1);
  SHOWX(s2);

  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (s1[i] != S[i]) ans1++;
    if (s2[i] != S[i]) ans2++;
  }
  SHOWX(ans1);
  SHOWX(ans2);
  cout << min(ans1, ans2) << endl;
    
  return 0;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<vector<int>> a(n, vector<int>(3));
    int r = 0, g = 0, b = 0;
    roop(i, n){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;

        a[i][0] = r;
        a[i][1] = g;
        a[i][2] = b;
    }

    ll ans = 0;

    int temp = 0;
    for(int i = 0;i < n-2;i++){
        for(int j = i+1;j < n-1;j++){
            if(s[i] != s[j]){
                if(s[i] == 'R' || s[j] == 'R') temp += 1;
                if(s[i] == 'G' || s[j] == 'G') temp += 2;
                if(s[i] == 'B' || s[j] == 'B') temp += 4;

                if(j+(j-i) < n){
                    if(7 - temp == 1 && s[j+(j-i)] == 'R') ans--;
                    if(7 - temp == 2 && s[j+(j-i)] == 'G') ans--;
                    if(7 - temp == 4 && s[j+(j-i)] == 'B') ans--;
                }

                if(7 - temp == 1) ans += a[n-1][0]-a[j][0];
                if(7 - temp == 2) ans += a[n-1][1]-a[j][1];
                if(7 - temp == 4) ans += a[n-1][2]-a[j][2];
            }
            temp = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3796
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
int main()
{
	LL a,b,now=1;a=read();b=read();
	LL fi=1,se=1+b;
	for(int i=1;i<=b;++i)
	{
		if(fi>=se)
		{
			fi=b+2;
			se=2*b+1;
		}
		printf("%lld %lld\n",fi,se);
		fi++;se--;
	}
}

Measured memory_bytes: 3760