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

const int N = 1e5 + 9, P = 1e9 + 7;

int a[N], n, Gr[N], s[N], t, la, h[N], sh, f[N], ans = 1;
bool v[N], inh[N], is[N];
vector<int>V[N];
unordered_map<int, int>T;

void Ext () { puts("0"); exit(0); }

void Dfs (int x, int fr) {
	is[x] = 1; s[++t] = x; v[x] = 1;
	for (auto v : V[x]) if (v != fr) {
		if (is[v]) {
			la = v;
			break ;
		} else {
			Dfs(v, x);
			if (la != -2) break ;
		}
	} else fr = -1;
	if (la > 0) {
		h[sh++] = x;
		inh[x] = sh;
		if (Gr[x] > 3) Ext();
		if (x == la) la = -1;
	}
	is[x] = 0; --t;
}

namespace T1 {
	void Dfs (int u, int fa) {
		if (!inh[u]) {
			v[u] = 1;
			if (Gr[u] > 2) Ext();
		}
		for (auto v : V[u]) if (!inh[v] && v != fa) {
			Dfs(v, u);
			f[u] = f[v] + 1;
		}
	}
	int main () {
		for (int i = 0; i < sh; ++i) Dfs(h[i], 0);
		int ans = 1, i = 0, j, k;
		while (i < sh && !f[h[i]]) ++i; if (i == sh) return ++T[sh], 1;
		do if (f[h[i]]) {
			for (j = (i + 1) % sh, k = 1; !f[h[j]]; j = (j + 1) % sh, ++k);
			int ret = 0;
			if (f[h[i]] < k) ++ret;
			if (f[h[i]] <= k) ++ret;
			ans = 1ll * ans * ret % P;
			if (j <= i) break ;
		} while (i = j, 1);
		return ans;
	}
}

int Sol (int m, int n) {
	f[0] = f[1] = 1; int b = 1 + (m > 1 && (m & 1));
	for (int i = 1; i <= n; ++i) f[i] = (1ll * f[i - 2] * m % P * (i - 1) + f[i - 1] * b) % P;
	return f[n];
}

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		V[i].emplace_back(a[i]), V[a[i]].emplace_back(i);
		++Gr[i]; ++Gr[a[i]];
	}
	for (int i = 1; i <= n; ++i) if (!v[i]) {
		la = -2, sh = 0, Dfs(i, 0);
		if (sh > 1 && a[h[0]] == h[1]) reverse(h, h + sh);
		ans = 1ll * ans * T1::main() % P;
	}
	for (auto v : T) ans = 1ll * ans * Sol(v.first, v.second) % P;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12672
#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;

// dp[i][j] - the number of ways to put numbers in prefix of size 'i'
// such that the last number is 'j'

const int nax = 3005;
char cmp[nax];
int dp[nax][nax], pref[nax][nax];

const int mod = 1e9 + 7;

void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", cmp);
    dp[1][1] = 1;
    for(int len = 2; len <= n; ++len) {
        // let's compute prefix sums on dp[len-1]
        for(int i = 1; i <= len - 1; ++i) {
            pref[len-1][i] = (pref[len-1][i-1] + dp[len-1][i]) % mod;
        }
        for(int b = 1; b <= len; ++b) {
            int L, R;
            if(cmp[len-2] == '<') {
                L = 1, R = b - 1;
            }
            else {
                L = b, R = len - 1;
            }
            if(L <= R) {
                add_self(dp[len][b], (pref[len-1][R] - pref[len-1][L-1] + mod) % mod);
            }
            //~ for(int i = L; i <= R; ++i) {
                //~ add_self(dp[len][b], dp[len-1][i]);
            //~ }
            
            //~ for(int a = 1; a <= len - 1; ++a) {
                //~ int real_a = a;
                //~ if(a >= b) {
                    //~ ++real_a;
                //~ }
                //~ assert(real_a != b);
                //~ if((real_a < b) != (cmp[len-2] == '<')) {
                    //~ continue;
                //~ }
                //~ add_self(dp[len][b], dp[len-1][a]);
            //~ }
        }
    }
    int answer = 0;
    for(int b = 1; b <= n; ++b) {
        add_self(answer, dp[n][b]);
    }
    printf("%d\n", answer);
}

Measured memory_bytes: 58772
#include<iostream>	// 入出力
#include<stdio.h>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;

using ll = long long;

ll N, K;

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

	ll ans = 0;

	if (K == 0) { cout << N*N << endl; return 0; }

	for (int b = K; b <= N; ++b)
	{

		ans += (b - K)*(N / b);
		
		if (N - b*(N / b) - K + 1 > 0)
		{
			ans += N - b*(N / b) - K + 1;
		}

		
		
	}

	
	

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = 3;
		for (int i = 0; i < 3; i++) {
			sb.append(sc.next().charAt(0));
		}
		System.out.println(sb);
		sc.close();
	}
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

int n, m;
int s, t;
vi g[100000];

signed main(){
	cin >> n >> m;
	rep(i, 0, m){
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].pb(v);
	}
	cin >> s >> t;
	s--; t--;

	priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> que;
	vvi d(3, vi(n, inf));
	d[0][s] = 0;
	que.push(pair<int, pii>(0, pii(0, s)));
	while(!que.empty()){
		auto p = que.top(); 
		que.pop();
    int u = p.second.first;
		int v = p.second.second;
		if(p.first > d[u][v]) continue;
//    cout << u << ", " << v << endl;

		for(auto to : g[v]){
			if(d[(u+1)%3][to] > d[u][v]+1){
				d[(u+1)%3][to] = d[u][v]+1;	
        que.push(pair<int, pii>(d[(u+1)%3][to], pii((u+1)%3, to)));
			}
		}
	}

	if(d[0][t] == inf) cout << -1 << endl;
	else cout << d[0][t]/3 << endl;

	return 0;
}


Measured memory_bytes: 8832
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int h, w;
    int i, j;
    int a[500][500], b[500][500];
    int count=0;
    int  *y,  *x;
    int *yy, *xx;

    y = (int*)malloc(sizeof(int)*250000);
    x = (int*)malloc(sizeof(int)*250000);
    yy = (int*)malloc(sizeof(int)*250000);
    xx = (int*)malloc(sizeof(int)*250000);


    scanf("%d %d", &h, &w);
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0; i<h-1; i++) {
        //printf("i = %d\n",i);
        for(j=0; j<w-1; j++) {
            //printf("\tj = %d\n",j);
            if(a[i][j]%2==1) {
                a[i][j+1]++;
                y[count] = i+1;
                x[count] = j+1;
                yy[count] = i+1;
                xx[count] = j+2;
                count++;
            }
        }
        // j = w-1
        //printf("\tj = %d\n",j);
        if(a[i][j]%2==1) {
            a[i+1][j]++;
            y[count] = i+1;
            x[count] = j+1;
            yy[count] = i+2;
            xx[count] = j+1;
            count++;
        }
    }
    // i = h-1
    //printf("i = %d\n",i);
    for(j=0; j<w-1; j++) {
        //printf("\tj = %d\n",j);
        if(a[i][j]%2==1) {
            a[i][j+1]++;
            y[count] = i+1;
            x[count] = j+1;
            yy[count] = i+1;
            xx[count] = j+2;
            count++;
        }
    }

    printf("%d\n",count);
    for(i=0; i<count; i++) {
        printf("%d %d %d %d\n", y[i],x[i],yy[i],xx[i]);
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int x, y, z, k;
	V ans ;
	cin >> x >> y >> z >> k;
	V a(x), b(y), c(z);
	cin >> a >> b >> c;
	sort(all(a), greater<ll>());
	sort(all(b), greater<ll>());
	sort(all(c), greater<ll>());
	priority_queue<ll, V, greater<ll>> dis,det;
	rep(i, x) {
		rep(j, y) {
			dis.push(a[i] + b[j]);
			if (dis.size() == k+1) {
				if (dis.top() == a[i] + b[j]) {
					dis.pop();
					break;
				}else{
					dis.pop();
				}
			}
		}
	}
	ll at;
	while(!dis.empty()){
		at = dis.top();
		rep(i, z) { det.push(at + c[i]); 
		if(det.size()==k+1){
			if(det.top()==at+c[i]){
				det.pop();
				break;
			}else{
				det.pop();
			}
		}
		}
		dis.pop();
	}
	while(!det.empty()){
		ans.pb( det.top());
		det.pop();
	}
	reverse(all(ans));
	rep(i, k) { cout << ans[i] << endl; }
	
}
/*
xy log xy + kC log kC + klogk

*/

Measured memory_bytes: 3740
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main()
{
    ll h,n;
    ll total=0;
    cin>>h>>n;
    rep(i,n)
    {
        ll l;
        cin>>l;
        total+=l;
    }
    if(total>=h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    
}

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

const int MAX = 200010;
vector<long long> fac(MAX,1),finv(MAX,1),inv(MAX,1);
void init() {
  for(int i = 2;i < MAX;i++) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}

long long comb(long long n,long long k) {
    if(n < k || n < 0 || k < 0) return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%MOD)%MOD;
}


int main() {
  
  long long n,k;
  cin >> n >> k;

 
  long long sum = 0;
  init();
  for(int i = 0;i <= min(n-1,k);i++) {
    long long m = 1;
    m = (m*fac[n-1]%MOD*(finv[i]*finv[n-i-1]%MOD))%MOD;
    m = (m*fac[n]%MOD*(finv[i]*finv[n-i]%MOD))%MOD;
    sum = (sum+m)%MOD;
  }

  cout << sum << endl;
  

}


Measured memory_bytes: 4992
def main():
    n, q = map(int, input().split())
    queue = []
    for i in range(n):
        name, time = input().split()
        time = int(time)
        queue.append([name, time])

    t = 0
    while queue:
        process = queue.pop(0)
        if process[1] > q:
            t += q
            queue.append([process[0], process[1] - q])
        else:
            t += process[1]
            print("{} {}".format(process[0], t))


if __name__ == '__main__':
    main()



Measured memory_bytes: 12876
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

  int ans = 0;
  vi d(3); cin >> d[0] >> d[1] >> d[2];
  int n_even = 0;

  REP(i, 3){
    if( d[i]%2 == 0 ) n_even++;
  }

  if( n_even == 1 ){
    REP(i, 3){
      if( d[i]%2 == 1 ) d[i]++;
    }
    ans++;
  } else if ( n_even == 2 ) {
    REP(i, 3){
      if( d[i]%2 == 0 ) d[i]++;
    }
    ans++;
  }

  sort(d.begin(), d.end());
  ans += (2*d[2]-d[1]-d[0])/2;

  cout << ans << endl;

  return 0;
}



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

def main():
    N =int(input())
    ps = [int(s) for s in input().split()]
    result = 0
    for i, p in enumerate(ps):
        if i==0 or i==N-1:
            continue
        if (ps[i-1] > p and p > ps[i+1]) or (ps[i-1] < p and p < ps[i+1]):
            result += 1
    print(result)


if __name__ == "__main__":
    main()


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

int main() {
  int h, w;
  cin >> h >> w;
  
  for (int i = 0; i < w + 2; i++)
    cout << "#";
  cout << endl;
  
  for (int i = 0; i < h; i++) {
    string A;
    cout << "#";
    cin >> A;
    cout << A;
    cout << "#" << endl;
  }
  
  for (int i = 0; i < w + 2; i++)
    cout << "#";
  cout << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n;
	cin >> n;
	set<string> s;
	for (int i = 0; i < n; ++i){
		string t;
		cin >> t;
		s.insert(t);
	}
	cout << s.size();
	return 0;
}



Measured memory_bytes: 19284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
#define N 100010
int main(){
    int a,b;cin>>a>>b;
    int sum = 1;
    int ans = 0;
    while(sum<b){
        sum = sum+a-1;
        ans++;
    }
    co(ans);
}

Measured memory_bytes: 256
from sys import stdin,stdout
input = stdin.readline
print = stdout.write
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = sum(a)
for _ in range(int(input())):
    b1,c1 = map(int,input().split())
    if b1 in c and c[b1]:
      s+=c[b1]*c1-c[b1]*b1
      c[c1]= c.get(c1,0)+c[b1]
      c[b1]=0
    print(str(s)+'\n')

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N;

    vector<double> A(N);
    vector<double> vec(N);
    double ans = 0;

    REP(i,N){
        cin >> A.at(i);
        vec.at(i) = 1.0 / A.at(i);
        ans += vec.at(i);
    }
    cout <<setprecision(12)<< 1.0/ans << endl;
}


Measured memory_bytes: 3800
#include<stdio.h>
 
int main(){
    int i, n, r, min, max;
    long int sum;
    scanf("%d", &n);
    i = 1;
    scanf("%d", &r);
    min = r;
    max = r;
    sum = r;
    while(i < n){
        scanf("%d", &r);
        if(min > r) min = r;
        if(max < r) max = r;
        sum = sum + r;
        i++;
    }
    printf("%d %d %ld\n", min, max, sum);
}


Measured memory_bytes: 2120
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		char table[][] = {{'a', 'b', 'c', 'd', 'e'}, {'f', 'g', 'h', 'i', 'j'}, {'k', 'l', 'm', 'n', 'o'}, {'p', 'q', 'r', 's', 't'}, {'u', 'v', 'w', 'x', 'y'}, {'z', '.', '?', '!', ' '}};
		String answer;
		int index;

		while (sc.hasNext()) {
			answer = "";
			index = 0;
			String s = sc.next();
			while (true) {
				int a;
				int b;
				if (index < s.length()) {
					if ('1' <= s.charAt(index) && s.charAt(index) <= '6') {
						a = s.charAt(index) - '0' - 1;
						index++;
					} else {
						answer = "NA";
						break;
					}
				} else {
					break;
				}
				if (index < s.length() && '1' <= s.charAt(index) && s.charAt(index) <= '5') {
					b = s.charAt(index) - '0' - 1;
					index++;
				} else {
					answer = "NA";
					break;
				}
				answer += table[a][b];
			}
			System.out.println(answer);
		}
	}
}

Measured memory_bytes: 11000
l,r = gets.split(' ').map(&:to_i)
min = 1000000
if l/2019 != r/2019
  puts 0
else
   (l..r-1).each do |i|
     (i+1..r).each do |j|
      ans = (i * j) % 2019
      if ans < min
        min = ans
      end
    end
  end
    puts min
end


Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) nums[i] = scanner.nextInt();

        selectionSort(n, nums);
    }

    private static void selectionSort(int n, int[] a) {
    	int sw = 0;
    	for (int i = 0; i < n - 1; i++) {
    		int minj = i;
    		for (int j = i + 1; j < n; j++) {
    			if (a[minj] > a[j]) minj = j;
    		}
    		if (minj != i) {
    			int tmp = a[i];
    			a[i] = a[minj];
    			a[minj] = tmp;
    			sw++;
     		}
    	}
    	trace(a);
    	System.out.println(sw);
    }

    private static void trace(int[] nums) {
    	System.out.println(Arrays.toString(nums).replaceAll("[\\[\\],]", ""));
    }

}


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

#define MAX_N 1000000

//Union-Find木
int par[MAX_N]; //親
int depth[MAX_N]; //木の深さ
int num[MAX_N];

//n要素で初期化
void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        depth[i] = 0;
        num[i] = 1;
    }
}

//木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unit(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(depth[x] < depth[y]){
        par[x] = y;
        num[y] += num[x];
    }else{
        par[y] = x;
        num[x] += num[y];
        if(depth[x] == depth[y]) depth[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


int main(void){
    ll n, m;
    cin >> n >> m;

    ll a[m], b[m];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    ll sum = (n - 1) / 2.0 * n;
    ll ans[m];
    init(n);
    for(int i = m - 1; i >= 0; i--){
        ans[i] = sum;
        ll a_par = find(a[i]);
        ll b_par = find(b[i]);
        if(a_par != b_par){
            sum -= num[a_par] * num[b_par];
            unit(a[i], b[i]);
        }
    }

    rep(i, m){
        cout << ans[i] << endl;
    }
    return 0;
}


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

int One_Count_in_Binary(int N)
{
    int one = 0;
    while(N!=0)
    {
        if(N%2==1)
        {
            one+=1;
        }
        N/=2;
    }
    return(one);
}

int main()
{
    vector<char> X;
    vector<int> ans;
    int N, i, one_count=0, val_left, val_right, left_mod=0, right_mod=0, temp, count;
    char a;
    cin>>N;
    for(i=0;i<N;i+=1)
    {
        cin>>a;
        if(a=='1')
        {
            one_count+=1;
        }
        X.push_back(a);
    }
    val_left = val_right = 1;
    for(i=N-1;i>=0;i-=1)
    {
        if(one_count>1)
        {
            left_mod = (left_mod+(val_left*((int)X[i]-48))%(one_count-1))%(one_count-1);   
        }
        right_mod = (right_mod+(val_right*((int)X[i]-48))%(one_count+1))%(one_count+1);
        if(one_count>1)
        {
            val_left = (val_left*2)%(one_count-1);   
        }
        val_right = (val_right*2)%(one_count+1);
    }
    val_left = val_right = 1;
    for(i=N-1;i>=0;i-=1)
    {
        temp=-1;
        if(one_count>1 && X[i]=='1')
        {
            temp = (left_mod - val_left + (one_count-1))%(one_count-1);
        }
        else if(X[i]=='0')
        {
            temp = (right_mod + val_right)%(one_count+1);
        }
        if(one_count>1)
        {
            val_left = (val_left*2)%(one_count-1);   
        }
        val_right = (val_right*2)%(one_count+1);
        if(temp==-1)
        {
            temp = 0;
            count = 0;
        }
        else
        {
            count=1;
        }
        while(temp!=0)
        {
            temp = temp%One_Count_in_Binary(temp);
            count+=1;
        }
        ans.push_back(count);
    }
    for(i=N-1;i>=0;i-=1)
    {
        cout<<ans[i]<<endl;
    }
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const ll MOD = 998244353;
const int maxn = 3010;

int X;
ll way[maxn][maxn * 2];
ll comb[maxn][maxn];

ll f(int num, int sum) {
	//if (sum == X || sum == X * 2) return 0;
	if (sum == X) return 0;

	ll res = 0;
	if (sum < X) {
		res = way[num][sum];
	} else { //sum >= X
		if (X <= sum - X) {
			if (sum % 2 == 0 && X % 2 != 0 && num == sum / 2) {
				res = 1;
			}
		} else {
			if ((sum - X - 1) % 2 == 0) {
				int zan = num - (sum - X + 1);
				if (zan >= 0 && X * 2 - sum - 2 >= 0) {
					res = way[zan][X * 2 - sum - 2];
				}
			}
		}
	}
	return res;
}

int main() {
	rep(i, maxn) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
		}
	}

	way[0][0] = 1;
	for (int i = 0; i < maxn - 1; ++i) {
		rep(j, maxn * 2) {
			if (way[i][j] == 0) continue;
			way[i+1][j+1] = (way[i+1][j+1] + way[i][j]) % MOD;
			way[i+1][j+2] = (way[i+1][j+2] + way[i][j]) % MOD;
		}
	}

	int N; cin >> N >> X;

	ll ans = 0;

	for (int num = 0; num <= N; ++num) { //1 or 2
		for (int S = num; S <= 2 * num; ++S) {
			//cout << num << " " << S << " " << f(num, S) << endl;
			ans = (ans + f(num, S) * comb[N][num]) % MOD;
		}
	}

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

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

int main(){
    string s,t;
    cin >> s >> t;
    string u = s + s;
    if(u.find(t)!=string::npos)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

int s, n, cnt = 0;

void solve(int x, int y, int sum){
	if(y == n){
		if(sum == s){
			++cnt;
		}
		return ;
	}
	if(x > 9) return ;
	solve(x + 1, y + 1, sum + x);
	solve(x + 1, y, sum);
	return ;
}

int main(){
	while(1){
		cin >> n >> s;
		if(n == 0 && s == 0) break;
		cnt = 0;
		solve(0, 0, 0);
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>


#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;


int main() {
  int n,m,max_odd=0,max_even=0,num_odd=1,num_even=1,second_odd=0,second_even=0,
  mn_odd,mn_even;
  cin >> n;
  m=n/2;
  std::vector<int> odd(m),even(m);
  for (int i = 0; i < m; i++) {
    cin >> odd[i] >> even[i];
  }
  VSORT(odd);
  VSORT(even);
  // cout << odd[0] << ':' << odd[1] << endl;
  for (int i = 1; i < m; i++) {
    if(odd[i] - odd[i-1]) {

      if(num_odd > max_odd) {
        second_odd = max_odd;
        max_odd = num_odd;
        mn_odd = odd[i-1];
      } else {
        second_odd = num_odd < second_odd ? second_odd : num_odd;
      }
      second_odd = 1 > second_odd ? 1 : second_odd;
      // cout << "debug1: " << second_odd << endl;
      num_odd = 1;
    } else if(i==m-1) {
      num_odd++;
      if(num_odd > max_odd) {
        second_odd = max_odd;
        max_odd = num_odd;
        mn_odd = odd[i-1];
      }else {
        second_odd = num_odd < second_odd ? second_odd : num_odd;
      }
      // cout << "debug2: " << max_odd << endl;
    } else {
      num_odd++;
    }
    if(even[i] - even[i-1]) {
      if(num_even > max_even) {
        second_even = max_even;
        max_even = num_even;
        mn_even = even[i-1];
      } else {
        second_even = num_even < second_even ? second_even : num_even;
      }
      second_even = 1 < second_even ? second_even : 1;
      num_even = 1;
    } else if(i==m-1) {
      num_even++;
      if(num_even > max_even) {
        second_even = max_even;
        max_even = num_even;
        mn_even = even[i-1];
      } else {
        second_even = num_even < second_even ? second_even : num_even;
      }
    } else {
      num_even++;
    }
  }
  // cout << "max_odd: " << max_odd << endl;
  // cout << "max_even: " << max_even << endl;
  // cout << "second_odd: " << second_odd << endl;
  // cout << "second_even: " << second_even << endl;
  int result = max_odd + max_even;
  if(mn_odd == mn_even) {
    result = max_even + second_odd >  max_odd + second_even ? max_even + second_odd : max_odd+second_even;
  }
  cout << n - result << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

double cross(double x1,double y1,double x2,double y2)
{
	return x1*y2-x2*y1;
}

int ccw(double x1,double y1,double x2,double y2,double x3,double y3)
{
	return cross(x2-x1,y2-y1,x3-x1,y3-y1)>0;
}

int main()
{
	//float x,y,a,b,n,m,p,q;
	//int i;
	//for(;~scanf("%f%f%f%f%f%f%f%f",&x,&y,&a,&b,&n,&m,&p,&q);puts(i>2^!i?"YES":"NO"))
	//	i=((p-x)*(b-y)>(q-y)*(a-x))+((p-a)*(m-b)>(q-b)*(n-a))+((p-n)*(y-m)>(q-m)*(x-n));
	
	for(double x,y,a,b,n,m,p,q;scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x,&y,&a,&b,&n,&m,&p,&q)==8;){
		int counter=0;
		counter+=(p-x)*(b-y)>(q-y)*(a-x);
		counter+=(p-a)*(m-b)>(q-b)*(n-a);
		counter+=(p-n)*(y-m)>(q-m)*(x-n);
		
		cout<<(counter%3==0?"YES":"NO")<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 59; //MAX 9223372036854775807

int main()
{
ll n,m,q;
cin >> n >> m >> q ;
ll ans[q] = {};
ll t[n][n] = {};
rep(i, m){
    ll ss,tt;
    cin >> ss >> tt ;
    ss--;tt--;
    t[ss][tt]++;
}
vector<vector<ll>> s(n+1, vector<ll>(n+1,0) );
rep(i,n)rep(j,n){
    s[i+1][j+1]=t[i][j]+s[i][j+1]+s[i+1][j]-s[i][j];
}

rep(i,q){
    ll pp,qq;
    cin >> pp >> qq ;
    pp--;qq--;
    ans[i]=s[qq+1][qq+1]-s[qq+1][pp]-s[pp][qq+1]+s[pp][pp];
}

rep(i,q)cout << ans[i] << endl;
return 0;
}


Measured memory_bytes: 7040
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int numOfOne = 0;
        int numOfTwo = 0;
        int numOfFour = 0;
        
        for (int i = 0; i < N; i++) {
            long value = sc.nextLong();
            if (value % 2 == 1) {
                numOfOne++; // 1
            } else if (value % 4 == 0) {
                numOfFour++; // 4
            } else {
                numOfTwo++; // 2
            }
        }
        if (numOfTwo > 0) {
            numOfOne++;
        }
        System.out.println(numOfFour + 1 >= numOfOne ? "Yes" : "No");
    }
}

Measured memory_bytes: 48724
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> P = new ArrayList<>();
        for(int i=0;i<N;i++)P.add(sc.nextInt());
        int sum=1;
        int now = P.get(0);
        for(int i=1;i<N;i++){
            if(now>=P.get(i)){
                sum++;
                now = P.get(i);
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 68900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    string S, T; cin >> S >> T;
    int ans = 0;
    rep(i, S.size()){
        if(S.at(i)!=T.at(i)) ans++;
    }

    cout << ans << endl;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s.at(i);
  sort(s.begin(), s.end());

  int sum = 0;
  rep(i, n) {
    sum += s.at(i);
  }
  int res = sum;
  int i = 0;
  while (res % 10 == 0 && i < n) {
    if ((res - s.at(i)) % 10 != 0) {
      res -= s.at(i);
    }
    i++;
  }
  if (res == sum && res % 10 == 0) {
    res = 0;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;

#define minX -1000000
#define maxX 1000000
int main()
{
    int N, X;
    cin >> N >> X;
    for (int i = max(X - N + 1, minX); i <= min(X + N - 1, maxX); i++)
    {
        cout << i << (i == min(X + N, maxX) ? "" : " ");
    }
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

Measured memory_bytes: 256
#include <stdio.h>
 
int main( void )
{
    double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
    double x = 0;
    double y = 0;
 
    while( scanf( "%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f ) != EOF )
    {
 
        y = ( c * d - a * f ) / ( b * d - e * a );  //x,yについて解くと
                                                    //これらの式が導出できる
        x = ( c - ( b * y ) ) / a;
 
        printf( "%.3lf %.3lf\n", x, y );
    }
 
    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a + b == 60) {
    if (c <= a)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    int t = a + b;
    if (c % t <= a)
      cout << c << endl;
    else {
      for (; ;) {
	c += 60;
	if (c < 0) {
	  cout << -1 << endl;
	  break;
	}
	if (c % t <= a) {
	  cout << c << endl;
	  break;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

int main(){
	int point[5], k;
	int i, j;

	for(i = 0; i < 5; i++){
		scanf("%d", &point[i]);
	}

	scanf("%d", &k);

	for(i = 0; i < 5; i++){
		for(j = 0; j < 5; j++){
			if(point[i] - point[j] > k){
				printf(":(\n");
				return 0;
			}
		}
	}

	printf("Yay!\n");

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <iostream>
#include <list>
#include <vector>
using namespace std;

inline bool swap_if_match(bool *is_black, int i) {
  if (is_black[i] && !is_black[i + 1]) {
    is_black[i] = false;
    is_black[i + 1] = true;
    return true;
  } else {
    return false;
  }
}

int main() {
  string S;
  cin >> S;
  int size = S.size();
  long long cnt = 0;
  long long w_cnt = 0;
  for (int i=0; i< size; ++i) {
    if(S[i] == 'W') {
      cnt += i - w_cnt;
      w_cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e6+7;

int ans=0;
int n,m,k,q;
string s;
int a,w,t,r;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    FOR(i,0,n){
        cin>>s;
        if(s=="AC")++a;
        if(s=="WA")++w;
        if(s=="TLE")++t;
        if(s=="RE")++r;
    }
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<w<<"\n";
    cout<<"TLE x "<<t<<"\n";
    cout<<"RE x "<<r<<"\n";
    return 0;
}


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

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))

/// returns count of non-overlapping occurrences of 'sub' in 'str'
int countSubstring(const std::string& str, const std::string& sub)
{
    if (sub.length() == 0) return 0;
    int cnt = 0;
    for (size_t offset = str.find(sub); offset != std::string::npos;
	 offset = str.find(sub, offset + sub.length()))
    {
        ++cnt;
    }
    return cnt;
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<string> s(n);
    int c1=0, c2=0, c3=0;
    int cnt=0;
    for(int i=0; i<n; i++){
        cin>>s[i];
        cnt+= countSubstring(s[i], "AB");
        ///cout<<"s[i]="<<s[i]<<"\t cnt="<<cnt<<"\n";
        if(s[i][0]=='B' && s[i][s[i].length()-1]=='A') c1++;
        else if(s[i][0]=='B') c2++;
        else if(s[i][s[i].length()-1]=='A') c3++;

    }
    //cout<<"c1="<<c1<<"\t c2="<<c2<<"\tc3="<<c3<<"\n";

    if(c1==0) cnt+= min(c2,c3);
    else if(c2+c3>0) cnt+= (c1+min(c2,c3));
    else cnt+= (c1-1);
    cout<<cnt<<"\n";






    return 0;
}








/**********************************************************************************







*************************************************************************************/


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int main(){
    string w;
    cin >> w;
    int n = w.size();

    map<char, int> a;
    rep(i, n) {
        a[w[i]]++;
    }

    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (a[w[i]] % 2) ok = false;
    }

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

    return 0;
}

Measured memory_bytes: 3568
N = int(input())
T, A = (int(x) for x in input().split())
altitude_list = [int(x) for x in input().split()]
for index, item in enumerate(altitude_list) :
    avr = T - item * 0.006
    dif = abs(A - avr)
    if index == 0 or dif < mini :
        mini = dif
        num = index
print(num + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N, M;
    cin >> N >> M;
    ll L[M], R[M];
    rep(i, M){
        cin >> L[i] >> R[i];
    }
    ll maxL = 1;
    ll minR = N;
    rep(i, M){
        maxL = max(maxL, L[i]);
        minR = min(minR, R[i]);
    }

    ll ans = minR - maxL + 1;
    ans = max((ll)0, ans);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int N;
ll A, B;
ll h[100000];
bool C(ll x){
    ll cnt = 0;
    FOR(i,0,N){
        ll now = h[i] - B * x;
        if(now <= 0) continue;
        cnt += (now + A - B - 1)/(A - B);
    }
    return cnt <= x;
}
int main(){
    cin >> N >> A >> B;
    FOR(i,0,N) cin >> h[i];
    ll l = -1, r = 1000000005;
    while(r-l>1){
        ll cen = (r + l) / 2;
        if(C(cen)) r = cen;
        else l = cen;
    }
    cout << r << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int N,M,max=0;
	int d[100] = { 0 };
	int v[100] = { 0 };
	int anser[50] = { 0 };
	int count = 0;

	scanf("%d %d", &N, &M);

start:

	for (int i = 0; i < N; i++) {
		scanf("%d %d", &d[i], &v[i]);
	}

	for (int i = 1; i <= M; i++) {
		for (int j = 0; j < N; j++) {
			if (d[j] == i) {
				if (v[j] > max) {
					max = v[j];
				}
			}
		}
		anser[count] += max;
		max = 0;
	}

	scanf("%d %d", &N, &M);

	if (!(N == 0 && M == 0)) {
		count++;
		max = 0;
		for (int i = 0; i < 100; i++) {
			d[i] = 0;
			v[i] = 0;
		}
		goto start;
	}
	
	for (int i = 0; i <= count; i++){
		cout << anser[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3136
var
  n,y,i,j,k:longint;
begin
  readln(n,y);
  if (y div n=10000) then//以下为特殊判断，会快很多
  begin
     writeln(n,' ',0,' ',0);
     halt;
  end;
  if (y div n=5000) then
  begin
    writeln(0,' ',n,' ',0);
    halt;
  end;
  if (y div n=1000) then
  begin
    writeln(0,' ',0,' ',n);
    halt;
  end;
  if (n*10000<y) then
  begin
    writeln('-1 -1 -1');
    halt;
  end;
  if (n*1000>y) then
  begin
    writeln('-1 -1 -1');
    halt;
  end;
  if (y mod 1000<>0) then
  begin
    writeln('-1 -1 -1');
    halt;
  end;//暴力开始！
  for i:=0 to y div 10000 do//从不选到至少选多少个，这样时间复杂度会少，最重要！
  for j:=0 to n-i do//n-i去重，减时间，不然过不去
  if (i*10000+j*5000+(n-i-j)*1000=y) //判断这个方案是否成立
  then begin
     writeln(i,' ',j,' ',n-i-j);//成立输出
     halt;//结束所有程序
  end;
  writeln('-1 -1 -1');//如果不成立那么他就不会结束程序，就可以输出不成立的结果拉
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int,int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

int main() {
  ll n;
  cin >> n;

  map<char, int > m;
  string tmp;
  rep(i, n){
    cin >> tmp;
    m[tmp[0]]++;
  }

  tmp = "MARCH";
  ll cnt;
  ll ad;
  ll ans = 0;
  for(int i=0;(1<<5)>i;i++){
    cnt = 0;
    ad = 1;
    rep(j, 5){
      if(i&(1<<j)) {
	cnt++;
	ad *= m[tmp[j]];
      }
    }
    if(cnt==3) ans += ad;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.*


fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val q = sc.nextInt()

    data class ABCD(val a: Int, val b: Int, val c: Int, val d: Int)

    val tuples = Array(q) { ABCD(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()) }

    var maxSums = 0
    for (listA in getAs(n, m)) {
        var sum = 0
        for ((a, b, c, d) in tuples) {
            if (listA[b-1] - listA[a-1] == c)
                sum += d
        }
        //println("${listA.contentToString()}     : $sum")
        maxSums = maxOf(maxSums, sum)
    }

    println(maxSums)
}

fun getAs(n: Int, m: Int) = sequence<IntArray> {
    fun b(ary: IntArray, prev: Int, dims: Int): Sequence<IntArray> = sequence {
        if (dims == 0) yield(ary)
        else {
            for (v in prev..m) {
                ary[ary.size - dims] = v
                yieldAll(b(ary, v, dims - 1))
            }
        }
    }
    yieldAll(b(IntArray(n), 1, n))
}


Measured memory_bytes: 55868
$_=<>;
$C=y/C//;
$c=y/?//;
$%=1e9+7;
@3=(1,map$.=$.*3%$%,1..1e5);
$x=0;
for(/./g){
	if(/A/){
		++$A
	}elsif(/C/){
		--$C
	}else{
		$c-=/\?/;
		$x+=
			($A*$3[$a]%$%+$a*$3[$a-1]%$%)%$%
			*
			(($C*$3[$c]%$%+$c*$3[$c-1]%$%)%$%);
		$x%=$%;
		$a+=/\?/
	}
	
}
print$x


Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	if(s[i]==s[i+1])
	{
		cout<<"Bad";
		return 0;
	}
	cout<<"Good";
	return 0;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	int n, k;
	char s[51];
	scanf("%d %d %s", &n, &k, s);

	s[k - 1] += 32;
	puts(s);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

int main(){
    int N; std::cin >> N;
    std::vector<int> a(N);
    for (auto& r : a) std::cin >> r;
    int count = 0;
    for (auto& r : a) {
        while (true) {
            if (r % 2 == 0) {
                ++count;
                r /= 2;
            }
            else
                break;
        }
    }
    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 3636
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    X = NLI()
    ans = 10**20
    for i in range(100):
        sq = 0
        for x in X:
            sq += (i-x)**2
        ans = min(ans, sq)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int X, Y, Z; cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
}


Measured memory_bytes: 256