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

int main(){
  int N,M;
  cin>>N>>M;
  
  vector<char> S(N+1);
  for(int i=0;i<=N;++i) cin>>S[i];

  vector<int> v;
  bool frag=true;
  int x=N;
  
  while(x>0){
    int nx=x-M;
    if(nx<=0){
    v.push_back(x);
    x=0;
    }
    else{
      while(S[nx]=='1') ++nx;
      if(nx==x){
        frag=false;
        break;
      }
      else{
        v.push_back(x-nx);
        x=nx;
      }
    }
  }

  if(frag){
    for(int i=0;i<v.size();++i){
      cout<<v[v.size()-i-1]<<" ";
    }
  }
  else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long power(long a, long b) {
    return b ? power(a*a%MOD, b/2) * (b%2?a:1)%MOD:1;
}

long perm(int N, int K) {
    long x = 1;
    for(int i = 1; i <= K; i++) x = x * (N-i+1) % MOD;
    return x % MOD;
}

long comb(int N,int K) {
    long x = 1, y = 1;
    for(int i = 1; i <= K; i++) {
        x = x * (N-i+1) % MOD;
        y = y * i % MOD;
    }
    return x * power(y, MOD-2) % MOD;
}

bool isprime(int n) {
    if(n < 2) return false;
    for(int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true;

    for(int next_v : G[v]) {
        if(seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

void yes() { cout << "Yes" << endl;}
void no() { cout << "No" << endl;}



int main() {
  string s, t; cin >> s >> t;
  bool flag = s.substr(0, s.size()) == t.substr(0, s.size()) && s.size() + 1 == t.size();
  if (flag) yes();
  else no();
  

}

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

int main()
{
	int n, m, l;
	long long int a[100][100], b[100][100], c[100][100];
	int i, j, k;
	
	cin >> n >> m >> l;

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			a[i][j] = 0;
			cin >> a[i][j];
		}
	}

	for (j = 0; j < m; j++) {
		for (k = 0; k < l; k++) {
			b[j][k] = 0;
			cin >> b[j][k];
		}
	}

	for (i = 0; i < n; i++) {
		for (k = 0; k < l; k++) {
			c[i][k] = 0;
		}
	}

	//計算部分
	for (i = 0; i < n; i++) {
		for (k = 0; k < l; k++) {
			for (j = 0; j < m; j++) {
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}

	for (i = 0; i < n; i++) {
		for (k = 0; k < l-1; k++) {
			cout << c[i][k] << " ";
		}
		cout << c[i][l-1] << endl;
	}
    return 0;
}




Measured memory_bytes: 3332
import itertools

n = int(input())
nums = [i for i in range(1, n+1)]
p = tuple(map(int, input().split(" ")))
q = tuple(map(int, input().split(" ")))

count = 0
p_v = None
q_v = None
for i, v in enumerate(itertools.permutations(nums, n)):
    if v == p:
        count += 1
        p_v = i
    if v == q:
        count += 1
        q_v = i
    if count == 2:
        break

print(abs(q_v-p_v))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define tam 220000
#define offset 
const ll MOD= 998244353;
int mapa[tam];
int main()
{
    int n;
    cin>>n;
    forr(i,0,n-1)
    {
        int valor;
        cin>>valor;
        mapa[valor]++;
    }
    forr(i,1,n+1)
    cout<<mapa[i]<<endl;
}
// PLUS ULTRA!


Measured memory_bytes: 4368
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    vi in(n+1);
    loop(i,1,n+1)cin >> in[i];
    vi a(n+1,0);
    vi ans;
    for(int i = n; i > 0; i--){
        if(a[i] != in[i]){
            ans.push_back(i);
            for(int j = 1; j*j <= i; j++)if(i%j == 0){
                a[j] = 1 - a[j];
                if(j*j < i)a[i/j] = 1 - a[i/j];
            }
        }
    }
    sort(all(ans));
    cout << ans.size() << endl;
    rep(i,ans.size())cout << ans[i] << " \n"[i == ans.size()];
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define si(n) scanf("%d",&n);
#define pi(n) printf("%d\n",n);
#define pl(n) printf("%lld\n",n);
#define sl(n) scanf("%lld",&n);
#define pd(n) printf("%lf\n",n);
#define ss(s) scanf("%s",s);
#define ps(s) printf("%s\n",s);
#define ll long long int
#define pb push_back
#define maxn 100005
#define sqrtn 317
#define maxm 2e9
#define pii pair<int,int>
#define eps 1e-9
#define mod 1000000007
using namespace std;
char s[maxn];
int main()
{
    ss(s);
    int len=strlen(s);
    int n=0,e=0,so=0,w=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='N')
        {
            n=1;
        }
        else if(s[i]=='S')
        {
            so=1;
        }
        else if(s[i]=='E')
        {
            e=1;
        }
        else{
            w=1;
        }
    }
    if(e^w!=1 && n^so!=1)
    {
        ps("Yes");
    }
    else
    {
        ps("No");
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
int main() {
    ll N;
    cin>>N;
    vi bin(9,0);
    REP(i,N){
        ll a;
        cin>>a;
        a=min(a,3200ll);
        bin[a/400]+=1;
    }
    ll x=0;
    REP(i,8){
        if(bin[i]>0)x++;
    }
    cout<<max(1ll,x)<<" "<<x+bin[8]<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
if not (1 <= N <= 86):
    sys.exit()

L = [2,1]
if N == 1:
    print(1)
    sys.exit()

for I in range(2,N+2):
    L.append(L[I-1] + L[I-2])
print(L[N])


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  int a[4]={0,0,0,0};
  for(int i=0;i<n;i++){
  	cin>>s;
    if(s=="AC") a[0]++;
    else if(s=="WA") a[1]++;
    else if(s=="TLE") a[2]++;
    else if(s=="RE") a[3]++;
  }
  cout<<"AC"<<" "<<"x"<<" "<<a[0]<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<a[1]<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<a[2]<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<a[3]<<endl;
  return 0;
}


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

int main () {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    vector <int> ax = {x+r, x-r};
    vector <int> ay = {y+r, y-r};
    string ans = "Yes";
    for (int i = 0; i < ax.size(); i++) 
        if (0 > ax[i] || ax[i] > W ) ans = "No";
    for (int i = 0; i < ay.size(); i++) 
        if (0 > ay[i] || ay[i] > H ) ans = "No";

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<vector>
using namespace std;
const long long mod=1000000007;
int counter(long long n)
{
    int ctr=0;
    while(n!=0)
    {
        ctr++;
        n=n&(n-1);
    }
    return ctr;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,i,j,k;
    cin>>n;
    vector<bool>tmp1(n);
    vector<vector<bool> >arr(n,tmp1);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            int x;
            cin>>x;
            arr[i][j]=(x?true:false);
        }
    }
    vector<long long>tmp(1<<n);
    vector<vector<long long> >dp(n+1,tmp);
    for(j=0;j<(1<<n);j++)   dp[n][j]=0;
    dp[n][(1<<n)-1]=1l;
    for(i=n-1;i>=0;i--)
    {
        for(j=0;j<(1<<n);j++)
        {
            int cnt=counter(j);
            dp[i][j]=0;
            if(cnt!=i) continue;
            for(int k=0;k<n;k++)
            {
                if((((1<<k)&j)==0) && arr[i][k])
                    dp[i][j]=(dp[i][j]+dp[i+1][j|(1<<k)])%mod;
            }
        }
    }
    long long ans=dp[0][0];
    cout<<ans;
}


Measured memory_bytes: 377216
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll n;
	cin >> n;
	vector<ll> h(n);
	REP(i,n) cin >> h[i];
	
	ll ans=0;
	ll mizu=0;
	REP(i,n){
		if(mizu < h[i]){
			ans += h[i]-mizu;
		}
		mizu = h[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

import java.util.ArrayList;
import java.util.Collections;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); //ぜんぶ
    int K = sc.nextInt(); //買うやつ
    
    ArrayList<Integer> list = new ArrayList<Integer>(); //ねだん
    
    for(int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    Collections.sort(list);
    
    Integer sum = 0;
    for(int i = 0; i < K; i++) {
      sum += list.get(i);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 39000
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void)
{
    int N;
    string s0, s1;
    map<string, int> m;

    cin >> N;
    cin >> s0;
    m.insert(make_pair(s0, 0));

    bool is_ok = true;
    for(int i = 1; i < N; ++i)
    {
        cin >> s1;

        if(s0.back() != s1.front())
        {
            is_ok = false;
        }

        pair<map<string, int>::iterator, bool> ret = m.insert(make_pair(s1, 0));
        if(!ret.second)
        {
            is_ok = false;
        }

        s0 = s1;
    }

    if(is_ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}

//x未満の要素数を返す二分探索関数
int b_s(vector<int>&vecxx, int xx) {
	if (xx <= vecxx[0]) { //x以下の要素数を返させる時は"<"に変える
		return 0;
	}
	if (vecxx.back() < xx) { //x以下の要素数を返させる時は"<="に変える
		return vecxx.size();
	}
	int aa1 = 0, aa2 = vecxx.size() - 1, aa3;
	while (aa1 + 1 < aa2) {
		aa3 = (aa1 + aa2) / 2;
		if (vecxx[aa3] >= xx) { //x以下の要素数を返させる時は">"に変える
			aa2 = aa3;
		}
		else {
			aa1 = aa3;
		}
	}
	return aa2;
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す

int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,t=0;
	cin >> n;
	vector<int>vec(n - 1),vec2(n);
	vecin(vec);
	
	for (int i = 0; i < n-1; i++) {
		vec2[i] = min(vec2[i], vec[i]);
		vec2[i + 1] = vec[i];
	}
	vec2[0] = vec[0];
	rep(i, n) {
		t += vec2[i];
	}
	cout << t << endl;
}




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


int main(){
    while(1){
        string str;
        cin >> str;
        if(str=="#") break;

        int len = str.length();
        vector<int> seq(len);
        for(int i=0; i<len; i++){
            seq[i] = (str[i]-'1')%3;
        }
        
        int leg = -1; //l:0,r:1
        int ans = 0;
        for(int i=0; i<len-1; i++){
            if(seq[i+1]-seq[i] > 0){ //move right
                if(leg==1) ans++;
                else if(leg==-1) leg=1;
                else leg = 1-leg;
            }else if(seq[i+1]-seq[i] < 0){
                if(leg==0) ans++;
                else if(leg==-1) leg=0;
                else leg = 1-leg;
            }else{
                if(leg!=-1) leg = 1-leg;
            }
        }       
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            //var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();



            Console.WriteLine(N >= 3200 ? s : "red");

            //Console.Out.Flush();

        }
    }

    //010100

    public class Calculation
    {

    }

    public class Graph
    {

    }
}




Measured memory_bytes: 11092
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

s = lc()

cnt = Counter([])

for si in s:
    cnt[si] += 1
    

ans = True

for key, value in cnt.items():
    if value != 1:
        ans = False
        break
    
if ans:
    print("yes")
else:
    print("no")

Measured memory_bytes: 3316
#include<stdio.h>

int main(){
	int N, M, X;
	scanf("%d %d %d", &N, &M, &X);
	
	int A[M], i=0;
	for(i=0; i<M; i++){
		scanf("%d", &A[i]);
	}
	
	i=-1;
	do{
		i++;
	}while(A[i]<X);
	
	if(i<M-i)	printf("%d\n", i);
	else if(A[i]==X)	printf("%d\n", M-i-1);
	else			printf("%d\n", M-i);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  vll a(n);
  re(i, n) std::cin >> a[i];
  sort(all(a));
  ll ans = 0;
  for(int i=0;i<k;i++) ans += a[i];
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;

public class Main{
    static boolean is_prime(int p){
        for(int i = 2; i * i <= p; i++)
            if(p % i == 0) return false;
        return true;
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int ps = scan.nextInt(); int r = 0;
        for(int i = 0; i < ps; i++)
            if(is_prime(scan.nextInt())) r++;
        System.out.println(r);
    }
}

Measured memory_bytes: 40744
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define pb	push_back

using namespace std;

const int N = 100005;

long long n, a[N];

int main(){
	scanf("%lld", &n);
	repn(i, n) scanf("%lld", &a[i]);
	long long ret = 0;
	long long cnt = 0;
	long long sum = 0;
	repn(i, n){
		sum += a[i];
		if(i & 1){
			if(sum <= 0) cnt += 1LL - sum, sum = 1;
		}
		else{
			if(sum >= 0) cnt += 1LL + sum, sum = -1;
		}
	}
	ret = cnt;
	cnt = 0, sum = 0;
	repn(i, n){
		sum += a[i];
		if(i & 1){
			if(sum >= 0) cnt += 1LL + sum, sum = -1;
		}
		else{
			if(sum <= 0) cnt += 1LL - sum, sum = 1;
		}
	}
	ret = min(ret, cnt);
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 1024
import sys
from collections import defaultdict, Counter

input = sys.stdin.readline
N, M = map(int, input().split())
A = (Counter(list(map(int, input().split()))))
for i in range(M):
    B,C=map(int,input().split())
    if C in A:
        A[C] += B
    else:
        A[C] = B
A = sorted(A.items(),reverse=True)
tmp = 0
cnt = 0
ans = 0
while tmp < N:
    i,j = A[cnt]
    ans += min(N-tmp,j)*i
    cnt += 1
    tmp += min(N-tmp,j)
print(ans)

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

int n;
vector<int> a, b;

int calc(int bit) {
    vector<array<int, 2>> v;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        if (bit & (1 << i)) v.push_back({b[i], i}), c[i] = 1;
        else v.push_back({a[i], i}), c[i] = 0;
    }
    sort(v.begin(), v.end());
    map<int, vector<int>> m;
    for (int i = 0; i < n; i++) {
        m[v[i][0]].emplace_back(v[i][1]);
    }
    int cnt = 0;
    vector<int> fn;
    for (auto &iter: m) {
        auto &w = iter.second;
        int l = w.size();
        int od = l / 2, ev = l / 2;
        if (l & 1) {
            if (cnt & 1) od++;
            else ev++;
        }
        queue<int> o, e;
        for (int i = 0; i < l; i++) {
            if ((w[i] & 1) ^ c[w[i]]) o.emplace(w[i]);
            else e.emplace(w[i]);
        }
        if (od == o.size() && ev == e.size()) {
            for (int i = 0; i < l; i++) {
                if (cnt & 1) {
                    fn.emplace_back(o.front()); o.pop();
                } else {
                    fn.emplace_back(e.front()); e.pop();
                }
                cnt++;
            }
        } else return -1;
    }

    int minop = 0;
    vector<int> op(n, 0), used(n, 0);
    for (int i = 0; i < n; i++) {
        auto x = fn[i];
        used[x]++;
        for (int j = 0; j < x; j++) {
            if (!used[j]) op[j]++, op[x]++, minop++;
        }
    }
    return minop;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    int ans = 1e9;
    for (int bit = 0; bit < (1 << n); bit++) {
        int d = calc(bit);
        if (d >= 0) ans = min(d, ans);
    }
    cout << (ans == 1e9 ? -1 : ans) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#if 1
    #define u8 unsigned char
    #define u16 unsigned short
    #define u32 unsigned int
    #define u64 unsigned long
    #define s8 char
    #define s16 short
    #define s32 int
    #define s64 long
    #define f32 float
    #define f64 double
    #define forin(_x,_y) for(auto& _x: _y)
    #define iter(_i,_c) for(auto _i=0; _i<_c; ++_i)
#endif

using namespace std;
#if 1
    int ctoi(char a){return a-'0';}

    template<class T> T max(const vector<T> &x){return *std::max_element(x.begin(), x.end());}
    template<class T> T min(const vector<T> &x){return *std::min_element(x.begin(), x.end());}
    template<class T> size_t argmax(const vector<T> &x){auto iter = std::max_element(x.begin(), x.end()); return std::distance(x.begin(), iter);}
    template<class T> size_t argmin(const vector<T> &x){auto iter = std::min_element(x.begin(), x.end()); return std::distance(x.begin(), iter);}
    template<class T> T sum(const vector<T> &x){ return std::accumulate(x.begin(), x.end());}
    template <class T> void sort(vector<T> &x){sort(x.begin(), x.end());}
    template <class T, class Compare> void sort(vector<T> &x, Compare comp){sort(x.begin(), x.end(),comp);}
    template<class T> void len(const vector<T> &x){return x.size();}
    template<class T> ostream& operator<<(ostream& os, const vector<T> &x){forin(y,x)os<<y<<" "; return os;}

    template<class T, size_t SIZE> T max(const array<T,SIZE> &x){return *std::max_element(x.begin(), x.end());}
    template<class T, size_t SIZE> T min(const array<T,SIZE> &x){return *std::min_element(x.begin(), x.end());}
    template<class T, size_t SIZE> size_t argmax(const array<T,SIZE> &x){auto iter = std::max_element(x.begin(), x.end()); return std::distance(x.begin(), iter);}
    template<class T, size_t SIZE> size_t argmin(const array<T,SIZE> &x){auto iter = std::min_element(x.begin(), x.end()); return std::distance(x.begin(), iter);}
    template<class T, size_t SIZE> T sum(const array<T,SIZE> &x){ return std::accumulate(x.begin(), x.end());}
    template<class T, size_t SIZE> void sort(array<T,SIZE> &x){sort(x.begin(), x.end());}
    template<class T, size_t SIZE, class Compare> void sort(array<T,SIZE> &x, Compare comp){sort(x.begin(), x.end(),comp);}
    template<class T, size_t SIZE> ostream& operator<<(ostream& os, const array<T,SIZE> &x){forin(y,x)os<<y<<" "; return os;}
#endif

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

    u32 N;
    cin>>N;
    vector<u32> P(N);
    iter(i, N){
        u32 p;
        cin>>p;
        P[i] = p;
    }

    u32 m = N+1;
    u32 count = 0;

    iter(i,N){
        m = min(m, P[i]);
        if(m==P[i]) count++;
    }

    cout<<count;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = inl()
ans = 0
b = [0] * (10**5 + 1)
for i in a:
    b[i] += 1
for i in range(10**5-1):
    ans = max(ans, b[i] + b[i+1] + b[i+2])
print(ans)

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

    ll i,j,k,c,d,a,b,e,f,p,q,n,t,m,r,u,x,y;
    vector<ll > vv,ss,v,s;
    string st,et;
    map<ll,ll > pa,ea,ma;
    cin>>a>>b;
    cout<<a*b<<endl;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(){
  int A, B, C;
  
  cin >> A >> B >> C;
  
  if((A == B && A == C) || (A != B && A != C && B != C)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int d;
    if((a+b)%2==0)
    	printf("%d",(a+b)/2);
    else
    	printf("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 256
def setHeapDown_max(heap, pos):
    targetkey = heap[pos]
    while pos > 0:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < targetkey:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = targetkey

def setHeapUp_max(heap, pos):
    endpos = len(heap)
    targetkey = heap[pos]
    childpos = 2*pos + 1
    while childpos < endpos:
        rightpos = childpos + 1
        if rightpos < endpos and not heap[rightpos] < heap[childpos]:
            childpos = rightpos
        childkey = heap[childpos]
        if targetkey > childkey:
            break
        heap[pos] = childkey
        pos = childpos
        childpos = 2*pos + 1
    heap[pos] = targetkey

def heapPush_max(heap, key):
    heap.append(key)
    setHeapDown_max(heap, len(heap) - 1)

def heapPop_max(heap):
    lastkey = heap.pop()
    if heap:
        returnkey = heap[0]
        heap[0] = lastkey
        setHeapUp_max(heap, 0)
        return returnkey
    return lastkey


import sys

S = []

for x in sys.stdin.readlines():
    if x[0] == 'i':
        k = int(x[7:])
        heapPush_max(S, k)
    elif x[1] == 'x':
        print(heapPop_max(S))
    else:
        pass

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream&
operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream&
operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream&
operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

vector<ll> generate_primes(ll N) {
    vector<int> is_prime(N, 1);
    vector<ll> primes;
    repeat(i, 2, N) {
        if(not is_prime[i]) continue;
        primes.push_back(i);
        for(ll j = i * 2; j < is_prime.size(); j += i) is_prime[j] = 0;        
    }
    return primes;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    auto primes = generate_primes(pow(1e10, 1.0/3.0)+10);
    
    int N; cin >> N;
    vector<ll> S(N); cin >> S;

    map<ll, int> normalized_s;

    auto normalize = [&] (ll s) {
        for(ll p : primes) {
            ll ppp = p * p * p;
            while(s % ppp == 0) s /= ppp;            
            if(s == 1) break;
        }
        return s;
    };
    
    for(ll s : S) {
        normalized_s[normalize(s)]++;
    }
    
    int ans = 0;
    set<ll> used;
    for(auto s_ : normalized_s) {
        ll s = s_.first;
        if(used.count(s)) continue;
        
        ll t = normalize(s * s);
        used.insert(s);
        used.insert(t);
        
        int s_cnt = s_.second;
        int t_cnt = normalized_s.count(t) ? normalized_s[t] : 0;
        
        ans += s == t ? 1 : max(s_cnt, t_cnt);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 16640
n = int(input())
D = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
    s = input()
    k = s[0]
    if k in D:
        D[k] += 1
L = list(D.values())
ans = 0
for i in range(len(L) - 2):
    for j in range(i + 1, len(L) - 1):
        for k in range(j + 1, len(L)):
            ans += L[i] * L[j] * L[k]
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>

using namespace std;

int h[100000];
int cost[100000];

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

  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  cost[1] = abs(h[0] - h[1]);
  for (int i = 2; i < N; i++) {
    cost[i] = min(cost[i - 1] + abs(h[i - 1] - h[i]),
                  cost[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << cost[N - 1] << endl;
  return 0;
}


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

int main(){
    int H,W,i,j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        for(i=0;i<W;i++){
            cout<<"#";
        }
        cout<<endl;
        for(j=2;j<H;j++){
            cout<<"#";
            for(i=2;i<W;i++){
                cout<<".";
            }
            cout<<"#"<<endl;
        }
        for(i=0;i<W;i++){
            cout<<"#";
        }
        cout<<endl<<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include<cstdio>
using namespace std;
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>b)
        printf("a > b");
    else
        if(a<b)
        printf("a < b");
        else
            printf("a == b");
        printf("\n");
    return 0;
}



Measured memory_bytes: 2756
import sys
input = sys.stdin.readline
mod = 998244353
n = int(input())
XY = sorted(tuple(map(int, input().split())) for _ in range(n))
X, Y = zip(*XY)
L = {y:i+1 for i, y in enumerate(sorted(Y))}
Y = tuple(L[y] for y in Y)
BIT = [0]*(n+1)
def add(i):
  while i<=n:
    BIT[i] += 1
    i += i&-i
def acc(i):
  res = 0
  while i:
    res += BIT[i]
    i -= i&-i
  return res
A = [0]*n
B = [0]*n
C = [0]*n
D = [0]*n
for i, y in enumerate(Y):
  A[i] = acc(y)
  B[i] = i - A[i]
  add(y)
BIT = [0]*(n+1)
for i in range(n-1, -1, -1):
  y = Y[i]
  C[i] = acc(y)
  D[i] = n-1-i - C[i]
  add(y)
T = [1]*n
for i in range(n-1):
  T[i+1] = T[i]*2%mod
ans = T[n-1] * n % mod
for a, b, c, d in zip(A, B, C, D):
  a = T[a]
  b = T[b]
  c = T[c]
  d = T[d]
  temp = (a-1)*b*c*(d-1) + a*(b-1)*(c-1)*d - (a-1)*(b-1)*(c-1)*(d-1)
  ans += temp
  ans %= mod
print(ans)

Measured memory_bytes: 177424
#include <bits/stdc++.h>
#include <vector>
#include <tgmath.h>

using namespace std;


void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    cout<<fixed<<setprecision(10);
    double ans =0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ans += sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
    }
    ans /= N;
    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
S = list(input())
n = len(S)
ACGT = ["A","C","G","T"]
ans = 0
for i in range(n):
    if S[i] in ACGT:
        if i == n-1:
            ans = max(ans,1)
        else:
            streak = 1
            for j in range(i+1,n):
                if S[j] in ACGT:
                    streak += 1
                else:
                    break
            ans = max(ans,streak)

print(ans)


Measured memory_bytes: 3060
#   AtCoder abc054 a
#   ストレッチ課題

#   入力
alice, bob = map(int, input().split())

#   判定
if alice == bob:
    print("Draw")
elif (alice == 1) or ((bob != 1) and (alice > bob)):
    print("Alice")
else:
    print("Bob")


Measured memory_bytes: 9128
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let x:i32 = read();
    let a:i32 = read();

    println!("{}", if x < a {0} else {10});

}


Measured memory_bytes: 4352
<?php
while (true) {
    list($x, $y) = array_map("intval", explode(' ', trim(fgets(STDIN))));
    
    if ($x == 0 and $y == 0) {
        break;
    } else {
        if ($x > $y) {
            echo "{$y} {$x}\n";
        } else {
            echo "{$x} {$y}\n";
        }
    }
}
?>


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

void rec(int k,ll lunlun,vector<ll> &ans){
  ans.push_back(lunlun);
  if(k==10) return;

  for(ll j=-1;j<=1;++j){
    ll ad=(lunlun%10)+j;
    if(ad>=0 && ad<=9) rec(k+1,lunlun*10+ad,ans);
  }
}


int main(){
  ll k;
  cin >> k;
  vector<ll> ans;
  for(ll i=1;i<=9;++i){
    rec(1,i,ans);
  }
  sort(ans.begin(),ans.end());
  cout << ans[k-1] << endl;
  return 0;

}


Measured memory_bytes: 2420
# https://atcoder.jp/contests/dp/tasks/dp_a

n = int(input())
h = list(map(int, input().split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(0, n - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    if i < n - 2:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))

print(dp[-1])


Measured memory_bytes: 13928
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), k = in();
    cout << n - k + 1 << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]

    for a in a_list:
        if a == a_first:
            print(a_second)
        else:
            print(a_first)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14112
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890

using namespace std;

struct info
{
    int w;
    int v;
};
bool operator<(info a,info b)
{
    return a.w < b.w;
}

info arr[100007];

int main()
{
    int i,j;
    int N,M;

    scanf("%d %d",&N,&M);
    for( i=0; i<N; i++)
    {
        scanf("%d %d",&(arr[i].w),&(arr[i].v));
    }
    sort(arr,arr+N);
    // for( i=0; i<N; i++)
    // {
    //     printf("{%d,%d}\n",arr[i].w,arr[i].v);
    // }

    priority_queue<int>pq;
    int total = 0;
    for( i=1,j=0; i<=M; i++)
    {
        // printf("i = %d\n",i);
        while(j<N && arr[j].w <= i)
        {
            // printf("push(%d,%d)\n",arr[j].w,arr[j].v);
            pq.push(arr[j++].v);
        }
        if(!pq.empty())
        {
            total += pq.top();
            pq.pop();
        }
    }

    printf("%d\n",total);


    return 0;
}


Measured memory_bytes: 1660
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define mn 100005
#define inf 4444444444444444444
#define mod 1000000009
#define FLN "test"
#define pii pair <int, int>
#define XX first
#define YY second

int n, A[mn];

signed main()
{
#ifdef lowie
	freopen(FLN".inp", "r", stdin);
	freopen(FLN".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	int w=0;
	for (int i=1; i<=n; i++) if (A[i]%2==1) w=1;
	if (w==1) cout<<"first";
	else cout<<"second";
}

// PLEASE REMOVE "cout" AND "cerr" DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Code by low_
// Contact me via mail: dung.totuan01@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie_review/


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Linq;


public class Test
{	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split(' ');
		int[] nums = new int[str.Length];
		int ans = 0;

		for(int i = 0 ; i < nums.Length ; i++)
		{
			nums[i] = int.Parse(str[i]);
		}

		int m = int.Parse(Console.ReadLine());
		int P = 0;
		int X = 0;
		for(int i = 0 ; i < m ; i++)
		{
			ans = 0;
			str = Console.ReadLine().Split(' ');
			P = int.Parse(str[0]);
			X = int.Parse(str[1]);
			for(int j = 0 ; j < nums.Length ; j++)
			{
				if(j+1 == P)
				{
					ans += X;
				}
				else {
					ans += nums[j];
				}
			}
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;



int main(){
    int n;cin>>n;
    int s[n+1];for(int i=1;i<=n;i++)cin>>s[i];
    bool dp[n+1][10005];
    for(int i=0;i<=10004;i++)dp[0][i]=false,dp[n][i]=false;
    dp[0][0]=true;
    for(int i=1;i<=n;i++)for(int j=0;j<=10004;j++){
        if(j<s[i])dp[i][j]=dp[i-1][j];
        else dp[i][j]=dp[i-1][j]||dp[i-1][j-s[i]];
    }
    int j;
    for(j=10004;j>=1;j--){
        if(dp[n][j]==true&&j%10!=0)break;
    }
    cout<<j<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main(void){
    int N,M;
    int a[52],b[52],c[52]={};
    cin >> N >> M;
    REP(i,M){cin >> a[i] >> b[i];}
    REP(i,M){
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    REP(i,N){cout << c[i] << endl;}
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(12);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K;

  std::cin >> N >> K;

  long double P = 0.0;

  std::map<int, long double> memo;

  for (int i = 1; i <= N; i ++) {
    int c = 0, n = i;

    for ( ; n < K; n *= 2, c ++)
      ;

    long double p = 1.0;

    if (memo.count(c)) {
      p = memo.at(c);
    }
    else {
      for (int i = 0; i < c; i ++)
        p /= 2.0;
      
      p /= N;

      memo[c] = p;
    }

    P += p;
  }

  std::cout << P << std::endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class ABC135A {
    public static void Main() {
        int A, B;
        string[] str = Console.ReadLine().Split(' ');
        A = int.Parse(str[0]);
        B = int.Parse(str[1]);
        if ((A + B) % 2 == 0) Console.WriteLine((A + B) / 2);
        else Console.WriteLine("IMPOSSIBLE");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <tuple>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef vector<tuple<int,int,int>> City;//to,limit,distance
vector<City> C;
typedef tuple<double,int,int,int> T;//time,cityid,speed,prev
priority_queue<T,vector<T>,greater<T>> que;
double memo[31][31][31];//[prev][cityid][speed]

int main(){
    cout.precision(5);
    cout<<fixed;
    int n,m;
    while(cin>>n>>m,n){
        int s,g;
        cin>>s>>g;
        C.clear();
        for(int i=0;i<=n;i++) C.push_back(City());
        for(int i=0;i<m;i++){
            int x,y,d,c;
            cin>>x>>y>>d>>c;
            C[x].emplace_back(y,c,d);
            C[y].emplace_back(x,c,d);
        }
        fill(memo[0][0],memo[31][0],1e8);
        memo[0][s][0]=0;
        while(!que.empty())que.pop();
        que.emplace(0,s,0,0);
        double ans=1e8;
        while(!que.empty()){
            T t=que.top(); que.pop();
            double time=get<0>(t);
            int cityid=get<1>(t);
            int speed=get<2>(t);
            int prev=get<3>(t);
            if(time>memo[prev][cityid][speed]) continue;
            if(cityid==g&&speed==1){
                ans=time;
                break;
            }
            for(auto& e:C[cityid]){
                int to=get<0>(e);
                int limit=get<1>(e);
                double distance=get<2>(e);
                if(to==prev)continue;
                if(speed+1<=limit){
                    if(memo[cityid][to][speed+1]>time+distance/(speed+1)){
                        memo[cityid][to][speed+1]=time+distance/(speed+1);
                        que.emplace(memo[cityid][to][speed+1],to,speed+1,cityid);
                    }
                }
                if(speed<=limit&&speed>0){
                    if(memo[cityid][to][speed]>time+distance/(speed)){
                        memo[cityid][to][speed]=time+distance/(speed);
                        que.emplace(memo[cityid][to][speed],to,speed,cityid);
                    }
                }
                if(speed-1<=limit&&speed-1>0){
                    if(memo[cityid][to][speed-1]>time+distance/(speed-1)){
                        memo[cityid][to][speed-1]=time+distance/(speed-1);
                        que.emplace(memo[cityid][to][speed-1],to,speed-1,cityid);
                    }
                }
            }
        }
        if(ans==1e8){
            cout<<"unreachable"<<endl;
        }else{
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3876
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;

void max_self(ll& a, ll b) {
    if(a < b) {
        a = b;
    }
}

int main() {
    
    int n, w;
    scanf("%d%d",&n,&w);
    
    vector<ll> dp(w+1, 0);
    
    for(int i = 0; i < n; ++i) {
        ll weight, value;
        scanf("%lld%lld", &weight, &value);
        
        for(int prevWeight = w-weight; prevWeight >= 0; --prevWeight) {
            max_self(dp[prevWeight+weight], dp[prevWeight]+value);
        }
    }
    
    debug() << imie(dp);
    
    ll ans = 0;
    for(int weight = w; weight >= 0; --weight) {
        ans = max(ans, dp[weight]);
    }
    
    printf("%lld\n", ans);
    
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1001001001;

int MAX, N, dist[260][260], D[260];
bool can[260];

void dfs(int u){
	FOR(v,1,N+3){
		if(dist[u][v] != INF && !can[v]){
			can[v] = true;
			dfs(v);
		}
	}
}

int main(){
  while(scanf("%d %d", &MAX, &N), MAX){
    std::fill(D, D+260, 0);
    std::fill(can, can+260, false);

    FOR(i,2,N+2){
      scanf("%d", D+i);
      // printf("%d: %d\n", i, D[i]);
    }

    FOR(i,1,N+3){FOR(j,1,N+3){if(i==j){dist[i][j]=0;}else{dist[i][j]=INF;}}}

    FOR(i,1,N+3){
      for(int j=1;j<=MAX&&i+j<=N+2;j++){
        int k = i+j+D[i+j];
        if(k < 0){k = 0;}
        if(k > N+2){k = N+2;}
        if(i == k){continue;}
        // printf("%d, %d, %d, %d\n", i, j, D[i+j], k);
        dist[i][k] = 1;
      }
    }
    
    can[1] = true;
    dfs(1);

    FOR(k,1,N+3){
      FOR(i,1,N+3){
        FOR(j,1,N+3){
          if(dist[i][j] > dist[i][k] + dist[k][j]){dist[i][j] = dist[i][k] + dist[k][j];}
        }
      }
    }

    bool f = true;
    FOR(i,1,N+3){
      if(!can[i]){continue;}
      // printf("%d->N+2: %d\n", i, dist[i][N+2]);
      if(dist[i][N+2] == INF){f = false;}
    }

    if(f){puts("OK");}
    else{puts("NG");}
  }
}

Measured memory_bytes: 1432
#include <stdio.h>

int main(){
  int x[3000], y[3000], i, n=0, tmp;

  while(1){
    scanf("%d %d", &x[n], &y[n]);
    if(x[n] == 0 && y[n] == 0)
      break;
    if(x[n] > y[n]){
      tmp = x[n];
      x[n] = y[n];
      y[n] = tmp;
    }
    n++;
  }

  for(i = 0; i < n; i++)
    printf("%d %d\n", x[i], y[i]);

  return 0;
}



Measured memory_bytes: 1932
#include<stdio.h>

int main(){
	int i,d[100]={0},x,max=0;
	while(scanf("%d",&x)!=-1) d[x]++;
	for(i=0;i<100;i++) if(d[i]>=max) max=d[i];
	for(i=0;i<100;i++) if(d[i]==max) printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 596