akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  int ma=0;
  for(int &i:A){
    cin>>i;
    ma=max(ma,i);
  }
  sort(A.begin(),A.end());
  vector<bool> B(ma+1,false);
  for(int i:A)
    B[i]=true;
  for(int i=0;i<N;i++){
    if(!B[A[i]])
      continue;
    for(;i<N-1 && A[i]==A[i+1];i++)
      B[A[i]]=false;
    for(int j=2;A[i]*j<=ma;j++)
      B[A[i]*j]=false;
  }
  int i=0;
  for(bool b:B)
    if(b)
      i++;
  cout<<i<<endl;
}

Measured memory_bytes: 3992
N,K=map(int,input().split())
list1=[]
for i in range(N):
    a,b=map(int,input().split())
    list1.append([a,b])
list1.sort()
for j in range(N):
    K-=list1[j][1]
    if K<=0:
        print(list1[j][0])
        exit()

Measured memory_bytes: 20104
# Bounding
# https://atcoder.jp/contests/abc130/tasks/abc130_b

from sys import stdin, stdout

n, x = map(int, stdin.readline().split())
l = list(map(int, stdin.readline().split()))
coordinates = [0]
for i in range(1, n + 1):
    next_coordinate = coordinates[i - 1] + l[i - 1]
    if next_coordinate > x:
        break
    coordinates.append(next_coordinate)
stdout.write("%d\n" % len(coordinates))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto x : v) cerr << x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int i = 0; i < (n); ++i) cerr << a[i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int A[2005];
int main() {
	int N, K, Q;
	scanf("%d%d%d", &N, &K, &Q);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &A[i]);
	}
	int ans = INT_MAX;
	for (int i = 0; i < N; ++i) {
		vector<int> take;
		vector<int> L;
		for (int j = 0; j <= N; ++j) {
			if (j < N && A[j] >= A[i]) {
				L.push_back(A[j]);
			} else {
				if (L.size() >= K) {
					int pos = L.size() - K + 1;
					nth_element(L.begin(), L.begin() + pos, L.end());
					take.insert(take.end(), L.begin(), L.begin() + pos);
				}
				L.clear();
			}
		}
		sort(take.begin(), take.end());
		if (take.size() < Q) continue;
		int val = take[Q - 1] - A[i];
		ans = min(ans, val);
	}
	printf("%d\n", ans);
}


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

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

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

#define mkp make_pair
#define pb push_back

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



int main(){
    bool flag=true;
    ll ans=0,sum=0;

    int h,w,a,b;
    cin >>h>>w>>a>>b;

    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            
            if(j <= a){
                if(i <= b){
                    cout << 1;
                }else{
                    cout << 0;
                }
            }else{
                if(i <= b){
                    cout << 0;
                }else{
                    cout << 1;
                }
            }
        }
        cout <<'\n';
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1280
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();
		if (B%A==0) {
			System.out.println(A+B);
		} else {
			System.out.println(B-A);
		}
	}
}


Measured memory_bytes: 21588
import std.stdio;
import std.conv;
import std.string;
import std.format;
 
void main()
{
  string s = chomp(readln());
  string[] array = s.split(" ");
 
  int W = to!int(array[0]);
  int H = to!int(array[1]);
  int x = to!int(array[2]);
  int y = to!int(array[3]);
  int r = to!int(array[4]);
 
  // (0, 0) <= (x, y) <= (W, H)
  int left   = x - r;
  int right  = x + r;
  if ( (0 <= left && left <= W) &&
       (0 <= right && right <= W)) {
 
  } else {
    writeln("No");
    return;
  }
 
  int upper  = y + r;
  int bottom = y - r;
 
  if ( (0 <= upper && upper <= H) &&
       (0 <= bottom && bottom <= H)) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}

Measured memory_bytes: 2524
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        int sum = 0;
        int count = 1;
        for (int i = 0; i < n; i++) {
            sum += l[i];
            if (sum > x) {
                break;
            }
            count++;
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

#define nextInt(n) scanf("%d",&n)
#define nextLong(n) scanf("%lld",&n)
#define nextDouble(n) scanf("%lf",&n)


ll INF=1LL<<58;
class Main{
public:	
	void run(){
		int H,W;cin >> H >>W;
		vector<vector<int>> as(H,vector<int>(W));
		REP(y,H)REP(x,W) cin >> as[y][x];
		vector<vector<int>> bs(H,vector<int>(W));
		REP(y,H)REP(x,W) cin >> bs[y][x];
		int h,w;cin >> h >> w;
		vector<vector<int>> cs(h,vector<int>(w));
		REP(y,h)REP(x,w) cin >> cs[y][x];

		ll Mv=-INF;
		REP(y,H)REP(x,W){
			ll v=0;

			bool ok=true;
			REP(dy,h)REP(dx,w){
				if(y+dy>=H || x+dx>=W){
					ok=false;break;
				}
				v+=as[y+dy][x+dx];
				if(bs[y+dy][x+dx]!=cs[dy][dx]){
					ok=false;break;
				}
			}
			if(ok)Mv=max(Mv,v);
		}

		if(Mv==-INF){
			cout <<"NA"<<endl;
		}else{
			cout <<Mv<<endl;
		}
	}
};
 int main(){
 	cout <<fixed<<setprecision(15);
	ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }


Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, w, k, ans;
string s[110];
int main() {
    cin >> h >> w >> k;
    REP(i, h){
        cin >> s[i];
    }
    REP(x, 1ll << h){
        REP(y, 1ll << w){
            ll cnt = 0;
            REP(i, h){
                REP(j, w){
                    if (s[i][j] == '#' and !(x & (1ll << i)) and !(y & (1ll << j))) cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

int main() {
  ll N, M;
  std::cin >> N >> M;
  ll S[N];
  ll T[M];
  REP(i, N) { std::cin >> S[i]; }
  REP(i, M) { std::cin >> T[i]; }
  ll dp[N + 1][M + 1] = {};
  ll sum[N + 1][M + 1] = {};
  ll ans = 1;
  REP(i, N) {
    REP(j, M) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = sum[i][j] + 1;
        ans += dp[i + 1][j + 1] % MOD;
      }
      sum[i + 1][j + 1] =
          (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1] + MOD) %
          MOD;
    }
  }
  std::cout << ans % MOD << '\n';
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main() {
    int x; cin >> x;
    int m = 0;int point = 0;
    for(int i = 0;i < x;i++){
        int a,b; cin >> a >> b;
        if(a > m){
            m = a; point = b;
        }
    }
    cout << m+point;
}




Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main(){
	int A;
	int B;
	int C;
	int D;
	
	cin>>A>>B>>C>>D;
	
	if((A*B)>=(C*D)){
		cout<<A*B<<endl;}
	else{
		cout<<C*D<<endl;}
		
return 0;
}

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

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int c1=0,c2=0;
    string s;
    cin >> s;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]!='0'){
                c1++;
            }
        }
        else{
            if(s[i]!='1'){
                c1++;
            }
        }
    }
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]!='1'){
                c2++;
            }
        }
        else{
            if(s[i]!='0'){
                c2++;
            }
        }
    }
    cout << min(c1,c2);

    return 0;
}

Measured memory_bytes: 512
N = int(input())
S = input().split()[0]

length = len(S)

W_count = S.count('W')
R_count = S.count('R')

c = 0
if R_count < W_count:
    
    for i in range(R_count):
        s = S[i]
        if s !='R':
            c+=1
        
            
else:
    for i in range(W_count):
        s = S[-1-i]
        if s != 'W':
            c+=1
print(c)

Measured memory_bytes: 9448
use std::io;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

const SPLIT_DELIMITER: char = ' ';

#[allow(dead_code)]
fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

fn f(v: &mut Vec<isize>, i: &Vec<isize>) {
    for z in 1..v.len() {
        v[z] = i[z - 1] - (v[z - 1] / 2);
        v[z] *= 2;
    }
}

fn main() {
    let n: usize;
    input!(n);

    let i: Vec<isize> = input_vector();
    let mut v: Vec<isize> = vec![0; n];

    //A1-A2+A3 ... Anを求める。
    let mut flag = true;
    for z in &i {
        if flag {
            v[0] += *z;
            flag = false;
        } else {
            v[0] -= *z;
            flag = true;
        }
    }

    f(&mut v, &i);

    for z in v {
        write!(io::stdout(), "{} ", z).unwrap();
    }
    println!("");
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int i;
  for(i=0;i<s.size();i++){
    if(i+1<s.size() && s[i]==s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }else if(i+2<s.size() && s[i]==s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[int], nb: int) -> int:
    for _v in values:
        pass
    return nb


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    N = int(input())
    values = set()
    for _ in range(N):
        values.add(input().strip())
    print(len(values))


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 40536
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();

        long cnt=0;
        for(int i=0;i<m;i++){
            cnt+=scan.nextLong();
        }
        if(n-cnt>-1) System.out.println(n-cnt);
        else System.out.println(-1);
    }
}

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

int main() {
  int N, D;
  cin >> N >> D;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    if (hypot(X, Y) <= D) cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt(),c=nxt();
    if(b-a==c-b)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size() - 1;
  string tmp;
  long long ans = 0;
  for (int bit = 0; bit < (1<<n); bit++) {
    for (int j = 0; j <= n; j++) {
      tmp += s.at(j);
      if (bit & (1 << j)) {
        ans += stoll(tmp);
        tmp.clear();
      }
    }
    ans += stoll(tmp);
    tmp.clear();
  }
  cout << ans << endl;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 100005;
int N;
int A[MAX_N];

using II = pair<int, int>;

II odd[MAX_N];
II even[MAX_N];

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i%2 == 0) {
            even[A[i]].first++;
            even[A[i]].second = A[i];
        } else {
            odd[A[i]].first++;
            odd[A[i]].second = A[i];
        }
    }

    sort(even, even+MAX_N, greater<II>());
    sort(odd, odd+MAX_N, greater<II>());

    if(odd[0].second != even[0].second)
        cout << N - even[0].first - odd[0].first << endl;
    else
        cout << min(N - even[0].first - odd[1].first, N - odd[0].first - even[1].first) << endl;

    return 0;
}

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define max_heap priority_queue <int> pq; // max heap 
#define min_heap priority_queue <int, vector<int>, greater<int> > pq;  //min heap
#define make_pairVector vector<pair<long long int,long long int> > pairVector // vector of pairs
#define hashmap unordered_map<long long int, long long int>hashmap;
#define pb push_back


//map<pair<ll,ll>, ll > hash;          // pair,value hashmap where key is a pair
//hash[make_pair(i,j)] = 0;
//if(hash.find(make_pair(i,j)) == hash.end())


//map<ll,ll>::iterator itr;           // iterating a map
//for (itr = hash.begin();itr != hash.end(); itr++)
//{
//   itr->first = key  
//   itr->second = value
//}


// vector<string> v; //to convert vector to a set
// set<string> s(v.begin(), v.end());


// set<string>s;     // to convert set to a vector
// vector<string> v(s.begin(),s.end());


// cin >> x >> y;
// pairVector.pb(mp(x,y));


// string size = str.size()


// stack <int> s; 


// queue <int> gquiz; 


// __gcd(m, n) 

// ll arr[10e5 + 5];


// char arr[10e5 + 5];


// printf ("%.9f\n",x);
// cout << fixed << setprecision(9);



bool sortbysec(const pair<long long int,long long int> &a, const pair<long long int,long long int> &b) 
{ 
    return (a.second < b.second); 
}
bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
int check_key(map<long long int, long long int> m, long long int key) 
{ 
    // Key is not present 
    if (m.find(key) == m.end()) 
        return 0; 
  
    return 1; 
} 

void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}

int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}   

Measured memory_bytes: 3696
#include<stdio.h>
int hz(int x);
int n,m;

int main(){
    scanf("%d",&n);
    m=hz(n);
	printf("%d\n",m);
}

int hz(int x){
	int a,b,i;
	a=b=x; 
	for(i=2;i*i<=b;i++){
		if(b%i==0){
		    a=a/i*(i-1);
		    while(b%i==0)    b/=i;
		}
	}
	if(b>1)    a=a/b*(b-1);
	return a;
}


Measured memory_bytes: 2108
##(A,B,C,D)=map(int,input().split())

N=int(input())
##c=list(map(int, input().split()))
c=str(input())
k=int(0)


if(N%2==1):
    print("No")
else:
    N=int(N/2)
    for i in range(N):
        if(c[i]!=c[N+i]):
            k=1
    if(k==1):
        print("No")
    else:
        print("Yes")



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
int x=a+b+c;
a=max(a,b);
a=max(a,c);
if((x-a)==a)
cout<<"Yes";
else cout<<"No";
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, M, K; cin >> N >> M >> K;
    vector<long long> a(N), b(M);
    for(auto& t : a) cin >> t;
    for(auto& t : b) cin >> t;
    long long cur = 0;
    int idxB = 0;
    while(idxB < M){
        if(cur + b[idxB] > K) break;
        cur += b[idxB];
        ++idxB;
    }
    int num = idxB;
    int res = idxB;
    for(int i=0;i<N;i++){
        cur += a[i];
        ++num;
        while(idxB > 0 && cur > K){
            --idxB;
            --num;
            cur -= b[idxB];
        }
        if(cur > K) break;
        res = max(res, num);
    }
    cout << res << endl;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int64_t INF = 1LL << 60;

int main() {
 int a,b,c;
 cin>>a>>b>>c;
 if(c>=min(a,b)&&c<=max(a,b)){cout<<"Yes"<<endl;}
 else{cout<<"No"<<endl;}
return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{ 
  IOS
  ll x,a;
  cin>>x>>a;
  if(x<a)
    cout<<0;
  else
    cout<<10;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

s = deque([sys.stdin.readline().rstrip()])
q = int(input())
cnt = 0
for i in range(q):
    query = sys.stdin.readline().split()
    if query[0] == '1':
        cnt = (cnt + 1)%2
    else:
        if (int(query[1]) + cnt)%2 == 1:
            s.appendleft(query[2])
        else:
            s.append(query[2])
s = "".join(s)
if cnt:
    s = s[::-1]
print(s)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    int a, b, q; cin >> a >> b >> q;
    vector<ll> s(a);
    vector<ll> t(b);
    vector<ll> x(q);
    rep(i, a) cin >> s[i];
    rep(i, b) cin >> t[i];
    rep(i, q) cin >> x[i];

    // 昇順ソート
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    rep(i, q) {

        ll ans = LONG_MAX;

        ll s_itr = upper_bound(s.begin(), s.end(), x[i]) - s.begin();
        ll t_itr = upper_bound(t.begin(), t.end(), x[i]) - t.begin();
        // 領域外アクセス対応
        if(s_itr == a) s_itr--;
        if(t_itr == b) t_itr--;

        rep(j, 2) rep(k, 2) {
            ll s_tmp = max((ll)0, (s_itr-j));
            ll t_tmp = max((ll)0, (t_itr-k));

            ll tmp_a = abs(s[s_tmp] - x[i]) + abs(t[t_tmp]-s[s_tmp]);
            ll tmp_b = abs(t[t_tmp] - x[i]) + abs(s[s_tmp]-t[t_tmp]);
            chmin(ans, tmp_a);
            chmin(ans, tmp_b);
        }

        cout << ans << endl;

    }



    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int H,W; cin>>H>>W;
  vector<string> S(H);
  rep(i,0,H) cin>>S[i];
  vii dp(H+1,vi(W+1));
  dp[0][1]=1;
  rep(i,0,H){
    rep(j,0,W){
      if(S[i][j]=='.'){
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
        dp[i+1][j+1]%=MOD;
      }
    }
  }
  cout<<dp[H][W]<<endl;
  }


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

int main() {
  int K,S,ans=0;
  cin >> K >> S;
  
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      if(x+y<=S && x+y+K>=S) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


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

int main() {
	int a,b,c,k,s;
	cin >> a >> b >> c >> k;
	if(a >= k)
	{
		s = k;
	}
	else if(a + b >= k)
	{
		s = a;
	}
	else
	{
		s = a - k + a + b;
	}
	cout << s << endl;
	return 0;
}


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

int main(){
    string s;
    ll k;
    cin >> s >> k;
    
    
        int i = 0;
        while(s[i]=='1'){
            i++;
            if(i==k){
                cout << 1 << endl;
                return 0;
            }
            
        }
        cout << s[i] << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;

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

    long long dp[100010][3];
    memset(dp, 0, sizeof dp);
    long long now_num = 1LL;

    for(int i = 1; i <= (int)s.size(); i++){
        char alpha = s[i - 1];
        
        //(dp[i][0] += dp[i - 1][0]) % MOD;
        //(dp[i][1] += dp[i - 1][1]) % MOD;
        //(dp[i][2] += dp[i - 1][2]) % MOD;
        

        if(alpha == 'A' || alpha == '?'){
            dp[i][0] += ((dp[i - 1][0] + now_num) % MOD);
            dp[i][0] %= MOD;
            dp[i][1] += (dp[i - 1][1] % MOD);
            dp[i][1] %= MOD;
            dp[i][2] += (dp[i - 1][2] % MOD);
            dp[i][2] %= MOD;
        }

        if(alpha == 'B' || alpha == '?'){
            dp[i][0] += (dp[i - 1][0] % MOD);
            dp[i][0] %= MOD;
            dp[i][1] += ((dp[i - 1][0] + dp[i - 1][1]) % MOD);
            dp[i][1] %= MOD;
            dp[i][2] += (dp[i - 1][2] % MOD);
            dp[i][2] %= MOD;
        }

        if(alpha == 'C' || alpha == '?'){
            dp[i][0] += (dp[i - 1][0] % MOD);
            dp[i][0] %= MOD;
            dp[i][1] += (dp[i - 1][1] % MOD);
            dp[i][1] %= MOD;
            dp[i][2] += ((dp[i - 1][1] + dp[i - 1][2]) % MOD);
            dp[i][2] %= MOD;
        }

        if(alpha == '?') now_num = ((now_num % MOD) * 3) % MOD;
    }

    /*for(int i = 0; i <= (int)s.size(); i++){
        for(int j = 0; j < 3; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    cout << dp[(int)s.size()][2] % MOD << endl;
    
    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<Int Modulo = MOD> struct MInt {
	Int val;
	constexpr MInt(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr Int getmod() { return Modulo; }
	constexpr MInt operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr MInt operator + (const MInt& r) const noexcept { return MInt(*this) += r; }
	constexpr MInt operator - (const MInt& r) const noexcept { return MInt(*this) -= r; }
	constexpr MInt operator * (const MInt& r) const noexcept { return MInt(*this) *= r; }
	constexpr MInt operator / (const MInt& r) const noexcept { return MInt(*this) /= r; }
	constexpr MInt& operator += (const MInt& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr MInt& operator -= (const MInt& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr MInt& operator *= (const MInt& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr MInt& operator /= (const MInt& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const MInt& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const MInt& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const MInt<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, MInt<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = MInt<Modulo>(tmp);
		return is;
	}
	friend constexpr MInt<Modulo> modpow(const MInt<Modulo>& a, Int n) noexcept {
		MInt res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mInt = MInt<>;

class UnionFind {
private:
	vector<Int> data;
	Int root(Int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(Int size) : data(size, -1) { }
	bool same(Int x, Int y) { return root(x) == root(y); }
	Int size(Int x) { return -data[root(x)]; }

	void unite(Int x, Int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	vector<Int> p(N);
	for (Int i = 0; i < N; i++) {
		cin >> p[i];
	}

	vector<Int> x(M);
	vector<Int> y(M);
	for (Int i = 0; i < M; i++) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}

	UnionFind tree(N);

	for (Int i = 0; i < M; i++) {
		tree.unite(x[i], y[i]);
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		if (tree.same(i, p[i]-1))ans++;
	}

	cout << ans << "\n";
}

Measured memory_bytes: 3456
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l, r; cin >> l >> r;
    ll d = r - l;
    if(d >= 2018) d = 2018;
    r = l + d;
    ll mn = INF;
    for(ll i = l; i < r; i++){
        for(ll j = i + 1; j <= r; j++)
            chmin(mn, ((i % 2019) * (j % 2019)) % 2019);
    }
    cout << mn;
    cout << endl;
    return 0;
}


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

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (int)
N = int(input().rstrip())

# N ✕ M (2D array)
A = list(map(int, input().rstrip().split()) for _ in range(N - 1))

items = [[] for _ in range(N)]
colors = [-1 for _ in range(N)]

for i in range(N - 1):
    a, b, w = A[i]
    items[a - 1].append((b - 1, w))
    items[b - 1].append((a - 1, w))

queue = collections.deque()
queue.append(0)
colors[0] = 0
while queue:
    v = queue.popleft()
    c = colors[v]
    for k, w in items[v]:
        cc = colors[k]
        if cc == -1:
            nc = c if w % 2 == 0 else not c
            colors[k] = nc
            queue.append(k)

# def dfs(v, c):
#     colors[v] = c
#
#     cc = colors[k]
#
#     if cc == -1:
#         if not dfs(k, nc):
#             return False
#     else:
#         if colors[i] != nc:
#             return False
#
#
# return True
#
# dfs(0, True)
for c in colors:
    print(int(not c))


Measured memory_bytes: 73976
#include <bits/stdc++.h>
using namespace std;
const int sz=1e5+9;
int n,k;
char a[sz];
int v[sz],cnt;
int cs[sz];
int ans;
int l[sz],r[sz];

int bs(int pos){
    int st=pos,en=n;
    while(st<en){
        int mid=(st+en+1)>>1;
        if(cs[mid]-cs[pos-1]<=k) st=mid;
        else en=mid-1;
    }
    if(st<=n&&cs[st]-cs[pos-1]<=k) return st;
    return -1;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d %d",&n,&k);
    scanf("%s",a+1);
    for(int i=1;i<=n;i++) cs[i]=cs[i-1]+(a[i]=='0'&&(i==1||a[i-1]=='1'));
    for(int i=1;i<=n;i++){
        if(a[i]=='0'&&i!=1&&a[i-1]!='1') continue;
        int myr=bs(i);
        if(myr==-1) continue;
        ans=max(ans,myr-i+1);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define print(n) cout<<n<<endl
const int M=100111;
const int mod=1000000007;

int main(){
	int n,k,a[M];
	ll dp[101][M]={},sum[M]={};
	cin>>n>>k;
	rep(i,1,n+1)cin>>a[i];
	dp[0][0]=1;
	rep(i,1,n+1){
		rep(j,1,k+1)sum[j]=(sum[j-1]+dp[i-1][j-1])%mod;
		//sum[j]=dp[i-1][j-1] + ... + dp[i-1][0];
		rep(j,0,k+1)
			dp[i][j]=(sum[j]-sum[max(0,j-a[i])]+dp[i-1][j]+mod)%mod;
	}
	print(dp[n][k]);
}

Measured memory_bytes: 80256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod=1000000007;
typedef vector<vector<int> >mat;
int getrank(mat m)
{
	int r=0;
	for(int i=0;i<m.size();i++)
	{
		for(int j=r;j<m.size();j++)
		{
			if(m[j][i]==1)
			{
				swap(m[r],m[j]);
				for(int k=r+1;k<m.size();k++)
				{
					if(m[k][i]==1)
					{
						for(int l=0;l<m.size();l++)m[k][l]^=m[r][l];
					}
				}
				r++;
				break;
			}
		}
	}
	return r;
}
ll po(ll a,ll b)
{
	if(b==0)return 1;
	ll z=po(a,b/2);
	z=z*z%mod;
	if(b%2==1)z=z*a%mod;
	return z;
}
ll inv(ll a)
{
	return po(a,mod-2);
}
ll dp[500][500];//rank rの行列の数
ll db[500];//d次元subvectorspaceの数
ll p2[500];
ll inv2[500][500];
int main()
{
	int num;
	scanf("%d",&num);
	mat m;
	m.resize(num);
	for(int i=0;i<num;i++)
	{
		for(int j=0;j<num;j++)
		{
			int z;
			scanf("%d",&z);
			m[i].push_back(z);
		}
	}
	int r=getrank(m);
	p2[0]=1;
	for(int i=1;i<500;i++)p2[i]=p2[i-1]*2%mod;
	dp[0][0]=1;
	for(int i=0;i<num;i++)
	{
		for(int j=0;j<num;j++)
		{
			dp[i+1][j]+=dp[i][j]*p2[j];
			dp[i+1][j+1]+=dp[i][j]*(p2[num]+mod-p2[j]);
			dp[i+1][j]%=mod;
			dp[i+1][j+1]%=mod;
		}
	}
	for(int i=0;i<500;i++)for(int j=0;j<500;j++)inv2[i][j]=inv((p2[i]+mod-p2[j])%mod);
	for(int i=0;i<=num;i++)
	{
		ll x=1;
		for(int j=0;j<i;j++)
		{
			x*=(p2[num]+mod-p2[j]);
			x%=mod;
		}
		for(int j=0;j<i;j++)
		{
			x*=inv2[i][j];
			x%=mod;
		}
		db[i]=x;
	}
	ll ans=0;
	for(int a=r;a<=num;a++)
	{
		for(int b=r;b<=num&&a+b-num<=r;b++)
		{
			int s=r,t=b-r,u=(num-a)-(b-r);
			//printf("%d %d %d\n",s,t,u);
			ll x=1;
			for(int i=0;i<s+t+u;i++)
			{
				x*=(p2[num]+mod-p2[i]);
				x%=mod;
			}
			for(int i=0;i<t;i++)
			{
				x*=inv2[t][i];
				x%=mod;
			}
			for(int i=0;i<s;i++)
			{
				x*=inv2[s+t][i+t];
				x%=mod;
			}
			for(int i=0;i<u;i++)
			{
				x*=inv2[u+t][i+t];
				x%=mod;
			}
			ll kak=x*inv(db[a])%mod*inv(db[b])%mod;
			//printf("%d %d %lld %lld %lld\n",a,b,x,kak,dp[num][a]*dp[num][b]%mod*kak%mod);
			ans+=dp[num][a]*dp[num][b]%mod*kak;
			ans%=mod;
		}
	}
	printf("%lld\n",ans*inv(dp[num][r])%mod);
}

Measured memory_bytes: 4128
import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

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

int main(){
	long long n;
	cin>>n;
	
	char a[100];
	int i=0;
	while(n!=0){
		if(n%26==0){
			a[i]='z';
			n=n/26-1;
		}

		else{
			a[i]='a'+n%26-1;
			n=n/26;
		}
		
		i++;	
	}
	
	for(int j=i-1;j>=0;j--) cout<<a[j];
	
	return 0;
}

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

#define SZ(a) (int)(a).size()
typedef long long ll;
const int C = 501;

int main() {
	cin.sync_with_stdio(false);
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	if (H%h == 0 && W%w == 0) {
		puts("No");
		return 0;
	}
	vector<vector<int>> ans(H, vector<int>(W, C));
	if (H%h != 0) {
		for (int i = h-1; i < H; i += h) {
			ans[i].assign(W, -(h-1)*C-1);
		}
	}
	else {
		for (int i = 0; i < H; i++) {
			for (int j = w-1; j < W; j += w) {
				ans[i][j] = -(w-1)*C-1;
			}
		}
	}
	puts("Yes");
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			printf("%d%c", ans[i][j], " \n"[j == W-1]);
		}
	}
	return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		String ans = "No";
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		
		if (a <= c && c <= b){
			
			ans = "Yes";
		}

		System.out.print(ans);
		return;
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

a = int(input())
b = int(input())
c = int(input())
x = int(input())

xx = x/50
count=0

for na in range(a+1):
    for nb in range(b+1):
        for nc in range(c+1):
            if na*10 + nb*2 + nc == xx:
                count+=1

print(count)


Measured memory_bytes: 3060
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;

void main() {
    int N = readln.chomp.to!int;
    auto c = readln.chomp.split.map!(to!int).array;
    int Q = readln.chomp.to!int;
    bool flag = true;

    int[] apple = new int[](N);

    for (int i = 0; i < Q; i++) {
        auto operation = readln.chomp.split.map!(to!int).array;
        int x = operation[1] - 1, d = operation[2];

        if (!flag) {
            continue;
        }

        if (operation[0] == 1) {
            if (apple[x] + d <= c[x]) {
                apple[x] += d;
            }
            else {
                writeln(x + 1);
                flag = false;
            }
        }
        else {
            if (apple[x] - d >= 0) {
                apple[x] -= d;
            }
            else {
                writeln(x + 1);
                flag = false;
            }
        }
    }

    if (flag) {
        0.writeln;
    }

    return;
}


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

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

	int n,k,t;
	vector <int> v;
	long long int res = 0;

	cin >> n >> k;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}

	sort(v.rbegin(),v.rend());

	for(int i=k;i<n;i++)
	{
		res += v[i];
	}

	cout << res << '\n';

	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, t[100], m, p[100], x[100];

int main() {
	cin >> n;
	inc(i, n) { cin >> t[i]; }
	cin >> m;
	inc(i, m) { cin >> p[i] >> x[i]; }
	
	int sum = 0;
	inc(i, n) { sum += t[i]; }
	
	inc(i, m) {
		cout << sum - t[ p[i] - 1 ] + x[i] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
   
#define N 100000
 
int Partition(int *,int,int);
 
int main(){
  int n,i,p,r;
  int A[N];
 
  scanf("%d", &n);
 for(i = 0; i < n; i++) {
  scanf("%d", &A[i]);
 }
   
  r = Partition(A,p,n-1);
 
  for(i=0; i<n; i++){
    if(i != 0)
      printf(" ");
    if(r == i)
      printf("[%d]",A[i]);
    else
      printf("%d",A[i]);
  }
  printf("\n");
   
  return 0;
}
 
int Partition(int *A,int p,int r){
  int i,j,s,t;
  s=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=s){
      i++;
      t=A[i];     
      A[i]=A[j];
      A[j]=t;
    }
 
  }
 
  t=A[i+1];       
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}



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

#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define REP(i,k,n) for(int i = k; i < n; i++)

#define vi vector<int>
#define pb push_back
using namespace std;

int w,h;
bool is_small(int h1,int w1,int h2, int w2){
    int d1 = pow(h1,2) + pow(w1,2);
    int d2 = pow(h2,2) + pow(w2,2);
    if(d1 < d2) return true;
    else if(d1 > d2) return false;
    else if(d1 == d2 && h1 < h2) return true;
    return false;
}
int main(){
    int h,w;
    while(cin >> h >> w,h) {
        int mnh = 1000,mnw = 1000;
        REP(nh,1,151) REP(nw,nh + 1,151){
            if(h == nh && w == nw) continue;
            if(is_small(nh,nw,h,w)) continue;
            if(is_small(nh,nw,mnh,mnw)) {
                mnh = nh; mnw = nw;
            }
        }
        cout << mnh << " " << mnw << endl;
    }
    return 0;

}



Measured memory_bytes: 3100