akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }

int n;
int a[100010];

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
  }
  int s = -1;
  int pr = -1;
  Mod ans = 1;
  REP( i , n ){
    if( pr == a[i] - 1 ){
      ans *= ( i - s );
      s++;
    } else {
      pr = pr + 2;
    }
  }
  while( s < n-1 ){
    ans *= n - 1 - s;
    s++;
  }
  cout << ans.n << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
#define fr first
#define sc second
const int dy[] = { 0, -1, 0, 1}, dx[] = { 1, 0, -1, 0}; //右上左下
typedef pair< int , int > Pt;
int m,n,mas[1005][1005],hw = 1000;
Pt buff[1000001],max_cost[1005][1005];
bool prime[1000001];
void Prime_set(){
  prime[1] = true;
  for(int i = 2 ; i * i < 1000001 ; i++ ){
    if(!prime[i]) for(int j = i + i ; j < 1000001 ; j += i ) prime[j] = true;
  }
}
bool isover(int y,int x){
  return x < 0 || !mas[y][x] || mas[y][x] > m;
}
void make_map(){
  fill_n(*mas,1005*1005,0);
  int cnt = 1,muki = 3;
  Pt now = Pt( hw / 2,  hw / 2),St;
  while(cnt <= 1000000){
    buff[cnt] = Pt(now.fr,now.sc);
    mas[now.fr][now.sc] = cnt++;
    Pt magaru = Pt( now.fr + dy[(muki + 1) % 4], now.sc + dx[(muki + 1) % 4]);
    if(!mas[magaru.fr][magaru.sc]) muki = (muki + 1) % 4, now = magaru;
    else now.fr += dy[muki], now.sc += dx[muki];
  }
}
Pt dfs(Pt now){
  if(max_cost[now.fr][now.sc] != Pt(-1,-1)) return max_cost[now.fr][now.sc];
  Pt ret = Pt();
  for(int i = 0 ; i < 3 ; i++ ){
    int nx = now.sc + dx[i];
    if(!isover(now.fr+1,nx)) ret = max(ret,dfs(Pt(now.fr+1,nx)));
  }
  if(!ret.sc && !prime[mas[now.fr][now.sc]]) ret.sc = mas[now.fr][now.sc];
  return max_cost[now.fr][now.sc] = Pt(ret.fr+!prime[mas[now.fr][now.sc]],ret.sc);
}
int main(){
  Prime_set();
  make_map();
  while(cin >> m >> n , m){
    fill_n(*max_cost,1005*1005,Pt(-1,-1));
    Pt ans = dfs(buff[n]);
    cout << ans.fr << " " << ans.sc << endl;
  }
}

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

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

    multiset<int> pi;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        pi.insert(p);
    }

    int sum = 0;
    int i = 0;
    for (int p: pi) {
        if (i >= k) {
            break;
        }
        sum += p;
        i++;
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 4e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, K; cin >> n >> K;
    vector<ll> X(n), Y(n);
    rep(i, n) cin >> X[i] >> Y[i];
    ll ans = linf;
    rep(a, n) rep(b, a+1, n) rep(c, n) rep(d, c+1, n) {
        ll cnt = 0;
        ll x1 = min(X[a], X[b]);
        ll x2 = max(X[a], X[b]);
        ll y1 = min(Y[c], Y[d]);
        ll y2 = max(Y[c], Y[d]);
        rep(k, n) {
            ll x = X[k], y = Y[k];
            if (x1 <= x && x <= x2 && y1 <= y && y <= y2) {
                ++cnt;
            }
        }
        // cout << x1 << " " << x2 << " " << y1 << " " << y2 << endl;
        // cout << i << " " << j << " " << cnt << " " << (y2-y1) * (x2-x1) << endl;
        if (cnt >= K) {
            chmin(ans, (y2-y1) * (x2-x1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    S = input()
    T = input()
    for i in range(len(S)):
        if S == T:
            print('Yes')
            return
        T = T[1:] + T[0]
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
s = input()
K = int(input())

len_s = len(s)

sub_set = set()
for k in range(1,6):
    for i in range(len_s-k+1):
        sub_set.add(s[i:i+k])
        
sub_list = list(sub_set)
sub_list.sort()
print(sub_list[K-1])
        
        

Measured memory_bytes: 4464
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

int main(){
	std::vector<int> v;
	for(int i = 0; i < 3; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	std::sort(v.begin(), v.end());
	/*
	 * for(int i = 0; i < 3; i++){
		printf("%d\n", v[i]);
	}//*/
	int cnt = (v[2] - v[1])%2 + (v[2] - v[0])%2;
	int ans = (v[2]-v[1])/2 + (v[2]-v[0])/2;
	if(cnt == 0){
		printf("%d\n", ans);
	}else if(cnt == 1){
		printf("%d\n", ans + 2);
	}else{
		printf("%d\n", ans + 1);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__llong32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong N, K, A[MAX_N + 2], res;
llong diff[MAX_N];

vector<llong> pl_sections;
int main(int argc, char **argv) {
    cin >> N >> K;
    for(llong i = 0; i < N; ++i)
        cin >> A[i];


    multiset<llong> st;
    for(llong i = 0; i <= K; ++i) {
        st.insert(A[i]);
    }

    llong sub1 = 0;
    for(llong i = 0; i <= N - (K + 1); ++i) {
        auto last_it = st.end();    last_it--;
        if(*st.begin() == A[i] && *last_it == A[i + K])
            sub1++;
        
        st.erase(A[i]);
        if(i < N - (K + 1))
            st.insert(A[i + K + 1]);
    }

    for(llong i = 0; i < N - 1; ++i)
        diff[i] = A[i + 1] - A[i];
    
    llong len = 0;
    for(llong i = 0; i < N - 1; ++i) {
        if(diff[i] >= 0) {
            len++;
        } else {
            if(len > 0)
                pl_sections.push_back(len + 1);
            len = 0;
        }
    }
    if(len > 0) pl_sections.push_back(len + 1);

    llong sct_cnt = 0;
    for(llong i = 0; i < pl_sections.size(); ++i) {
        if(pl_sections[i] >= K) {
            sct_cnt++;
        }
    }
    
    res = N - K + 1 - sub1;
    if(sct_cnt > 1)
        res -= sct_cnt - 1;
    cout << res << endl;

    res = max(res, 0ll);
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    int N;cin>>N;
    vector<ll> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    sort(all(S));
    
    if(N%2==0){
        ll ans=0;
        for(int i=0;i<N;i++){
            if(i==N/2-1) ans-=S[i];
            if(i==N/2) ans+=S[i];
            if(i<N/2-1) ans-=2*S[i];
            if(i>N/2) ans+=2*S[i];
        }
        
        cout<<ans<<endl;
    }else{
        ll ans1=0,ans2=0;
        for(int i=0;i<N;i++){
            if(i==N/2-1||i==N/2) ans1-=S[i];
            else if(i<N/2) ans1-=2*S[i];
            else ans1+=2*S[i];
        }
        for(int i=0;i<N;i++){
            if(i==N/2||i==N/2+1) ans2+=S[i];
            else if(i>N/2) ans2+=2*S[i];
            else ans2-=2*S[i];
        }
        
        cout<<max(ans1,ans2)<<endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	int sum = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'p')
			sum++;
	}
	cout << (s.size() / 2) - sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LL long long
#define PB push_back
#define INF 1000 * 1000 * 1000
#define X first
#define Y second
#define x first
#define y second
#define pt pair<int , int> 
using namespace std;
const int mod = 998244353;
int n , a , b;
int t[1005];

int main()
{
	ios_base::sync_with_stdio(0);
	int ans = 0;
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++)
	{
		cin >> t[i];
		ans += t[i] < a || t[i] >= b;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s, t;
    cin>>s>>t;
    cout<<t+s<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    static final long MOD = 1_000_000_007;
    static long inv(long a, long m) {
        long r1 = a, r0 = m;
        long x1 = 1, x0 = 0;
        while (r1 != 0) {
            long q = r0 / r1;
            long v = r1;
            r1 = r0 - q * r1;
            r0 = v;
            long w = x1;
            x1 = x0 - q * x1;
            x0 = w;
        }
        if (x0 < 0) {
            x0 += m;
        }
        return x0;
    }
    static long f(long x, long y) {
        if ((x + y) % 3 != 0) return 0;
        long n = (x + y) / 3;
        long k = (2 * x - y) / 3;
        if (k < 0 || k > n) return 0;
        long ret = 1;
        for (long i = 0; i < k; i++) {
            ret = ret * (n - i) % MOD * inv(i + 1, MOD) % MOD;
        }
        return ret;
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        System.out.println(f(x,y));
    }
}


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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a <= b) && (b <= c)) cout << a << " " << b << " " << c << endl;
    else if ((a <= c) && (c <= b)) cout << a << " " << c << " " << b << endl;
    else if ((b <= a) && (a <= c)) cout << b << " " << a << " " << c << endl;
    else if ((b <= c) && (c <= a)) cout << b << " " << c << " " << a << endl;
    else if ((c <= a) && (a <= b)) cout << c << " " << a << " " << b << endl;
    else if ((c <= b) && (b <= a)) cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3108
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

void play(int n , int c){
    int mas[1005]={0};
    int lock[1005] = {0};
    int cur = 0;
    int left = 0;
    int maxx = -1;
    int minn = -1;
    int step = 0;
    
    int a,b;
    for(int i = 0 ; i < c ; i++){
        cin >> a >> b;
        if(lock[a] < b){
            lock[a] = b;
        }
    }
    
    //cout << cur << endl;
    
    while(cur < n+1){
        //cout << cur << endl;
        if(lock[cur] != 0 && lock[cur] > maxx) maxx = lock[cur];
        if(lock[cur] != 0 && minn == -1) minn = cur;
        
        if(cur == maxx){
            while(cur > minn){
                
                cur--;
                lock[cur] = 0;
                //cout << "minn " << minn << endl;
                //cout << cur << endl;
                step++;
            }
            maxx = -1;
            minn = -1;
        }
        cur++;
        step++;
    }

    cout << step << endl;
}
main(){
    int a,b;
    
    cin >> a >> b;
    
    play(a,b);
    
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>

using namespace std;

struct info {
	int Cx, Cy, H;
};

struct pos {
	int x, y, h;
};

int N;
stack<info> center;
vector<pos> survey;

int calc_h(info i, int x, int y) {
	return max(i.H - abs(x - i.Cx) - abs(y - i.Cy), 0);
}

int main() {
	pos tmp;
	cin >> N;
	for (int i = 0; i < N; i++) {

		cin >> tmp.x >> tmp.y >> tmp.h;
		survey.push_back(tmp);
	}

	sort(survey.begin(), survey.end(), [](const pos a, const pos b) { return a.h > b.h; });

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			center.push({ i,j,0 });
		}
	}

	info sample;
	while (center.size() > 0) {
		sample = center.top(); center.pop();
		sample.H = survey[0].h + abs(survey[0].x - sample.Cx) + abs(survey[0].y - sample.Cy);
		int i;
		for (i = 1; i < N; i++) {
			if (survey[i].h != calc_h(sample, survey[i].x, survey[i].y)) break;
		}
		if (i == N) break;
	}

	cout << sample.Cx << " " << sample.Cy << " " << sample.H << endl;

	return 0;
}

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

int n, m;

int main()
{
  std::cin >> n >> m;
  std::vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i)
  {
    std::cin >> a[i] >> b[i];
  }

  std::vector<int> road(n);
  for (int i = 0; i < n; ++i) {
	road[i] = 0;
  }

  for (int i = 0; i < m; ++i) {
	road[a[i]-1] += 1;
	road[b[i]-1] += 1;
  }

  for (int i = 0; i < n; ++i) {
	std::cout << road[i] << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

ll par[100000 + 10];
ll ran[100000 + 10];

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

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

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

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

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


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

	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i, n) {
		int t;
		cin >> t;
		p[i] = t - 1;
	}
	vector<pair<int, int>> xy(m);
	rep(i, m){
		int x, y;
		cin >> x >> y;
		xy[i].first = x - 1;
		xy[i].second = y - 1;
	}

	// Union-FInd木つかえないか？

	// 繋がりのあるマスとマスのグループを作る
	init(n);

	rep(i, m) {
		//unite(xy[i].first, xy[i].second);
		unite(xy[i].first,xy[i].second);
	}

	int ans = 0;

	rep(i, n) {
		if (same(i, p[i])) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2944
//def
#include <iostream>

#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;

#define rep(i,q) for(int i = 0; (q) > i; i++)
#define anyfill(n,s) setw(n) << setfill(s)
#define pb push_back
#define MOD 1000000007

int main(){
  int a,b,c,d,e;cin>>a>>b>>c>>d>>e;
  int mn = 10;
  if(a % 10 != 0)mn = min(mn,a%10);
  if(b % 10 != 0)mn = min(mn,b%10);
  if(c % 10 != 0)mn = min(mn,c%10);
  if(d % 10 != 0)mn = min(mn,d%10);
  if(e % 10 != 0)mn = min(mn,e%10);
  int kekka = 0;
  kekka += (a % 10 == 0 ? a : a/10*10+10);
  kekka += (b % 10 == 0 ? b : b/10*10+10);
  kekka += (c % 10 == 0 ? c : c/10*10+10);
  kekka += (d % 10 == 0 ? d : d/10*10+10);
  kekka += (e % 10 == 0 ? e : e/10*10+10);
  cout << kekka-10+mn << endl;
}

Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    S = [list(input()) for _ in range(h)]

    for x in range(h):
        for y in range(w):
            cnt = 0
            if S[x][y] == ".":
                if x != 0:
                    if S[x - 1][y] == "#":
                        cnt += 1
                if y != 0:
                    if S[x][y - 1] == "#":
                        cnt += 1
                if x != h - 1:
                    if S[x + 1][y] == "#":
                        cnt += 1
                if y != w - 1:
                    if S[x][y + 1] == "#":
                        cnt += 1
                if x >= 1 and y >= 1:
                    if S[x - 1][y - 1] == "#":
                        cnt += 1
                if x >= 1 and y < w - 1:
                    if S[x - 1][y + 1] == "#":
                        cnt += 1
                if x < h - 1 and y >= 1:
                    if S[x + 1][y - 1] == "#":
                        cnt += 1
                if x < h - 1 and y < w - 1:
                    if S[x + 1][y + 1] == "#":
                        cnt += 1
                S[x][y] = cnt 

    for x in range(h):
        for y in range(w):
            print(S[x][y], end = "")
        print()

if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    string str;
    cin >> str;
    rep(i, str.length()){
        if(i == str.length() - 1){
            if(str[i] == '?') str[i] = 'D';
        }else if(str[i] == '?'){
            if(str[i + 1] == '?'){
                str[i] = 'P';
                str[i + 1] = 'D';
            }else if(str[i + 1] == 'P'){
                str[i] = 'D';
            }else{
                str[i] = 'P';
            }
        }else if(str[i] == 'P' && str[i + 1] == '?'){
            str[i + 1] = 'D';
        }
    }

    rep(i, str.length()) cout << str[i];
    cout << endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint cnt(n+1);
  FOR(x,1,101)FOR(y,1,101)FOR(z,1,101) {
    int g = x*x + y*y + z*z + x*y + y*z + z*x;
    if (g <= n) ++cnt[g];
  }
  FOR(i,1,n+1) {
    cout<<cnt[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3584
import java.util.Scanner;

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

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		sc.close();
		System.out.println(2 * g - r);
	}
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll max_val=0;
    ssort(a);
    cout << a[n-1]-a[0] << endl;




}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

int main(){
    int k;
    string s,subs;
    cin>>k>>s;

    if(s.size()<=k){
        cout<<s<<endl;
    }else{
        subs=s.substr(0,k);
        cout<<subs<<"..."<<endl;
    }
}

Measured memory_bytes: 3632
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A, B) = read!(usize, usize);

    // k(A - 1) + 1 >= B
    // k >= (B-1)/(A-1)

    println!("{}", ((B - 1) + (A - 2)) / (A - 1))
}


Measured memory_bytes: 4352
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto X = readln.chomp.to!long;
    long x = 100;
    foreach (t; 1..10000) {
        x = (x.to!double * 1.01).to!long;
        if (x >= X) {
            writeln(t);
            return;
        }
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

  const double EPS = 1e-8;
  const double INF = 1e12;
  typedef complex<double> P;//????´???°????????¢?????????????????¨?§£???
  namespace std {
    bool operator < (const P& a, const P& b) {//x????????????
      return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool sorty(const P& a, const P& b) {//y????????????
      return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
    }
  }
  double cross(const P& a, const P& b) {//??????
    return imag(conj(a)*b);
  }
  double dot(const P& a, const P& b) {//??????
    return real(conj(a)*b);
  }

  struct L : public vector<P> {//??´???
    L(){};
    L(const P &a, const P &b) {
      push_back(a); push_back(b);
    }
  };

  typedef vector<P> G;

  struct C {//???
    P p; double r;
    C(){};
    C(const P &p, double r) : p(p), r(r) { }
  };

int linejudge(const L &ab,const L &cd){
  P a = ab[1] - ab[0],b = cd[1] - cd[0];
  if(abs(cross(a,b)) < EPS){ // parallel
    return 2;
  }
  else if(abs(dot(a,b)) < EPS){ //Orthogonal
    return 1;
  }
  return 0;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  cin >> q;
  double x,y;
  rep(i,q){
    cin >> x >> y;
    P a(x,y);
    cin >> x >> y;
    P b(x,y);
    cin >> x >> y;
    P c(x,y);
    cin >> x >> y;
    P d(x,y);
    L ab(a,b),cd(c,d);
    std::cout << linejudge(ab,cd) << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3248
import java.util.ArrayList;
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> brick = new ArrayList<>();
		int ans = 0;
		for(int i = 0; i < n; i++) {
			brick.add(sc.nextInt());
		}
		int index = 1; 
		
		for(int i = 1; i <= n; i++) {
			if(brick.get(i-1) == index) {
				index++;
			}else {
				ans++;
			}
		}
		
		System.out.println(index == 1 ? -1 : ans);
		sc.close();
	}
}


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

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> left(N + 1), right(N + 1);
    left[0] = 0; right[N] = 0;
    for (int i = 0; i < N; i++)
        left[i + 1] = gcd(left[i], A[i]);
    for (int i = N; i > 0; i--)
        right[i - 1] = gcd(right[i], A[i - 1]);

    int res = 0;
    for (int i = 0; i < N; i++) {
        int l = left[i];
        int r = right[i + 1];

        res = max(res, gcd(l, r));
    }
    cout << res << endl;
    return 0;
}

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

long long c2(long long n){
    return n*(n-1)/2;
}


void solve(long long N, std::vector<long long> A){
    vector<int> cnt(N);
    rep(i,N) cnt[A[i]]++;
    long long total = 0;
    rep(i,N) {
        total += c2(cnt[i]);
    }
    rep(i,N){
        long long ans = total;
        ans -= c2(cnt[A[i]]);
        ans += c2(cnt[A[i]]-1);
        cout << ans << endl;
    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    rep(i,N) A[i]--;
    solve(N, A);
    return 0;
}


Measured memory_bytes: 6528
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    string S=get_str();
    unordered_set<int> list;
    FOR(i,S.size()){
        if(list.count(S[i])){
            print("no");
            return 0;
        }else{
            list.insert(S[i]);
        }
    }
    print("yes");
    return 0;
}

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

int main() {
    int N, M, tot;

    cin >> N >> M;

    tot = 0;
    for (int i = 1; i <= M; i++) {
        int A;
        cin >> A;

        tot += A;
    }

    if (tot > N)
        cout << -1 << endl;
    else
        cout << N - tot << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string s;
	cin >> s;

	int ans = 1e9;
	for(int i = 0; i < s.size() - 2; i++){
		int x = atoi(s.substr(i, 3).c_str());
		ans = min(ans, abs(753 - x));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[4][10000];
int main()
{
    int n;
    cin>>n;
    int i,a[2][n],j;
    for(i=0;i<2;i++)
    {
        for(j=0;j<n;j++)
            cin>>a[i][j];
    }
    for(i=0;i<n;i++)
    {
        dp[0][i]=-1;
        dp[0][i]=-1;
    }
    dp[0][0]=a[0][0];
    dp[1][0]=a[0][0]+a[1][0];
    for(i=1;i<n;i++)
    {
        dp[0][i]=max(dp[0][i-1],dp[0][i])+a[0][i];
        dp[1][i]=max(dp[0][i],dp[1][i-1])+a[1][i];
   //     cout<<dp[i][0]<<" ";
    //    cout<<dp[i][1]<<endl;
    }
    cout<<dp[1][n-1]<<endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for i in range(m):
    bc.append(list(map(int,input().split())))
#print(bc)
bc.sort(key=lambda x:x[1],reverse=True)
a.sort()

ind = 0
i = 0
for i in range(n):
    
    if a[i] < bc[ind][1]:
        a[i] = bc[ind][1]
        bc[ind][0] -= 1

        if ind == m-1 and bc[ind][0] == 0:
            break
        if bc[ind][0] == 0:
            ind = ind +1
print(sum(a))


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



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

	string s;
	cin >> s;
	if (s == "Sunny")cout << "Cloudy";
	else if (s == "Cloudy")cout << "Rainy";
	else cout << "Sunny";
}

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

int n, k;
char s[310];

int dp[310][310][310];

int main()
{
	cin >> (s+1) >> k;
	n = strlen(s+1);
	for(int l=1; l<=n; ++l){
		for(int r=n; l<=r; --r){
			for(int u=0; u<=k; ++u){
				int d = max(dp[l-1][r][u], dp[l][r+1][u]);
				if(s[l] == s[r]){
					d = max(d, dp[l-1][r+1][u] + 1);
				}
				if(u){
					d = max(d, dp[l-1][r+1][u-1] + 1);
				}
				dp[l][r][u] = d;
			}
		}
	}
	int ans = 0;
	for(int i=1; i+1<=n; ++i){
		for(int u=0; u<=k; ++u){
			ans = max(ans, 2*dp[i][i+1][u]);
		}
	}
	for(int i=1; i<=n; ++i){
		for(int u=0; u<=k; ++u){
			ans = max(ans, 2*dp[i][i][u] - 1);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 114560
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
   input! {
       n: u64,
       k: u64,
   } 

    let d = 10u64.pow(9)+7;

   for i in 1..k+1 {
       if n-k+1 < i {
            println!("0");
            continue;
        }
       println!("{}", comb(n-k+1, i, d) * comb(k-1, i-1, d) % d);
   }

}

fn comb(m: u64, n: u64, d: u64) -> u64{
    if n == 0 {
        return 1;
    }
    let m_fact: u64 = (1..m+1).fold(1, |n, i| n*i%d);
    let n_fact: u64 = (1..n+1).fold(1, |n, i| n*i%d);
    let m_n_fact: u64 = (1..m-n+1).fold(1, |n, i| n*i%d);
    
    m_fact*modinv(n_fact*m_n_fact%d, d) % d
}
fn modinv (a: u64, d: u64) -> u64 {
    modpow(a, d - 2, d)
}

fn modpow(x: u64, y: u64, d: u64) -> u64 {
    let mut res = 1;
    let mut a = x;
    let mut n = y;
    while n > 0 {
        if n & 1 != 0 {
            res = res * a % d;
        }
        a = a * a % d;
        n = n >> 1;
    }
    res
}

#[test]
fn comb_test() {
    let d = 1e9 as u64 + 7;
    assert_eq!(comb(3,1,d), 3);
}


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

int main()
{
    int K, N;
    vector<int> As;
    cin >> K >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(As));

    vector<int> distances;
    std::transform(
        As.begin(), As.end() - 1,
        As.begin() + 1,
        back_inserter(distances),
        [](int a, int b) {
            return b - a;
        });
    distances.push_back(K - As.back() + As.front());

    auto max_distance = *max_element(distances.begin(), distances.end());

    cout << K - max_distance << endl;
    return 0;
}


Measured memory_bytes: 2548
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

$allApproved = true;
foreach($A as $v) {
  if ($v % 2 == 0) {
    if (($v % 3 == 0) || ($v % 5 == 0)) {
    }
    else {
      $allApproved = false;
    }
  }
}
printf("%s\n",$allApproved?"APPROVED":"DENIED");


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

//Compiler version g++ 6.3.0

int main()
{
    int n,i;char s[100],t[100];
    cin>>n;
    
    scanf("%s",s);
    scanf("%s",t);
    for(i=0;i<n;i++){
      cout<<s[i]<<t[i];
    }
}

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

using namespace std;
 
#define EPS 1e-6
#define INF 1e8
typedef complex<double> P;
 
double dot(P a,P b){
  return real(conj(a)*b);
}
 
double cross(P a,P b){
  return imag(conj(a)*b);
}
 
struct Point{
  double x,y;
};
 
int main(){
  double D;
 
  while(scanf("%lf",&D), D){
    Point v,p;
     
    scanf("%lf%lf%lf%lf",&p.x,&p.y,&v.x,&v.y);
    P np = P(p.x,p.y), nv = P(v.x,v.y);
    double dist = INF;
 
    if(abs(cross(np,nv)) < EPS){
      if(dot(np,nv) < -EPS){
        dist = abs(np);
      }else{
        dist = 2-abs(np);
      }
    }
    
    if(dist < D - EPS){
      printf("%.8f\n",dist);
    }else{
      printf("impossible\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 1268
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())
L = list(map(int, input().split()))

print(sum(1 for i in range(N + 1) if sum(L[:i]) <= X))



Measured memory_bytes: 38512
n = int(input())
list_place = []
max_t = 0
for _ in range(n):
  t, x, y = map(int, input().split())
  if t > max_t:
    max_t = t
  list_place.append([t, x, y])

t = 0
place = [0, 0]
for tgt_t, tgt_x, tgt_y in list_place:
  while t < tgt_t:
    dif_x = tgt_x - place[0]
    dif_y = tgt_y - place[1]
    if dif_x > 0:
      place[0] += 1
    elif dif_x < 0:
      place[0] -= 1
    else:
      if dif_y > 0:
        place[1] += 1
      else:
        place[1] -= 1
    t += 1
  if place[0] != tgt_x or place[1] != tgt_y:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 19572
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>

using namespace std;

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

static const int MAX = 100010;
int N, M, K;
vector<int> FR[MAX], BL[MAX];
int cluster[MAX], cluster_size[MAX], current_cluster = 0, f[MAX], b[MAX];

void bfs(int u) {
  if(cluster[u]>0) return;
  current_cluster++;
  cluster[u] = current_cluster;
  cluster_size[current_cluster]++;
  queue<int> que;
  que.push(u);
  while(!que.empty()) {
    int v = que.front(); que.pop();
    for(const int& i : FR[v]) {
      if(cluster[i]==0) {
        cluster[i] = current_cluster;
        cluster_size[current_cluster]++;
        que.push(i);
      }
    }
  }
}

int main() {
  cin >> N >> M >> K;
  rep(i, M) {
    int A, B;
    scanf("%d %d", &A, &B);
    A--;
    B--;
    FR[A].push_back(B);
    FR[B].push_back(A);
    f[A]++;
    f[B]++;
  }
  rep(i, N) bfs(i);
  rep(i, K) {
    int C, D;
    scanf("%d %d", &C, &D);
    C--;
    D--;
    BL[C].push_back(D);
    BL[D].push_back(C);
    if(cluster[C] != 0 && cluster[C] == cluster[D]) {
      b[C]++;
      b[D]++;
    }
  }
  rep(i, N) {
    if(i) cout << " ";
    cout << cluster_size[cluster[i]] - 1 - f[i] - b[i];
  }
  cout << endl;
  return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rALL(x) x.rbegin(),x.rend()

using namespace std;
using ll=long long;


int main(){
  int n;cin>>n;
  int z=1;
  rep(i,n)z*=3;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int cnt=0;
  for(auto x:a)if(x%2==0)cnt++;
  int t=1;
  rep(i,cnt)t*=2;
  cout<<(z-t);
}

Measured memory_bytes: 3580
use proconio::input;

use std::io::stdout;
use std::io::Write;
use std::io::BufWriter;
use std::cmp;

fn main() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    input! {
        n: u64,
        m: u64,
    }
    //ooo
    //ouo
    //ooo

    //ouo

    //u
    if n == 1 && m == 1 {
        writeln!(out, "1").unwrap();
    } else if n == 1 || m == 1 {
        writeln!(out, "{}", cmp::max(n, m) - 2).unwrap();
    } else {
        writeln!(out, "{}", (n - 2) * (m - 2)).unwrap();
    }
}


Measured memory_bytes: 2196
N = int(input())
X = list(map(int, input().split()))

X_sort=sorted(X)
mid_l = X_sort[N // 2 - 1]
mid_r = X_sort[N // 2]

for i in range(N):

    if (X[i] <= mid_l):
        ans = mid_r
    
    else:
        ans = mid_l
    
    print(ans)

Measured memory_bytes: 26772
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char b;
	cin>>b;
	if(b=='A'){
		cout<<'T';
		return 0;
	}
	if(b=='C'){
		cout<<'G';
		return 0;
	}
	if(b=='T'){
		cout<<'A';
		return 0;
	}
	if(b=='G'){
		cout<<'C';
		return 0;
	}
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int sum = 0;
        for (int i = 0; i < 5; i++) {
            sum += Math.max(40, Integer.parseInt(br.readLine()));
        }
        System.out.println(sum / 5);
    }
}


Measured memory_bytes: 24428
def solve():
  n,k = (int(i) for i in input().split())
  s = input()
  ans = 0
  for i in range(n-1):
    if s[i] == s[i+1]:
      ans += 1
  rest = n-ans
  ans = min(n-1,ans+k*2)
  print(ans)
solve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m, k;
  cin >> n >> m >> k;
  
  vector<int> A(n), B(m);
  for(int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  
  long long total = 0;
  for(int i = 0; i < m; i++) {
    cin >> B.at(i);
    total += B.at(i);
  }
  
  int bound = m;
  int ans = 0;
  for(int i = 0; i < n;i++) {
    while(total > k && bound > 0) {
      bound--;
      total -= B.at(bound);
    }
    
    if(total > k) {
      cout << ans << endl;
      return 0;
    }
    
    ans = max(ans, bound + i);
    total += A.at(i);
  }
  
  while(total > k && bound > 0) {
    bound--;
    total -= B.at(bound);
  }
  
  if(total <= k) {
    ans = max(ans, bound + n);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4844