akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	long k = sc.nextLong();
    	Map<Integer,Integer> teleport = new HashMap<>();
    	Map<Integer,Long> history = new HashMap<>();
    	for(int i = 1 ; i <= n; i++){
    		teleport.put(i, sc.nextInt());
    	}
    	long i;
    	int now = 1;
    	boolean flag = false;
    	for(i = 0; i <= k; i++){
    		if(history.containsKey(now)){
    			flag = true;
    			break;
    		}
    		history.put(now, i);
    		now = teleport.get(now);
    	}
    	if(flag){
    		long pastTime = history.get(now);
    		k = pastTime + (k - pastTime) % (i - pastTime);
    	}
    	for(int p : history.keySet()){
    		if(history.get(p) == k){
    			System.out.println(p);
    			return;
    		}
    	}
    }
}

Measured memory_bytes: 76728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1<<27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    ll N, M; cin >> N >> M;
    vector<ll> l(M), r(M);
    rep(i, M){
        cin >> l[i] >> r[i];
    }
    pt(max(0LL, 1-((ll)*max_element(all(l)) - *min_element(all(r)))));

}

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


vector<long long> count_v(vector<long long> v){
    long long n = v.size();

    vector<long long> ans(n, 0);
    for(long long i = 0; i < n; i++){
        long long left = max((long long)0, i-v[i]);
        long long right = min(n-1, i+v[i]);
        ans[left]++;
        if(right+1 < n){
            ans[right+1]--;
        }
        
    }

    for(long long i = 1; i < n; i++){
        ans[i] += ans[i-1];
    }

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

    vector<long long> a(n);
    vector<long long> ans_n(n, n);

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

    

    for(long long i = 0; i < k; i++){
        a = count_v(a);
        if(a == ans_n){
            for(long long j = 0; j < n; j++){
                printf("%lld ", n);
            }
            printf("\n");
            return 0;
        }
    }

    for(long long i = 0; i < n; i++){
        printf("%lld ", a[i]);
    }

    printf("\n");

    return 0;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	char s[334][334];
	cin>>n;
	REP(i, n){
		REP(j, n){
			cin>>s[i][j];
		}
	}
	char t[334][334];
	int ans=0;
	REP(i, n){
		REP(x, n){
			REP(y, n){
				t[x][y]=s[(x+i)%n][y];
			}
		}
		bool ok=true;
		REP(x, n){
			REP(y, x){
				if(t[x][y]!=t[y][x]){
					ok=false;
					break;
				}
			}
		}
		if(ok){
			++ans;
		}
	}
	cout<<ans*n<<'\n';
	return 0;
}


Measured memory_bytes: 512
import math

N, K = map(int, input().split())

total = 0
for d in range(1, N + 1):
    if d < K:
        ceil = math.ceil(math.log2(K) - math.log2(d))
        total += 1 / (2 ** ceil)
    else:
        total += 1

print(total / N)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	float sum = 0;
	
	for(int i = 0; i<n; i++){
		cin>>a[i];
		sum += (float)1/a[i];
	}
	if(n == 1){
		cout<<a[0]<<"\n";
		return 0;
	}
	float ans = 1/sum;
	cout<<setprecision(6)<<fixed<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X, Y = [], []
d = {n:1 for n in range(N)}
r = set([0])
for _ in range(M):
    x, y = map(int, input().split())
    d[x-1] -= 1
    d[y-1] += 1
    if x - 1 in r:
        r.add(y - 1)
        if d[x - 1] == 0:
            r.remove(x - 1)
    X.append(x)
    Y.append(y)

print(len(r))

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

int main(){
	string S;
	cin >> S;
	string ans = "AC";
	if(S[0] != 'A'){
		ans = "WA";
	}
	int cnt = 0;
	for(int i = 1; i < S.size(); ++i){
		if(isupper(S[i])){
			if(i == 1 || i == S.size() - 1 || S[i] != 'C'){
				ans = "WA";
			}
			++cnt;
		}
	}
	if(cnt != 1){
		ans = "WA";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    string S, output = "";
    int w, rp = 0, tmp;
    getline(cin, S);
    cin >> w;
    tmp = w;
    if(w == 1)output += S;
    else{
        output += S[0];
        if (S.length() % w == 0)rp = S.length() / w;
        else rp = S.length() / w + 1;
        for(int i = 0; i < rp - 1; i++){
            output += S[tmp];
            tmp += w;
        }
    }
    cout << output << endl;
}

Measured memory_bytes: 256
//***No one wants to die...yet death is the destiation we all share***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[2*100002],b[2*100002];
int main(){
  ll n,m,k,c=0;
  cin>>n>>m>>k;
  forn(i,n) cin>>a[i];
  forn(i,m) cin>>b[i];
  ll t1=-1,t2=-1,an=0;
  while((t1<n-1)&&(an+a[t1+1]<=k)) an+=a[++t1];
    ll ma=t1+1+t2+1;
    
  while(t1>=-1){
      while((t2+1<m)&&((an+b[t2+1])<=k)){
          an+=b[++t2];
      }
      ma=max(ma,t1+2+t2);
      if(t1<=-1){
          t1--;
          continue;
      }
      an-=a[t1--];
  }
  cout<<ma;
}

Measured memory_bytes: 6708
L =[]
L.append(input())
L.append(input())
L.append(input())
i = 0
win = ['a','b','c']
while len(L[i]) > 0:
  if L[i][0] == 'a':
    L[i] = L[i][1:]
    i = 0
  elif L[i][0] == 'b':
    L[i] = L[i][1:]
    i = 1
  else:
    L[i] = L[i][1:]
    i = 2
print(win[i].upper())

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string S; cin >> S;
    string aim = "CODEFESTIVAL2016";
    int ans = 0;
    rep(i, 16) if(S[i] != aim[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (int)1.01e4;
const int N = 1 << 18;



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    string s;
    while (cin >> s) {
        int n = s.length();
        vector<int> cnt(26);
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            int c = s[i] - 'a';
            cnt[c]++;
            ans += (i + 1) - cnt[c];
        }
        cout << ans + 1 << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    long long int cnt = 0;

    std::map<int, int> mp;
    //for(int i=0; i<n; i++){
        cnt = 0;
        //cout << "### " << i+1 << endl;
        for(int x=1; x<=n; x++){
            long long int x2 = x*x;
            if(x2 > n) continue;
            for(int y=1; y<=101; y++){
                //long long int y2 = y*y;
                //long long int xy = x*y;
                //long long int num = x2+y2+xy;
                //if(num+3 > n) continue;
                for(int z=1; z<=101; z++){
                    
                    //long long int z2 = z*z;
                    //long long int xz = x*z;
                    //long long int yz = y*z;
                    long long int num = x*x + y*y + z*z + x*y + x*z + y*z;
                    mp[num]++;
                    /*
                    if(num == i+1){
                        //cout << x << ", " << y << ", " << z << endl;
                        //cout << num << ":" << num+z2+xz+yz << endl;
                        cnt++;
                    }
                    */
                }
            }
        }
        //cout << cnt << endl;
    //}
    for(int i=1; i<=n; i++){
        cout << mp[i] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 5456
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>

#define LOP(N) for(int i=0; i<N; i++)
#define LOOP(i, N) for(int i=0; i<N; i++)
#define LOOP_s(i, start, end) for(int i=start; i<end; i++)

using namespace std;


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

    int result = K;
    LOP(N-1) {
        result *= K-1;
    }
    cout << result;
}


Measured memory_bytes: 256
table = list(map(int,input().split()))

for i in range(2,0,-1):
    k = 0
    while k < i:
        if table[k] > table[k+1]:
            table[k],table[k+1] = table[k+1],table[k]
        k += 1;


print(table[0],table[1],table[2])


Measured memory_bytes: 5600
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let mut a = i::uv(n);
    a.sort();
    let m = 1_000_000_007usize;
    if n % 2 == 0 {
        for i in 0..n / 2 {
            if a[i * 2] != i * 2 + 1 || a[i * 2 + 1] != i * 2 + 1 {
                println!("{}", 0);
                return;
            }
        }
    } else {
        if a[0] != 0 {
            println!("{}", 0);
            return;
        }
        for i in 1..n / 2 {
            if a[i * 2 - 1] != i * 2 || a[i * 2] != i * 2 {
                println!("{}", 0);
                return;
            }
        }
    }
    println!("{}", (0..n / 2).fold(1, |x, _| x * 2 % m));
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long INF=pow(2,31)-1;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const long P_SIZE=301;
const long MAX_N=100004;
long packet[401];
long arr[MAX_N];

long getSum(long x,long y){
	long res=0;
	if(y-x<=4*P_SIZE){//1???????????±??????????????¨??§?????????
		FOR(i,x,y+1){
			res+=arr[i];
		}
		return res;
	}
	long pb=x/P_SIZE+1;
	long pd=y/P_SIZE-1;
	for(long i=x;i<pb*P_SIZE;i++){
		res+=arr[i];//????????????
	}
	for(long i=pb;i<pd;i++){//i=[pb*P_SIZE,pd*P_SIZE)
		//cout<<"!2"<<endl;
		res+=packet[i];//?????±????????????????????????
	}
	for(long i=pd*P_SIZE;i<=y;i++){
		//cout<<"!3"<<endl;
		res+=arr[i];//????????????
	}
	return res;
}

void add(long x,long y){
	arr[x]+=y;
	long pb=x/P_SIZE;//?????????????±????????????±??????
	packet[pb]+=y;//[pb*P_SIZE,(pb+1)*P_SIZE)
}

int main(){
	long N,Q;
	cin>>N>>Q;
	CLR(packet);
	CLR(arr);	
	REP(i,Q){
		long c,x,y;
		cin>>c>>x>>y;
		if(c==0){
			add(x,y);
		}else{
			cout<<getSum(x,y)<<endl;
		}
	}
	//REP(i,SZ(res))cout<<res[i]<<endl;
	return 0;
}

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

int main() {
  string s;
  cin>>s;
  int N=s.size();
  int n=(N-1)/2;
  bool flag=true;
  for(int i=0;i<(n+1)/2;i++){
    if(s[i]==s[n-i-1]&&s[i]==s[n+i+1]&&s[i]==s[2*n-i]) continue;
    else flag=false;
  }
  if(flag==true) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int N,T,c[101],t[101],i,w=1001;
  t[0]=1001;
  scanf("%d %d",&N,&T);
  for(i=1;i<=N;i++){
    scanf("%d %d",&c[i],&t[i]);
    if(t[i]<=T){
      if(c[i]<w){
        w=c[i];
      }
    }
  }
  if(w==1001){
    puts("TLE");
  }else{
    printf("%d",w);
}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;

int main(void) {
    cin >> n;
    ll ans = 1; 
    for (int i = 0; i < n; i++) {
        if (n < i*i) {
            ans = (i-1) * (i-1);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<uint64_t> A(N);
  bool zeroExists = false;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    if(A[i] == 0)
      zeroExists = true;
  }
  if (zeroExists) {
    cout << 0 << endl;
    return 0;
  }
  const uint64_t big = 1000000000000000000;
  uint64_t ans = 1;
  for (int i=0; i<N; i++) {
    if (ans > big / A[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      ans *= A[i];
    }
  }
  cout << ans << endl;
  return 0;
}
  

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d});
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;
 
ll a[100000+50],b[100000+50];
 
int main ()
{
	ll n,k,i;
	cin>>n>>k;
	for(i=0;i<n;i++)
		scanf("%lld %lld",&a[i],&b[i]);
	ll r=2999999999999999999,l=0,now;
	while(l<=r)
	{
		now=(r+l)/2;
		ll ans=0;
		for(i=0;i<n;i++)
			if(now>=a[i])
			ans+=(now-a[i]+b[i])/b[i];
		if(ans>=k)
			r=now-1;
		else
			l=now+1;
	}
	printf("%lld\n",l);
	return 0;
}

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

int main(){
	
	int n;cin>>n;
	int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
	
	while(n--){
		string s;
		cin>>s;
		if(s[0]=='A' && s[1]=='C'){
			cnt1++;
		}else if(s[0]=='W' && s[1]=='A'){
			cnt2++;
		}else if(s[0]=='T' && s[1]=='L' && s[2]=='E'){
			cnt3++;
		}
		else if(s[0]=='R' && s[1]=='E'){
			cnt4++;
		}
	}
	cout<<"AC "<<"x "<<cnt1<<"\n";
	cout<<"WA "<<"x "<<cnt2<<"\n";
	cout<<"TLE "<<"x "<<cnt3<<"\n";
	cout<<"RE "<<"x "<<cnt4<<"\n";
	
}

Measured memory_bytes: 3640
#include <iostream>
//#include <cstdlib>
#include <map>
using namespace std;
int main() {
  long H, W, N;
  cin >> H >> W >> N;
  int a[N], b[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  map<long,int> m;

  for (int p = 0; p < N; p++) {
    for (int dx = -1; dx <= 1; dx++) {
      for (int dy = -1; dy <= 1; dy++) {
        long x = b[p]+dx;
        long y = a[p]+dy;
        if (1 <= y && y < H-1 && 1 <= x && x < W-1)
          m[y*W+x]++;
      }
    }
  }

  long ans[] = {0,0,0,0,0,0,0,0,0,0};
  for (map<long,int>::iterator itr = m.begin(); itr != m.end(); itr++) {
    ans[itr->second]++;
  }
  
  // int *masu;
  // masu = (int *)malloc(sizeof(int)*H*W);
  // if (masu == NULL) {
  //   cout << "メモリが足りない" << endl;
  //   return 0;
  // }
  // for (int i = 0; i < H; i++)
  //   for (int j = 0; j < W; j++)
  //     masu[i][j] = 0;
  // for (int p = 0; p < N; p++) {
  //   for (int dx = -1; dx <= 1; dx++) {
  //     for (int dy = -1; dy <= 1; dy++) {
  //       int x = a[p]+dx;
  //       int y = b[p]+dy;
  //       if (0 <= y && y < H && 0 <= x && x < W)
  //         masu[x][y]++;
  //     }
  //   }
  // }

  // long ans[] = {0,0,0,0,0,0,0,0,0,0};
  // for (int i = 1; i < H-1; i++) {
  //   for (int j = 1; j < W-1; j++) {
  //     ans[masu[i][j]]++;
  //   }
  // }

  int long sum = 0;
  for (int n = 1; n < 10; n++) {
    sum += ans[n];
  }
  cout << ((W-2)*(H-2)-sum) << endl;
  for (int n = 1; n < 10; n++) {
    sum += ans[n];
    cout << ans[n] << endl;
  }

  return 0;
}


Measured memory_bytes: 57216
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b;
    cin >> a >> b;
    int c, d;
    cin >> c >> d;
    if (a+b > c+d) {
        OUT("Left")
    } else if (a+b < c+d) {
        OUT("Right")
    } else {
        OUT("Balanced")
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int main(){
	scanf("%d%d%d%d", &n, &m, &x, &y);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++)
			if((i <= y && j <= x) || (i > y && j > x))
				printf("%d", 1);
			else printf("%d", 0);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<string> split(string &s){
    vector<string> res;
    string tmp;
    for (auto &&i : s) {
        if(i == ' '){
            if(!tmp.empty()) {
                res.emplace_back(tmp);
                tmp.clear();
            }
        }else tmp += i;
    }
    if(!tmp.empty()) res.emplace_back(tmp);
    return res;
}
bitset<1 << 20> dp[50];
int main() {
    int n;
    cin >> n;
    vector<vector<string>> v(n);
    map<string, int> m;
    array<char, 256> vars;
    fill(vars.begin(),vars.end(), -1);
    int cnt = 0;
    cin.ignore();
    for (int i = 0; i < n; ++i) {
        string s;
        getline(cin, s);
        v[i] = split(s);
        m[v[i][0]] = i;
        v[i].erase(v[i].begin());
        for (int j = 1; j < v[i].size(); ++j) {
            if(islower(v[i][j][0]) && !~vars[v[i][j][0]]){
                vars[v[i][j][0]] = cnt++;
            }
        }
    }
    int cur = 0, val = 0;
    while(true){
        if(cur == n) break;
        if(dp[cur][val]) {
            puts("inf");
            return 0;
        }
        /*for (auto &&i : v[cur]) {
            cout << i << " ";
        }
        puts("");*/
        dp[cur].set(val);
        if(v[cur][0] == "HALT"){
            break;
        }else if(v[cur][0] == "ADD"){
            int val1 = (val >> (vars[v[cur][2][0]]*4))&15, val2 = (~vars[v[cur][3][0]] ? (val >> (vars[v[cur][3][0]]*4))&15 : stoi(v[cur][3]));
            if(val1 + val2 > 15) break;
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + ((val1+val2) << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "SUB"){
            int val1 = (val >> (vars[v[cur][2][0]]*4))&15, val2 = (~vars[v[cur][3][0]] ? (val >> (vars[v[cur][3][0]]*4))&15 : stoi(v[cur][3]));
            if(val1 - val2 < 0) break;
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + ((val1-val2) << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "SET"){
            int vall = (~vars[v[cur][2][0]] ? (val >> (vars[v[cur][2][0]]*4))&15 : stoi(v[cur][2]));
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + (vall << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "IF"){
            int val1 = (val >> (vars[v[cur][1][0]]*4))&15;
            if(val1) {
                if(!m.count(v[cur][2])) break;
                cur = m[v[cur][2]];
                continue;
            }
        }
        cur++;
    }
    for (int i = 0; i < 256; ++i) {
        if(~vars[i]){
            printf("%c=%d\n", i, (val >> (vars[i]*4))&15);
        }
    }
    return 0;
}


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

int main(){
  int H, W; cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> row(H, false);
  vector<bool> column(W, false);
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(a.at(i).at(j) == '#'){
        row[i] = true;
        column[j] = true;
      }
    }
  }
  
  for(int i = 0; i < H; i++){
    bool disp = false;
    for(int j = 0; j < W; j++){
      if(row[i] && column[j]){
        cout << a.at(i).at(j);
        disp = true;
      }
    }
    if(disp) cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int n = sc.nextInt();
		long d = sc.nextLong();
      	int count = 0;
      	long doubled = d*d;
      
      for(int i = 0; i < n ; i++){
      	long x = sc.nextLong();
      	long y = sc.nextLong();
        if((x*x + y*y)<= doubled){
        	count++;
        }
      }

		System.out.println(count);

		
	}
}

Measured memory_bytes: 60472
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int64_t max(int64_t x, int64_t y) {
    if (x >= y) return x; else return y;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64_t a, b, x;
    cin >> a >> b >> x;
    int64_t u = b / x, v = (a + x - 1) / x;
    cout << max(0, (u - v + 1)) << endl;

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    auto xs = readints;

    auto deque = DList!int();
    for (int i = 0; i < xs.length; i++) {
        if ((i & 1) == (n & 1)) {
            deque.insertBack(xs[i]);
        }
        else {
            deque.insertFront(xs[i]);
        }
    }

    writeln(deque[].map!(e => e.to!string).join(" "));
}


Measured memory_bytes: 23664
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,x,a[100000],ans=0;
    cin >> n >> x;
    for(long long int i=0;i<n;i++){
        cin >> a[i];
    }
    for(long long int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            ans+=a[i]+a[i+1]-x;
            a[i+1]-=a[i]+a[i+1]-x;
            if(a[i+1]<0){
              a[i+1]=0;
            }
            }
            
        
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main()
{
    int N;
    cin >> N;
    map<string, int> dic;
    for (int i = 0; i < N; ++i)
    {
        string S;
        cin >> S;
        if (dic[S] != 0) continue;
        else ++dic[S];
    }
    int ans = 0;
    for (auto e : dic)
    {
        ans += e.second;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int h, w;
	cin >> h >> w;
	int c[h][w];
	REP(i, h) REP(j, w) cin >> c[i][j];
	vector<int> v1, v2, v3, v4;
	REP(i, h){
		REP(j, w-1){
			if(c[i][j]%2==1){
				c[i][j]--;
				c[i][j+1]++;
				v1.pb(i);
				v2.pb(j);
				v3.pb(i);
				v4.pb(j+1);
			}
		}
	}
	REP(i, h-1){
		if(c[i][w-1]%2==1){
			c[i][w-1]--;
			c[i+1][w-1]++;
				v1.pb(i);
				v2.pb(w-1);
				v3.pb(i+1);
				v4.pb(w-1);
		}
	}
	cout << v1.size() << endl;
	REP(i, v1.size()){
		cout << v1[i]+1 << " " << v2[i]+1 << " " << v3[i]+1 << " " << v4[i]+1 << endl;
	}
	return 0;
} 


Measured memory_bytes: 5220
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	
	ll N, K;

	cin >> N >> K;
	
	vector<ll> H(N);

	
	rep(i, N) cin >> H[i];
	
	if (N > K) {
		
		sort(H.begin(), H.end());
		
		ll cnt = 0;

		rep(i, K) {
			H.pop_back();
			cnt++;
		}
		ll ans = 0;

		rep(i, N-cnt) ans += H[i];

		cout << ans << endl;
	}
	else if (K >= N) {
		cout << 0 << endl;
}

	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C086
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int[]> list = new List<int[]>();
            for(int i = 0; i < N; i++)
            {
                int[] a = Console.ReadLine().Split(' ').Select(z=>int.Parse(z)).ToArray();
                list.Add(a);
            }

            string plan = "Yes";
            int x = 0, y = 0, t = 0;
            foreach (int[] a in list)
            {
                int tn = a[0], xn = a[1], yn = a[2];
                int dt = tn - t;
                int ds = Math.Abs(xn - x) + Math.Abs(yn - y);
                int d = dt - ds;
                if (d < 0 || d % 2 != 0)
                {
                    plan = "No";
                    break;
                }
                t = tn; x = xn; y = yn;
            }
            Console.WriteLine(plan);
        }

    }
}


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

int main(){
  char x,y;
  cin >> x >> y;
  map<char,int> hex;
  hex['A'] = 10;
  hex['B'] = 11;
  hex['C'] = 12;
  hex['D'] = 13;
  hex['E'] = 14;
  hex['F'] = 15;
  if(hex.at(x)<hex.at(y))
    cout << "<" << endl;
  else if(hex.at(x)==hex.at(y))
    cout << "=" << endl;
  else
    cout << ">" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
 float vmin;
 int ans;

 while(scanf("%f",&vmin)!=EOF){

       ans=ceil( ( (4.9 * pow(vmin/9.8,2) )+5)/5 );
       printf("%d\n",ans);

 }

return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=55;
int n,m,a[N],b[N],ans,forbid1,forbid2;
bool visit[N];
vector<int>v[N];
void dfs(int now)
{
	visit[now]=true;
	for(int i=0;i<v[now].size();i++)
	{
		if(visit[v[now][i]])continue;
		if((forbid1==now&&forbid2==v[now][i])||(forbid2==now&&forbid1==v[now][i]))continue;
		dfs(v[now][i]);
	}
}
bool check()
{
	memset(visit,false,sizeof(visit));
	dfs(0);
	for(int i=0;i<n;i++)
		if(!visit[i])
			return false;
	return true;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		v[a[i]].pb(b[i]);
		v[b[i]].pb(a[i]);
	}
	for(int i=0;i<m;i++)
	{
		forbid1=a[i];
		forbid2=b[i];
		if(!check())ans++;
	}
	cout<<ans;
}
/*
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
*/

Measured memory_bytes: 256
//#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll n;
int main(){
    cin>>n;
    ll ans=n/500*1000;
    n-=n/500*500;
    ans+=n/5*5;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
function main()
  N,M=map(x->parse(Int,x),split(readline()))
  H=map(x->parse(Int,x),split(readline()))
  ok=[true for _=1:N]
  for _=1:M
    a,b=map(x->parse(Int,x),split(readline()))
    if H[a]<=H[b]
      ok[a]=false
    end
    if H[b]<=H[a]
      ok[b]=false
    end
  end
  println(count(x->x,ok))
end
main()

Measured memory_bytes: 202504
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> x1(n);
    rep(i,n) {
        cin >> x[i];
        x1[i] = x[i];
    }
    sort(x.begin(),x.end());
    ll a,b;
    a = x[n/2];
    b = x[n/2-1];

    rep(i,n){
        if(x1[i]<b){
            cout << a << endl;
        }else if(x1[i]==b){
            cout << a << endl;
        }else if(x1[i]==a){
            cout << b << endl;
        }else{
            cout << b << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6352
// Aizu 1117: Missing Numbers
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { int r, c, f; } T;
T q[1005]; int len;
long long a[105][15]; char b[105][15]; int h, w;
long long sr[105], sc[15];
int kr[105], kc[15];

int main()
{
	int r, c, i, k, f;
	char buf[20];
	int cno = 0;

	while (scanf("%d", &h) && h) {
		scanf("%d", &w); cno++;
		for (len = 0, r = 0; r <= h; r++) for (c = 0; c <= w; c++) {
			scanf("%s", buf);
			if (*buf == '?') a[r][c] = 0, b[r][c] = 1, q[len].r = r, q[len].c = c, q[len++].f = 1;
			else             a[r][c] = atoi(buf), b[r][c] = 0;
		}
		f = 1; while (f) {
			f = 0;
			for (r = 0; r < h; r++) {
				for (sc[r] = k = 0, c = 0; c < w; c++) {
					sc[r] += a[r][c], k += b[r][c]; if (b[r][c]) i = c;
				}
				if (k == 1) {
					c = i, a[r][c] = a[r][w] - sc[r], b[r][c] = 0, sc[r] += a[r][c], sr[c] += a[r][c];
					f = 1;
				}
			}
			for (c = 0; c < w; c++) {
				for (sr[c] = k = 0, r = 0; r < h; r++) {
					sr[c] += a[r][c], k += b[r][c]; if (b[r][c]) i = r;
				}
				if (k == 1) {
					r = i, a[r][c] = a[h][c] - sr[c], b[r][c] = 0, sr[c] += a[r][c], sc[r] += a[r][c];
					f = 1;
				}
			}
		}
		for (k = 0, i = 0; i < len; i++) if (b[q[i].r][q[i].c]) k = 1; else q[i].f = 0;
		if (cno > 1) putchar('\n');
		if (k == 0) for (i = 0; i < len; i++) printf("%lld\n", a[q[i].r][q[i].c]);
		else puts("NO");
    }
	return 0;
}

Measured memory_bytes: 1612
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  modint pow(u64 exp){
    modint res=1,rhs=*this;
    while (exp) {
      if (exp % 2) {
        res *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return res;
  }

  friend ostream& operator<<(ostream& os,modint& rhs){
    os << rhs.value();
    return os;
  }

  friend istream& operator>>(istream &is,modint &rhs){
      is>>rhs.value();
      rhs.value()%=Modulus;
      return is;
  }

};
using mint=modint<(ll)1e9+7>;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll  n;
  mint a,b,c;cin>>n>>a>>b>>c;
  a/=100;
  b/=100;
  c/=100;
  c=(mint)1-c;
  c=(mint)1/c;
  a*=c;
  b*=c;
  mint res=0;
  vector<mint>fact(2e5+7),inv(2e5+7);
  fact[0]=1;
  rep(i,2e5){
    fact[i+1]=fact[i]*(i+1);
  }
  inv[2e5]=(mint)1/fact[2e5];
  rrep(i,2e5){
    inv[i]=inv[i+1]*(i+1);
  }
  auto comb=[&](ll a,ll b){
    return fact[a]*inv[b]*inv[a-b];
  };
  rep(i,n){
    res+=comb(n+i-1,i)*a.pow(n)*b.pow(i)*(i+n)*c;
    res+=comb(n+i-1,i)*b.pow(n)*a.pow(i)*(i+n)*c;
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner (System.in);
		int k = in.nextInt();
		int[] primes = new int[k];
		int item = 0;
		String numString = "";
		for ( int i = 3; i < 55555; i++ ) {
			if (item == k)
				break;
			numString = Integer.toString(i);
			if (isPrime(i) && numString.charAt(numString.length()-1) == '1' ) {
				primes[item] = i;
				item++;
			}
		}
		
		String fin = "";
		
		for ( int i = 0; i < k; i++ ) {
			fin += primes[i];
			if ( i != k-1 )
				fin += " ";
		}
		System.out.println(fin);
		// System.out.println(Arrays.toString(primes));
	}
	
	public static boolean isPrime(int n) {
		for ( int i = 2; i*i <= n; i++ ) {
			if ( n%i == 0 )
				return false;
		}
		return true;
	}

}

Measured memory_bytes: 20308
import sys
import collections

def swap(t):
    if t[1] < t[0] :
        return (t[1],t[0])
    else:
        return t

n = int(sys.stdin.readline().rstrip())
a = [int(x) for x in sys.stdin.readline().rstrip().split()]

zippeda = list(map(swap,list(zip(range(1,n+1),a))))
zippeda.sort()
c = collections.Counter(zippeda)
counter = 0
for a in c.most_common():
    if a[1] < 2:
        break
    else:
        counter = counter + 1

print(counter)


Measured memory_bytes: 72684
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()
d = LI()

limit = 11*n
while n < limit:
    flg = 1
    for x in list(str(n)):
        if int(x) in d:
            flg = 0
            break
    if flg:
        print(n)
        break
    n += 1

Measured memory_bytes: 74596
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int sum = 0;
int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	int diff = 0;
	for(int i = 0; i < n; i++){
		if(i % 2){
			diff -= a[i];
		} else {
			diff += a[i];
		}
	}
	if(n % 2 == 0){
		cout << (sum + max(diff, -diff)) / 2 << " " << (sum - max(diff, -diff)) / 2 << '\n';
		return 0;
	}
	if(diff >= 1000){
		cout << (sum + diff) / 2 << " " << (sum - diff) / 2 << '\n';
		return 0;
	}
	int s = 0;
	int e = 1000;
	while(s + 1 < e){
		int d = (s + e) / 2;
		vector<int> r;
		r.push_back(a[0]);
		for(int i = 1; i < n; i += 2){
			if(r[r.size() - 1] < d || a[i] <= r[r.size() - 1]){
				r[r.size() - 1] += a[i+1] - a[i];
			} else {
				r.push_back(a[i]);
				r.push_back(a[i+1]);
			}
		}
		if(r[r.size() - 1] >= d){
			s = d;
		} else {
			e = d;
		}
	}
	cout << (sum + max(diff, (-diff + 2 * s))) / 2 << " " << (sum - max(diff, (-diff + 2 * s))) / 2 << '\n';
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int n;


int main(){
    cin>>n;
    multiset<int> m;

    rep(i,n){
        int x;
        cin>>x;
        auto it=m.lower_bound(x);
        if(it!=m.begin()) m.erase(--it);
        m.insert(x);
    }

    cout<<m.size()<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

int show(int x, int y) {
    cout << x << " " << y << endl;
    return x - y;
}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    if (n == 2) {
        cout << a[0] - a[1] << endl;
        cout << a[0] << " " << a[1] << endl;
        return;
    }
    int sum = a[0];
    REP(i,1,n-1) sum += abs(a[i]);
    sum -= a[n-1];
    cout << sum << endl;
    int ne = a[n-1];
    REP(i,1,n-1) {
        if (a[i] < 0) break;
        ne = show(ne, a[i]);
    }
    ne = show(a[0], ne);
    RREP(i,1,n-1) {
        if (a[i] >= 0) break;
        ne = show(ne, a[i]);
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 2304
object Main extends App {
  val n: Int = io.StdIn.readLine().toInt
  val arr: Array[Int] = io.StdIn.readLine().split(" ") map(_.toInt)

  def partition(arr: Array[Int], i: Int, p: Int, r:Int): (Array[Int], Int) = {
    val a: Array[Int] = arr.clone()
    var p: Int = 0

    for(i <- 0 until r) {
      val (ai, ap, ar) = (a(i), a(p), a(r))
      if (i == p) {if (ai <= ar) p += 1}
      else {if (ai <= ar && ai < ap) {a(i) = ap; a(p) = ai; p += 1}}
    }
    val ap = a(p)
    a(p) = a(r); a(r) = ap
    
    (a,p)
  }

  val (pa, i): (Array[Int], Int) = partition(arr, 0, 0, n-1)
  println(pa.slice(0, i).mkString(" ") + " [" + pa(i) + "] " + pa.slice(i+1, n).mkString(" "))
}

Measured memory_bytes: 85672
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#define INF 1000000000
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i=0;i<m;i++){
        int x;
        cin >> x;
        b[i] = x;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        int total = 0;
        for(int j=0;j<m;j++){
            int x;
            cin >> x;
            total+=x*b[j];
        }
        if(total+c>0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N, K; cin>>N>>K;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];

  //prev,afterベクトルの作成
  vector<ll> prev(N), after(N);
  rep(i,N){
    ll tmp1 = 0, tmp2 = 0;
    for(int j = 0; j < i; j++){
      if(a[i] > a[j]){
        tmp1++;
      }
    }
    for(int j = i + 1; j < N; j++){
      if(a[i] > a[j]){
        tmp2++;
      }
    }
    prev[i] = tmp1;
    after[i] = tmp2;
  }

  //ansの処理
  ll asum = K * (K + 1) / 2;
  ll ssum = K * (K - 1) / 2;
  asum %= MOD; ssum %= MOD;
  ll ans = 0;
  rep(i,N){
    ans += prev[i] * ssum;
    ans %= MOD;
    ans += after[i] * asum;
    ans %= MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def C(n, m):
	return 0 if n < m else fact[n] * inv[m] % MOD * inv[n - m] % MOD

MOD = 1000000007
n = int(raw_input())
fact = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % MOD
inv[n] = pow(fact[n], MOD - 2, MOD)
for i in range(n, 0, -1):
	inv[i - 1] = inv[i] * i % MOD
ans = 0
for i in range(1, n):
	ans += C(i - 1, n - i - 1) * fact[i] % MOD * fact[n - i - 1] % MOD
print (fact[n - 1] * n - ans % MOD + MOD) % MOD

Measured memory_bytes: 98044