akhauriyash/Code-Regression huggingface dataset:
X = int(input())

def is_prime_number(n):
    """
    >>> is_prime_number(1)
    False

    >>> is_prime_number(29)
    True

    >>> is_prime_number(30)
    False
    """
    import math
    if n == 1:
        return False

    r = True
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            r = False
    return r

for i in range(X, 10**9):
    if is_prime_number(i):
        print(i)
        break

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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    #define FOR(i,a,n,j) for(int i=a;i<n;i+=j)

    const int INF = 1e9+9;




    int main()
    {

        string s,m;
        cin>>s>>m;
        for(int i=0;i<s.size();i++){
            if(s[i]!=m[i]) {
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(s.size()+1 == m.size()) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    return 0;
    }
        // gotcha;


Measured memory_bytes: 3620
package main

import "fmt"

func main() {
	var a, b string
	fmt.Scan(&a, &b)

	rsb := []rune(b)
    for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
        rsb[i], rsb[j] = rsb[j], rsb[i]
	}
	// fmt.Println(rsb)
	if a == string(rsb) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner n=new Scanner(System.in);
		int w = n.nextInt();
		int h = n.nextInt();
		int x = n.nextInt();
		int y = n.nextInt();
		int r = n.nextInt();
		if ((x+r)>w||(y+r)>h||(x-r)<0||(y-r)<0)System.out.println("No");
		else System.out.println("Yes");
}}

Measured memory_bytes: 17360
from operator import itemgetter
import sys
input = sys.stdin.readline


class BIT():
    """一点加算、区間取得クエリをそれぞれO(logN)で答える
    add: i番目にvalを加える
    get_sum: 区間[l, r)の和を求める
    i, l, rは0-indexed
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目にvalを加える"""
        i = i + 1
        while i <= self.n:
            self.bit[i] += val
            i += i & -i

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        return self._sum(r) - self._sum(l)



n =int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)


def solve(val):
    val = a_sorted[val]
    ruiseki = [0] * (n + 1)
    for i, num in enumerate(a):
        if num >= val:
            ruiseki[i + 1] = ruiseki[i] + 1
        else:
            ruiseki[i + 1] = ruiseki[i] - 1
    b = sorted(enumerate(ruiseki), key = itemgetter(1))
    for i in range(n + 1):
        bit.bit[i] = 0
    res = 0
    for i, _ in b:
        bit.add(i, 1)
        res += bit.get_sum(0, i)
        if res >= cnt:
            return True
    return False


cnt = 0
for i in range(n):
    cnt += n - i
cnt = (cnt + 1) // 2

bit = BIT(n + 1)
ok = 0
ng = n
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid
print(a_sorted[ok])

Measured memory_bytes: 123080
A, B, C, X, Y = map(int, input().split())

ans = 10 ** 18
for i in range(0, 2 * max(X, Y) + 1, 2):
    tmpx = X - (i // 2)
    if tmpx <= 0:
        tmpx = 0
    tmpy = Y - (i // 2)
    if tmpy <= 0:
        tmpy = 0
    ans = min(ans, (i * C) + (tmpx * A) + (tmpy * B))

print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int f[109],x[109];

int main(){
	DRI(n);
	REP(i,n){
		RI(x[i]);
		f[x[i]]++;
	}
	sort(x,x+n);
	if(n>2&&f[1]>=2){
		printf("Impossible");return 0;
	}
	int h=x[n-1]/2;
	if(x[n-1]%2){
		REPP(i,h+2,x[n-1]+1){
			if(f[i]<2){
				printf("Impossible");return 0;
			}
		}
		if(f[h+1]!=2){
			printf("Impossible");return 0;
		}
		REP(i,h+1){
			if(f[i]){
				printf("Impossible");return 0;
			}
		}
	}
	else{
		REPP(i,h+1,x[n-1]+1){
			if(f[i]<2){
				printf("Impossible");return 0;
			}
		}
		if(f[h]!=1){
			printf("Impossible");return 0;
		}
		REP(i,h){
			if(f[i]){
				printf("Impossible");return 0;
			}
		}
	}
	printf("Possible");
}


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

int main(){
  string N;
  cin >> N;
  
  string ans = "Yes";
  
  for(int i = 0; i < N.size(); i++){
    if(N.at(0+i) != N.at(N.size() - i - 1)){
      ans = "No";
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int d,g;
  cin >> d >> g;
  int p[d],c[d];
  rep(i,d)cin >> p[i] >> c[i];
  int ans = INF;
  rep(bit,1<<d){
    int l=0;
    int sum = 0;
    int solved = 0;
    rep(i,d){
      if(bit>>i&1){
        sum += (i+1)*100*p[i]+c[i];
        solved += p[i];
      }
      else l=i;
    }
    int v = g - sum;
    if(v>0){
      int t = (v + (l+1)*100 - 1) / ((l+1)*100);
      if(t<p[l]){
        v -= t*(l+1)*100;
        solved += t;
      }
    }
    if(v<=0){
      chmin(ans,solved);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[3][3]; 
    rep (i, 3) {
        rep (j, 3) {
            cin >> a[i][j];
        }
    }
    
    int n;
    cin >> n;
    vector<int> b(n);
    rep (i, n) cin >> b[i];
    bool ok[3][3] = {};
    rep (i, n) {
        rep (y, 3) {
            rep (x, 3) {
                eprintf("(%d,%d)", a[y][x], b[i]);
                if (a[y][x] == b[i]) {
                    ok[y][x] = true;
                    eprintf("*");
                }
            }
        }
    }
    bool flg = false;
    rep (i, 3) {
        bool aaa = true;
        rep (j, 3) if (!ok[i][j]) aaa = false;
        if (aaa) flg = true;
    }
    rep (i, 3) {
        bool aaa = true;
        rep (j, 3) if (!ok[j][i]) aaa = false;
        if (aaa) flg = true;
    }
    bool aaa = true;
    rep (i, 3) if (!ok[i][i]) aaa = false;
    if (aaa) flg = true;
    aaa = true;
    rep (i, 3) if (!ok[2 - i][i]) aaa = false;
    if (aaa) flg = true;
    cout << (flg ? "Yes" : "No") << "\n";
    rep (i, 3) {
        rep (j, 3) eprintf("%d ", ok[i][j]);
        eprintf("\n");
    }
    rep (i, 3) {
        rep (j, 3) eprintf("%d ", a[i][j]);
        eprintf("\n");
    }
    return 0;
}

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

using namespace std;

int main() {
    
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s,t;
    cin >> s >> t;
    int operations=0;
    
    for(int i =0; i< s.length(); i++) 
    {
        if(s[i] != t[i]) 
        operations++;
    }

    cout<< operations;
   
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;
int b=1,p=2,x;
int maxx=INT_MIN;
int main(){
	cin>>x;
	rep(i,1,1000) rep(j,2,1000)
	{
		if(pow(i,j)<=x) 
		{
		maxx=max((int)pow(i,j),maxx);
		}
		else break;
	}
	cout<<maxx<<endl;
	



    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0 ; i < 30 ; i++) {
            for (int j = 0 ; j < 30 ; j++) {
                if (i * 4 + j * 7 == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Mod = 1000000007;

int main() {
  ll N;
  cin >> N;
  for (ll i = N; i >= 0; i--) {
    if (i % (ll)((ll)(sqrt(i)) * (ll)(sqrt(i))) == 0 && i / (ll)((ll)(sqrt(i)) * (ll)(sqrt(i))) == 1) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#1:???????????????H?????°????????????puts
#2:1???????\????????????????????????§??°?????????
#3:loop do if??????break
loop do
    h, w = gets.chomp.split.map(&:to_i)
    if h == 0 && w == 0
        break
    end
    h.times do |line|
        line = "#" * w
        puts "#{line}"
    end
    puts ""
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N;
	vector<ll>A(N + 1);
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		A[i] = a - i;
	}
	sort(A.begin() + 1, A.end());
	int b = A[N / 2 + 1];
	for (int i = 1; i <= N; i++) {
		ans += abs(A[i] - b);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;
int main(){
    string s;
    cin>>s;
    int ans = 0;
    rep(i,s.size()/2){
        if(s[i] != s[s.size()-1-i])ans++;

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){


int a ,b ,d ,r;

double f ;

scanf("%d",&a) ;

scanf("%d",&b) ;

d = a/b ;

r = a%b ;

f = (double)a/(double)b ;

printf("%d %d %lf\n",d,r,f) ;

return 0 ;

}

Measured memory_bytes: 636
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main (void) {
    int num=0;
    string str[3];  
    cin >> str[0];
    cin >> str[1];
    cin >> str[2];
    while(1){
        if(str[num][0]=='a'){
            str[num].erase(str[num].begin());
            num = 0;
        }
        else if(str[num][0]=='b'){
            str[num].erase(str[num].begin());
            num = 1;
        }
        else{
            str[num].erase(str[num].begin());
            num = 2;
        }
        if(str[num].size()==0){
            if(num==0)    cout << "A\n";
            else if(num==1)   cout << "B\n";
            else    cout << "C\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    N, M= map(int, input().split())
    
    acList = [False] * N
    waList = [0] * N
    waCount = 0

    for _ in range(M):
        p, s = map(str, input().split())
        p = int(p) - 1
        if acList[p]:
            continue
        if s == "WA":
            waList[p] += 1
            continue
        waCount += waList[p]
        acList[p] = True

    print(sum(acList), waCount)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int n,a,b,c;
vector<int> l;
int ans = INF;

void dfs(vector<int> v, int cnt){
    if(cnt == n){
        int cnt1 = 0,cnt2 = 0,cnt3 = 0;
        int len1 = 0,len2 = 0,len3 = 0;
        rep(i,n){
            if(v[i] == 1){
                cnt1++;
                len1 += l[i];
            }
            if(v[i] == 2){
                cnt2++;
                len2 += l[i];
            }
            if(v[i] == 3){
                cnt3++;
                len3 += l[i];
            }
        }
        if(len1 == 0 || len2 == 0 || len3 == 0) return;
        int now = (cnt1-1)*10+(cnt2-1)*10+(cnt3-1)*10+abs(len1-a)+abs(len2-b)+abs(len3-c);
        ans = min(ans,now);
        return;
    }

    rep(i,4){
        v[cnt] = i;
        dfs(v,cnt+1);
    }

}

int main(){
    cin >> n >> a >> b >> c;
    l.resize(n);
    rep(i,n) cin >> l[i];
    vector<int> v(n);
    int cnt = 0;
    dfs(v,cnt);
    cout << ans << endl;
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

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

const int MAXN = 1e5 + 5;

vi g[MAXN];
int gr[MAXN], prv[MAXN];
int mex[MAXN];

void dfs(int s) {
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (to != prv[s]) {
			prv[to] = s;
			dfs(to);
		}
	}
	/*REPN(i, 0, SZ(g[s])) {
		mex[i] = 0;
	}
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (to != prv[s]) {
			mex[gr[to] + 1] = 1;
		}
	}
	for(; mex[gr[s]]; gr[s]++);*/
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (to != prv[s]) {
			gr[s] ^= (gr[to] + 1);
		}
	}
}

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 1, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(1);
	if (gr[1]) {
		printf("Alice\n");
	} else {
		printf("Bob\n");
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 14336
#include <stdio.h>
#define change(x, y) {int t = x; x = y; y = t;}

int main(int argc, const char * argv[])
{
    
    int input1, input2;
    int cm;
    int rest, divided, divider;
    int i;
    
    while (scanf("%d %d", &input1, &input2) != EOF) {
        if (input1 < input2) {
            change(input1, input2);
        }
        divided = input1;
        divider = input2;
        for (i = 0; i < input1; i++) {                //ユークリッドの互除法
            rest = divided % divider;
            if (rest == 0) {
                cm = input1 / divider;
                cm *= input2;
                printf("%d %d\n", divider, cm);
                break;
            }
            divided = divider;
            divider = rest;
        }
        
    }
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k, ans =0;
	cin >>n >>k;
	int s=0, s1=0;
	for(int i=1;i<=n;i+=2){
		s++;
	}
	for(int i=2;i<=n;i+=2){
		s1++;
	}
	
	if(s>=k || s1>=k) puts("YES");
	else puts("NO");
	return 0;
}



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


using namespace std;
using ll = long long int;

#define rep(i, n) for(ll i = 0; i < (n); i++)
#define MOD 1000000007LL


ll pow(ll n, ll k) {
  ll r = 1;

  while (k > 0) {
    if (k % 2 == 1) {
      r = r * n % MOD;
    }
    n = n * n % MOD;
    k /= 2;
  }
  return r;
}

ll fac[1000000];

ll inv(ll x) {
  return pow(x, MOD - 2);
}


ll C(ll n, ll k) {
  if (k > 0) {
    return fac[n] * inv(fac[n - k]) % MOD * inv(fac[k]) % MOD;
  } else {
    return 1;
  }
}

ll P(ll n, ll k) {
  return fac[n] * inv(fac[n - k]) % MOD;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;

  fac[0] = 1;
  ll f = 1;
  for (ll i = 1; i < 1000000; i++) {
    f *= i;
    f %= MOD;
    fac[i] = f;
  }

  ll sum = 0;

  for (ll i = 0; i <= N; i++) {
    ll tmp = P(M - i, N - i) % MOD;
    ll term = C(N, i) * P(M, i) % MOD * tmp % MOD * tmp % MOD;
    if (i % 2 == 0) {
      sum = (sum + term) % MOD;
    } else {
      sum = (sum + MOD - term) % MOD;
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 11412
N,K =map(int,input().split())
S =input()
lis = [[],[]]
if S[0]=="0":
    lis[1].append(0)
j = S[0]
su = 0
for i in S:
    if i ==j:
        su += 1
    else:
        lis[int(j)].append(su)
        j = i
        su = 1
lis[int(j)].append(su)
if j=="0":
    lis[1].append(0)
if len(lis[0])<=K:
    print(N)
else:
    ans = 0

    ans = sum(lis[0][0:K]) + sum(lis[1][0:K+1])
    foo = ans
    for i in range(len(lis[0])-K):
        foo += lis[0][K+i] -lis[0][i] +lis[1][K+1+i] -lis[1][i]
        if ans < foo:
            ans = foo
    print(ans)


Measured memory_bytes: 45148
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let d = read::<u32>();

    let e = 25 - d;
    print!("Christmas");
    for _ in 0..e {
        print!(" Eve");
    }
    println!("");
}


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

using namespace std;

int main() {
  int n, d, x, a[100], count = 0;
  cin >> n >> d >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 1; j <= d; j += a[i]) {
      count++;
    }
  }
  cout << count + x << endl;
  return 0;
}


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

int main() {
string n,b;
cin>>n;
for(int i=0;i<n.size();i++){
	if(n[i]=='B'){if(b.empty()==0)b.pop_back();}
	else b.push_back(n[i]);
}
cout<<b<<endl;
return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  vector<ll> y(n);
  y = x;
  sort(ALL(y));
  ll l = y[n/2-1], r = y[n/2];
  rep(i, n) {
    if(x[i] < r) cout << r << endl;
    else cout << l << endl;
  }
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
struct edge{int to, cap, rev;};
int INF = 10000000;
int iter[1002];
int level[1002];

void bfs(vector< vector<edge> > &G, int s){
  memset(level,-1,sizeof(level));
  level[s] = 0;
  queue<int> que;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int i = 0; i < G[v].size(); ++i){
      edge &e = G[v][i];
      if(e.cap > 0 && level[e.to] < 0){
	level[e.to] = level[v] + 1;
	que.push(e.to);
      }
    }
  }
}

int dfs(vector< vector<edge> > &G, int v, int t, int f){
  if(v == t) return f;
  for(int &i = iter[v]; i < G[v].size(); ++i){
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(G,e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(vector< vector<edge> > &G, int s, int t){
  int flow = 0;
  for(;;){
    bfs(G,s);
    if(level[t] < 0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f = dfs(G,s,t,INF)) > 0){
      flow += f;
    }
  }
}

int gcd(int a, int b){
  if(a < b) swap(a,b);
  if(a % b) return gcd(b,a%b);
  return b;
}

int main(){
  int m, n;
  while(cin >> m >> n, m){
    int b[m], r[n];
    vector< vector<edge> > G(n+m+2);
    for(int i = 0; i < m; ++i)
      cin >> b[i];
    for(int i = 0; i < n; ++i)
      cin >> r[i];
    for(int i = 0; i < m; ++i){
      for(int j = 0; j < n; ++j){
	if(gcd(b[i],r[j]) != 1){
	  G[i].push_back((edge){j+m,1,G[j+m].size()});
	  G[j+m].push_back((edge){i,0,G[i].size()-1});
	}
      }
    }
    int s = n + m, t = n + m + 1;
    for(int i = 0; i < m; ++i){
      G[s].push_back((edge){i,1,G[i].size()});
      G[i].push_back((edge){s,0,G[s].size()-1});
    }
    for(int i = 0; i < n; ++i){
      G[i+m].push_back((edge){t,1,G[t].size()});
      G[t].push_back((edge){i+m,0,G[i+m].size()});
    }
    cout << max_flow(G,s,t) << endl;
  }
  return 0;
}

Measured memory_bytes: 7356
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <cctype>
#include <stack>
#define mst(a,b) memset(a,b,sizeof(a));
const int mod = (int)1e9+7;
const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;
typedef long long LL;

using namespace std;


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

bool cmp(LL a, LL b)
{
    return a>b;
}

int main()
{
    int x, a, b, c, ans = 0, x1,x2,x3;
    x1 = 500;
    x2 = 100;
    x3 = 50;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for(int i = 0; i <= a; i++){
        for(int j = 0 ; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(x1*i+x2*j+x3*k>x) break;
                else if(x1*i+x2*j+x3*k==x) ans++;
            }
        }
    }
    printf("%d", ans);
    return 0;
}

/*
0 0 0 0 0 0 0 0 0 0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

10
11
100 1 1 1 1 1 1 1 1 1 1

1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648

*/




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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n+1];
    rep(i,1,n+1) cin >> a[i];
    int money=1000;
    int mini=inf;
    for(int i=1; i<=n; i++){
        if(a[i]>mini){
            int z=money/mini;
            int y=money%mini;
            money=y+z*a[i];
            mini=inf;
        }
        mini=min(a[i],mini);
    }
    cout << money;
    return 0;
}


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

const int N = 2000 + 10;
int d[N], n, u[N], v[N];
vector<int> adj[N];
bool mark[N];

void bfs(vector<int> e) {
	for (int i = 0; i < n; i++)
		mark[i] = false;
  	queue<int> q;
  	for (int i = 0; i < e.size(); i++) {
    	mark[e[i]] = true;
      	q.push(e[i]);
      	d[e[i]] = 0;
    }
  	while(q.size()) {
    	int root = q.front();
      	q.pop();
      	for (int i = 0; i < adj[root].size(); i++) {
        	if(!mark[adj[root][i]]) {
            	mark[adj[root][i]] = true;
              	d[adj[root][i]] = d[root] + 1;
           		q.push(adj[root][i]);
            }
        }
    }

}

int main() {
	int k;
  	cin >> n >> k;
  	for (int i = 1; i < n; i++) {
		cin >> u[i] >> v[i];
      	u[i]--, v[i]--;
      	adj[u[i]].push_back(v[i]);
      	adj[v[i]].push_back(u[i]);
    }
  	int ans = n;
  	if(k % 2 == 0) {
    	for (int i = 0; i < n; i++) {
        	vector<int> e;
          	e.push_back(i);
          	bfs(e);
          	int cnt = 0;
          	for (int j = 0; j < n; j++)
            	if(d[j] > k / 2)
                  cnt++;
         	ans = min(ans, cnt);
        }
    }
  	else {
    	for (int i = 1; i < n; i++) {
        	vector<int> e;
          	e.push_back(v[i]);
          	e.push_back(u[i]);
          	bfs(e);
          	int cnt = 0;
          	for (int j = 0; j < n; j++)
            	if(d[j] > k / 2)
                	cnt++;
          	ans = min(ans, cnt);
    	}
    }
   	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = list(input())
    result = 0
    for i in range(N + 3):
        if S[i:i + 3] == ['A', 'B', 'C']:
            result += 1

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
void outtrue() {
    cout << "Yes" << endl;
}

void outfalse() {
    cout << "No" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,A;
    cin >> N >> A;
    if (N % 500 <= A) outtrue();
    else outfalse();
}
// vim: set fileencoding=utf-8


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int nibeki(int n);
void solve_odd(int n);
void solve_even(int n);


int main(){
  int n,flag;
  scanf("%d",&n);
  if(nibeki(n)) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  if(n%2){
    solve_odd(n);
  }else{
    solve_even(n);
  }

  return 0;
}
int nibeki(int n){
  while(n%2==0)n/=2;
  return n==1?1:0;
}
void solve_odd(int n){
  int i,k=n/2;
  printf("%d %d\n",n,n+1);
  for(i=1;i<=k;i++){
    printf("%d %d\n",1,2*i);
    printf("%d %d\n",2*i,2*i+1);
    printf("%d %d\n",1,2*i+1+n);
    printf("%d %d\n",2*i+1+n,2*i+n);
  }
}
void solve_even(int n){
  int i,k=n/2;
  printf("%d %d\n",n,2*n-1);
  printf("%d %d\n",n*2,n^(n-1)^1);
  printf("%d %d\n",n+1,3);
  for(i=1;i<k;i++){
    printf("%d %d\n",1,2*i);
    printf("%d %d\n",2*i,2*i+1);
    printf("%d %d\n",1,2*i+1+n);
    printf("%d %d\n",2*i+1+n,2*i+n);
  }
}


/// confirm df==0 ///


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

int main(){
    int N;
    cin >>N;
    vector<string> S;
    string s;
    for (int i = 0;i<N;i++){
        cin >>s;
        S.push_back(s);
    }
    sort(S.begin(),S.end());
    S.erase(unique(S.begin(),S.end()),S.end());
    cout << S.size();
}

Measured memory_bytes: 11664
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

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

// 品物の価値が最大でも 10^3 * 100 = 10^5なので、品物の価値で全探索

int N;
ll W;
const int MAX_N = 110;
const int MAX_V = 100100;
ll w[MAX_N], v[MAX_N];

ll dp[MAX_N][MAX_V];

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

    cin >> N >> W;

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

    for(int i = 0; i < MAX_N; i++){
        for(int iv = 0; iv < MAX_V; iv++){
            dp[i][iv] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < N; i++){
        for(int iv = 0; iv <= MAX_V; iv++){
            if(iv-v[i] >= 0){
                chmin(dp[i+1][iv], dp[i][iv-v[i]]+w[i]);
            }

            chmin(dp[i+1][iv], dp[i][iv]);

        }
    }
    
    ll ans = 0;
    for(int iv = 0; iv < MAX_V; iv++){
        if(dp[N][iv] <= W){
            ans = iv;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 86400
#include <iostream>
using namespace std;
int main(void) {
	long long int N,M;
	cin >> N >> M;
	if (N == 1 && M == 1)
		cout << 1 << endl;
	else if (N == 1)
		cout << M - 2 << endl;
	else if (M == 1)
		cout << N - 2 << endl;
	else
		cout << (M - 2) * (N - 2) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;

struct Union_find
{
    vector<int> par;
    vector<int> rank;

    Union_find(int n) : par(n), rank(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        //根にのみランクが保持されればいい
        if (rank[x] < rank[y])
            par[x] = y;
        else
        {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

int main(){
    int a, b;
    cin >> a >> b;
    if (a<=0 && b>=0)
        cout << "Zero" << endl;
    else if (a>0 && b >0)
        cout << "Positive" << endl;
    else if ((b-a+1) %2 == 0){
        cout << "Positive" << endl;

    }
    else
        cout << "Negative" << endl;
}

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

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define emp What is it
#define SORRY FUL Accepted 
#define dimash the top one
#define I wish 
#define you be a little more calm
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 5e3 + 123;                                          
const int NN = 5e5 + 123;
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int n, m, k, a[NN], cnt, ans;
string s;

inline void Solve () {
	// easy
	cin >> n >> k;
	for (int i = 1; i <= n; i ++) {
		int a;
		cin >> a;
		if(a % 2 == 1) cnt = 1;
	}

	if(!cnt) {
		if(k == 1) {
			cout << 0;
		} else {
			cout << (1ll << n);
		}
	} else {
		cout << (1ll << (n - 1));
	}
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int ans = 700;
  cin >> S;
  for (int i=0; i<3; i++){
    if (S.at(i) == 'o'){
      ans += 100;
    }
  }
  cout << ans << endl;  
}

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

using namespace std;

class cPlant {
public :
	cPlant(){};
	cPlant(string name, double sale) {
		mname = name;
		msale = sale;
	}
	string GetName() const { return mname; }
	double GetSale() const { return msale; }
private :
	string mname;
	double msale;
};

bool Greater(const cPlant& lPlant, const cPlant& rPlant) {
	if(lPlant.GetSale() != rPlant.GetSale()) return lPlant.GetSale() > rPlant.GetSale();
	return lPlant.GetName() < rPlant.GetName();
}

int main()
{
	int n;
	while(cin >> n, n) {
		cPlant plants[51];
		for(int i = 0; i < n; ++i) {
			string name;
			int cost, a, b, c, d, e, num, price, rep;
			int plus, t;
			cin >> name >> cost >> a >> b >> c >> d >> e >> num >> price >> rep;
			t = a + b + c + (d + e) * rep;
			plus = price * num * rep - cost;
			plants[i] = cPlant(name, (double)plus / t);
		}
		sort(plants, plants + n, Greater);
		for(int i = 0; i < n; i++) {
			cout << plants[i].GetName() << endl;
		}
		cout << '#' << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;


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

    //ノードをまとめる
    vector<pair<int, int>> nodes, ans;
    
    int S = N % 2 == 0 ? N + 1 : N;

    REPS(i, N / 2) {
        nodes.push_back(mp(i, S - i));
    }
    if (N % 2 == 1) {
        nodes.push_back(mp(N, -1));
    }

    auto merge = [&](int i, int j) {
        int len = nodes.size();
        i %= len;
        j %= len;
        if (nodes[i].first != -1 && nodes[j].first != -1) {
            ans.push_back(mp(nodes[i].first, nodes[j].first));
        }
        if (nodes[i].first != -1 && nodes[j].second != -1) {
            ans.push_back(mp(nodes[i].first, nodes[j].second));
        }
        if (nodes[i].second != -1 && nodes[j].first != -1) {
            ans.push_back(mp(nodes[i].second, nodes[j].first));
        }
        if (nodes[i].second != -1 && nodes[j].second != -1) {
            ans.push_back(mp(nodes[i].second, nodes[j].second));
        }

    };
    if (nodes.size() != 2) {
        rep(i, nodes.size()) {
            merge(i, i + 1);
        }
    }
    else {
        merge(0, 1);
    }

    cout << ans.size() << "\n";
    for (auto p : ans) {
        cout << p.first << " " << p.second << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] n = new int[s.length()];
        int sum = 0;
        boolean hasNot9 = false;
        for (int i = 0; i < s.length(); i++) {
            n[i] = (int)(s.charAt(s.length() - i - 1) - '0');
            if(i != s.length() - 1 && n[i] != 9) hasNot9 = true;
            if(i == s.length() - 1) sum += n[i];
            else sum += 9;
        }
        if(hasNot9) sum--;
        System.out.println(sum);
        sc.close();
    }

}


Measured memory_bytes: 21332
import math
n = int(input())
coo = [list(map(int,input().split())) for i in range(n)]
s = sum([math.sqrt(((coo[i][0]-coo[j][0])**2 + (coo[i][1]-coo[j][1])**2)*(math.factorial(n-1))**2) for i in range(n) for j in range(n) if i != j])
print(s/math.factorial(n))


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll gr(ll n) {
	ll res = 1;
	while (!(n & 1)) {
		res <<= 1; n >>= 1;
	}
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, l;
	cin >> n >> l;
	vector<string> vec(n);
	rep(i, n) cin >> vec[i];
	sort(all(vec));
	ll grundy = 0; string pre = "";
	rep(i, n) {
		int m = max(pre.size(), vec[i].size()); 
		int idx = -1;
		rep(j, m) {
			if (vec[i][j] == '1' && j < pre.size() && pre[j] == '0') {
				idx = j; break;
			}
		}
		for (int j = idx + 1; j < m; j++) {
			if (j < pre.size() && pre[j] == '0') {
				grundy ^= gr(l - j);
			}
			if (j < vec[i].size() && vec[i][j] == '1') {
				grundy ^= gr(l - j);
			}
		}
		pre = vec[i];
	}
	int sz = vec[n - 1].size();
	rep(i, sz) {
		if (vec[n - 1][i] == '0') grundy ^= gr(l - i);
	}
	cerr << grundy << '\n';
	cout << (grundy ? "Alice" : "Bob") << '\n';
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b,c;

    Scd3(a,b,c);

    YesNo( c >= a && c <= b );


    return 0;
}



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

void solve(long long N, std::vector<long long> L){
    int ans = 0;
    for(int i = 0; i < N-2; ++i){
      for(int j = i+1; j < N-1; ++j){
        for(int k = j+1; k < N; ++k){
          if(abs(L[i]-L[j]) < L[k] && L[k] < L[i]+L[j] && L[i] != L[j] && L[j] != L[k] && L[i] != L[k]) ans++;
        }
      }
    }
    std::cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int h, w;
  while(cin >> h >> w, h || w){
    char m[101][101];
    bool visited[101][101];
    bool loop = false;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> m[i][j];
        visited[i][j] = false;
      }
    }
    int ph = 0, pw = 0;
    while(m[ph][pw] != '.'){
      if(visited[ph][pw]) { loop = true; break; }
      visited[ph][pw] = true;
      int op = m[ph][pw];
      switch(op){
        case '>':
          pw += 1;
          break;
        case '<':
          pw -= 1;
          break;
        case 'v':
          ph += 1;
          break;
        case '^':
          ph -= 1;
          break;
        default:
          break;
      }
    }
    if(loop) cout << "LOOP" << endl;
    else cout << pw << " " << ph << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    int N = s.length;

    int[] res = new int[N];
    for (int i = 0; i < N - 1; i++) {
      if (s[i] == 'R' && s[i + 1] == 'L') {
        for (int j = 0; i - j >= 0 && s[i - j] == 'R'; j++)
          if (j % 2 == 0) res[i]++; else res[i + 1]++;
        for (int j = 0; i + 1 + j < N && s[i + 1 + j] == 'L'; j++)
          if (j % 2 == 0) res[i + 1]++; else res[i]++;
      }
    }
    StringBuilder sb = new StringBuilder();
    for (int i : res) sb.append(i).append(' ');
    sb.setLength(sb.length() - 1);
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n;
    cin >> n;
    cout << 800 * n - 200 * (n / 15) << "\n";
    return 0;
}

Measured memory_bytes: 3604
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

aabbcc = [[0], [0], [0]]
tmp = [0]*3
for i in abc:
  for j in range(3):
    tmp[j] = i[j] + max(aabbcc[(j+1)%3][-1], aabbcc[(j+2)%3][-1])
  for j in range(3):
    aabbcc[j].append(tmp[j])
print(max([i[-1] for i in aabbcc]))

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

int main(void)
{
    ll N, K;
    ll MOD = 1000000000 + 7;
    cin >> N >> K;
    ll total = 0;
    for(ll k=K;k<=N+1;k++){
        ll ma = (k * (k - 1)) / 2 + k*(N-k+1);
        ll mi = (k * (k-1)) / 2;
        total += ma - mi + 1;
        total %= MOD;
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3632