akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

struct UnionFind {
private:
    vector<int> par,ran;
    vector<int> edge,size;
    int n;
public:
    UnionFind(int x){
      n=x;
      par.resize(n,0);
      ran.resize(n,0);
      edge.resize(n,0);
      size.resize(n,1);
      rep(i,n){
        par[i]=i;
      }
    }
    int find(int x) {
        if (par[x]==x)return x;
        else return par[x]=find(par[x]);
    }
    void unite(int x, int y) {
        x=find(x),y=find(y);
        if (x==y){
            edge[x]++;
            return;
        }
        if (ran[x]<ran[y]) {
            par[x]=y;
            size[y]+=size[x];
            edge[y]+=edge[x]+1;
        }
        else {
            par[y]=x;
            size[x]+=size[y];
            edge[x]+=edge[y]+1;
            if (ran[x]==ran[y])ran[x]++;
        }
    }
    bool same(int x,int y) {
        return find(x)==find(y);
    }
    int getSize(int x){
        return size[find(x)];
    }
    int getEdge(int x){
        return edge[find(x)];
    }
};

int n,m;

void solve(){
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m){
    int a,b;cin >> a >> b;a--;b--;
    uf.unite(a,b);
  }
  int ans=0;
  rep(i,n){
    ans=max(ans,uf.getSize(i));
  }
  cout << ans << endl;
}

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

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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int>v(n);
    vector<int>c(n);

    for(int i = 0; i < n; i++)
        scanf("%d", &v[i]);
    for(int i = 0; i < n; i++)
        scanf("%d", &c[i]);


    int res = 0;
    for(int i = 0; i < n; i++){
       res += max(v[i] - c[i], 0);
    }
    printf("%d\n",res);

    return 0;
}
/*
int main()
{
    int n;
    scanf("%d", &n);

    vector<int>v(n);
    vector<int>c(n);

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

    for(int i = 0; i < n; i ++)
        scanf("%d", &c[i]);


    int sum = 0;
    for(int i = 0; i < n; i++){
        if(v[i] > c[i]){
            sum += (v[i] - c[i]);
        }
    }
    printf("%d\n",sum);


    return 0;
}
*/


Measured memory_bytes: 3764
from itertools import accumulate
mod = 10**9 + 7
n, k = map(int, input().split())
arr = []
for i in range(n+1):
    arr.append(i)
ls = [0] + list(accumulate(arr))
ans = 0
for i in range(k, n+2):
    ans += (((ls[-1] - ls[-1-i]) - ls[i]) + 1)%mod
ans %= mod
print(ans)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n, m, l, r;
  cin >> n >> m;
  int imos[100005];
  fill(imos, imos + 100005, 0);
  for(int i = 0; i < m; ++i)
  {
    cin >> l >> r;
    imos[l]++;
    imos[r + 1]--;    
  }

  int ans = 0;
  for(int i = 0; i < 100004; ++i)
  {
    imos[i + 1] += imos[i];
    if(imos[i + 1] == m) ans++;
  }

  cout << ans;

}

int main()
{
	fastio;
	solve();

	return 0;
}

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

map <int,int> mp;

#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

typedef pair<int, int> P; //最短距離,頂点の番号
struct edge{
    int to,cost;
};
int N;
vector<edge> G[MAX]; //
int d[MAX]; //最短距離

void dijkstra(int s){
    priority_queue<P, vector<P>,greater<P> > que;
    
    fill(d,d+N,INF);
    d[s]=0;
    que.push(P(0,s));
    
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        
        if(d[v] < p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to] =d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}


int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    int k,u;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            edge e;
            cin>>e.to>>e.cost;
            G[u].push_back(e);
        }
    }
    dijkstra(0);
    for(int i=0;i<N;i++)
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<"\n";
    
    return 0;
    }



Measured memory_bytes: 10188
def solve(n, p, q)
  perms = [ *1..n ].permutation(n)
  a = perms.find_index { |perm| perm == p }
  b = perms.find_index { |perm| perm == q }
  (a - b).abs
end

n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)
q = gets.chomp.split.map(&:to_i)

puts solve(n, p, q)


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

#define imie(...) " [" <<#__VA_ARGS__<<':'<<(__VA_ARGS__)<<"] "
// #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int arr[100000+5];
int dp[100000+5];
int n;
// int go(int i){
// 	if(i >= n) return INT_MAX;
// 	if(i == n-1) return 0;
// 	if(dp[i]) return  dp[i];
// 	cout<< imie(i) <<'\n';
// 	int ans1 = INT_MAX;
// 	int ans2 = INT_MAX;
// 	if(i+1 < n) ans1 = go(i+1) + abs(arr[i+1] - arr[i]);
// 	if(i+2 < n) ans2 = go(i+2) + abs(arr[i+2] - arr[i]);
// 	return dp[i] = min(ans1, ans2);
// }

int main () {
	  #ifndef ONLINE_JUDGE
	    freopen("in.txt","r",stdin);
	    freopen("out.txt","w",stdout);
    #endif

	cin>>n;
	for(int i=0;i<n; i++){
		cin>>arr[i];
	}
	// cout<<go(0);
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;++i){
		dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]) ,dp[i-2] + abs(arr[i] - arr[i-2]));
	}
	cout<<dp[n-1];
	

}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m; cin>>n>>m;
	vector<pii> a(m);
	for(int i=0; i<m;++i) cin>>a[i].second>>a[i].first;
	sort(a.begin(), a.end());
	int last = 0, ans= 0;
	for(auto i: a) if(i.second >= last){
		ans++;
		last = i.first;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    vi x(5);
    rep(i,5){
        cin >> x[i];
    }
    rep(i,5){
        if(x[i]==0) {cout << i+1 << endl;return 0;}
    }


    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

#define f first 
#define s second 
#define mp make_pair
#define pb push_back

typedef long long ll;

const int mod=1e9+7;
const int INF=INT_MAX;



int main(){
    int n;
    cin >> n ;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans=INT_MAX;
    for(int i=0;i<n;i++){
        int sum1=0,sum2=0;
        for(int j=0;j<n;j++){
            if(j<=i){
                sum1+=a[j];
            }else{
                sum2+=a[j];
            }
        }
        ans=min(ans,abs(sum1-sum2));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

int main() {
    string s;
    cin >> s;

    int mn = 100000;
    for (int i = 'a'; i <= 'z'; i++) {
        int pos = -1;
        int mx = 0;
        for (int j = 0; j <= s.size(); j++) {
            if (j == s.size() || s[j] == i) {
                mx = mx > j - pos - 1 ? mx : j - pos - 1;
                pos = j;
            }
        }

        if (mx < mn) {
            mn = mx;
        }
    }

    cout << mn << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n,s;
    cin >> n >> s;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    vector<vector<ll>> dp(n+1, vector<ll>(3001));
    for (int i = 1; i < n+1; i++) {
        for (int j = 0; j < 3001; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        dp[i][z[i-1]] += i;
        dp[i][z[i-1]] %= 998244353;
        for (int j = 1; j < 3001; j++) {
            if (j + z[i-1] <= 3000) {
                dp[i][z[i - 1] + j] += dp[i - 1][j];
                dp[i][z[i - 1] + j] %= 998244353;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n + 1; i++) {
        ans += dp[i][s];
    }
    cout << ans % 998244353 << endl;
}

Measured memory_bytes: 73744
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long int a[1000000];
    long long int c;
    cin >> c;
    a[0] = 7 % c;
    long long int i;
    
    for(i=1;i<1000000;i++){
        a[i] = (((a[i-1] * 10) % c) + (7 % c)) % c;
    }
    
    //for(i=0;i<100;i++){
        //cout << a[i] << endl;
    //}
    
    int flag=0;
    long long num = -1;
    for(i=0;i<1000000;i++){
        if(a[i] == 0){
            flag = 1;
            num = i;
            break;
        }
    }
    
    
    if(flag == 0){
        cout << -1 << endl;
    }else{
        cout << num + 1<< endl;
    }
}

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

const ll MAX = 200000 + 1;

int main() {
  ll N;
  ll ans = MAX;
  ll index = 1;
  ll destroy = 0;
  cin >> N;
  vector<ll> a(N);

  for (int i = 0; i < N; i++) cin >> a[i];

  for (ll i = 1; i <= N; i++) {
    if (index != a[i - 1]) {
      destroy++;
    }
    else if (index == a[i - 1]){
      index++;
    }
  }

  if (destroy == N) {
    cout << -1 << endl;
  }
  else {
    cout << destroy << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#pragma GCC optimize ("-O3")

using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;  /* pi */

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n;
	cin >> n;
	if (n>=30)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


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

int main()
{
	long long N, Y;
	cin >> N >> Y;

	long long ansa = -1;
	long long ansb = -1;
	long long ansc = -1;
	for( long long a = 0; a <= 2000; a++ ) {
		for( long long b = 0; b <= 2000; b++ ) {
			long long cy = Y - (a * 10000 + b * 5000);
			long long c = N - (a + b);
			if( cy < 0 || c < 0 ) continue;
			if( cy == c * 1000 ) {
				ansa = a;
				ansb = b;
				ansc = c;
				break;
			}
		}
	}

	cout << ansa << " " << ansb << " " << ansc << endl;
}


Measured memory_bytes: 3628
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200005;
const int MOD =1000000007;

signed main(){
  int n;
  string s;
  cin>>n>>s;

 
 
  bool t=true;int x=0;
 string sx;
   vector<string> ss;
  for(int i=2*n-1;i>=0;i--){

    if(x==0){
      if(s[i]=='a'){
        t=false;
        string ns;
        ss.push_back(ns);
        ss[ss.size()-1].push_back(s[i]);
        x++;
        }
      else{
        if(t)sx.push_back(s[i]);
        x--;
      } 
   
      continue;
    }
    if(x>0)ss[ss.size()-1].push_back(s[i]);
    if(x<0&&t)sx.push_back(s[i]);
      if(s[i]=='a')x++;
      else x--;
  }
     
reverse(sx.begin(),sx.end());
for(int i=0;i<ss.size();i++)reverse(ss[i].begin(),ss[i].end());

  string ans[ss.size()],ans2=sx;

  for(int ii=0;ii<ss.size();ii++){
    ans[ii]=ss[ii];
    while(!ss[ii].empty()){
    int i=0;
    while(ss[ii][i]=='b')i++;
    ss[ii].erase(ss[ii].begin()+i);
    ss[ii].erase(ss[ii].begin());
    ans[ii]=max(ans[ii],ss[ii]);
  }
  }
  
string sxx[sx.size()];
bool b[sx.size()]={};
for(int i=sx.size()-1;i>=0;i--){
  if(sx[i]=='b'){
   if(i!=sx.size()-1) sxx[i]=sxx[i+1];
  
    continue;
  }
  for(int j=sx.size()-1;j>i;j--)if(sx[j]=='b'&&b[j]==false){
    b[j]=true;
    sxx[i]="ab"+sxx[j];
    break;
  }

  ans2=max(ans2,sxx[i]);
}
  
for(int i=0;i<ss.size();i++){
  ans2=max(ans2,ans[i]+ans2);
}
cout<<ans2<<endl;


}

Measured memory_bytes: 11048
import itertools
def main():
    n, m = list(map(int, input().split()))
    A = [[] for _ in range(n)]
    for i in range(m):
        p, y = list(map(int, input().split()))
        A[p - 1].append([i, y])
    for i, a in enumerate(A):
        a.sort(key = lambda x: x[1])
        for j in range(len(a)):
            a[j] = [a[j][0], '{:06}{:06}'.format(i + 1, j + 1)]
    A = list(itertools.chain.from_iterable(A))
    A.sort(key = lambda x: x[0])
    for a in A:
        print(a[1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 41244
loop do
  h,w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  mozi1 = String.new
  mozi2 = String.new
  w.times do |i|
    mozi1 = mozi1 + '#' if i%2==0
    mozi1 = mozi1 + '.' if i%2!=0
    mozi2 = mozi2 + '.' if i%2==0
    mozi2 = mozi2 + '#' if i%2!=0
  end
  h.times do |i|
    puts "#{mozi1}" if i%2==0
    puts "#{mozi2}" if i%2!=0
  end
    puts ""
end


Measured memory_bytes: 6948
A = list(map(int,input().split()))
A.sort()
B = []
for i in A:
    B.append(i%2)

ans = 0

if B.count(1) == 1:
    for i in range(3):
        if B[i] == 0:
            A[i] += 1
    ans += 1
elif B.count(0) == 1:
    for i in range(3):
        if B[i] == 1:
            A[i] += 1
    ans += 1

ans += A[2] - A[1]
A[0] += A[2] - A[1]
ans += (A[2]-A[0])//2

print(ans)


Measured memory_bytes: 3064
# include <bits/stdc++.h>
//# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define fors(i, s) for (int i = 0; s[i]; i++)
# define in freopen("input.txt", "r", stdin)
# define out freopen("output.txt", "w", stdout)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define mkp make_pair
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;
const ll mod = 1e17 + 7;
const int N = 5e2 + 7;


int main()
{
	speed;
	char c;
	cin >> c;
	c++;
	cout << c;
	time;
}


Measured memory_bytes: 764
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	long long ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	long long  num;
	pass = 10;
	cin >> num;
	if (num % 2 == 0) {
		while (num >= pass) {
			ans += num / pass;
			pass *= 5;
		}
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

struct edge {
	ll to, cost, time;
	bool operator<(const edge &e) {
		return (*this).time < e.time;
	}
};

constexpr ll MAXC = 50 * 52;
ll d[50][MAXC + 1];
typedef pair<ll, P> node;

int main() {
	IOS();
	int k;
	string s;
	cin >> k >> s;
	if(s.size() > k) {
		cout << s.substr(0, k) << "..." << endl;
	}else {
		dump(s);
	}
}


Measured memory_bytes: 3608
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc162/tasks/abc162_e

//参考：
//https://kmjp.hatenablog.jp/entry/2020/04/12/1000

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

LL N,K;

ModInt<mod> ans = 0;

void solve(){
	//dp[i]:
	//gcd(N個の要素)=iの倍数かつ、2i,3i,..,miの倍数ではない
	//となるような数列の数を各iについて求めれば良い
	vector<ModInt<mod>> dp(K+1,0);
	//Kの倍数から逆に見ていく
	//O(K/i)をi=K~1まで繰り返す
	//ΣK/i = KΣ1/i <= KlogK
	for(int i=K;i>=1;i--){
		//1~Kのうち、iの倍数となるような数はfloor(K/i)個
		//このfloor(K/i)個はiの倍数、2iの倍数、3iの倍数....を含む
		dp[i] = ModInt<mod>(K/i).pow(N);
		//j = 2i,3i,4i,5i....とループ
		//floor(K/i)個のうちからgcd(N個の要素)=jの倍数になるものを取り除く
		//O(K/i)
		for(int j=i*2;j<=K;j+=i) dp[i] -= dp[j];
		//この時点でdp[i]に
		//gcd(N個の要素)=ちょうどi　となるような数列の数
		//が格納されている
		ans += ModInt<mod>(i)*dp[i];
	}
}

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

    solve();

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

Measured memory_bytes: 3152
h, w, k = map(int,input().split())
import copy

def generate_n_bit(n):
    bins= []
    for i in range(2**n):
        bins.append(list(str(format(i,'b').zfill(n))))
    
    return bins

h_all = generate_n_bit(h)
w_all = generate_n_bit(w)
ans = 0
n = 23
extra = 1
  
for i in range(1,n+1): 
    extra = extra * i 

    
field = [list(input()) for i in range(h)]

for i_l in h_all:
    for j_l in w_all:
        c  = 0 
        fields = copy.deepcopy(field)
       
        
        for i_i, i in enumerate(i_l):
            for j_i, j in enumerate(j_l):
                n = 23
                extra = 1
  
                for xx in range(1,n+1): 
                    extra = extra * xx 
                if i == '1':
                    for a in range(w):
                        fields[i_i][a] = 'r'
                    
                if j == '1':
                    for b in range(h):
                
                        fields[b][j_i] = 'r'
                        
        
        for q in range(h):
            for e in range(w):
                if fields[q][e] == '#':
                    c += 1
       
        if c == k:
            ans += 1
        
n = 23
fact = 1
  
for i in range(1,n+1): 
    fact = fact * i         
                
print(ans)


Measured memory_bytes: 9380
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    print(len(list(filter(lambda i: i >= K, h))))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12504
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
  char buf1[400001];
  gets(buf1);
  gets(buf1 + 200000);
  int ans = 0;
  int i = 200000;
  do if(buf1[i - 200000] != buf1[i]) ++ans; while(buf1[++i]);
  printf("%d", ans);
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeull(long long n){
		if(n<10)
			putchar(n+'0');
		else{
			writeull(n/10);
			putchar(n%10+'0');
		}
	}
	auto generate(string str, int n){
		map<pair<string, string>, int> result;
		for(int s=0; s<(1<<n); ++s){
			string r;
			string b;
			for(int i=0; i<n; ++i)
				if(s&(1<<i))
					r.push_back(str.at(i));
				else
					b.push_back(str.at(i));
			reverse(b.begin(), b.end());
			++result[make_pair(r, b)];
		}
		return result;
	}
	void run(){
		int n=readu();
		string s;
		cin>>s;
		string left_str(s.substr(0, n));
		auto left(generate(left_str, n));
		string right_str(s.substr(n));
		reverse(right_str.begin(), right_str.end());
		auto right(generate(right_str, n));
		long long result=0;
		for(auto cur: left){
			int cur_cnt=cur.second;
			string r=cur.first.first;
			string b=cur.first.second;
			result+=(long long)cur_cnt*right[make_pair(r, b)];
		}
		writeull(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[10];

double dist(vector<ll> v) {
    double ret = 0;
    REP(i, v.size() - 1) {

        ret += sqrt(pow(A[v[i]].first - A[v[i + 1]].first, 2) + pow(A[v[i]].second - A[v[i + 1]].second, 2));
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }
    vector<ll> v;
    REP(i, N) {
        v.push_back(i);
    }

    double sum = 0;
    ll num = 0;
    do {
        sum += dist(v);
        num++;
    } while (next_permutation(v.begin(), v.end()));

    cout << OF64 << sum / num << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rip(a,b,c) for(int (a)=(c);(a)<(b);(a)++)
const long long INF= 1LL << 60;
int main(){
    //入力始まり
    string S;
    cin >> S;
    //入力終わり


    bool flag;
    flag=(S=="AAA")||(S=="BBB");
    if(flag){
        cout << "No" << endl;
        }else{
        cout << "Yes" << endl;
    }

    
}



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

int main(){
  string s;
  cin>>s;
  
  ll sum=0;
  rep(i,s.size())sum+=s[i]-'0';
  
 if(stoll(s)%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
use std::io;

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn main() {
    let hoge = get_line();
    let fuga = get_line();
    let n: usize = hoge.trim().parse().unwrap();
    let a: Vec<i64> = fuga.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    let X: i64 = a.iter().sum();
    let mut x = 0;
    let mut result = std::i64::MAX;
    for i in 0..n-1 {
        x += a[i];
        result = if (result > (X - 2 * x).abs()) {
            (X - 2 * x).abs()
        } else {
            result
        };
    }
    println!("{}", result);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;

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

    cout << ((n%2) ? 1+n/2 : n/2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s;
 	cin>>s;
 	ll n=s.size();
 	for(ll i=0;i<n;i++)
 	{
 		cout<<"x";
 	}cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import copy
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
copy_A = copy.copy(A)
copy_A.sort(reverse=True)
max_a, sec_a = copy_A[0], copy_A[1]
for i in range(N):
  if A[i] == max_a:
    print(sec_a)
  else:
    print(max_a)

Measured memory_bytes: 59056
ans = 0
def dfs(x, a, b, c):
    global ans
    if x > N : return
    if a & b & c: ans += 1
    dfs(10*x+3, 1, b, c)
    dfs(10*x+5, a, 1, c)
    dfs(10*x+7, a, b, 1)

N = int(input())

dfs(0, 0, 0, 0)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<utility>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

int main(){
	int n;
	cin>>n;
	pll x[n];
	rep(i,n){
		cin>>x[i].first;
		x[i].second=i;
	}
	sort(x,x+n);
	int b[n];
	rep(i,n){
		if(i==0)b[x[i].second]=x[(n+1)/2].first;
		else{
			if(i<(n+1)/2)b[x[i].second]=x[(n+1)/2].first;
			else b[x[i].second]=x[(n-1)/2].first;
		}
	}
	rep(i,n){
		cout<<b[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N, T,an=10000;
	cin >> N >> T;
	rep(i, N) {
		ll c, t;
		cin >> c >> t;
		if (t <= T) {
			an = min(an, c);
		}
	}
	if (an == 10000) {
		cout << "TLE" << endl;
	}
	else {
		cout << an << endl;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)

using namespace std;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int tam = 10000010;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, a, prev = 0, res = 0;
	cin>>n;
	while(n--)
	{
		cin>>a;
		res += (prev < a? a - prev: 0);
		prev = a;
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

struct node {
	bool done;
	vi to;
	int id, from;
	int pre, low;
};

class lowlink {
	int ord;
public:
	vector<node> nodes;
	vector<P> bridges;
	set<int> arts; //articulation point
	lowlink(vector<node> A) {
		ord = 0;
		nodes = A;
	}
	void dfs(int a, int root) {
		nodes[a].done = 1;
		nodes[a].pre = nodes[a].low = ord;
		ord++;
		int cnt = 0;
		Loop(i, nodes[a].to.size()) {
			int b = nodes[a].to[i];
			if (b == nodes[a].from) continue;
			if (!nodes[b].done) {
				nodes[b].from = a;
				dfs(b, root);
				nodes[a].low = min(nodes[a].low, nodes[b].low);
				if (nodes[a].pre <= nodes[b].low) cnt++;
				if (nodes[a].pre < nodes[b].low) bridges.push_back({ a,b });
			}
			else {
				nodes[a].low = min(nodes[a].low, nodes[b].pre);
			}
		}
		if (cnt > (a == root ? 1 : 0)) arts.insert(a);
		return;
	}
	void find_bridges_and_arts() {
		Loop(i, nodes.size()) {
			if (!nodes[i].done) dfs(i, i);
		}
		Loop(i, bridges.size()) {
			if (bridges[i].first > bridges[i].second) swap(bridges[i].first, bridges[i].second);
		}
		sort(bridges.begin(), bridges.end());
	}
};

int main() {
	int v, e; cin >> v >> e;
	vector<node> nodes(v);
	Loop(i, v) nodes[i] = { 0,{}, i,-1,-1,-1 };
	Loop(i, e) {
		int s, t;
		cin >> s >> t;
		nodes[s].to.push_back(t);
		nodes[t].to.push_back(s);
	}
	lowlink lk(nodes);
	lk.find_bridges_and_arts();
	auto itr = lk.arts.begin();
	Loop(i, lk.arts.size()) {
		cout << *itr << endl;
		itr++;
	}
	return 0;
}

Measured memory_bytes: 5896
ans=0

def dfs(pos, open):
    if open.count(False)==len(arr):
        global ans
        ans+=1

    for i in range(2,N+1):
        if c[pos][i] and open[i]:
            open_next=open.copy()
            open_next[i]=False
            dfs(i, open_next)

N,M=map(int,input().split())
c=[[False for j in range(N+1)] for i in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    c[a][b]=c[b][a]=True

arr=[True for i in range(N+1)]
arr[0]=arr[1]=False
dfs(1, arr)
print(ans)


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

int main(){
  int i,min,N;
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;

  char str[N];
  for(int i = 0;i < N;++i){
    cin >> str[i];
  }


  int f[N],b[N];
  for(int i = 0;i < N;i++){
    f[i] = 0;
    b[i] = 0;
  }
  scanf(" %c", &str[N]);

  for(int i = 1;i < N;i++){
    if(str[i] == 'E'){
      b[0]++;
    }
  }

  for(int i = 1;i < N;i++){
    if(str[(i-1)] == 'W'){
      f[i] = f[i-1] + 1;
    }
    else{
      f[i] = f[i-1];
    }

    if(str[i] == 'E'){
      b[i] = b[i-1] - 1;
    }
    else{
      b[i] = b[i-1];
    }
  }
  min = 100000000;
  for(int i = 0;i < N;i++){
    if(min > f[i] + b[i]){
      min = f[i] + b[i];
    }
  }
  cout << min << "\n";
  return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main()
{
  int i,sum,a;
  char n[200000];
  
  scanf("%s", &n);
  i=0;
  sum=0;
  while(1) {
  if (n[i] != '\0'){
    a=n[i]-'0';
    //printf("a=");
    //printf("%d\n",a);
    
    sum=sum+a;
    //printf("SUM=");
  	//printf("%d\n",sum);
    i++;
  } else {
    break;
  }
  }
   //printf("%d",sum);
  if (sum % 9 == 0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(void)
{
    int n, inp;
    
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> inp;
        a[inp - 1] = i + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
void printDivisibleNumber(int arr[], int n){
   unordered_set<int> s;
   int maxElement = INT_MIN;
   for (int i = 0; i < n; i++) {
      s.insert(arr[i]);
      maxElement = max(maxElement, arr[i]);
   }
   unordered_set<int> res;
   for (int i = 0; i < n; i++) {
      if (arr[i] != 0) {
         for (int j = arr[i] * 2; j <= maxElement; j += arr[i]) {
            if (s.find(j) != s.end())
               res.insert(j);
            }
         }
      }
   unordered_map<int, int> mp;
   for (int i = 0; i <n; i++)
      mp[arr[i]]++;
   unordered_map<int, int>::iterator it;
   vector<int> ans;
   for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 2) {
         if (res.find(it->first) == res.end()) {
            int val = it->second;
            while (val--)
               ans.push_back(it->first);
         }
      }
      if (res.find(it->first) != res.end()) {
         int val = it->second;
         while (val--)
            ans.push_back(it->first);
      }
   }
   cout<<n-ans.size();
  // for (auto x : ans)
     // cout<<x<<"\t";
}
int main(){
    int n;
    cin>>n;
    int arr[n];
   for(int i=0;i<n;i++)cin>>arr[i];
   printDivisibleNumber(arr, n);
   return 0;
}

Measured memory_bytes: 30676
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

pair<int,int> ab[100001];

int main(){
  long long N,K;
  cin>>N>>K;
  for(int i=0;i<N;++i){
    cin>>ab[i].first>>ab[i].second;
  }
  
  sort(ab,ab+N);

  int num=0;
  for(int i=0;K>0;++i){
    num = ab[i].first;
    K-=ab[i].second;
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 1024
s=list(input())
k=int(input())
cnt=0
ans=0
flag=0
for i in s:
    if i =="1":
        cnt+=1
        continue
    else:
        if cnt<k:
            print(i)
        else:
            print("1")
        flag+=1
        break
if flag==0:
    print("1")

Measured memory_bytes: 38384
#include<iostream>

using namespace std;

#define MAX 10000005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": " ;
    cout << "parent = " << T[u].p << ", " ;
    cout << "depth = " << D[u] << ", " ;
    
    if(T[u].p == NIL) {
        
        cout << "root, ";
        
    } else if(T[u].l == NIL) {
        
        cout << "leaf, ";
        
    } else {
        
        cout << "internal node, ";
        
    }
    
    cout << "[";
    
    for(i = 0, c = T[u].l ; c != NIL; i ++ , c = T[c].r){
        
        if (i) {
            
            cout << ", ";
            
        }
        
        cout << c;
        
        
        
    }
    
    cout << "]" << endl;
    
}

int rec(int u, int p) {
    
    D[u] = p;
    
    if(T[u].r != NIL) {
        
        rec(T[u].r, p);
        
    }
    
    if(T[u].l != NIL) {
        
        rec(T[u].l, p + 1);
        
    }
    
}

int main() {
    
    int i,j,d,v,c,l,r;
    
    cin >> n;
    
    for (i = 0; i < n; i ++) {
        
        T[i].p = T[i].l = T[i].r = NIL;
        
    }
    
    for (i = 0; i < n; i ++) {
        
        cin >> v >> d;
        
        for (j = 0; j < d; j ++) {
            
            cin >> c;
            
            if (j == 0) {
                
                T[v].l = c;
                
            } else {
                
                T[l].r = c;
                
            }
            
            l = c;
            
            T[c].p = v;
            
        }
        
    }
    
    for (i = 0; i < n; i ++) {
        
        if (T[i].p == NIL) {
            
            r = i;
            
        }
        
    }
    
    rec(r,0);
    
    for (i = 0; i < n; i ++) {
        
        print(i);
        
    }
    
    return 0;
    
}


Measured memory_bytes: 7692
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,i,j,m,cnt=0;
    cin>>n;
    int l[n];
    for(i=0;i<n;i++) cin >> l[i];
    sort(l,l+n,greater<>());
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            for(m=j+1;m<n;m++){
                if(l[i]<l[j]+l[m]) cnt++;
                else break;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
# ABC068 B - Break Number
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def div2(n):
    cnt = 0
    while n>0:
        if n%2 == 0:
            cnt += 1
        n = n//2
    return cnt

N = ni()
ans = 0
ans2 = 0

for i in range(1,N+1):
    t = div2(i)
    if t > ans:
        ans = t
        ans2 = i

if N == 1:
    ans2 = 1
print(ans2)


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

using namespace std;

int n,m,cnt,sum = 1000001,t,f;
int a[102];
pair <int, string> p1[10001];
int main (){	
	cin >> n >> m >> t;
	f = m + t - n;
	if (f <= 0){
		f = 0;
	}
	cout << f;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int a,b,cards[4][13],c,d,kz;
	char mk,z;
	
	c=0;
	d=0;
	
	for(a=0;a<4;a++){
		for(b=0;b<13;b++){
			cards[a][b]=0;
		}
	}
	
	scanf("%d",&a);
	
	for(b=1;b<=a;b++){
		scanf("%c %c %d",&z,&mk,&kz);
		switch(mk){
		case 'S':cards[0][kz-1]=100; break;
		case 'H':cards[1][kz-1]=100; break;
		case 'C':cards[2][kz-1]=100; break;
		case 'D':cards[3][kz-1]=100;
		}
	}
	
	for(a=0;a<4;a++){
		for(b=0;b<13;b++){
			if(cards[a][b]==0){
				if(a==0){
					printf("S %d\n",b+1);
				}
				if(a==1){
					printf("H %d\n",b+1);
				}
				if(a==2){
					printf("C %d\n",b+1);
				}
				if(a==3){
					printf("D %d\n",b+1);
				}
			}
		}
	}
		
	return 0;
}

Measured memory_bytes: 596
def make_hikaku(num, n):
    org = num
    retval = []
    for i in range(n):
        retval.append(org)
        if org == 0:
            org = 1
        elif org == 1:
            org = 0
    return retval

def hikaku(a, b):
    if a == b:
        return 0
    else:
        return 1
    

def main(s):
    n = len(s)
    hikaku_a = make_hikaku(0, n)
    hikaku_b = make_hikaku(1, n)
    s_bit = 0
    s_l = list(map(int, list(s)))
    s_a = []
    s_b = []
    for i in range(n):
        s_a.append(hikaku(s_l[i], hikaku_a[i]))
        s_b.append(hikaku(s_l[i], hikaku_b[i]))
    
    print(min(sum(s_a), sum(s_b)))
    
if __name__ == '__main__':
    try:
        s = input().strip()
        main(s)
    except EOFError:
        pass


Measured memory_bytes: 8292
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 3010;
ll dp[N][N];
ll seq[N];
int n;

int main() {
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        cin >> seq[i];
        if(n % 2) {
            dp[i][i] = seq[i];
        } else dp[i][i] = -seq[i]; 
    }
    for(int len = 1; len < n; len ++) {
        for(int i = 1; i + len <= n; i ++) {
            int j = i + len;
            if((n - len - 1) % 2 == 0) {
                dp[i][j] = max(dp[i][j-1] + seq[j], dp[i+1][j] + seq[i]);
            } else {
                dp[i][j] = min(dp[i][j-1] - seq[j], dp[i+1][j] - seq[i]);
            }
        }
    }
    cout << dp[1][n] << endl;
    return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,C;cin>>n>>C;
  ll s[n],t[n],c[n];
  vector<double>tukeru[31],kesu[31];
  vector<pair<ll,ll>>v[31];
  for(ll i=0;i<n;i++){
    cin>>s[i]>>t[i]>>c[i];
    v[c[i]].push_back(make_pair(s[i],t[i]));
  }
  for(ll i=1;i<31;i++){
    if(v[i].size()==0)continue;
    sort(v[i].begin(),v[i].end());
    tukeru[i].push_back(v[i][0].first-0.5);
    kesu[i].push_back(v[i][0].second);
    for(ll j=1;j<v[i].size();j++){
      ll f=v[i][j].first,s=v[i][j].second;
      if(f==kesu[i].back()){
        kesu[i].pop_back();
      }
      else{
        //kesu[i][kesu[i].size()-1]++;
        tukeru[i].push_back(f-0.5);
      }
      kesu[i].push_back(s);
    }
    //kesu[i][kesu[i].size()-1]++;
  }
  //for(ll i=1;i<=C;i++)for(ll j=0;j<kesu[i].size();j++)cout<<tukeru[i][j]<<endl;
  ll now=0,ans=0;
  ll ban[31];
  //cout<<tukeru[2][0];return 0;
  fill(ban,ban+31,0);
  for(double i=0;i<=100001;i+=0.5){
    for(ll j=1;j<31;j++){
      if(v[j].size()==0)continue;
      if(tukeru[j][ban[j]]==i){
        now++; 
      }
      if(kesu[j][ban[j]]==i){
        now--;
        ban[j]++;
      }
      //cout<<j<<" "<<ban[j]<<endl;
    }
   //if(i<=100)cout<<now<<endl;
      ans=max(now,ans);
  }
  ll d[100010];
  fill(d,d+100010,0);
  for(ll i=0;i<n;i++){
    
    d[s[i]]++;
    d[t[i]+1]--;
  }
  ll noww=0,anss=0;
  for(ll i=1;i<=100000;i++){
    noww+=d[i];
    anss=max(anss,noww);
  }
  cout<<min(ans,anss);
}

Measured memory_bytes: 7424
def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    N = I()
    A = LI()
    ans = 0
    while(True):
        cur = 0
        for i in range(N):
            cur += A[i]//N
        for i in range(N):
            A[i] = A[i]%N + cur-A[i]//N
        ans += cur
        if cur==0:
            break
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 3572