akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		int n = scan.nextInt(), m = scan.nextInt();
		long total = 0;
		Store[] s = new Store[n];
		for(int i = 0; i < n; i++) s[i] = new Store(scan.nextInt(), scan.nextInt());
		Arrays.sort(s);
		for(int i = 0; i < n; i++) {
			long need = Math.min(m, s[i].a);
			m -= need;
			total += s[i].p * need;
			if(m == 0) break;
		}
		System.out.println(total);
	}
	
	static class Store implements Comparable<Store>{
		long a;
		long p;
		
		public Store(int aa, int bb) {
			p = aa;
			a = bb;
		}

		@Override
		public int compareTo(Store o) {
			return Long.compare(this.p, o.p);
		}
		
		
	}
	
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }

}


Measured memory_bytes: 44628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007


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

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

int main() {
  int n,m,sum = 0;
  ll ans = 0;
  cin >> n >> m;
  vector<P>a(n);
  rep(i,0,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());
  rep(i,0,n){
    if(a[i].second+sum > m){
      ans += (m-sum)*a[i].first;
      break;
    }
    else{
      sum += a[i].second;
      ans += a[i].first*a[i].second;
    }
  }
  cout << ans << endl;
}

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

int main() {
	int a, b = 0, c = 0, ans;
	cin >> a ;
	b += a / 100;
	c += (a-b*100)/10;
	ans = (a - (b * 100 + c * 10)) + b + c;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

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

using namespace std;

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

	int A, B; cin >> A >> B;

	rep(i,max(A,B)) {

		if (abs(A-i)==abs(B-i)) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;



int main() {
	int n;
	ll ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				int g = __gcd(i, j);
				g = __gcd(g, k);
				ans += g;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
N = int(input())
a = list(map(int, input().split()))
for i in range(0, N):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            print('DENIED')
            break
else:
    print('APPROVED')

Measured memory_bytes: 3060
while 1:
    n=int(raw_input())
    if n==0:break
    s=raw_input()
    for i in xrange(n):
        news=""
        cnt=1
        for j in xrange(len(s)-1):
            if s[j]==s[j+1]:
                cnt+=1
            else:
                news+=str(cnt)+s[j]
                cnt=1
        news+=str(cnt)+s[-1]
        s=news
    print(s)

Measured memory_bytes: 6404
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> v;
	map<ll,int> m;
	for(int i=0;i<3*n;i++)
	{
		ll a;
		cin>>a;
		v.push_back(a);
	}
	ll brojac=0;
	vector<ll> v1(3*n+3,0),v2(3*n+3,0);
	for(int i=0;i<n;i++)
	{
		m[v[i]]++;
		brojac+=v[i];
	}
	v1[n]=brojac;
	for(int i=n;i<3*n;i++)
	{
		ll k=m.begin()->first;
		if(v[i]>k)
		{
			brojac-=k;
			brojac+=v[i];
			if(m.begin()->second==1)
				m.erase(m.begin());
			else
				m.begin()->second--;
			m[v[i]]++;
		}
		v1[i+1]=brojac;
	}
	reverse(v.begin(),v.end());
	brojac=0;
	m.clear();
	for(int i=0;i<n;i++)
	{
		m[v[i]]++;
		brojac+=v[i];
	}
	v2[n]=brojac;
	for(int i=n;i<3*n;i++)
	{
		ll k=m.rbegin()->first;
		if(v[i]<k)
		{
			brojac-=k;
			brojac+=v[i];
			if(m.rbegin()->second==1)
				m.erase(m.rbegin()->first);
			else
				m.rbegin()->second--;
			m[v[i]]++;
		}
		v2[i+1]=brojac;
	}
	ll maxi=-1e18;
	for(int i=n;i<=3*n;i++)
	{
		if((3*n-(i))<n)
			break;
		maxi=max(maxi,v1[i]-v2[3*n-i]);
	}
	cout<<maxi<<endl;
	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s1; cin >> s1;
  string s2 = "CODEFESTIVAL2016";
  int cnt = 0;
  for(int i=0;i<SZ(s2);++i) {
    cnt += s1[i] != s2[i];
  }
  cout << cnt << endl;
}


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

class Program{

  static string ans = "No";

  static int Main() {

    string[] nyu = Console.ReadLine().Split(' ');
    int a = int.Parse(nyu[0]);
    int b = int.Parse(nyu[1]);
    int c = int.Parse(nyu[2]);

    // ここまで入力

    if (a == b && b == c) {
      ans = "Yes";
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
int main(void){
char a[5],b[5];
  int k;
  scanf("%s %s",&a,&b);
  k=strcmp(a,b);
  if(k<0){printf("<");}
  if(k==0){printf("=");}
  if(k>0){printf(">");}
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int h,w;cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<string> t(h,string(w,'.'));
    rep(i,h){
        rep(j,w){
            if(s[i][j]!='#') continue;
            if(j+1<w&&s[i][j+1]=='#'){
                t[i][j] = '#';
                t[i][j+1]='#';
            }
            if(i+1<h&&s[i+1][j]=='#'){
                t[i][j]='#';
                t[i+1][j]='#';
            }
        }
    }
    cout << (s==t?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int s[110];
    cin >> N;
    rep(i,0,N){
        cin >> s[i];
    }
    sort(s, s+N);
    int sum = 0;
    rep(i,0,N){
        sum += s[i];
    }
    if(sum % 10 != 0){
        print(sum);
    }else{
        rep(i,0,N){
            if(s[i] % 10 != 0){
                sum -= s[i];
                print(sum);
                return 0;
            }
        }
        print(0);
    }

}


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



////a>=b>0

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


  
int main(){
  
  int64_t n;
  cin>>n;
  
  vector<int64_t> time(n);
  
  for (int64_t i=0;i<n;i++){
    int64_t tmp;
    cin>>tmp;
    time.at(i)=tmp;
  }
  
  int64_t answer=time.at(0);
  
  for (int64_t i=0;i<n-1;i++){
    
    int64_t large,small;
    
    large=max(answer,time.at(i+1));
    small=min(answer,time.at(i+1));
    answer=(large/gcd(large,small))*small;
  }
  

  
  cout<<answer<<endl;
    
  
  
}

















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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int[] a = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    unsigned long long A, B, N;
    cin >> A >> B >> N;
    if(B == 1) {
        cout << 0 << "\n";
        return 0;
    }
    if(B - 1 <= N) {
        cout << (A * (B - 1)) / B << "\n";
        return 0;
    }
    cout << (A * N) / B << "\n";

    return 0;
}

Measured memory_bytes: 3632
main :: IO ()
main = do ls <- getContents
          putStrLn (compose ls)

compose :: String -> String
compose = unwords . fmap show . mathOp . (\xs -> take (head xs) (tail xs)) . (=<<) (fmap (\x -> read x::Int) . words) . lines

mathOp  :: [Int] -> [Int]
mathOp  xs = fmap ($ xs) [minimum, maximum, sum]

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

N, M, X, Y = list(map(int, input().rstrip().split()))

ax = list(map(int, input().rstrip().split()))
ay = list(map(int, input().rstrip().split()))

bottom_x = max(ax)
top_y = min(ay)

result = 'War'
for Z in range(X + 1, Y + 1):
    if bottom_x < Z and Z <= top_y:
        result = 'No War'
        break

print(result)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int X, N;
    cin >> X >> N;
    set<int> n;
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        n.insert(p);
    }
    int ans = X;
    for (int i = 0; i < 120; i++) {
        if (n.count(X - i) == 0) {
            ans = X - i;
            break;
        }
        if (n.count(X + i) == 0) {
            ans = X + i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



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

void solve()
{
	int x;
	cin >> x;
	if(x == 0)
		cout << 1 << endl;
	else
		cout << 0 << endl;
}

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

	solve();
	return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

char S[100010];
char T[100010];

int table[26][100010];

signed main()
{
	cin >> S;
	cin >> T;

	int len = strlen(S);

	REP(i, 26) REP(j, len + 1) table[i][j] = -1;

	for (int c = 0; c < 26; c++)
	{
		char ch = c + 'a';

		int cur = -1;
		for (int i = len - 1; i >= 0; i--)
		{
			if (S[i] == ch)
			{
				cur = i;
				table[c][i] = i;
			}
			else
			{
				table[c][i] = table[c][i + 1];
			}
		}

		if (table[c][0] != -1)
		{
			for (int i = 0; i < len; i++)
			{
				if (table[c][i] == -1)
				{
					table[c][i] = table[c][0];
				}
			}
		}
	}

	int cur = 0;
	int ans = 0;

	int t_len = strlen(T);
	for (int i = 0; i < t_len; i++)
	{
		char ch = T[i];

		int t = table[ch - 'a'][cur];

		if (t < 0)
		{
			cout << -1 << endl;
			return 0;
		}

		if (cur <= t)
		{
			ans += t - cur + 1;
			cur = (t + 1) % len;
		}
		else
		{
			int a = (len - cur + 1) + t;
			ans += a;
			cur = (t + 1) % len;
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 20864
S = int(input())
mod = 10**9 + 7
dp = [0] * (S+1)

dp[0] = 1
x = 0
for i in range(1,S+1,1):
  if i >= 3:
    x += dp[i-3]
    x %= mod
  dp[i] = x

ans = dp[S]
print(ans)

Measured memory_bytes: 9128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,t,a;
	int x,m;
	double s;
	cin>>n;
	cin>>t>>a;
	m = 1;
	cin>>x;
	s = fabs(t-x*0.006-a);
	for(int i=2;i<=n;i++){
		cin>>x;
		if(fabs(t-x*0.006-a)<s){
			s = fabs(t-x*0.006-a);
			m = i;
		}
	}
	cout<<m<<endl;
	return 0;
} 

Measured memory_bytes: 256
read N
read W
W=($W)

sum=$(echo ${W[@]} | tr ' ' "\n" | awk '{sum+=$1} END {print sum}')

ans=1000000

for ((i=0; i<$N; i++)); do
    left=${W[@]:0:$i}
    X=$(echo ${left[@]} | tr ' ' "\n" | awk '{sum+=$1} END {print sum}')
    Y=$((sum-X))
    
    if [ $X -gt $Y ]; then
        V=$((X-Y))
    else
        V=$((Y-X))
    fi
    if [ $V -lt $ans ]; then
        ans=$V
    fi
done

echo $ans


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

const int MAX=100005;
vector<long long int> S(MAX,0),A(MAX),B(MAX);
int N,W;

void DP(int u){
    for(int i=1;i<=u;i++){
        for(long long int j=W-A[i];j>=0;j--){
            if(j==0||S[j]!=0) S[A[i]+j]=max(S[A[i]+j],S[j]+B[i]);
        }
    }
    long long int ans=0;
    for(int i=0;i<=W;i++){
        ans=max(ans,S[i]);
    }
    cout<<ans<<endl;
}

int main(){
    
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>A[i+1]>>B[i+1];
    }
    DP(N);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define d 1000000007
long long n,m,f[1005][1005];
char a[1005][1005];
int main(){
    cin >> n >> m;
    f[1][1]=1;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            cin >> a[i][j];
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            if(a[i][j]!='#'){
                f[i][j]+=(f[i-1][j]+f[i][j-1])%d;
            }
        }
    }
    cout << f[n][m];
    return 0;
}

Measured memory_bytes: 9088
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int N; cin >> N; int Q; cin >> Q;
    string S; cin >> S; 
    
    int pref[N-1];
    F0R(i, N-1) {
		pref[i] = 0;
		if (i > 0) pref[i] = pref[i-1];
		if (S[i] == 'A' && S[i+1] == 'C') {
			pref[i]++;
		}
	}
	F0R(query, Q) {
		
		int L, R; cin >> L >> R; 
		L--; R--;
		int ans = 0;
		R--; L--;
		if (R >= 0) ans += pref[R];
		if (L >= 0) ans -= pref[L];
		cout << ans << endl;
	}
	
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 1488
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5))+1):
        if n % i: continue
        ex = 0
        while n % i == 0:
            n = n // i
            ex += 1
        res.append((i, ex))
    if n != 1:
        res.append((n, 1))
    return res

def mcomb(n, k, mod):
    def mfac(l, r, mod):
        ans = l
        for i in reversed(range(r, l)):
            ans *= i
            ans %= mod
        return ans

    A = mfac(n, n-k+1, mod)
    B = mfac(k, 1, mod)
    # B = mpow(B,mod-2,mod)
    B = pow(B, mod-2, mod)
    return A * B % mod

def solve():
    N, M = MI()
    fact = prime_factorization(M)
    MOD = 1000000007

    if N == 1:
        print(1)
        return

    ans = 1
    for num, ex in fact:
        ans = ans * mcomb(ex+N-1, N-1, MOD)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
n = int(input())
ans = []
for i in range(n):
    if i == 0:
        s = input()
        S = {s: 1}
        ans.append(s)
        mx = 1
    else:
        s = input()
        if s in S:
            S[s] += 1
            if S[s] > mx:
                ans = [s]
                mx = S[s]
            elif S[s] == mx:
                ans.append(s)
        else:
            S[s] = 1
            if S[s] == mx:
                ans.append(s)
ans = sorted(ans)
for a in ans:
    print(a, sep="\n")

Measured memory_bytes: 33416
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		System.out.println(Math.max(sc.nextInt()*sc.nextInt(), sc.nextInt()*sc.nextInt()));
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35568
N = int(input())
S = input()
dic = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,
       'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,
       'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,
       'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,
       'Y':24,'Z':25}

res = ''
for s in S:
    idx = (dic[s]+N) % 26
    keys = [k for k, v in dic.items() if v == idx]
    res += keys[0]


print(res)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  string op;
  stack<ll> s;
  while (cin >> op) {
    if (isdigit(op[0])) {
      ll val = atoll(op.c_str());
      s.push(val);
    }
    else {
      ll a = s.top(); s.pop();
      ll b = s.top(); s.pop();
      ll c = 0;
      switch (op[0]) {
        case '+': {
          c = b + a;
          break;
        }
        case '-': {
          c = b - a;
          break;
        }
        case '*': {
          c = b * a;
          break;
        }
        default:
          break;
      }
      s.push(c);
    }
  }
  fprintf(stdout, "%lld\n", s.top());
  return 0;
}

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

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

   ll x;

   cin >> x;
   ll ans_1, ans_2;

   for(ll i = -100; i < 1000; i++){
       for(ll j = 0; j < 1000; j++){
           if(x==j*j*j*j*j-i*i*i*i*i){
               ans_1 = j;   ans_2=i;
               break;
           }
           else continue;
       }

   }

   cout << ans_1 << " " << ans_2;

    return 0;
}

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

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

    long long A, B;
    cin >> A >> B;
    if (abs(A + B) % 2 == 1)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << abs(A + B) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
  std::cout<<std::fixed<<std::setprecision(10);
  double l;cin>>l;
  l/=3;
  double ans=pow(l,3);
  cout<<ans<<endl;
}

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

int N; int arr[1000000];
int dp[1000000];
int main()
{
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> arr[i];
    }

    memset(dp, INT_MIN, sizeof(dp));

    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    for(int i = 2; i < N; i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
    }

    printf("%d\n", dp[N-1]);
}

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

int main(){
    int a,b,c,d,e;
    int k;

    cin >>a >>b >>c >>d >>e >>k;
    if(b-a<=k && c-a<=k && d-a<=k && e-a<=k && c-b<=k && d-b<=k && e-b<=k && d-c<=k && e-c<=k && e-d<=k){
        cout << "Yay!" <<endl;
    } else {
        cout <<":(" <<endl;
    }

    return 0;

}


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

int main() {
  int N, T, A; cin >> N >> T >> A;
  int H[N];
  double avetemp[N];
  double diff[N];
  for (int i = 0; i < N; ++i) {
    cin >> H[i]; 
    avetemp[i] = T - H[i] * 0.006;
  }
  int index = 0;
  for (int i = 1; i < N; ++i) { 
    if (abs(A - avetemp[i]) < abs(A - avetemp[index])) index = i;
  }
  
  cout << index + 1 << endl;  
}

Measured memory_bytes: 3620
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;


int main() {
  string s;
  cin >> s;
  
  int red = 0, blue = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      red++;
    } else {
      blue++;
    }
  }
  cout << min(red, blue) * 2 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,a[12];

	cin>>n;

	ll k=1,t=1;
	for(int i=1; i<n+1; i++){
		cin>>a[i];
		if(a[i]%2==0)k*=2;
		t*=3;
	}
	cout<<t-k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
constexpr int DIG = 39;
int main()
{
    int N;
    std::cin >> N;
    using P = std::pair<ll, ll>;
    std::vector<P> p(N);
    for (int i = 0; i < N; i++) { std::cin >> p[i].first >> p[i].second; }
    const ll S = std::abs(p[0].first) + std::abs(p[0].second);
    for (int i = 1; i < N; i++) {
        if (S % 2 != (std::abs(p[i].first) + std::abs(p[i].second)) % 2) { return std::cout << -1 << std::endl, 0; }
    }
    const ll D = (1LL << DIG) - 1;
    const ll NUM = DIG + (S % 2 == 1 ? 0 : 1);
    std::cout << NUM << std::endl;
    for (int i = 0; i < DIG; i++) { std::cout << (1LL << i) << " "; }
    if (S % 2 == 0) { std::cout << 1; }
    std::cout << std::endl;
    for (int i = 0; i < N; i++) {
        using Q = std::pair<ll, ll>;
        std::vector<Q> log(NUM);
        ll x = p[i].first, y = p[i].second;
        if (x == 0 and y == 0) {
            for (int i = 0; i < DIG - 1; i++) { std::cout << "L"; }
            std::cout << "RL" << std::endl;
            continue;
        }
        if (S % 2 == 0) {
            if (x != 0) {
                log[NUM - 1] = {0, (x < 0 ? -1 : 1)};
                x += (x < 0 ? 1 : -1);
            } else {
                log[NUM - 1] = {1, (y < 0 ? -1 : 1)};
                y += (y < 0 ? 1 : -1);
            }
        }
        ll X = std::abs(x), Y = std::abs(y);
        const ll S = X + Y;
        ll P = (D + S) / 2, M = D - P;
        std::bitset<DIG + 1> ng(M), ok(P);
        for (int i = 0; i < DIG; i++) {
            if (ng[i] and ((X >> i) & 1)) { log[i] = {0, -1 * (x < 0 ? -1 : 1)}, X += (1LL << i); }
            if (ng[i] and ((Y >> i) & 1)) { log[i] = {1, -1 * (y < 0 ? -1 : 1)}, Y += (1LL << i); }
            if (ok[i] and ((X >> i) & 1)) { log[i] = {0, 1 * (x < 0 ? -1 : 1)}, X -= (1LL << i); }
            if (ok[i] and ((Y >> i) & 1)) { log[i] = {1, 1 * (y < 0 ? -1 : 1)}, Y -= (1LL << i); }
        }
        for (int i = 0; i < NUM; i++) {
            if (log[i].first == 0) {
                if (log[i].second == 1) {
                    std::cout << "R";
                } else {
                    std::cout << "L";
                }
            } else {
                if (log[i].second == 1) {
                    std::cout << "U";
                } else {
                    std::cout << "D";
                }
            }
        }
        std::cout << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2977.cc: Bombing
 */

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

/* constant */

const int MAX_N = 500;
const int MAX_M = 500;
const int MAX_L = 200000;
const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };
const char dcs[] = "RULD";

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_L + 4];
int bs[MAX_N][MAX_N], cs[MAX_M][MAX_M], cds[128];
ll as[MAX_M][MAX_M];

/* subroutines */

/* main */

int main() {
  for (int di = 0; di < 4; di++) cds[dcs[di]] = di;

  int n, m, k, l;
  scanf("%d%d%d%d", &n, &m, &k, &l);

  for (int y = 0; y < n; y++) {
    scanf("%s", s);
    for (int x = 0; x < n; x++)
      bs[y][x] = (s[x] == 'X') ? 1 : 0;
  }
  scanf("%s", s);

  for (int i = 0, x = 0, y = 0; i < l; i++) {
    int di = cds[s[i]];
    x += dxs[di], y += dys[di];
    cs[y][x]++;
  }

  for (int y = 0; y + n <= m; y++)
    for (int x = 0; x + n <= m; x++)
      if (cs[y][x] > 0)
	for (int dy = 0; dy < n; dy++)
	  for (int dx = 0; dx < n; dx++)
	    as[y + dy][x + dx] += cs[y][x] * bs[dy][dx];

  int cnt = 0;
  for (int y = 0; y < m; y++)
    for (int x = 0; x < m; x++)
      if (as[y][x] >= k) cnt++;

  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 6340
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
int sx,sy,ex,ey,n,size,sta[200010],f[200010];
long double pi=3.1415926535897932384626433832795028841971;
struct node
{
    int x,y;
};
long long cmax(long long pp,long long qq)
{
    if(pp>qq) return pp;
    return qq;
}
node a[200010];
bool cmp(node xx,node yy)
{
    return xx.x<yy.x;
}
int main()
{
    cin>>sx>>sy>>ex>>ey;
    cin>>n;
    if(sx>ex) swap(sx,ex),swap(sy,ey);
    for(int i=1;i<=n;++i)
        scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;++i)
   if((a[i].x>=sx&&a[i].x<=ex)&&((a[i].y>=sy&&a[i].y<=ey)||(a[i].y>=ey&&a[i].y<=sy)))
       f[++size]=a[i].y;
    if(sy>ey) for(int i=1;i<=size;++i)
        f[i]=-f[i];
    
    long long len = 0;
    memset(sta,0x3f,sizeof(sta));
    for(int i=1;i<=size;++i)
    {long p=lower_bound(sta+1,sta+size+1,f[i])-sta;
        sta[p]=f[i];
        len=cmax(len,p);
    }
    long double ans;
    ans=abs(sx-ex)+abs(sy-ey);
    ans=ans*100.0;
    ans+=(pi*5.0-20.0)*len;
    if(len==abs(ey-sy)+1||len==abs(ex-sx)+1) ans+=pi*5.0;
    printf("%.15Lf",ans);
    return 0;
}


Measured memory_bytes: 3456
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        string[] a = new string[]{"1","3","5","7","8","10","12"};
        string[] b = new string[]{"4","6","9","11"};
        int ia1 = -1;
        int ia2 = -1;
        int ib1 = -1;
        int ib2 = -1;
        for(int i=0;i<7;i++){
            if(a[i] == input[0]){
                ia1 = 0;
            }
            if(a[i] == input[1]){
                ia2 = 0;
            }
            if(b[i%4] == input[0]){
                ib1 = 0;
            }
            if(b[i%4] == input[1]){
                ib2 = 0;
            }
        }
        if((ia1>=0&&ia2>=0) || (ib1>=0&&ib2>=0)){
            WriteLine("Yes");
        }else{
            WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

int n, A[500];
int count = 0;

int main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> A[i];
        if (A[i]%2 == 0) 
        {
            A[i] /= 2;
        }
        else
        {
            cout << count << endl;
            return 0;
        }
    }

    count++;

    for (int outer=0; outer<30; outer++ )
    {
        for(int inner=0; inner<n; inner++)
        {
            if(A[inner]%2 == 0)
            {
                A[inner] /= 2;
            }
            else
            {
                cout << count << endl;
                return 0;
            }   
        }
        count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    double ret   = 0.0;
    double denom = 0.0;
    do {
        denom += 1;
        for (int i = 1; i < n; ++i) {
            ret += sqrt((x[ord[i]] - x[ord[i - 1]]) * (x[ord[i]] - x[ord[i - 1]]) +
                        (y[ord[i]] - y[ord[i - 1]]) * (y[ord[i]] - y[ord[i - 1]]));
        }
    } while (next_permutation(ord.begin(), ord.end()));
    cout << fixed << setprecision(15) << ret / denom << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for( int i=a; i<b; i++)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<pii>vpi;

ll knapsack(vll &wt, vll &val, ll W, ll n){
    vvll dp(n+1,vll(W+1));
    
    for(ll i = 0;i<=n;i++){
        dp[i][0] = 0;
    }
    for(ll i = 0;i<=W;i++){
        dp[0][i] = 0;
    }

    for(ll i=1;i<=n;i++){
        for(ll j = 1;j<=W;j++){
            if(wt[i-1] <= j){
                dp[i][j] = max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    return dp[n][W];
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,W;
    cin>>n>>W;
    vll wt(n);
    vll val(n);
    for(ll i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
    cout<<knapsack(wt,val,W,n)<<"\n";
}

Measured memory_bytes: 83112
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back
 
void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}
 
typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9':return 9;
        default: return 0;
	}
}
int main(void){
    int d;
    cin >> d;
    if(d==25){
        cout << "Christmas" << endl;
    }
    if(d==24){
        cout << "Christmas Eve" << endl;
    }
    if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }
    if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 2000000

int n, A[MAX + 1];

void maxH(int i) {
	int l, r, largest;

	l = 2 * i;
	r = 2 * i + 1;

	if (l <= n && A[l] > A[i])largest = l;
	else largest = i;

	if (r <= n && A[r] > A[largest])largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxH(largest);
	}
}

int main() {

	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++)scanf("%d", &A[i]);

	for (i = n / 2; i >= 1 ; i--)maxH(i);

	for (i = 1; i <= n; i++)printf(" %d", A[i]);
	printf("\n");

	return 0;

}


Measured memory_bytes: 5088
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

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

    int x = 0;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        switch (S[i])
        {
        case 'I':
            x++;
            break;
        case 'D':
            x--;
            break;
        default:
            assert(false);
            break;
        }
        ans = max(ans, x);
    }

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


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

using namespace std;

const int N = 100000 + 5;

int num[N];
int y[N];


bool cmp(int a, int b) {
  return y[a] < y[b];
}


int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> y[i];
    num[i] = i;
  }
  sort(num + 1, num + 1 + n, cmp);
  for (int i = 1; i <= n; ++i) {
    cout << num[i] << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, m;
    cin >> n >> m;
    cout << n*m - n-m+1;
}

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

int arr[100005];
vector < int > v;
vector < pair < int , int > > vp;

int main(){

    int a,n,m,i,b,c,d,cnt=1,ans;
    cin>>n>>m;
    for(i=1; i<=m; i++){
        cin>>a>>b;
        vp.push_back({a,b});
    }
    sort(vp.begin(),vp.end());

    for(i=0; i<m-1; i++){
         a=vp[i].first;
         b=vp[i].second;
         c=vp[i+1].first;
         d=vp[i+1].second;

         if(b<=c){
            cnt++;
            arr[a]=1;
            continue;
         }
         vp[i+1].second=min(vp[i].second,vp[i+1].second);
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 1524
K, N = map(int, input().split())
A = list(map(int, input().split()))

A2 = [K+a for a in A]
A3 = A + A2

dist = [0] * N
for i in range(N):
    j = i + N - 1
    dist[i] = A3[j] - A[i]

print(min(dist))



Measured memory_bytes: 36140
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

int d[210][210];
int N, M, R;
int r[10];
int main()
{
	cin >> N >> M >> R;
	for (int i = 0; i < R; i++) {
		cin >> r[i];
		r[i]--;
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (d [i][j] == 0) {
				d[i][j] = mod;
			}
			if (i == j) {
				d[i][j] = 0;
			}
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int ans = mod, sum = 0;
	sort(r, r + R);
	do {
		sum = 0;
		for (int i = 0; i < R - 1; i++) {
			sum += d[r[i]][r[i + 1]];
		}
		ans = min(ans, sum);
	} while (next_permutation(r, r + R));
	cout << ans << endl;
}


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

typedef long long ll;

const int MOD = (int)1e9 + 7;
int N, M;
vector<int> A, B;

void input_init(void) {
	cin >> N >> M;
	A.resize(N);
	for (int j = 0; j < N; ++j)
		cin >> A[j];
	B.resize(M);
	for (int i = 0; i < M; ++i)
		cin >> B[i];
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	sort(B.begin(), B.end());
	B.erase(unique(B.begin(), B.end()), B.end());
}

int calcu(int n) {
	vector<int>::iterator it_a = lower_bound(A.begin(), A.end(), n);
	vector<int>::iterator it_b = lower_bound(B.begin(), B.end(), n);
	int idx_a = distance(A.begin(), it_a);
	int idx_b = distance(B.begin(), it_b);

	int ret = 0;
	if (*it_a == n && *it_b == n)			
		ret = 1;
	else if (*it_a == n)			
		ret = M - idx_b;
	else if (*it_b == n)			
		ret = N - idx_a;
	else								
		ret = (M - idx_b) * (N - idx_a) - (N * M - n);

	return ret;
}

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

	input_init();
	ll ans = (ll)0;
	if (A.size() == N && B.size() == M) {
		A.push_back(N * M + 1);
		B.push_back(N * M + 1);
		ans = (ll)1;
		for (int i = 1; i <= N * M; ++i) {
			ans *= (ll)calcu(i);
			ans %= (ll)MOD;
		}
	}

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



Measured memory_bytes: 256
#include <stdio.h>

int n,m[50];
bool prime[1000000],c[1000000];

void saiki(int total){
	int i;
	
	c[total]=1;
	
	for( i=total ; i>=0 ; i--){
		if(c[i]==1){
			for(int j=0;j<n;j++){
				if(i-m[j]>=0){
					c[i-m[j]]=1;
				}
			}
		}
	}
}




int main(void)
{
	int i,j;
	//f
	prime[0]=1;
	prime[1]=1;
	for(i=3;i<1000000;i++){
		if(i%2==0){
			prime[i]=1;
		}
	}
	for(i=3;i<1000000;i+=2){
		if(prime[i]==0){
			for(j=(i+i);j<1000000;j+=i){
				prime[j]=1;
			}
		}
	}
	//
	while(1){
		int x;
		int flg=0;
		scanf("%d%d",&n,&x);
		if(n==0)break;
		
		for(i=0;i<n;i++){
			scanf("%d",&m[i]);
		}
		saiki(x);
		//
		for(i=0;i<x;i++){
			if(c[i]==1 && prime[x-i]==0){
				flg=1;
				break;
			}
		}
		if(flg==1){
			printf("%d\n",x-i);
		}
		else puts("NA");
		for(i=0;i<1000000;i++){
			c[i]=0;
		}
		for(i=0;i<50;i++){
			m[i]=0;
		}
		//
	}
	
	return 0;
}

Measured memory_bytes: 2716
// D - Wall
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void warshall_floyd(vvi &C){
	rp(relay,0,C.size()) rp(from,0,C.size()) rp(to,0,C.size())
		C[from][to] = min(C[from][to], C[from][relay] + C[relay][to]);
}

int main(){
	int H,W; cin>>H>>W;
	vvi C(10, vi(10)), A(H, vi(W));
	rp(i,0,10) rp(j,0,10) cin>>C[i][j];
	warshall_floyd(C);
	int ans = 0;
	rp(h, 0, H) rp(w, 0, W){
		int a; cin>>a;
		if(a >= 0) ans += C[a][1];
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int A,B,C;scanf("%d%d%d",&A,&B,&C);
	if (A>B) swap(A,B);
	if (A>C) swap(A,C);
	if (B>C) swap(B,C);
	if (A==B&&A==C&&A%2==0) {puts("-1");return 0;}
	int ans=0;
	while (A%2==0&&B%2==0&&C%2==0)
	{
		ans++;
		int x=A/2+B/2,y=A/2+C/2,z=B/2+C/2;
		A=x;B=y;C=z;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
    cin>>N>>K;
    vec a(N);
    rep(i,N){
        cin>>a[i];
        --a[i];
    }
    vec spot(1, 0), visited(N, -1);
    int now = 0, last = -1;
    visited[0] = 0;
    rep(i,K){
        now = a[now];
        if(visited[now] != -1) {
            last = visited[now];
            break;
        }
        else {
            spot.push_back(now);
            visited[now] = i + 1;
        }
    }
    if(last == -1){
        cout<<now + 1<<endl;
    }else{
        K -= last;
        cout<<spot[last + (K%(spot.size() - last))] + 1<<endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
    ll A,B; cin>>A>>B;
    if(A%3==0 || B%3==0 || (A+B)%3==0) cout<<"Possible";
    else cout<<"Impossible";
}

Measured memory_bytes: 256
import math
a,b=map(int,input().split())
if a>3:
    a_v=math.factorial(a)//math.factorial(a-2)//math.factorial(2)
elif a==3:
    a_v=2
elif a==2:
    a_v=1
else:
    a_v=0
if b>3:
    b_v=math.factorial(b)//math.factorial(b-2)//math.factorial(2)
elif b==3:
    b_v=3
elif b==2:
    b_v=1
else:
    b_v=0
print(a_v+b_v)
    

Measured memory_bytes: 3060
while True:
    try:
        Num = []
        n = int(input())
        while n > 0:
            if n % 2 == 1:
                Num.append(1)
                n = (n - 1) / 2
            else:
                Num.append(0)
                n = n / 2
        for i in range(len(Num) - 1):
            if Num[i] == 1:
                print(2**i,end = " ")
        print(2**(len(Num)-1))
    except EOFError:
        break
            

Measured memory_bytes: 7536
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
V<ll> a(n);
for(int i=0;i<n;i++)cin>>a[i];
V<bool> used(10000000,false);
for(int i=0;i<n;i++){
  ll now=a[i];
  used[now]=true;
  if(now==0)continue;
  int cnt=1;
  while(i+cnt<n&&cnt<5){
    now*=10;
    now+=a[i+cnt];
    used[now]=true;
    cnt++;
  }
}
for(int i=0;i<10000000;i++){
  if(!used[i]){
    cout<<i<<"\n";
    break;
  }
}
}


Measured memory_bytes: 4168