akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		string s;
		cin>>s;
		if(s=="ABC")cout<<"ARC";
		else
			cout<<"ABC";

	}	
	return 0;
}

Measured memory_bytes: 3644
#include<algorithm>
#include <iostream>
#include<vector>
using namespace std;
int main()
{
    int n; cin >> n;int a, b,c;
    a = 0; b = 0;c = 1;
    vector<int> p(n), q(n),v(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        v[i] = i + 1;
    }
    for (int i = 0;i < n;i++)cin >> q[i];
    do {
        if (v == q) a = c;
        if (v == p) b = c;
        c++;
    } while (next_permutation(v.begin(),v.end()));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
using namespace std;
typedef long long i64;
 
const int maxn = (int) 2e5 + 1;
string s;
int n, k, c;

int main() {
  int n;
  cin >> n >> k >> c >> s;
  vector<int> first, last;
  for (int i = n - 1; i >= 0; ) {
    if (s[i] == 'o') {
      last.push_back(i + 1);
      if (last.size() == k) break;
      i -= c + 1;
    } else {
      i -= 1;
    }
  }
  for (int i = 0; i < n; ) {
    if (s[i] == 'o') {
      first.push_back(i + 1);
      if (first.size() == k) break;
      i += c + 1;
    } else {
      i += 1;
    }
  }

  reverse(last.begin(), last.end());
  if (first.size() == last.size()) {
    for (int i = 0; i < k; i++) {
      if (first[i] != last[i]) continue;
      cout << first[i] << endl;
    }
  } else if (first.size() == k) {
    for (int x : first)
      cout << x << endl;
  } else if (last.size() == k) {
    for (int x : last)
      cout << x << endl;
  }
}


Measured memory_bytes: 3448
#include<iostream>
#include<vector>
#include<algorithm>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
  int k;cin>>k;
  ll sum=0;
  rep(a,k)rep(b,k)rep(c,k)sum+=__gcd(__gcd((a+1),(b+1)),(c+1));
 	cout<<sum<<endl;
return 0;
}


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

int main(){
    int N=0,zen=0,zenzen=0,ima=0;
    int a=0,b=0;
    int check=0;

    cin>>a>>b;

vector<string> draw(a);
    
    for(auto&x: draw){
        cin>>x;
    }



    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            if(draw[i][j]=='#')cout<<'#';
            if(draw[i][j]=='.'){ 
                check=0;
                if(i>0&&j>0&&draw[i-1][j-1]=='#')check++;
                if(i>0&&draw[i-1][j]=='#')check++;
                if(j<b-1&&i>0&&draw[i-1][j+1]=='#')check++;
                if(j>0&&draw[i][j-1]=='#')check++;
                if(j<b-1&&draw[i][j+1]=='#')check++;
                if(j>0&&i<a-1&&draw[i+1][j-1]=='#')check++;
                if(i<a-1&&draw[i+1][j]=='#')check++;
                if(i<a-1&&j<b-1&&draw[i+1][j+1]=='#')check++;
                cout<<check;
            }
        }
        cout<<endl;
    }

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int h,w;
char s[100][100];
int main(){
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      s[i][j]='.';
    }
  }
  cin >> h >> w;
  
  for(int i=1;i<=h;i++)scanf("%s",&s[i]);
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(s[i][j]=='#'){
	if(s[i+1][j]=='.'&& s[i-1][j]=='.' && s[i][j-1]=='.'&& s[i][j+1]=='.'){
	  printf("No\n");
	  return 0;
	}
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h1,h2,m1,m2;
  cin>>h1>>m1>>h2>>m2;
  int k;
  cin>>k;
  m1 = h1*60 + m1;
  m2 = h2 * 60 + m2;
  int ans = m2 - k - m1;
  cout<<max(ans,0)<<endl;
  return 0; 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char a;cin>>a;
    if('a'<=a&&a<='z') cout<<'a'<<endl;
    else cout<<'A'<<endl;
}



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

int main() {
	int A,B;
	cin >> A >> B;
  if(B == 1){
    cout << 0 << endl;
    return 0;
  }
  
  int i = 0;
  int mouth = A;
  while(mouth < B){
    i++;
    mouth += A-1;
  }
  cout << i+1 << endl;
}

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

int main()
{
	int n;
	vector<string> w(100);
	cin>>n;
	for(int i;i<n;i++) cin>>w[i];
	
	bool f=1;
	for(int i=0;i<n-1;i++){
		if(w[i][w[i].length()-1]!=w[i+1][0]) f=0;
		for(int j=i+1;j<n;j++)
			if(w[i]==w[j]) f=0;
	}
	
	if(f==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


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

int main(){
    int x;
    cin >> x;
    if (x < 1200){
        cout << "ABC" << endl;
    }
    else{
        cout << "ARC" << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 4e3+5;
const long long MOD = 998244353;
long long dp[MAXN][MAXN];
int main() {
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    dp[a][b] = 1;
    
    for(long long i=a;i<=c;i++){
        for(long long j=b;j<=d;j++){
            if(i==a && j==b){
                continue;
            }
           dp[i][j] = ((dp[i][j-1]+dp[i-1][j])%MOD+(1LL*dp[i][j-1]*(i-1))%MOD+(1LL*dp[i-1][j]*(j-1))%MOD)%MOD-((1LL*dp[i-1][j-1]*(i-1)*(j-1))%MOD)+MOD;
           dp[i][j]%=MOD;
        }
    }
    //dp[a][b] = 0;
    cout<<dp[c][d]<<endl;
}

Measured memory_bytes: 85864
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
    int n,i;
    scanf("%d",&n);
    
    int max=0,tmp,count=0;
    for(i=0;i<n;i++){
        scanf("%d",&tmp);
        if(tmp==1){
            count++;
        }
        else{
            if(max<count){
                max=count;
            }
            count=0;
        }
    }
    if(max<count){
        max=count;
    }
    printf("%d\n",max+1);
    
    return 0;
}


Measured memory_bytes: 2112
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::VecDeque;

use permutohedron::LexicalPermutation as _;

fn main() {
	input! {
		n: usize,
		m: usize,
		rnum: usize,
		mut r: [usize; rnum],
		abc: [(usize, usize, usize); m],
	}

	let inf = 999999999999999999usize;

	let mut v: Vec<Vec<(usize, usize)>> = vec![vec![]; n];

	for i in 0..m {
		v[abc[i].0-1].push((abc[i].1-1, abc[i].2));
		v[abc[i].1-1].push((abc[i].0-1, abc[i].2));
	}

	// すべての町間の距離を求める
	let mut d: Vec<Vec<usize>> = vec![vec![inf; n]; n];
	// 起点iから幅優先で
	for i in 0..n {
		let mut q = VecDeque::new();
		q.push_back((i, 0));
		while q.len() > 0 {
			let tmp = q.pop_front().unwrap();
			if d[i][tmp.0] <= tmp.1 {
				continue;
			}
			d[i][tmp.0] = tmp.1;
//			d[tmp.0][i] = tmp.1;
			for j in 0..v[tmp.0].len() {
				q.push_back((v[tmp.0][j].0, tmp.1+v[tmp.0][j].1));
			}
		}
	}
//	println!("{:?}", d);

	r.sort();
	let mut dmin = inf;
	loop {
		if !r.next_permutation() {
			break;
		}

//	println!("{:?}", permutations);

		let mut dsum = 0usize;
		let mut p = r[0]-1;
		for j in 1..rnum {
			dsum += d[p][r[j]-1];
			p = r[j]-1;
		}
		dmin = min(dmin, dsum);
	}
	println!("{}", dmin);
}


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

int main() {
    int n, a[4] = {0, 0, 0, 0};
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    rep(i, n) {
        if ("AC" == s[i])
            a[0]++;
        else if ("TLE" == s[i])
            a[1]++;
        else if ("WA" == s[i])
            a[2]++;
        else if ("RE" == s[i])
            a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[2] << endl;
    cout << "TLE x " << a[1] << endl;
    cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 6336
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char hoge,fuga;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    int bits = 0;
    for(int i = 0; i < n; i++) {if(x[i] == '1') bits++;}
    if(bits == 0) {for(int i = 0; i < n; i++)cout << 1 << "\n"; return 0;}
    if(bits == 1){
        for(int i = 0; i < n; i++){
            if(i < n - 1){
                if(x[i] == '1') cout << 0 << "\n";
                else if(x[n - 1] == '1'){
                    cout << 2 << "\n";
                }else{
                    cout << 1 << "\n";
                }
            }else{
                if(x[i] == '1') cout << 0 << "\n";
                else cout << 2 << "\n";
            }
        }
        return 0;//後でやる
    }
    int bitsm = bits - 1;
    int bitsp = bits + 1;
    vector<ll> divm(n);
    vector<ll> divp(n);
    divp[0] = 1, divm[0] = 1;
    for(int i = 1; i < n; i++){
        divp[i] = (divp[i - 1] * 2) % bitsp;
    }
    for(int i = 1; i < n; i++){
        divm[i] = (divm[i - 1] * 2) % bitsm;
    }
    ll modp = 0, modm = 0;
    reverse(divm.begin(), divm.end());
    reverse(divp.begin(), divp.end());
    for(int i = 0; i < n; i++){
        if(x[i] == '1'){
            modp = (modp + divp[i]) % bitsp;
            modm = (modm + divm[i]) % bitsm;
        }
    }
    vector<ll> out;
    for(int i = 0; i < n; i++){
        ll ans = 1;
        if(x[i] == '1'){
            ll curm = (modm - divm[i] + bitsm) % bitsm;
            ll mod = 0;
            while(curm != 0){
                ans++;
                mod = bitset<64>(curm).count();
                curm = curm % mod;
            }
            out.push_back(ans);
        }else{
            ll curp = (modp + divp[i]) % bitsp;
            ll mod = 0;
            while(curp != 0){
                ans++;
                mod = bitset<64>(curp).count();
                curp = curp % mod;
            }
            out.push_back(ans);
        }
    }
    /*for(int i = 0; i < n; i++){
        cout << divp[i] << " " << divm[i] << "\n";
    }
    cout << modp << " " << modm << "\n";*/
    for(auto itr : out) cout << itr << "\n";
}

Measured memory_bytes: 8696
#include <iostream>

using namespace std;

int main () {
    int h, w;

    while (true) {
        cin >> h >> w;

        if (h == 0 && w == 0) break;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std; 
#define int long long
int N,a[110000];
signed main(){
  cin>>N;
  int ans=0,m=INT_MAX,minus=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    ans+=abs(a[i]);
    m=min(m,abs(a[i]));
    minus+=(a[i]<0);
  }
  if(minus&1)ans-=m*2;
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
def main():
    h, w, k = map(int, input().split())
    s = [[int(i) for i in list(input())] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2**(h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    for i in range(1, 2**(h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print(min(cnt))

if __name__ == '__main__':
    main()

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

int main() {
  string S;
  cin >> S;
  int n=S.size();
  //p.resize(D); c.resize(D);
  //for (int i = 0; i < D; ++i) cin >> p[i] >> c[i];

  long ans=0;
  for (int bit = 0; bit < (1<<n); ++bit) {
    long long sum = 0;
    long long num = 0;
    string tmp=S;
    int j=1;
    for (int i = 1; i < n; ++i) {
      if (bit & (1<<i)){
         tmp = tmp.insert(j,"+");
         j++;
       }
       j++;
    }
    //cout<<tmp<<endl;
    int s=0;
    int e=0;
    while(s<tmp.size()){
      while(tmp[e]!='+'&&e<tmp.size()){
        e++;
      }
      ans += stoll(tmp.substr(s,e));
      s=e+1;
      e=e+2;
      if(e>tmp.size()) break;
    }

  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, num):
        self.rank = [0] * num
        self.par = [i for i in range(num)]
        self.n = num
 
    def find_root(self, node):
        if self.par[node] == node:
            return node
        else:
            self.par[node] = self.find_root(self.par[node])
            return self.par[node]
 
    def same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)
 
    def union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1


N,M = map(int,input().split())

UF = UnionFind(N)
for i in range(M) :
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    UF.union(x, y)

ans = sum([1 if i == UF.par[i] else 0 for i in range(N)])
print(ans)


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

int main() {
	char S[1000001], check_alp[26];
	char alp[26];
	int i, j;
	scanf("%s", S);
	for (i = 0; i < 26; i++) {
		alp[i] = 97 + i;
	}
	for (i = 0; i < 26; i++) {
		for (j = 0; j < strlen(S); j++) {
			if (alp[i] == S[j])
				check_alp[i] += 1;
		}
		if (check_alp[i] == 0) {
			printf("%c\n", alp[i]);
			return 0;
		}
	}
	printf("None\n");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

a.sort()

suma, sumb = 0, 0
for i in range(n):
  if n % 2 != 0:
    if i % 2 == 0:
      suma += a[i]
    elif i % 2 != 0:
      sumb += a[i]
  elif n % 2 == 0:
    if i % 2 == 0:
      sumb += a[i]
    elif i % 2 != 0:
      suma += a[i]
      
print(suma - sumb)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  
 int n;
  cin>>n;
  if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9){
    cout<<"hon"<<endl;
  }
  
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
    cout<<"pon";
  }
  
  else cout<<"bon";
    
  
  
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  ci(n);
  vll A(n+2);
  vll B(n+2);
  vll C(n+2);
  
  A[0]=0;
  A[n+1]=0;
  B[0]=0;
  C[n+1]=0;
  FOR(i,1,n+1){
    ci(A[i]);
    B[i]=abs(A[i]-A[i-1])+B[i-1];
  }
  B[n+1]=abs(A[n]);
  
  rFOR(i,n,0){
    C[i]=abs(A[i]-A[i+1])+C[i+1];
  }
  C[0]=abs(A[1]);
  
  FOR(i,0,n){
    co(B[i]+C[i+2]+abs(A[i]-A[i+2]))
  }
}


Measured memory_bytes: 3584
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;

/* typedef */

/* global variables */

int n;
int hsums[MAX_N], vsums[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i < n; i++) cin >> hsums[i];
    for (int i = 0; i < n; i++) cin >> vsums[i];
    sort(hsums, hsums + n);
    sort(vsums, vsums + n);

    int hmin = 0, hmax = n, hp0 = 0, hp1 = n - 1;
    int vmin = 0, vmax = n, vp0 = 0, vp1 = n - 1;
    bool changed = true;

    while (changed) {
      changed = false;

      while (hp0 <= hp1 && hsums[hp0] == hmin)
	hp0++, vmax--, changed = true;
      while (hp0 <= hp1 && hsums[hp1] == hmax)
	hp1--, vmin++, changed = true;

      if (hp0 <= hp1 && (hsums[hp0] < hmin || hsums[hp1] > hmax)) break;

      while (vp0 <= vp1 && vsums[vp0] == vmin)
	vp0++, hmax--, changed = true;
      while (vp0 <= vp1 && vsums[vp1] == vmax)
	vp1--, hmin++, changed = true;
	
      if (vp0 <= vp1 && (vsums[vp0] < vmin || vsums[vp1] > vmax)) break;
    }

    bool ok = (hp0 > hp1 && vp0 > vp1);
    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//幅優先探索
//全て添字で扱うこと
vll bfs(ll n, vector<vll> &next, ll start, ll goal) {
  queue<ll> task;
  task.push(start);
  queue<ll> task2;
  task2.push(goal);

  vll seen(n, 0);
  seen[start] = 1;
  vll seen2(n, 0);
  seen2[goal] = 1;

  while (1) {
    ll sz = task.size(), sz2 = task2.size();
    for (ll i = 0; i < sz; i++) {
      for (ll j = 0; j < next[task.front()].size(); j++) {
        if (seen[next[task.front()][j]] == 0 && seen2[next[task.front()][j]] == 0) {
          task.push(next[task.front()][j]);
          seen[next[task.front()][j]] = 1;
        }
        else if (seen[next[task.front()][j]] == 0) {
          return {task.front(), next[task.front()][j]};
        }
      }
      task.pop();
    }

    for (ll i = 0; i < sz2; i++) {
      for (ll j = 0; j < next[task2.front()].size(); j++) {
        if (seen[next[task2.front()][j]] == 0 && seen2[next[task2.front()][j]] == 0) {
          task2.push(next[task2.front()][j]);
          seen2[next[task2.front()][j]] = 1;
        }
        else if (seen2[next[task2.front()][j]] == 0) {
          return {next[task2.front()][j], task2.front()};
        }
      }
      task2.pop();
    }
  }
}

ll bfs2(ll n, vector<vll> &next, ll start, ll goal) {
  queue<ll> task;
  task.push(start);

  vll seen(n, 0);
  seen[start] = 1;
  seen[goal] = 1;

  ll cnt = 0;
  while (task.size() > 0) {
    for (ll j = 0; j < next[task.front()].size(); j++) {
      if (seen[next[task.front()][j]] == 0) {
        cnt++;
        task.push(next[task.front()][j]);
        seen[next[task.front()][j]] = 1;
      }
    }
    task.pop();
  }
  return cnt;
}

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

  vector<vll> nx(n, vll(0));
  for (ll i = 0; i < n - 1; i++) {
    ll a, b;
    cin >> a >> b;
    nx[a - 1].push_back(b - 1);
    nx[b - 1].push_back(a - 1);
  }

  vll v = bfs(n, nx, 0, n - 1);

  ll a = bfs2(n, nx, v[0], v[1]), b = n - a - 2;
  if (a > b) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  //cout << v[0] << " " << v[1] << endl;
  //cout << a << " " << b << endl;
}

Measured memory_bytes: 7680
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, rl().split())
    
    d = [0] * N
    for i in range(N):
        d[i] = A[i] + B[i]
    d.sort(reverse=True)
    
    ans = sum(d[::2]) - sum(B)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 44636
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

a,b,c = I()
print(a+b+c-max(a,b,c))

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  string new_s;
  for (int i = 0; i < s.length(); i++){
    if (s[i] + n > 90){
      new_s += 65 + ((s[i] + n) % 91);
    }else{
      new_s += s[i] + n;
    }
  }
  cout << new_s << endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int count[749];
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch - 'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch - 'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


Measured memory_bytes: 2672
const main = stdin => {
  const input = stdin.trim().split('\n')

  const [A, B] = input[0].split(' ').map(x => parseInt(x))
  if (Math.abs(A - B) > 1) {
    console.log(Math.max(A, B) + Math.max(A, B) - 1)
  } else {
    console.log(A + B)
  }
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30332
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		long mon = 100_000;
		for(int i = 0; i < n; i++){
			mon *= 1.05;
			if(mon % 1000 > 0){
				mon += 1000;
				mon -= mon % 1000;
			}
		}
		System.out.printf("%d\n", mon);
	}
}

Measured memory_bytes: 25836
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            double in = sc.nextDouble();
            if(in==-1.0) break;

            in = in * 2 * 2 * 2 * 2;
            if(in%1.0!=0){
                System.out.println("NA");
                continue;
            }

            String bit = Integer.toBinaryString((int)in);
            if(bit.length()>12){
                System.out.println("NA");
                continue;
            }

            String seisu = bit.substring(0, bit.length()-4);
            String syousu = bit.substring(bit.length()-4, bit.length());
            while(seisu.length()<8) seisu = "0" + seisu;

            System.out.println(seisu+"."+syousu);
        }
    }

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

Measured memory_bytes: 27976
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    ll N,M;cin>>N>>M;
    ll ans=0;
    ll p=min(N, M/2);
    M = M -p*2;
    ans+=p;
    ans = ans + M/4;
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;

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

  sort(a, a + N);
  ll x = 0, y = 0;
  for (int i = N - 1; i > 0; i--) {
    if (a[i] == a[i-1]) {
      if (x == 0) x = a[i];
      else if (y == 0) y = a[i];
      i--;
    }
  }

  cout << x * y << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,l,sum,mi=1e9,mx=-1e9;
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++){
		int z=l+i-1;
		sum+=z;
		if(z>0)mi=min(z,mi);
		else mx=max(mx,z);
	}
	if(abs(mx)<mi)printf("%d\n",sum-mx);
	else printf("%d\n",sum-mi);
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
words = []
ans = 0
pair = {}
N.times do
  words << gets.chomp.split('').sort.join("")
end
words.each do |w|
  if pair.has_key?(w)
    ans += pair[w]
    pair[w] += 1
  else
    pair[w] = 1
  end
end
puts ans

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

ll GCD(ll a, ll b)
{
	if (b == 0) return a;
	else return GCD(b, a%b);
}

int main(int argc, char **argv)
{
	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	vector<ll> right(n+1, 0), left(n+1, 0);
	for (int i = 0; i < n; ++i) left[i+1] = GCD(left[i], a[i]);
	for (int i = n; i >= 1; --i) right[i-1] = GCD(right[i], a[i-1]);

	ll res{0};
	for (int i = 0; i < n; ++i)
	{
		res = max(res, GCD(right[i+1], left[i]));
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int t,n,i,j,a,b,c,flag=1;
	cin>>n;
	while(n--)
	{
		cin>>a;
		if(a%2==0)
		{
			if(a%3!=0&&a%5!=0) 
			flag=0;
		}
	}
	if(flag) cout<<"APPROVED";
	else cout<<"DENIED";
 } 

Measured memory_bytes: 256
x,l=int(input()),[0]*1001;l[1]=1
for i in range(2,x+1):
  if l[i]==0:j=i*i
  while 1:
    if j>x:break
    else:l[j]=1;j*=i
for i in range(x,-1,-1):
  if l[i]==1:print(i);break

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N,M;
  cin >> N >> M;
  int s[M];
  char c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int st = 0;
  if (N >= 2) st = pow(10,N - 1);
  int ed = pow(10,N) - 1;
  int ans = -1;
  for (int i = st; i <= ed; i++) {
    bool O = true;
    for (int j = 0; j < M; j++) {
      string Q = to_string(i);
      if (Q[s[j] - 1] != c[j]) O = false;
    }
    if (O) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

LL n, a, b, k;
vector< pair<LL, LL> > dat;
int main() {
  GLL(n);
  GLL(k);
  FORN(i, n) {
    GLL(a);
    GLL(b);

    dat.PB(MP(a,b));
  }
  sort(dat.begin(), dat.end());

  LL cnt = 0;
  int i = 0;
  while (cnt < k) {
    cnt += dat[i].SS;
    i += 1;
  }

  printf("%lld\n", dat[i-1].FF);
    
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,x;
    cin>>n>>x;
    vector<int> v(n);
    for(int&i:v)cin>>i;
    
    int ans=abs(x-v[0]);
    
    for(int i=1; i<n; i++){
        ans=__gcd(ans, abs(x-v[i]));
    }

    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string.h>
using namespace std;
int main(void){
    int a , b , c ;
    cin >> a >> b >> c ;
    bool flag = false ;
    
    for(int i = 0 ; i <= b ; i++){
        if(a * i % b == c){
            flag = true ;
        }
    }

    if(flag == true){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
n=int(input());s=input()

a=0
i=0
j=1
while j<n:
    if s[i:j] in s[j:]:
        a=max(a,j-i)
        j+=1
    else:
        i+=1

    if i==j:
        i+=1
        j+=2
print(a)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
    int a,b,c,d,s=0,i,j;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++){
        d=i;
        c=0;
        while(d/10!=0){
            c+=d%10;
            c=c*10;
            d=d/10;
        }
        c+=d;
        if(i-c==0)
            s++;
    }
    printf("%d\n",s);
    return 0;
}

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

int main() {
  int N, K, R, S, P; string T;
  cin >> N >> K >> R >> S >> P >> T;
  int score = 0;
  bool win[N]; for (int i = 0; i < N; i++) win[i] = false;
  for (int i = 0; i < N; i++) {
    if (i < K || !win[i - K] || T[i] != T[i - K]) {
      win[i] = true;
      if (T[i] == 'r') score += P;
      else if (T[i] == 's') score += R;
      else score += S;
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
ll n,x;
cin >>n >> x;
vector<ll>a(n+1);
for(ll i=0;i<n;i++){
  cin >> a.at(i);
}
a.at(n)=x;
sort(a.begin(),a.end());
vector<ll>b(n);
for(ll i=1;i<n+1;i++){
  b.at(i-1)=abs(a.at(i-1)-a.at(i));
}
if(n==1){cout<<b.at(0)<<endl;return 0;}
for(ll i=1;i<n;i++){
  b.at(0)=gcd(b.at(0),b.at(i));
}
cout<< b.at(0)<<endl;
}







Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static class Worker implements Comparable<Worker>{
		int id;
		long result;
		int number;

		Worker (int id, long result, int number) {
			this.id = id;
			this.result = result;
			this.number = number;
		}

		public int compareTo(Worker x) {
			return this.number - x.number;
		}
	}

	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		Worker worker[];
		int n;
		int index;
		ArrayList<Worker> list;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			index = 0;
			list = new ArrayList<Worker>();
			worker = new Worker[4001];

			for (int i = 0; i < n; i++) {
				int id = sc.nextInt();
				long cost = sc.nextLong();
				long lots = sc.nextLong();
				if (worker[id] == null) {
					worker[id] = new Worker(id, cost * lots, index++);
				} else {
					worker[id].result += (cost * lots);
				}
			}

			for (int i = 0; i < 4001; i++) {
				if (worker[i] != null && 1000000 <= worker[i].result) {
					list.add(worker[i]);
				}
			}
			Collections.sort(list);
			if (list.isEmpty()) {
				System.out.println("NA");
			} else {
				for (Worker w: list) {
					System.out.println(w.id);
				}
			}
		}
	}
}

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

int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  int x=0,maxi=0;
  for(auto i:s)
  {  if(i=='D')
      x--;
    else
      x++;
    maxi = max(maxi,x);
    }
  cout<<maxi<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  cout << s.substr(0, 3) << "\n";

  return 0;
}

Measured memory_bytes: 3648
arange = input()

times = 0
bottom = arange.find("B")
white_pos = arange[bottom:].find("W") + bottom

while bottom != -1 and white_pos != -1:
  times += white_pos - bottom
  bottom += 1
  
  pos = arange[white_pos+1:].find("W")
  if pos == -1:
    break
  white_pos += pos + 1
  
print(times)

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

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        String[] mem = readLineStandardInput().split(" ");
        int A = Integer.parseInt(mem[0]);
        int B = Integer.parseInt(mem[1]);
        int C = Integer.parseInt(mem[2]);
        int X = Integer.parseInt(mem[3]);
        int Y = Integer.parseInt(mem[4]);
        int remainX = X;
        int remainY = Y;
        int totalCost = 0;
        int sumAB = A + B;
        int minXY = X < Y ? X : Y;
        if(sumAB > 2 * C){
            totalCost += C * 2 * minXY;
            remainX -= minXY;
            remainY -= minXY;
        }
        if(remainX != 0){
            if(A > 2 * C){
                totalCost += 2 * C * remainX;
            }
            else{
                totalCost += A * remainX;
            }
        }
        if(remainY != 0) {
            if(B > 2 * C) {
                totalCost += 2 * C * remainY;
            }
            else {
                totalCost += B * remainY;
            }
        }
        System.out.println(totalCost);
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
            System.out.println(e);
        }
        return str;
    }
}


Measured memory_bytes: 20948
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll h,n;
  cin>>h>>n;
  vector<ll> w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  ll dp[h+1];
  rep(i,h+1) dp[i]=1e11;
  dp[0]=0;
  rep(i,n) rep(j,h+1) chmin(dp[min(j+w[i],h)],dp[j]+v[i]);
  cout<<dp[h]<<endl; 
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
    double v, t, y;
    int N;
    
    while (scanf("%lf", &v) != EOF) {
        t = v / 9.8;
        y = 4.9 * t * t;
        N = (int)((y + 5) / 5) + 1;
        printf("%d\n", N);
    }

    return (0);
}

Measured memory_bytes: 628
from operator import itemgetter

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
    print(-1)
else:
    ab = []
    husoku = 0
    ans = 0
    for i in range(n):
        sa = a[i] - b[i]
        ab.append((a[i], b[i], sa))
        if sa < 0:
            husoku += sa
            ans += 1
    ab = sorted(ab, key=itemgetter(2), reverse=True)
    count = 0
    i = 0
    while i < n and count < -husoku:
        count += ab[i][2]
        i += 1
    print(i + ans)

Measured memory_bytes: 24500
#include <iostream>
#include <cstdio>
using namespace std;
double a[200005],qzh[200005];
int main(int argc, char** argv) {
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
		a[i]=(a[i]+1)/(double)2;
		qzh[i]=qzh[i-1]+a[i];
	}
	double ans=0;
	for(int i=k;i<=n;i++)
		ans=max(ans,qzh[i]-qzh[i-k]);
	printf("%.1000lf",ans);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1ll << 60;
static const ll MOD = 1e9 + 7;

signed main() {
  int N;
  cin >> N;
  vector<ll> T(N), A(N);
  rep(i, N) { cin >> T[i]; }
  rep(i, N) { cin >> A[i]; }

  if (A[0] != T[N - 1]) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1ll;
  for (int i = 1; i < N - 1; i++) {
    if (T[i] == T[i - 1] && A[i + 1] == A[i]) {
      ans *= min(T[i], A[i]);
      ans %= MOD;
    } else if (T[i] > T[i - 1] && A[i + 1] == A[i] && A[i] < T[i]) {
      ans = 0;
    } else if (T[i] == T[i - 1] && A[i + 1] > A[i] && A[i] > T[i]) {
      ans = 0;
    } else if (T[i] > T[i - 1] && A[i + 1] > A[i] && A[i] != T[i]) {
      ans = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        Integer[] a = new Integer[n];
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        
        Arrays.sort(a);
        
        List<Pair<Integer,Integer>> list = new ArrayList<Pair<Integer,Integer>>();
        
        for(int i = 0; i < m; i++){
            list.add(new Pair<>(sc.nextInt(), sc.nextInt()));
        }
        
        list.sort((x,y) -> y.getValue() - x.getValue());
        
        //一回変えたやつを変えるのは無駄
        
        int next = 0; //次ぎかえるもの
        
        for(Pair<Integer, Integer> pair : list){
            int b = pair.getKey(); //個数
            int c = pair.getValue(); //値

            for(int i = next; i < n; i++){
                if(b == 0){
                    next = i;
                    break;
                }
                
                if(a[i] < c){
                    a[i] = c;
                    b--;
                }else{
                    next = i;
                    break;
                }
            }
        }

        System.out.println(Arrays.stream(a).mapToLong(x -> (long)x).sum());
        
    }
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {
 
    public Pair(K key, V value) {
        super(key, value);
    }
 
    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }


class UnionFind {
	int[] par;
	
	public UnionFind(int n) {
		par = new int[n];
		
		Arrays.fill(par,-1);
	}
	
	int root(int x) {
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	
	void unite(int x,int y) {
	    x = root(x);
	    y = root(y);
	    
	    if(x != y){
	        if(par[x] > par[y]){
	            int tmp = x;
	            x = y;
	            y = tmp;
	        }
	        par[x] += par[y];
	        par[y] = x;
	    }
	}
	
	boolean same(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
	
	int size(int x){
		return -par[root(x)];
	}
}

Measured memory_bytes: 102868
a=[]
while True:
 n=input()
 if n.find('?')>0:break
 a.append(n)
for s in a:
 t=s.split()
 if t[1]=='/':
  print(int(t[0])//int(t[2]))
 else:
  b=eval(''.join(t))
  print(b)

Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10, mod = 200003;
int n,a[N];

struct cp{
	double x,y;
	cp(double _x=0,double _y=0){x=_x,y=_y;}
	inline cp operator + (const cp &p)const{
		return (cp){x+p.x,y+p.y};
	} 
	inline cp operator - (const cp &p)const{
		return (cp){x-p.x,y-p.y};
	}
	inline cp operator * (const cp &p)const{
		return (cp){x*p.x-y*p.y,x*p.y+y*p.x};
	}
	inline cp operator * (const double &p)const{
		return (cp){x*p,y*p};
	}
};

const double pi=acos(-1);
vector<int>pos;
vector<cp>w;
inline int init(int n){
	int lim=1,lg=0;
	while (lim<n) lim<<=1,++lg;
	pos.resize(lim),w.resize(lim);
	FOR(i,0,lim) pos[i]=(pos[i>>1]>>1)|((i&1)<<(lg-1));
	for (int i=1;i<n;i<<=1){
		w[i]=(cp){1,0};
		FOR(j,1,i) w[i+j]=(cp){cos(j*pi/i),sin(j*pi/i)};
	}
	return lim;
}
inline void DFT(vector<cp>&a,int n){
	a.resize(n);
	FOR(i,0,n) if (i<pos[i]) swap(a[i],a[pos[i]]);
	for (int i=1;i<n;i<<=1)
		for (int j=0;j<n;j+=i<<1)
			for (int k=0;k<i;k++){
				cp x=a[j+k],y=w[i+k]*a[i+j+k];
				a[j+k]=x+y,a[i+j+k]=x-y;
			}
}
inline void IDFT(vector<cp>&a,int n){
	DFT(a,n),reverse(&a[1],&a[n]);
	FOR(i,0,n) a[i].x=a[i].x/n+0.5;
}
inline vector<ll> Mul(vector<ll>x,vector<ll>y){
	int n=siz(x),m=siz(y),lim=init(n+m-1);
	vector<cp>A(n),B(m);
	FOR(i,0,n) A[i].x=x[i];
	FOR(i,0,m) B[i].x=y[i];
	DFT(A,lim),DFT(B,lim);
	FOR(i,0,lim) A[i]=A[i]*B[i];
	IDFT(A,lim);
	vector<ll>ans;
	FOR(i,0,n+m-1) ans.pb(A[i].x);
	return ans;
}

int p[N*2],f[N];

int main(){
	n=read();
	int g=2,now=g;
	p[0]=1;
	FOR(i,1,mod) f[now]=i,p[i]=now,now=1ll*now*g%mod;
	For(i,mod,mod*2) p[i]=1ll*p[i-1]*g%mod;
	vector<ll> A(mod);
	For(i,1,n) a[i]=read(),a[i]>0?A[f[a[i]]]++:0;
	vector<ll> B=Mul(A,A);
	FOR(i,0,mod) if (A[i]) B[i*2]-=A[i];
	ll ans=0;
	FOR(i,0,siz(B)) if (B[i]) ans+=B[i]*p[i];
	printf("%lld\n",ans/2);
}

Measured memory_bytes: 45324
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

def g(m, k):
    if k == 0:
        return 1
    if k == 1:
        return m * 9
    if k == 2:
        return m * (m-1) // 2 * 81
    if k == 3:
        return m * (m-1) * (m-2) // 6 * 729

@lru_cache(maxsize=None)
def f(n, k):
    if n == 0 and k:
        return 0
    if k == 0:
        return 1
    S = str(n)
    t = int(S[0])
    m = len(S)
    return f(int("0" + S[1:]), k-1) + ((t-1) * g(m-1, k-1) if t else 0) + g(m-1, k)

N = int(input())
K = int(input())
print(f(N, K))

Measured memory_bytes: 3572