akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;

int N,D;
int X[15][15];

bool Check(int i,int j) {
	int x=0;
	for(int k=1;k<=D;k++)
		x+=((X[i][k]-X[j][k])*(X[i][k]-X[j][k]));
	int tmp=sqrt(x);
	return tmp*tmp==x;
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&D);
	for(int i=1;i<=N;i++) {
		for(int j=1;j<=D;j++)
			scanf("%d",&X[i][j]);
	}
	int ans=0;
	for(int i=1;i<=N;i++)
		for(int j=i+1;j<=N;j++)
			if(Check(i,j))ans++;
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int num ;
	char Blod[3] ;
	int Btype[4] = { 0,0,0,0 } ;

	while( scanf( "%d,%s", &num,&Blod ) != EOF  )
	{

		if( Blod[0] == 'A' )
		{
			if( Blod[1] == 'B' ) Btype[2] ++ ;
			else Btype[0] ++ ;
		}
		else if( Blod[0] == 'B' ) Btype[1] ++ ;
		else if( Blod[0] == 'O' ) Btype[3] ++ ;
	}

	for( int i = 0 ; i < 4 ; i ++ )
	{
		cout << Btype[i] << endl ;
	}

	return 0 ;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }

    ll cnt = 1;
    vector<bool> is_sorted(n,false);
    for(i = 1;i < n;++i){
        if(p.at(i-1) < p.at(i)) ++cnt;
        else cnt = 1;
        if(cnt >= k){
            is_sorted.at(i-(k-1)) = true;
        }
    }

    set<ll> s;
    for(i = 0;i < k;++i){
        s.insert(p.at(i));
    }
    ll ans = !is_sorted.at(0);
    for(i = 1;i + k - 1 < n;++i){
        s.erase(p.at(i-1));
        s.insert(p.at(i+k-1));
        if(!is_sorted.at(i) && !(p.at(i-1) < *s.begin() && p.at(i+k-1) == *s.rbegin())) ++ans;
    }
    for(i = 0;i < n;++i){
        if(is_sorted.at(i)){
            ++ans;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
import math
N=int(input())

lst=[[0,0] for _ in range(N)]
for i in range(N):
  lst[i]=list(map(int,input().split()))
dist=[]
for i in range(N-1):
  for j in range(i+1,N):
    v=math.sqrt((lst[i][0]-lst[j][0])**2+(lst[i][1]-lst[j][1])**2)
    dist.append(v)
print(2*sum(dist)/N)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
 
int main(void){
    int c[3][3];
    rep(i,3)rep(j,3){
        cin>>c[i][j];
    }
    rep(i,3){
        set<int> st;
        rep(j,3) st.insert(c[i][j]-c[(i+1)%3][j]);
        if(st.size() > 1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

const int MAX_N=1000000;

typedef long long ll;

using namespace std;

ll n,dat[2*MAX_N-1];

void init(int n_){
	n=1;
	while(n<n_)n*=2;
}

void update(int k,ll a){
	k+=n-1;
	dat[k]=a;
	
	while(k>0){
		k=(k-1)/2;
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}

ll query(int a,int b,int k,int l,int r){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dat[k];
	else {
		ll vl=query(a,b,k*2+1,l,(l+r)/2);
		ll vr=query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}

int main(void){
	
	ll in,m,ans=0;
	
	cin >> m;
	
	init(m);
	
	for(int i=0;i<m;i++){
		cin >> in;
		update(in,in+query(1,in,0,0,n));
	}
	cout << m*(m+1)/2-query(1,m+1,0,0,n) << endl;
	
	return 0;
}

Measured memory_bytes: 2744
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin>>n;
    long long int a[n],i,h[n+1];
    for(int i=0;i<=n;i++){
        h[i]=0;
    }
    for(i=0;i<n-1;i++){
        cin>>a[i];
        h[a[i]]++;
    }
    for(i=1;i<=n;i++)
    cout<<h[i]<<endl;
    return 0;
}

Measured memory_bytes: 6760
#include <iostream>
#include <vector>
#include <utility>              // swap
using namespace std;

int bubbleSort(vector<int>& A) {
    bool flag = true;
    int i = 0;
    int cnt = 0;                // 交換した回数

    while (flag) {
        flag = false;
        for (auto j = A.size()-1; j >= i+1; j--) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                flag = true;
                cnt++;
            }
        }
    }
    return cnt;
}

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

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

    int ans = bubbleSort(ary);
    for (auto i = 0; i < ary.size(); i++) {
        cout << (i ? " " : "") << ary[i];
    }
    cout << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1200
import sys
from collections import deque, defaultdict

sys.setrecursionlimit(10000)

H, W = map(int, input().split())
C = tuple(map(int, input().split()))
D = tuple(map(int, input().split()))
S = [list(input()) for _ in range(H)]

d = [(0, 1), (1, 0), (0, -1), (-1, 0)]


def dfs(h, w, i):
    S[h][w] = i

    for dh, dw in d:
        nh = h + dh
        nw = w + dw
        if nh < 0 or nh >= H or nw < 0 or nw >= W:
            continue
        if S[nh][nw] != '.':
            continue
        dfs(nh, nw, i)


# 領域毎に番号を振る
count = 1
for h in range(H):
    for w in range(W):
        if S[h][w] != '.':
            continue
        dfs(h, w, count)
        count += 1

# 各領域をノードとしてグラフを構築
graph = defaultdict(set)
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue

        for dh in range(-2, 3):
            for dw in range(-2, 3):
                nh = h + dh
                nw = w + dw
                if nh < 0 or nh >= H or nw < 0 or nw >= W:
                    continue
                if S[nh][nw] == '#':
                    continue
                graph[S[h][w]].add(S[nh][nw])

start = S[C[0]-1][C[1]-1]
goal = S[D[0]-1][D[1]-1]


def shortest_dist(graph, start, goal):
    queue = deque([start])
    visited = set()
    visited.add(start)
    dist = defaultdict(int)
    dist[start] = 0
    while queue:
        current_vertex = queue.popleft()
        if current_vertex == goal:
            return dist[goal]
        for v in graph[current_vertex]:
            if v not in visited:
                visited.add(v)
                queue.append(v)
                dist[v] = dist[current_vertex] + 1
    return -1

# 最短距離を求める
ans = shortest_dist(graph, start, goal)

print(ans)


Measured memory_bytes: 224036
//
//  main.cpp
//  ALDS1_10_A:FibonacciNumber
//
//  Created by Kang on 2020/8/12.
//  Copyright © 2020 Kang. All rights reserved.
//

#include <cstdio>
#include <cstring>
using namespace std;


int fiboFromTop(int n, int fibo[]) {
    if (fibo[n] != 0) {
        return fibo[n];
    }
    
    if (n == 0 || n == 1) {
        fibo[n] = 1;
        return 1;
    }
    else {
        fibo[n - 1] = fiboFromTop(n-1, fibo);
        fibo[n - 2] = fiboFromTop(n - 2, fibo);
        return fibo[n - 1] + fibo[n - 2];
    }
    
    
    return 0;
}

int fiboFromBottom(int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    int fibo[45];
    fibo[0] = 1;
    fibo[1] = 1;
    for (int i = 2; i <= n; i++) {
        fibo[i] = fibo[i-1] + fibo[i - 2];
    }
    return fibo[n];
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    int fibonacci[45];
    memset(fibonacci, 0, 45 * sizeof(int));
    scanf("%d", &n);
    
    // printf("%d\n", fiboFromTop(n, fibonacci));
    printf("%d\n", fiboFromBottom(n));
    
    return 0;
}



Measured memory_bytes: 2756
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef vector < long long > vll;
typedef pair <long long, long long> pll;
typedef pair <int, int> pii;
typedef vector < int > vii;
typedef complex < double > Point;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define fst first
#define snd second

ll t, n, m, u, v, q, r, ql, qr, k, l, s, w, z, x, y, d, p, c, L, b;
const int N = 1e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 52LL;
string str;
int a[N];
int main() {
    csl;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int sol = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] > i && a[a[i]] == i) sol++;
    }
    cout << sol << '\n';
    return 0;
}










Measured memory_bytes: 640
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

bool check(vector<int> a,vector<int> b){
	rep(i,a.size()){
		if(a[i]==b[i])return false;
	}
	return true;
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N),B(N);
	rep(i,N){
		cin>>A[i];
	}
	
	rep(i,N){
		cin>>B[i];
	}
	vector<int> C = B;
	deque<int> ng,ok;
	
	rep(i,N){
		if(A[i]!=B[i])ok.push_back(i);
		else{
			if(ng.size()>0&&B[ng[0]]!=B[i]){
				swap(B[ng[0]],B[i]);
				ng.pop_front();
				continue;
			}
			else{
				ng.push_back(i);
			}
		}
	}

	while(ng.size()>0&&ok.size()>0){
		if(B[ng.front()]!=A[ok.front()]){
			swap(B[ng.front()],B[ok.front()]);
			ng.pop_front();
			ok.pop_front();
			continue;
		}
		else{
			ok.pop_front();
		}
	}
	
	vector<int> ans;
	if(check(A,B)){
		ans = B;
		goto Label;
	}
	B = C;
	rep(i,N/2){
		B.push_back(B[i]);
	}
	
	
	while(ans.size()!=N){
		ans.push_back(B.back());
		B.pop_back();
	}
	
	reverse(ans.begin(),ans.end());
	
	if(check(A,ans)){
		Label:
		cout<<"Yes"<<endl;
		rep(i,N){
			if(i!=0)cout<<' ';
			cout<<ans[i];
		}
		cout<<endl;
	}
	else{
		int t = ans[0];
		ans.erase(ans.begin());
		ans.push_back(t);
		
		if(check(A,ans)){
			goto Label;
		}
		else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	
    return 0;
}


Measured memory_bytes: 9148
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;


int main() {
    ull H, W, N, sr, sc;
    string S, T;
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S;
    cin >> T;


    map<char, int> index;
    index['L'] = 0;
    index['R'] = 1;
    index['U'] = 2;
    index['D'] = 3;

    ull cumS[4] = {0}, cumT[4] = {0};
    for(ull i=0; i<N; i++) {
        cumS[index[S[i]]]++;

        bool f = false;
        f = f || (sc - (cumS[index['L']] - cumT[index['R']]) <= 0);
        f = f || (sc + (cumS[index['R']] - cumT[index['L']]) >= W+1);
        f = f || (sr - (cumS[index['U']] - cumT[index['D']]) <= 0);
        f = f || (sr + (cumS[index['D']] - cumT[index['U']]) >= H+1);

        if(f) {
            cout << "NO" << endl;
            return 0;
        }

        f = true;
        if(T[i]=='L')
            f = f && (sc-(cumT[index['L']]-cumS[index['R']]) >= 2);
        else if(T[i]=='R')
            f = f && (sc+(cumT[index['R']]-cumS[index['L']]) <= W-1);
        else if(T[i]=='U')
            f = f && (sr-(cumT[index['U']]-cumS[index['D']]) >= 2);
        else
            f = f && (sr+(cumT[index['D']]-cumS[index['U']]) <= H-1);

        if(f)
            cumT[index[T[i]]]++;

    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 776
N = gets.chomp.to_i
a = Array.new(N)
b = Array.new(N)
str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
    b[a[i]-1] = i+1
end

for i in 0...N do
    print b[i]
    print " "
end
puts

Measured memory_bytes: 12036
//#include "pch.h"
#include <iostream>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
typedef long long ll;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,k;
	cin >> n >> k;
	k--;
	
	string s;
	cin >> s;
	
	if (s[k] == 'A') s[k] = 'a';
	else if (s[k] == 'B') s[k] = 'b';
	else if (s[k] == 'C') s[k] = 'c';
	
	cout << s << endl;
	
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = (base + base) % mod;
    }
    return tot;
}

unsigned long long pre[100005], suf[100005], conf[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n; cin >> n;

    for(int i = 0; i < n; ++i)
        cin >> pre[i];
    for(int i = 0; i < n; ++i)
        cin >> suf[i];

    unsigned long long prod = 1;

    for(int i = 0; i < n; ++i){
        conf[i] = -1;
        if(i == 0 || pre[i] != pre[i - 1]){
            conf[i] = pre[i];
            if(conf[i] > suf[i]){
                cout << "0\n";
                return 0;
            }
        }
    }

    for(int i = n - 1; i >= 0; --i){
        if(i == n - 1 || suf[i] != suf[i + 1]){
            if(conf[i] != -1 && conf[i] != suf[i]){
                cout << "0\n";
                return 0;
            }
            conf[i] = suf[i];
            if(conf[i] > pre[i]){
                cout << "0\n";
                return 0;
            }
        }
    }

    if(pre[n - 1] != suf[0]){
        cout << "0\n";
        return 0;
    }

    bool opp = false;

    for(int i = 0; i < n; ++i){
        if(opp == false){
            if(pre[i] >= suf[i])
                opp = true;
        } else {
            if(pre[i] < suf[i]){
                cout << "0\n";
                return 0;
            }
        }
    }

    opp = false;

    for(int i = n - 1; i >= 0; --i){
        if(opp == false){
            if(pre[i] <= suf[i])
                opp = true;
        } else {
            if(pre[i] > suf[i]){
                cout << "0\n";
                return 0;
            }
        }
    }


    for(int i = 0; i < n; ++i){
        if(conf[i] != -1) continue;
        prod = slow_mult(prod, min(pre[i], suf[i]));
    }

    cout << prod << "\n";

    return 0;

}


Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

const int DEBUG = 0;

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 100100;
int n;
VI g[N];
int deg[N];
int alivecnt = 0;
bool alive[N];

VI gdist(int v, const VI &vals) {
  VI ret(n, -1);
  queue<PI> que;
  que.push(PI(v, vals[v]));
  while (not que.empty()) {
    PI t = que.front(); que.pop();
    int w = t.first;
    int d = t.second;
    if (ret[w] >= 0) continue;
    ret[w] = d;
    REP(i, 0, g[w].size()) {
      int u = g[w][i];
      que.push(PI(u, d + vals[u]));
    }
  }
  return ret;
}

string c;


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  REP(i, 0, n - 1) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> c;
  {
    queue<int> que;
    REP(i, 0, n) {
      alive[i] = true;
      deg[i] = g[i].size();
      if (g[i].size() == 1) que.push(i);
      alivecnt++;
    }
    while (not que.empty()) {
      int v = que.front(); que.pop();
      if (c[v] == 'B') {
	// delete
	int nxt = -1;
	REP(i, 0, g[v].size()) {
	  if (alive[g[v][i]]) {
	    nxt = g[v][i];
	    break;
	  }
	}
	alive[v] = false;
	alivecnt--;
	deg[nxt]--;
	if (deg[nxt] == 1) que.push(nxt);
      }
    }
    // deletes all unnecessary edges
    REP(i, 0, n) {
      VI cp;
      REP(j, 0, g[i].size()) {
	int w = g[i][j];
	if (not alive[w]) continue;
	cp.push_back(w);
      }
      g[i] = cp;
    }
  }
  if (DEBUG) {
    REP(i, 0, n) {
      if (alive[i]) {
	REP(j, 0, g[i].size()) {
	  int w = g[i][j];
	  cerr << " (" << i << "," << w << ")";
	}
	cerr << endl;
      }
    }
  }
  VI vals(n);
  REP(i, 0, n) {
    vals[i] = (c[i] == 'W') ^ (deg[i] % 2);
  }
  int idx = -1;
  REP(i, 0, n) {
    if (alive[i] && c[i] == 'W') idx = i;
  }
  if (idx < 0) {
    cout << 0 << endl;
    return 0;
  }
  if (alivecnt <= 1) {
    cout << alivecnt << endl;
    return 0;
  }
  assert (idx >= 0);
  PI ma1(-1, -1);
  VI d1 = gdist(idx, vals);
  REP(i, 0, n) {
    if (c[i] == 'W') {
      ma1 = max(ma1, PI(d1[i], i));
    }
  }
  PI ma2(-1, -1);
  VI d2 = gdist(ma1.second, vals);
  REP(i, 0, n) {
    if (c[i] == 'W') {
      ma2 = max(ma2, PI(d2[i], i));
    }
  }
  if (DEBUG) {
    cerr << "vals:";
    REP(i, 0, n) cerr << " " << vals[i];
    cerr << endl;
    cerr << "d2:";
    REP(i, 0, n) cerr << " " << d2[i];
    cerr << endl;
  }
  int diam = ma2.first;
  int base = 2 * (alivecnt - 1);
  REP(i, 0, n) {
    if (alive[i]) {
      base += vals[i];
    }
  }
  DEBUGP(base);
  DEBUGP(diam);
  cout << base - 2 * diam << endl;
}


Measured memory_bytes: 8816
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  if (n < 1000) cout << "ABC" << '\n';
  else cout << "ABD" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String input = scanner.next();
    scanner.close();

    char[] inputChars = new char[input.length()];
    for(int i=0; i<input.length(); i++){
      inputChars[i] = input.charAt(i);
    }

    Arrays.sort(inputChars);

    if(inputChars.length == 1){
      System.out.println("No");
    }

    for(int i=1; i<inputChars.length; i++){
      if(inputChars[i-1]!=inputChars[i] && i%2==1){
        System.out.println("No");
        break;
      }
      if(i == inputChars.length-1){
        System.out.println("Yes");
        break;
      }
    }
  }
}


Measured memory_bytes: 22612
fun main(arg: Array<String>) {
    val N = nextInt()
    val S1 = next()
    val S2 = next()
    val Tate = BooleanArray(N) { S1[it] == S2[it] }
    val C = LongArray(N) { n -> 
        if (n == 0) if (Tate[n]) 3 else 6
        else if (S1[n - 1] == S1[n]) 1
        else if (Tate[n]) if (Tate[n - 1]) 2L else 1L
                     else if (Tate[n - 1]) 2L else 3L
    }
    val MOD = 1000000007L
    val ans = C.reduce { acc, c -> (acc * c) % MOD }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }



Measured memory_bytes: 33788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, k, a[100000];
vector<int> vec;
map<int, int> mp;
int ans;

int bit[100010];
void add(int a, int w) {
	for (int x = a; x <= n; x += x & -x) bit[x] += w;
}
int sum(int a) {
	int ret = 0;
	for (int x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}

signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (!i)a[i] -= k;
		else a[i] = a[i - 1] + a[i] - k;
		vec.push_back(a[i]);
	}
	sort(all(vec));
	int cnt = 0;
	int zero = 0;
	if (vec[0] <= 0)cnt = 1;
	else {
		zero = 1;
		cnt = 2;
	}
	for (int i = 0; i < n; i++) {
		mp[vec[i]] = cnt;
		if (i < n - 1) {
			if (vec[i] != vec[i + 1]) {
				if (vec[i + 1] == 0)zero = cnt + 1;
				if (vec[i] < 0 && 0 < vec[i + 1]) {
					zero = cnt + 1;
					cnt += 2;
				}
				else cnt++;
			}
		}
	}
	if (!zero)zero = cnt + 1;
	for (int i = 0; i < n; i++) {
		a[i] = mp[a[i]];
	}
	add(zero, 1);
	for (int i = 0; i < n; i++) {
		ans += sum(a[i]);
		add(a[i], 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 11600
(*
 * forall l r (p : forall n, l < n <= r -> bool),
 *   ( exists m,
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n ) ->
 *   { m |
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n }
 *)
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let () = Scanf.scanf "%d %d %d\n" @@ fun n a b ->
  let hs = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun h -> h in
  Printf.printf "%d\n" @@
    lower_bound 0 ((Array.fold_left max 0 hs + b - 1) / b) @@ fun x ->
      ( >= ) x @@ Array.fold_left ( + ) 0 @@
      Array.map (fun h -> max 0 ((h - b * x + a - b - 1) / (a - b))) hs

Measured memory_bytes: 11648
from collections import deque

def BFS01(d,K):
    d[1] = 1
    q = deque([1])
    while q:
        n = q.popleft()
        l, r = map(lambda x: (x) % K, [n * 10, n + 1])
        if d[l] > d[n]:
            d[l] = d[n]
            q.appendleft(l)

        if d[r] > d[n] + 1:
            d[r] = d[n] + 1
            q.append(r)
    return d[0]

K = int(input())
d = [float('inf')] * K

print(BFS01(d,K))

Measured memory_bytes: 6000
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n ;
int a[N], b[N] ;
bool used[N] ;
vi good, bad ;

signed main(){
	scanf("%d", &n) ;
	rep(i, 1, n) scanf("%d", &a[i]) ;
	rep(i, 1, n) scanf("%d", &b[i]) ;
	rep(i, 1, n) {
		if (a[i] < b[i]) bad.pb(b[i] - a[i]) ;
		if (a[i] > b[i]) good.pb(a[i] - b[i]) ;
	}
	sort(bad.begin(), bad.end()) ; sort(good.begin(), good.end()) ;
	int sz = siz(good) ;
	int l = 0 ;
	while (l < siz(bad)) {
		if (good.empty()) print(-1) ;
		else if (good.back() >= bad[l]) good.back() -= bad[l++], used[siz(good) - 1] = 1 ;
		else bad[l] -= good.back(), good.pop_back() ;
	}
	printf("%d\n", siz(bad) + sz - siz(good) + (siz(good) ? used[siz(good) - 1] : 0)) ;
	return 0 ;
}

/*
Ð´´úÂëÊ±Çë×¢Òâ£º
	1.ll£¿Êý×é´óÐ¡£¬±ß½ç£¿Êý¾Ý·¶Î§£¿
	2.¾«¶È£¿
	3.ÌØÅÐ£¿
	4.ÖÁÉÙ×öÒ»Ð©
Ë¼¿¼ÌáÐÑ£º
	1.×î´óÖµ×îÐ¡->¶þ·Ö£¿
	2.¿ÉÒÔÌ°ÐÄÃ´£¿²»ÐÐdp¿ÉÒÔÃ´
	3.¿ÉÒÔÓÅ»¯Ã´
	4.Î¬»¤Çø¼äÓÃÊ²Ã´Êý¾Ý½á¹¹£¿
	5.Í³¼Æ·½°¸ÊÇÓÃdp£¿Ä£ÁËÃ´£¿
*/


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}


void cerrall(const vector<bool>& a){rep(i,a.size()) cerr << i << " " << (a[i]? "True" : "False") << "\n"; cerr << "\n";}
template<class T> void cerrall(const vector<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const set<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T> void cerrall(const multiset<T>& a){for(auto& t : a) cerr << t << " "; cerr << "\n";}
template<class T, class U> void cerrall(const vector<pair<T,U>>& a){rep(i,a.size()) cerr << i << " : " << a[i].first << " " << a[i].second << "\n";}
template<class T, class U> void cerrall(const map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}
template<class T, class U> void cerrall(const unordered_map<T,U>& a){for(auto& t : a) cerr << t.first << " " << t.second << "\n";}

template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; 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, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int x,y;cin >> x >> y;
    int ans;
    ans = 100000 * (max(0, 4-x) + max(0, 4-y));
    if(x == 1 && y == 1){
        ans += 400000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
drinks=[]
for i in range(N):
    A,B=map(int,input().split())
    drinks.append((A,B))

drinks.sort(key=lambda x: x[0])

total=0
ans=0
for price,num in drinks:
    if total+num<M:
        total+=num
        ans+=price*num
    else:
        ans+=price*(M-total)
        break

print(ans)
  
  
  
  

Measured memory_bytes: 18136
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int N,a,b,c;

int look(char ch){
	if(ch == 'A'){
		return a;
	}else if(ch == 'B'){
		return b;
	}else{
		return c;
	}
}

void chval(char ch, int v){
	if(ch == 'A'){
		a += v;
	}else if(ch == 'B'){
		b += v;
	}else{
		c += v;
	}
	return ;
}

int main(){
	cin>>N>>a>>b>>c;
	vector<pair<char,char>> can(N);
	vector<char> ans(N);
	rep(i,N)cin>>can[i].first>>can[i].second;
	if(a+b+c == 0){cout<<"No"<<endl; return 0;}
	if(a+b+c == 1){
		rep(i,N){
			char x = can[i].first, y= can[i].second;
			if(look(x) == 0 && look(y) == 0){cout<<"No"<<endl; return 0;}
			if(look(x) == 1){ans[i] = y; chval(y,1); chval(x, -1);}
			else if(look(y) == 1){ans[i] = x; chval(x,1); chval(y, -1);}
		}
	}else{
		rep(i,N){
			char x = can[i].first, y = can[i].second;
			if(look(x) == 0 && look(y) == 0){cout<<"No"<<endl; return 0;}
			if(look(x) > look(y)){ans[i] = y; chval(y,1); chval(x, -1);}
			else if(look(y) > look(x)){ans[i] = x; chval(x,1); chval(y, -1);}
			else{
				if(i+1<N && (can[i+1].first == x || can[i+1].second == x)){
					ans[i] = x; chval(x,1); chval(y, -1);
				}else{
					ans[i] = y; chval(y,1); chval(x, -1);
				}
			}
			// printf("[%d] %d %d %d\n", i,a,b,c);
		}
	}
	cout<<"Yes"<<endl;
	show(ans);
	return 0;
}

// int main(){
// 	int N,a,b,c; cin>>N>>a>>b>>c;
// 	int score[3] = {0};
// 	int cnt[3] = {0};
// 	score[0] = a; score[1] = b; score[2] = c;
// 	vector<char> ans(N);
// 	vector<string> input(N);
// 	a = 0; b = 0; c = 0;
// 	rep(i,N){
// 		cin>>input[i];
// 		int a = input[i][0]-'A';
// 		int b = input[i][1]-'A';
// 		cnt[a]++; cnt[b]++;
// 	}
// 	int x,y;
// 	rep(i,N){
// 		x = input[i][0]-'A';
// 		y = input[i][1]-'A';
// 		if(score[x] == 0 && score[y] == 0){
// 			cout<<"No"<<endl; return 0;
// 		}
// 		if(score[x]>score[y]){
// 			score[x]--;
// 			score[y]++;
// 			ans[i] = (char)('A'+y);
// 		}
// 		if(score[x]<score[y]){
// 			score[x]++;
// 			score[y]--;
// 			ans[i] = (char)('A'+x);
// 		}
// 		if(score[x]==score[y]){
// 			if(cnt[x]>cnt[y]){
// 				score[x]++;
// 				score[y]--;
// 				ans[i] = (char)('A'+x);
// 			}else{
// 				score[x]--;
// 				score[y]++;
// 				ans[i] = (char)('A'+y);
// 			}
// 		}
// 		cnt[x]--; cnt[y]--;
// 	}
// 	cout<<"Yes"<<endl;
// 	show(ans);
// 	return 0;
// }

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int sum=0;
    cin>>a;
    for (int i=1;i<a.length();i++)
    {
        if (a[i]!=a[i-1])
            sum++;
    }
    cout <<sum<<endl;
    return 0;
}

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

using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

const int N = 111111;
const int LOG = 20;

int a[N];
int nxt[N][LOG];

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, L;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &L);
  for (int i = 0; i < n; ++i) {
    nxt[i][0] = upper_bound(a.begin(), a.end(), a[i] + L) - a.begin() - 1;
  }
  for (int j = 1; j < LOG; ++j) {
    for (int i = 0; i < n; ++i) {
      nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
    }
  }
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x; --y;
    if (x > y) {
      swap(x, y);
    }
    int step = 0;
    for (int i = LOG - 1; i >= 0; --i) {
      if (nxt[x][i] < y) {
        x = nxt[x][i];
        step += (1 << i);
      }
    }
    printf("%d\n", ++step);
  }
  return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b,S;
  cin>>r>>g>>b;
  S=100*r+10*g+b;
  S%=4;
  if(S==0)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

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

#define int long long int
#define mp make_pair
using namespace std;

int n,k;
vector <int> v(102);
int dp[100002];

int fun(int left)
{
    if(left == 0){
        return 0;
    }
    if(left < 0){
        return 1;
    }
    if(dp[left] != -1){
        return dp[left];
    }
    dp[left] = 0;
    for (int i = 0; i < n; ++i) {
        dp[left] |= (fun(left - v[i]) == 0);
    }
    return dp[left];
}


int32_t main() {
    scanf("%lld", &n);
    scanf("%lld", &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    for (int i = 0; i < 100002; ++i) {
        dp[i] = -1;
    }
    int ans = fun(k);
    /*for (int i = 1; i < 9; ++i) {
        printf("%lld\n",dp[i]);
    }*/
    if(ans){
        printf("First");
    }
    else{
        printf("Second");
    }
    return 0;
}

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


int main() {
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int ans=(h2-h1)*60+(m2-m1)-k;
  cout<<max(0,ans)<<endl;
}


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

int main() {
    int n, s[100010], q;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    cin >> q;
    int ans = 0;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        int l = 0, r = n;
        while (l < r) {
            int m = (l + r) / 2;
            if (s[m] == t) {
                ++ans;
                break;
            }
            if (s[m] > t) {
                r = m;
            }
            else {
                l = m + 1;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
int n, h; cin >> n >> h;
vector<int> a(n), b(n); 
for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
sort(begin(a), end(a));
sort(begin(b), end(b));
int ans = 1e9, sum = 0;
for (int i = 0; i < n; ++i) sum += b[n-1-i], ans = min(ans,  i+1 + max(0, (h - sum + a[n-1] - 1) / a[n-1]));
cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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;
}

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,K;
    cin >> N >> K;
    vector<ll> not_minus;
    vector<ll> minus;
    for(int i = 0;i < N;i++) {
        ll A;
        cin >> A;
        if(A >= 0) {
            not_minus.push_back(A);
        }
        else {
            minus.push_back(A);
        }
    }
    if(K == N) {
        ll ret = 1;
        for(int i = 0;i < not_minus.size();i++) {
            ret *= not_minus.at(i);
            mod(ret,MOD);
        }
        for(int i = 0;i < minus.size();i++) {
            ret *= minus.at(i);
            mod(ret,MOD);
        }
        cout << ret << endl;
    }
    else if(minus.size() == N && K % 2 == 1) {
        sort(minus.begin(),minus.end());
        reverse(minus.begin(),minus.end());
        ll ret = 1;
        for(int i = 0;i < K;i++) {
            ret *= minus.at(i);
            mod(ret,MOD);
        }
        cout << ret << endl;
    }
    else {
        sort(not_minus.begin(),not_minus.end());
        reverse(not_minus.begin(),not_minus.end());
        sort(minus.begin(),minus.end());
        not_minus.push_back(0);
        minus.push_back(0);
        not_minus.push_back(0);
        minus.push_back(0);
        ll ret = 1;
        int itr1 = 0;
        int itr2 = 0;
        int Sum = 0;
        while(true) {
            if(Sum == K) {
                break;
            }
            else if(Sum == K - 1) {
                ret *= not_minus.at(itr1);
                mod(ret,MOD);
                break;
            }
            else {
                ll cnt1 = not_minus.at(itr1) * not_minus.at(itr1 + 1);
                ll cnt2 = minus.at(itr2) * minus.at(itr2 + 1);
                if(cnt1 >= cnt2) {
                    ret *= not_minus.at(itr1);
                    mod(ret,MOD);
                    itr1++;
                    Sum++;
                }
                else {
                    ret *= minus.at(itr2);
                    mod(ret,MOD);
                    ret *= minus.at(itr2 + 1);
                    mod(ret,MOD);
                    itr2 += 2;
                    Sum += 2;
                }
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 5508
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n;
  cin >> n;
  vector<P> a(n);
  rep(i,n) {
    int x, l;
    cin >> x >> l;
    a[i] = make_pair(x+l,x-l);
  }
  sort(rng(a));
  int cnt = 0;
  int cur = -1001001001;
  for(int i = 0; i < n; i++) {
      if(cur<=a[i].second) {
        cnt++;
        cur = a[i].first;
      }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3984
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n,m;cin>>n>>m;
  vvi a(n, vi(m));
  rep(i,n){
    rep(j,m){
      cin>>a[i][j];
    }
  }
  vi now(n);

  int ans = INF;
  set<int> removed;
  while(true){
    dump(now);
    map<int, int> cnt;
    rep(i, n){
      cnt[a[i][now[i]]]++;
    }
    dump(cnt);
    int M = -INF;
    each(el, cnt){
      int sp = el.first;
      int v = el.second;
      dump(sp, v);
      chmax(M, v);
    }
    dump(M);
    chmin(ans, M);
    each(el, cnt){
      int sp = el.first;
      int v = el.second;
      if (v==M) {
        removed.insert(sp);
        dump(sp);
        rep(i, n){
          while (removed.find(a[i][now[i]])!=removed.end()){
            now[i]++;
            if (now[i]==m) {
              cout << ans << endl;
              return 0;
            }
          }
        }
        break;
      }
    }
  }
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 1024
N = int(input())
l = []
for i in range(N):
    a, b = input().split(" ")
    l.append([a, int(b), i + 1])

# 数字でソート
l = sorted(l, key=lambda x: (x[1]), reverse=True)
# 文字でソート
l = sorted(l, key=lambda x: (x[0]))
for k in l:
    print(k[-1])

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

int main() {
    int N,i,r;
    string S;
    char p;
    cin >> N >> S;
    r = N;

    p = S.at(0);
    for(i=1; i<N; i++) {
        if(p == S.at(i))
            r--;
        p = S.at(i);
    }

    cout << r << endl;
}

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

int main(){
    //int flag=0;
    int p;ll sum=0;
    cin>>p;
    for(int n=1;n<=p;n++){
        if(n%3==0 && n%5!=0) continue;//cout<<"Fizz";
        else if(n%5==0 && n%3!=0) continue;//cout<<"Buzz";
        else if(n%3==0 && n%5==0) continue;//cout<<"FizzBuzz";
        else sum+=n;
    }
    cout<<sum<<endl;
    
}

Measured memory_bytes: 3648
n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
chars_odd = list(set(v_odd))
cnt_odd = dict()
for char in chars_odd:
    cnt_odd[char] = 0
for char in v_odd:
    cnt_odd[char] += 1
odd_cnt = sorted(cnt_odd.items(), key=lambda x:x[1], reverse=True)
odd_cnt.append(('_', 0))

chars_even = list(set(v_even))
cnt_even = dict()
for char in chars_even:
    cnt_even[char] = 0
for char in v_even:
    cnt_even[char] += 1
even_cnt = sorted(cnt_even.items(), key=lambda x:x[1], reverse=True)
even_cnt.append(('_', 0))

if odd_cnt[0][0] == even_cnt[0][0]:
    res = max(odd_cnt[0][1] + even_cnt[1][1], odd_cnt[1][1] + even_cnt[0][1])
else:
    res = odd_cnt[0][1] + even_cnt[0][1]
print(n - res)

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

template<typename ... Ts> void read (Ts&       ... vs){(std::cin  >> ... >> vs);}
template<typename ... Ts> void write(Ts const& ... vs){(std::cout << ... << vs); std::cout << std::endl;}

int main()
{
    int A, B, C;
    read(A, B, C);

    std::swap(A, B);
    std::swap(A, C);

    write(A, ' ', B, ' ', C);
    return 0;
}


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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	int t[N] = {}, x[N] = {}, y[N] = {}, dt, dist;
	
	for(int i=1; i<=N; i++)
		cin >> t[i] >> x[i] >> y[i];
	
	for(int i=0; i<N; i++){
		dt = t[i+1] - t[i];
		dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
		if(dist > dt){
			cout << "No";
			return 0;
		}
		if(dist%2 != dt%2){
			cout << "No";
			return 0;
		}
	}
	
	cout << "Yes";
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int N,K;

int main() {
  cin >>N >>K;
  vector<int> A(N); rep(i, N) cin >>A[i];
  vector<bool> dp(K+1, false);
  // dp[i]...残りi個で自分の番が来たら勝てるかどうか
  for (int i=0; i<K; i++){
    // 残りi個で自分の番が来たら負け。よって相手を残りi個にできる取り方は勝てる
    // 逆にどんな取り方をしてもdp[i] = true の所にしか行けないなら負け
    if (dp[i]) continue;
    for (int j=0; j<N; j++){
      if (i + A[j] > K) break;
      dp[i+A[j]] = true;
    }
  }
  cout <<(dp[K] ? "First" : "Second") <<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<long long, long long> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	long long H, M, h, m, K;
	cin >> H >> M >> h >> m >> K;
	cout << (h * 60 + m) - (H * 60 + M) - K << endl;
}

Measured memory_bytes: 3676
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Measured memory_bytes: 52204
N,K = map(int,input().split())

ans = 0
for b in range(K+1,N+1):
    tmp = 0
    multi = int(N/b)
    tmp += (b-K) * multi
    if K==0:
        tmp += max(0,N%b)
    else:
        tmp += max(0,(N%b-K+1))
    ans += tmp
print(ans)

Measured memory_bytes: 3060
import sys
head = -1
tail = -1
dll = []
for i in range(int(sys.stdin.readline())):
    line = sys.stdin.readline()

    if line[6]=='F':
        if head==tail:
            dll=[]
            head=-1
            tail=-1
        else:
            nxt=dll[head][2] #                                                  
            if nxt>=0:  dll[nxt][1]=-1
            if tail==head: tail=-1
            head=nxt
    elif line[6]=='L':
        if head==tail:
            dll=[]
            head=-1
            tail=-1
        else:
            prv=dll[tail][1]
            if prv>=0:  dll[prv][2]=-1
            if tail==head: head=-1
            tail=prv

    elif line[0]=='i': # 'insert':                                              
        x = int(line[7:])
        dll.append([x, -1, head])
        llen = len(dll)-1
        if head==-1:   tail=llen
        else:            dll[head][1]=llen
        head=llen
    elif line[0]=='d': # 'delete':                                              
        x = int(line[7:])
        cur=head
        while cur>=0:
            if dll[cur][0]==x:
                nxt=dll[cur][2]
                prv=dll[cur][1]
                dll[nxt][1]=prv
                dll[prv][2]=nxt
                if nxt==-1: tail=prv
                if prv==-1: head=nxt
                break
            cur=dll[cur][2]

print(dll[head][0], end='')
cur = dll[head][2]
while cur>=0:
    print('',dll[cur][0], end='')
    cur=dll[cur][2]
print()


Measured memory_bytes: 181240
#include "bits/stdc++.h"
using namespace std;

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

    vector<int> road(M * 2);
    for (int i = 0; i < M * 2; i++) {
        cin >> road.at(i);
    }

    for (int i = 0; i < N; i++) {
        int res = 0;
        for (int j = 0; j < M * 2; j++) {
            if (road.at(j) == i + 1) {
                res++;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256