akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

const int N = 1e5;

int n, m;
int arr[N + 5];
vi lst;


int solve(){
	int mx = 0, dif = 0;
	FORD(i,n){
		if(mx > arr[i]){
			lst.PB(mx-arr[i]);
			dif = max(dif, mx-arr[i]);
		}
		mx = max(mx, arr[i]);
	}
	sort(lst.begin(), lst.end());
	int ret = 0;
	FORD(i,lst.size()){
		if(lst[i] == dif) ret++;
	}
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	FOR(i,n){
		cin >> arr[i];
	}
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 1276
S = input()

start_0 = 0
start_1 = 0

for i, S_i in enumerate(S):
    # print(i, S_i)
    if i % 2 == 0:
        if S_i == "0":
            start_1 += 1
            # print("a")
        else:
            start_0 += 1
            # print("b")
    else:
        if S_i == "0":
            start_0 += 1
            # print("c")
        else:
            start_1 += 1
            # print("d")

print(min(start_0, start_1))


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

int main(){
int a[3];
for(int i=0;i<3;i++){
    cin>>a[i];
}
    sort(a,a+3);
    if(a[2]=='0'){
        cout << "0"<<endl;
    }else{
        cout << a[2]*10+a[1]+a[0]<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1e5 + 5, M = 1005;
int n, a[M][M], prime[N], vis[N], tot;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
void init(int n)
{
	for(int i = 2; i <= n; i ++)
	{
		if(!vis[i]) prime[++ tot] = i;
		for(int j = 1; j <= tot && i * prime[j] <= n; j ++)
		{
			vis[i * prime[j]] = 1;
			if(i % prime[j] == 0) break;
		}
	}
}
//int gcd(int a, int b) {return !b ? a : gcd(b, a % b);}
//int lcm(int a, int b) {return a / gcd(a, b) * b;}
long long gcd(long long x, long long y) {
    while (y ^= x ^= y ^= x %= y) void();
    return x;
}

long long lcm(long long x, long long y) {
    if (!x || !y) return x + y;
    return x / gcd(x, y) * y;
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	init(10000); n = read();
	if(n == 2) {puts("4 7\n23 10\n"); return 0;}
	for(int i = 1; i <= n; i ++)
		for(int j = ((i + 1) & 1) + 1; j <= n; j += 2)
			a[i][j] = prime[(i + j) / 2] * prime[n + (i - j) / 2 + (n + 1) / 2];
	for(int i = 1; i <= n; i ++)
		for(int j = (i & 1) + 1; j <= n; j += 2)
			a[i][j] = lcm(lcm(a[i - 1][j], a[i][j - 1]), lcm(a[i + 1][j], a[i][j + 1])) + 1;
	for(int i = 1; i <= n; i ++, printf("\n"))
		for(int j = 1; j <= n; j ++, printf(" "))
			printf("%lld", a[i][j]);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int a,b,ans=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
  int a1,a2,a4,a5;
  a1=i/10000;
  a2=(i/1000)%10;
  a4=(i/10)%10;
  a5=i%10;
  if(a1==a5 && a2==a4) ans++;
    
  }
  cout<<ans<<endl;
}

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

int main(void){
	int c[] = {1000,500,100}, cnt[3], r, s, t, j;
	while(1){
		scanf("%d%d",&s,&t);
		if(s + t == 0) break;
		memset(cnt,0,sizeof(cnt));
		r = t - s;
		while(r){
			for(j = 0;j < 3;j++){
				if(c[j] <= r){
					r -= c[j];
					cnt[j]++;
					break;
				}
			}
		}
		for(j = 2;j >= 0;j--){
			printf("%d",cnt[j]);
			if(j) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a <= b && a <= c){
            if(b <= c) {
                System.out.println(a+" "+b+" "+c);
            }else if(b > c){
                System.out.println(a+" "+c+" "+b);
            }
        }else if(b <= a && b <= c){
            if(a <= c){
                System.out.println(b+" "+a+" "+c);
            }else if(a > c){
                System.out.println(b+" "+c+" "+a);
            }
        }else if(c <= a && c <= b){
            if(a <= b){
                System.out.println(c+" "+a+" "+b);
            }else if(a > b){
                System.out.println(c+" "+b+" "+a);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26188
# coding: utf-8
# Your code here!

s = list(input())
s_len = len(s)
arr = []
ctr = 0

for i in range(s_len):
    if arr == [] or s[i] == arr[-1]:
        arr.append(s[i])
    else:
        ctr += 2
        arr.pop()
print(ctr)

Measured memory_bytes: 49392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

ll dp[101010];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int H,N; cin>>H>>N;
  ll A[N],B[N]; rep(i,N) cin>>A[i]>>B[i];
  rep(i,101010) dp[i]=1e15;
  dp[0]=0;
  ll ans=1e15;
  rep(i,H+1) rep(j,N){
    dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j]);
    if(i+A[j]>=H) ans=min(ans,dp[i+A[j]]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
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); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m;
    vi vx(n), vy(m);
    REP(i,n) {
        cin >> vx[i];
        sum += (2 * i - n + 1) * vx[i];
        sum %= MOD;
    }
    REP(i,m) {
        cin >> vy[i];
        cnt += (2 * i - m + 1) * vy[i];
        cnt %= MOD;
    }
    cout << (sum * cnt)%MOD << endl;
}

Measured memory_bytes: 1920
a = input().upper()
b = input().upper()
c = input().upper()
t = "A"

while True:
  if t == "A":
    if len(a)<1:
      t = "A"
      break
    t = a[0]
    a = a[1:]
  elif t == "B":  
    if len(b)<1:
      t = "B"
      break
    t = b[0]
    b = b[1:]
  elif t == "C":
    if len(c)<1:
      t = "C"
      break
    t = c[0]
    c = c[1:]


print(t)

Measured memory_bytes: 9004
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int h,n,tmp;
  cin >> h >> n;
  rep(i,n){
    cin >> tmp;
    h-=tmp;
  }
  cout << ((h>0)?"No":"Yes") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    set<int> se;
    REP(i,k){
        if(a+i<=b){
            se.insert(a+i);
        }
    }
    REP(i,k){
        if(b-i>=a){
            se.insert(b-i);
        }
    }
    for(auto itr:se){
        cout<<itr<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#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 all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

ll C[55][55];
void comb_table(int n){
    rep(i,n+1){
        rep(j,n+1){
            if(j==0||j==i)C[i][j]=(ll)1;
            else C[i][j]=C[i-1][j-1]+C[i-1][j];
        }
    }
}

int main(){
    int n,a,b;
    vector<ll> v;
    cin>>n>>a>>b;
    comb_table(n+1);
    rep(i,n){
        ll data;
        cin>>data;v.pb(data);
    }
    sort(all(v),greater<ll>());
    
    ll ave=0;
    rep(i,a)ave+=v[i];
    // cout<<ave<<" "<<a<<endl;
    printf("%.10f\n",ave/(double)a);
    
    ll cnt=0;
    if(v[0]==v[a-1]){
        int max_cnt=0;
        rep(i,n)if(v[i]==v[a-1])max_cnt++;
        REP(i,a,min(b,max_cnt)+1){
            cnt+=C[max_cnt][i];
            // cout<<C[max_cnt][i]<<endl;
        }  
    }else{
        int min_cnt=0,max_cnt=0;
        rep(i,n){
            if(v[i]==v[a-1]){
                max_cnt++;
                if(i<a)min_cnt++;
            }
        }
        cnt=C[max_cnt][min_cnt];
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; // assert(a[i]<n ) // if we want to check for special cond , used for debug                     
using namespace __gnu_pbds; // make less_equal in order to make a multiset pbds
#define INF (ll)1e18 
const ll Mod = (ll)1e9+7;
ll CaseN=1;
const ld PI = 22/7.0;


ll tst()
{
ll ans=0;

return ans;
}


void solve()
{
	ld n,x,t;
	cin>>n>>x>>t;
	ll ans=0;
	
	ans = ceil((t*n)/x) ;
	t = (ll)t;
	// ans = closet T mul
	ll p = ans/(ll)t;
	p++;
	if(ans%(ll)t==0)
	{
	p--;	
	}
	
	ans= p*t;
	
	cout<<ans<<endl;
	//cout<<"Case #"<<CaseN<<": ";
		CaseN++;
		// print your ans below;
	
return ;

}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	}
	
}


Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        double ans = 0;
        int point;
        int a;
        for(int i = 1; i <= n; i++){
            point = i;
            if(point >= k){
                ans += n-(point-1);
                break;
            }
            a = 0;
            while(true){
                point = point << 1;
                if(point >= k){
                    ans += 1 / Double.valueOf(2 << a);
                    break;
                }
                a++;
            }
        }
        ans /= n;
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
def main():
    a, b, c, d, e, f = map(int, input().split())

    maxConcentration = 0
    resSugarWater = 0
    resSugar = 0

    for i in range(31):
        for j in range((29 * a * i // b) + 1):
            water = (i * a + j * b) * 100
            possibleSugar = int(min(f - water, water * e / 100))
            for k in range((possibleSugar // c) + 1):
                for l in range(((possibleSugar - k * c) // d) + 1):
                    sugar = k * c + l * d

                    if water + sugar > f:
                        break

                    if water + sugar == 0:
                        continue

                    concentration = 100 * sugar / (water + sugar)

                    if concentration >= maxConcentration:
                        maxConcentration = concentration
                        resSugarWater = water + sugar
                        resSugar = sugar
    
    print(resSugarWater, resSugar)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import collections
s = input()
n = len(s)
mod_list = [0]

T = 0
for i in range(n):
    T += int(s[-1-i])*pow(10, i, 2019)%2019
    T = T%2019
    mod_list.append(T)

res = collections.Counter(mod_list)
cnt = 0
for d in res.values():
    cnt += int(d*(d-1)/2)
print(cnt)

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

int main() {
	int N;
	string S;
	int i ,c ;
	cin >> N;
	cin >> S;
	c = 0;
	if (N % 2 != 0) {
		c = c + 1;
	}
	else {
		for (i = 0;i < N / 2; i++) {
			if (S[i] != S[N / 2 + i]) {
				c = c + 1;
			}
		}
	}
	
	if (c > 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
	
}

Measured memory_bytes: 3096
N = int(input())
A = list(map(int, input().split()))
B = [i+1+A[i] for i in range(N)]
C = [i+1-A[i] for i in range(N)]
num = set(B) | set(C)


db = {n:0 for n in num}
dc = {n:0 for n in num}
for i in range(N):
  db[B[i]] += 1
  dc[C[i]] += 1

ans = 0
for k, v in db.items():
  ans += v * dc[k]
print(ans)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;


void solve() {
	int a, b, c; cin >> a >> b >> c;
	cout << min(min(a, b), c);
	cout << " ";
	cout << max(max(a, b), c);
	cout << endl;
}

int main() {

	solve();

	return 0;
}



Measured memory_bytes: 3076
import sys

def main():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())

    ans = 0
    for i in range(N+1):
        a = [0] * 5
        a[0] = i // 10**4
        a[1] = (i % 10**4) // 10**3
        a[2] = (i % 10**3) // 10**2
        a[3] = (i % 10**2) // 10
        a[4] = i % 10

        if sum(a) >= A and sum(a) <= B:
            ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
const int nmax = 200000;
int n;
int q;
string s;
vector<char> t(nmax);
vector<char> d(nmax);
bool lenough(int mid){
    int here = mid;
    REP(i,q){
        if(here>=n){
            return true;
        }else if(here<0){
            return false;
        }
        if(t[i]==s[here]){
            if(d[i]=='L'){
                here--;
            }else{
                here++;
            }
        }
    }
    if(here<0){
            return false;
    }
    return true;
}
bool renough(int mid){
    int here = mid;
    REP(i,q){
        if(here>=n){
            return false;
        }else if(here<0){
            return true;
        }
        if(t[i]==s[here]){
            if(d[i]=='L'){
                here--;
            }else{
                here++;
            }
        }
    }
    if(here>=n){
            return false;
    }
    return true;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >>q;
    cin >> s;
    REP(i,q){
        cin >> t[i] >> d[i];
    }
    int ok = n;
    int ng = -1;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(lenough(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    int lok = ok;
    ok = -1;
    ng = n;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(renough(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    int rok = ok;
    cout << n-lok-(n-1-rok) << endl;
    return 0;
}

Measured memory_bytes: 1104
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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


int T, n, m, to[10101];
vector<int> v[404];
vector<P> G[404];
vector<vector<int>> dist(404, vector<int>(404, INF));
vector<int> route[404][404];

void floyd(){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				if(dist[j][k] > dist[j][i] + dist[i][k]){
					//route[j][k] = route[j][i]+route[i][k];
					route[j][k] = route[j][i];
					route[j][k].insert(route[j][k].end(),route[i][k].begin(),route[i][k].end());
					dist[j][k] = dist[j][i] + dist[i][k];
				}
			}
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0; i <= n; i++){
		dist[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
		int a,b,c;
		cin >> a >> b >> c;
		G[a].push_back(P(b,c));
		G[b].push_back(P(a,c));
		dist[a][b] = c;
		dist[b][a] = c;
		route[a][b].push_back(b);
		route[b][a].push_back(a);
	}
	cin >> T;
	for(int i = 0; i < T; i++){
		int a,b,c;
		cin >> a;
		if(a){
			cin >> b >> c;
			v[c].push_back(i);
			to[i] = c;
		}
	}
	
	floyd();
	
	int now = 1, next = 0;
	int have[404] = {0};
	for(int t = 0; t < T; t++){
		if(now == 1) have[to[t]]++;
		if(next > t) continue;
		int k, ma = -1;
		for(int i = 2; i <= n; i++){
			if(!have[i]) continue;
			if(dist[1][i] >= T-t) continue;
			int cnt = 0;
			for(int j = 0; j < route[1][i].size(); j++){
				cnt += have[route[1][i][j]];
			}
			if(ma < cnt * 10000 / dist[1][i]){
				ma = cnt;
				k = i;
			}
		}
		
		if(ma >= 1){
			next = t + dist[1][k]*2;
			int cnt = t;
			for(int j = 0; j < route[1][k].size(); j++){
				int npos = route[1][k][j];
				have[npos] = 0;
				for(int i = 0; i < dist[now][npos]; i++){
					if(cnt >= T) break;
					cnt++;
					cout << npos << endl;
				}
				now = npos;
			}
			for(int i = route[1][k].size()-2; i >= -1; i--){
				int npos;
				if(i == -1) npos = 1;
				else npos = route[1][k][i];
				for(int j = 0; j < dist[now][npos]; j++){
					if(cnt >= T) break;
					cnt++;
					cout << npos << endl;
				}
				now = npos;
			}
		}
		else{
			cout << -1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 27136
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void inverse(int n,vector<ll> &inv){
    //要素数:n+1
    inv[1]=1;
    for(int i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}



int main() {
    int n,dis; cin>>n;
    vector<int> me(n+1,-1);
    int ad;
    rep(i,n+1){
        cin>>ad;
        if(me[ad]>=0){
            dis=i-me[ad]+1; break;
        }
        else{
            me[ad]=i;
        }
    }
    vector<ll> v(n+2,0);
    inverse(n+1,v);

    ll c=1,d=1;
    rep(i,n+1){
        c=((c*(n+1-i))%MOD)*v[i+1]%MOD;
        c=(c+MOD)%MOD;
        printf("%lld\n",(c-d+MOD)%MOD);
        d=((d*(n+1-dis-i))%MOD)*v[i+1]%MOD;
        d=(d+MOD)%MOD;
    }
}

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

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n + 1;

    while (head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0){
            enqueue(u);
        }else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}



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

using namespace std;

#define N 100005

int n, m, i, x, y, H[N], flag, j, ans;
vector<int> a[N];

int main (void)
{
	scanf("%d%d",&n,&m);
	for (i=1; i<=n; i++) scanf("%d",&H[i]);
	for (i=1; i<=m; i++) {
	    scanf("%d%d",&x,&y);
	    a[x].push_back(y);
	    a[y].push_back(x);
	}
	for (i=1; i<=n; i++) {
		flag=0;
		for (j=0; j<a[i].size(); j++) {
			if (H[i]<=H[a[i][j]]) {
				flag=1;
				break;
			}
		} 
		if (!flag) ans++;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}



signed main(){
	int n,m; cin>>n>>m;
	if(n%2){
		int a=1, b=n-1;
		rep(i,m){
			cout<<a SP b<<endl;
			a++; b--;
		}
	}else{
		int a=1, b=m+1, c=m+2, d=2*m+1;
		rep(i,m){
			if(i%2==0){
				cout<<a SP b<<endl;
				a++; b--;
			}else{
				cout<<c SP d<<endl;
				c++; d--;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3696
import itertools
n=int(input())
j=list(itertools.permutations(range(1,n+1)))
p=tuple([int(i) for i in input().split()])
q=tuple([int(i) for i in input().split()])
a=j.index(p)
b=j.index(q)
print(abs(a-b))

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL n;cin >> n;
    vector<int> a(n);
    inc(i, 0, n) cin >> a[i];
    LL sum = 0;
    inc(i, 0, n){
        sum += a[i];
    }
    string ans = "YES";
    if(sum%(n*(n+1)/2) != 0){
        ans = "NO";
    }
    LL k = sum/(n*(n+1)/2);
    LL dsum = 0;
    int cnt = 0;
    inc(i, 0, n){
        int d = a[(i+1)%n]-a[i]-k;
        dsum += a[(i+1)%n]-a[i];
        if(d < 0){
            if((-d)%n != 0){
                ans = "NO";
            }else{
                cnt+=(-d)/n;
            }
        }else if(d > 0){
            ans = "NO";
        }
    }
    if(cnt != k) ans = "NO";
    if(dsum != 0) ans = "NO";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include <math.h> 
int main(){
    int n,k;
    int h[100000];
    scanf("%d %d",&n,&k);
    int i;
    for(i=1;i<=n;i++){
        scanf("%d",&h[i]);
    }
    int count =0;
    for(i=1;i<=n;i++){
        if(h[i]>=k){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
#define fi first
#define se second
vector <pair <int, int> > adj[100001];
int color[100001];
bool visited[100001];
void dfs (pair <int, int> cur){
    visited[cur.fi]=true;
    for (int i=0; i<adj[cur.fi].size(); i++){
        if (!visited[adj[cur.fi][i].fi]){
            if (adj[cur.fi][i].se%2==0) color[adj[cur.fi][i].fi]=color[cur.fi];
            else color[adj[cur.fi][i].fi]=1-color[cur.fi];
            dfs(adj[cur.fi][i]);
        } 
    }
}
int main(){
    int a, x, y, z;
    cin>>a;
    for (int i=1; i<a; i++){
        cin>>x>>y>>z;
        adj[x].push_back({y, z});
        adj[y].push_back({x, z});
    }
    pair <int, int> param;
    param.fi=1;
    dfs(param);
    for (int i=1; i<=a; i++) cout<<color[i]<<endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int x,a,b; cin >> x >> a >> b;
  x-=a;
  COUT(x%b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,n,m;
    cin>>n;
    for(i=1;i<=(n/i);i++)
    {
        if(n%i==0)
        {
            int d=n/i;
            if(i>=1 && i<=9 && d>=1 && d<=9)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
n=int(input())
mount=[int(i) for i in input().split()]

center=n//2
# 中央から最初の水の量を求める
a=mount[center]
for i in range(center-1,-1,-1):
    tmp=mount[-1-i]+mount[i]
    a=tmp-a

print(a,end=" ")
a//=2
for mi in range(n-1):
    a=mount[mi]-a
    print(2*a,end=" ")
print()

Measured memory_bytes: 14028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    class Node<T>
    {
        private int m_height;
        private Node<T> m_parent;
        public T Item { get; private set; }
        public Node(T item)
        {
            m_height = 0;
            m_parent = this;
            Item = item;
        }
        public Node<T> Find()
        {
            if (m_parent == this) { return this; }

            Node<T> parent = m_parent.Find();
            m_parent = parent;
            return parent;
        }
        public static void Unite(Node<T> a, Node<T> b)
        {
            Node<T> p = a.Find();
            Node<T> q = b.Find();
            if (p.m_height < q.m_height)
            {
                p.m_parent = q;
                q.m_height = Math.Max(p.m_height + 1, q.m_height);
            }
            else
            {
                q.m_parent = p;
                p.m_height = Math.Max(q.m_height + 1, p.m_height);
            }
        }
    }

    static IEnumerable<int> Solve(int N, int M, int K, int[][] p1, int[][] p2)
    {
        var nodes = new Node<int>[N];
        for (int i = 0; i < N; ++i) { nodes[i] = new Node<int>(i); }
        var answers = new int[N];
        foreach (int[] p in p1)
        {
            int a = p[0] - 1;
            int b = p[1] - 1;
            Node<int>.Unite(nodes[a], nodes[b]);
            --answers[a];
            --answers[b];
        }
        var counts = new int[N];
        foreach (var node in nodes) { ++counts[node.Find().Item]; }
        for (int i = 0; i < N; ++i)
        {
            answers[i] += counts[nodes[i].Find().Item] - 1;
        }
        foreach (int[] p in p2)
        {
            int a = p[0] - 1;
            int b = p[1] - 1;
            if (nodes[a].Find() == nodes[b].Find())
            {
                --answers[a];
                --answers[b];
            }
        }
        return answers;
    }

    static void Main(string[] args)
    {
        var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V1[0], M = V1[1], K = V1[2];
        var p1 = new int[M][];
        for (int i = 0; i < M; ++i) { p1[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
        var p2 = new int[K][];
        for (int i = 0; i < K; ++i) { p2[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
        Console.WriteLine(string.Join(" ", Solve(N, M, K, p1, p2)));
    }
}


Measured memory_bytes: 32324
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

vector<bool> prm(100010,true);

void Inite(){
  prm.at(0) = false;
  prm.at(1) = false;
  for(int i=2;i<100010;i++){
    if(prm.at(i)){
      for(int j=2;i*j<100010;j++){
        prm.at(i*j) = false;
      }
    }
  }
}

int main(){
  int x;
  cin >> x;
  Inite();
  for(int i=x;i<100100;i++){
    if(prm.at(i)){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int INF=1<<30;

ll f(ll b,ll n){//nをb進数表記した時の各桁の和
  ll res=0;
  if(n<b) return n;
  else res=n%b+f(b,n/b);
  return res;
}

int main(){
  ll n,s;
  cin >> n >> s ;
  if(s==n){
    cout << n+1 << endl;
    return 0;
  }
  if( s > (ll)((2*n-1)/2LL) ) {
    cout << "-1" << endl;
    return 0;
  }
  for(ll b=2; b*b<=n; b++){
    ll temp=f(b,n);
    if(temp==s){
      cout << b << endl;
      return 0;
    }
  }
  ll ans=-1;
  for(ll p=1; p*p<=n; p++){
    ll q=s-p;
    if(q<0) continue;
    if((n-q)%p) continue;
    ll b=(n-q)/p;
    if(f(b,n)==s){
      if(ans==-1) ans=b;
      else ans=min(ans,b);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 1008
def water(l,x,c):
    if l==1:
        return x[0]
    if l==0:
        return 0
    k=j=0
    for i in x:
        if i==0:
            k=j
            break
        j+=1
    if j<l:
        c += water(k, x[:k], 0)
        c += water(l - (k+1) , x[k+1:], 0)
    else:
        c+=1
        for i in range(l):
            x[i]-=1
        i=0
        while x[i]==0 and i < l-1:
            i+=1
        c+=water(l-i,x[i:],0)
    return c

a=int(input())
b=[int(i) for i in input().split()]
c=water(a,b,0)
print(c)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll Perm(ll x, ll y) {
    
    if(x < y || x < 0 || y < 0) {
        re0;
    }
    
    ll res = 1;
    rep(i, y) {
        res *= x;
        res %= mod;
        x--;
    }

    return res;
}

ll n, k, ans = 1;
vl G[MAX_N];

void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
    }
    if(p == -1) { 
      ans *= Perm(k, (ll)G[v].size() + 1);
    }
    else {
      ans *= Perm(k-2, (ll)G[v].size() - 1);
    }
    ans %= mod;
}

int main() {
    
    cin >> n >> k;
    
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    dfs(0);

    out(ans);
    re0;
}

Measured memory_bytes: 9216
from _collections import deque
n,m=map(int,input().split())
ab=[[0,0]  for i in range(m)]
for i in range(m):
    ab[i][0],ab[i][1]=map(int,input().split())
ans=0
for i in range(m):
    edg=[[] for j in range(n+1)]
    for j in range(m):
        if j!=i:
            a,b=ab[j][0],ab[j][1]
            edg[a].append(b)
            edg[b].append(a)
    che=[0]*(n+1)
    che[0]=1
    data=deque([1])
    while len(data)>0:
        p=data.popleft()
        che[p]=1
        for j in range(len(edg[p])):
            r=edg[p][j]
            if che[r]==0:
                data.append(r)
                che[r]=1
    if not all(che[j]==1 for j in range(n+1)):
        ans+=1
print(ans)


Measured memory_bytes: 74192
def d_cake_123_sort_all(X, Y, Z, K, A, B, C):
    # editionalの解法2
    a, b, c = sorted(A, reverse=True), sorted(B, reverse=True), sorted(C, reverse=True)
    ans = []
    for i, a_i in enumerate(a, 1):
        for j, b_j in enumerate(b, 1):
            for k, c_k in enumerate(c, 1):
                if i * j * k <= K:
                    ans.append(a_i + b_j + c_k)
                else:
                    break
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
print(d_cake_123_sort_all(X, Y, Z, K, A, B, C))

Measured memory_bytes: 8752
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 998244353LL;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

string str;
vector<int> pos[256];
int n;

inline ll count(const vector<int>& vec, int l, int r)
{
	auto fst = lower_bound(vec.begin(), vec.end(), l);
	auto lst = upper_bound(vec.begin(), vec.end(), r);

	return lst - fst;
}

void solve()
{
	cin >> n >> str;
	n *= 3;

	for(int i = 0; i < n; ++i)
		pos[str[i]].push_back(i);

	for(int i = 0; i < n / 3; ++i)
	{
		int R = pos['R'][i];
		int G = pos['G'][i];
		int B = pos['B'][i];

		int left  = min({R, G, B});
		int right = max({R, G, B});
		int mid   = R ^ G ^ B ^ left ^ right;

		str[left] = '1';
		str[mid] = '2';
		str[right] = '3';
	}

	for(int i = 0; i < n; ++i)
		pos[str[i]].push_back(i);

	ll answ12 = 1LL, answ23 = 1LL;

	vector<int> cur1, cur2, cur3;

	for(int i = 0; i < n / 3; ++i)
	{
		cur1.push_back(pos['1'][i]);
		cur2.push_back(pos['2'][i]);
		cur3.push_back(pos['3'][i]);

		ll mult12 = 1LL, mult23 = 1LL;

		mult12 += count(cur2, pos['1'][i], pos['2'][i] - 1);
		mult23 += count(cur3, pos['2'][i], pos['3'][i] - 1);

		answ12 = (answ12 * mult12) % mod;
		answ23 = (answ23 * mult23) % mod;
	}

	ll answ = (answ12 * answ23) % mod;

	for(ll f = 1; f <= n / 3; ++f)
		answ = (answ * f) % mod;

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


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

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

    vector<int> num;
    if (S[0] == '0') {
        num.push_back(0);
    }

    int pos = 0;
    char now = S[0];
    while (pos < S.size()) {
        int count = 0;
        while (S[pos] == S[pos + 1]) {
            pos++;
            count++;
        }
        pos++;
        count++;
        num.push_back(count);
        if (now == '0') {
            now = '1';
        } else {
            now = '0';
        }
        count = 0;
    }
    if (S[S.size() - 1] == '0') {
        num.push_back(0);
    }

    int k = min(2*K, int(num.size()) - 1);
    int ans = 0;
    if (k == 0) {
        for (int i = 0; i < num.size(); i += 2) {
            int cand = num[i];
            if (ans < cand) {
                ans = cand;
            }
        }
    } else {
        for (int i = 0; i <= k; i++) {
            ans += num[i];
        }
        int cand = ans;
        int pos = k;
        while (0 <= pos - k and pos + 2 < num.size()) {
            cand += num[pos + 1] + num[pos + 2];
            cand -= num[pos - k] + num[pos - k + 1];
            if (ans < cand) {
                ans = cand;
            }
            pos += 2;
        }
    }

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

Measured memory_bytes: 1020
#!/usr/bin/env python
# coding: utf-8

# In[40]:


S = list(input())
K = int(input())


# In[41]:


min_idx = min((i for i in range(len(S)) if S[i] != "1"), default=-1)

if min_idx > K-1:
    print("1")
else:
    print(S[min_idx])


# In[ ]:






Measured memory_bytes: 2940
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

   public:
    u64 a;

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

using mint = ModInt<MOD>;

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

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

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

long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

template <typename T>
using Vec = vector<T>;
template <typename T>
using VVec = vector<vector<T>>;
using LL = long long;
int main() {
    int N;
    cin >> N;
    Vec<int> d(N);
    REP(i, N) { cin >> d[i]; }
    sort(ALL(d));
    cout << d[N / 2] - d[N / 2 - 1] << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int p=sc.nextInt();
		String s=sc.next();
		long ans=0;
		if(p==2 || p==5){
			for(int i=n-1; i>=0; i--){
				if((s.charAt(i)-'0')%p==0){
					ans+=i+1;
				}
			}
			System.out.println(ans);
			return;
		}
		int[] mod=new int[p];
		int ms=0;
		int ten=1;
		for(int i=n-1; i>=0; i--){
			ms=(ms+(s.charAt(i)-'0')*ten)%p;
			ten=(ten*10)%p;
			mod[ms]++;
		}
		ans=mod[0];
		for(int i=0; i<p; i++){
			ans+=(long)mod[i]*(mod[i]-1)/2;
		}
		System.out.println(ans);
	}
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, H) cin >> a[i];
    vector<vector<ll>> dp(H, vector<ll>(W));

    rep(w, W) rep(h, H) {
        if (a[h][w] == '#') {
            dp[h][w] = 0;
            continue;
        }
        if (h == 0 && w == 0) {
            dp[h][w] = 1;
        }
        else if (h != 0 && w == 0) {
            dp[h][w] = dp[h - 1][w];
        }
        else if (h == 0 && w != 0) {
            dp[h][w] = dp[h][w - 1];
        }
        else {
            dp[h][w] = dp[h - 1][w] + dp[h][w - 1];
            dp[h][w] %= mod;
        }
    }

    cout << dp[H-1][W-1] << endl;
}

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

int main(){
	int n, k, ans = 0;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; ++i) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());
	for (int i = 0; i < k; ++i) {
		ans += l[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,n) for(int i = 0; i < (int)(n);++i)
using ll = long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  vector<ll> v(n);
  rep(i,n)
    cin >> v[i];
  rep(x,m){
    int k = x+1;
    rep(i,n-1){
      if(v[i] % k > v[i+1] % k)
        swap(v[i],v[i+1]);
    }
  }
  rep(i,n) cout << v[i] << endl;
  return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    cout << N / 3 << endl;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		String s,t;
		int length;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		s = br.readLine();
		t = br.readLine();

		length = s.length();

		if(s.equals(t)) {
			System.out.println("Yes");
			return;
		}

		for(int i=0;i<length;i++){
		char s_part = s.charAt(length-1);
		s = s.substring(0, length-1);
		s = s_part + s;
		if(s.equals(t)) {
			System.out.println("Yes");
			return;
		}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c;
    cin>>a>>b;
    c=0;
    vector<int> d(a);
    for(int i=0;i<a;i++){
        cin>>d.at(i);
    }
    sort(d.begin(),d.end());
    for(int i=0;i<a;i++){
        c+=d.at(i);
        if(b<c){
            cout<<i<<endl;
            break;
        }
        if(i==a-1){
            if(b==c)
                cout<<a<<endl;
            else
                cout<<i<<endl;
        }
    }
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){ 
    map <int,int> cnt; 
    int n,m,accepted=0,penalti=0; 
    cin>>n>>m; 
    vi  ac(n+1,0); 
    for (int i=0;i<m;i++){ 
        string  s; int a; 
        cin >> a >> s; 
        if (s =="WA") cnt[a]++; 
        if (s=="AC" and ac[a]==0){
            ac[a]=1;
            accepted++;
            penalti += cnt[a];
        }
    }
    cout << accepted << " " << penalti << endl;
    
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 10328