akhauriyash/Code-Regression huggingface dataset:
s = gets.chomp
k = gets.chomp.to_i

q = s.split("")
=begin
l = q.map.with_index{|t, i| [t, i]}.sort{|a,b| a[0]<=>b[0]}
p l
z = l.select{|e| e[0] != "a"}.map{|t| ["z".ord - t[0].ord+1, t[1]]}

nxt = z[-1][0]
fix = []

while k - nxt >= 0
  s = z.pop
  k -= nxt
  fix << s[1]
  nxt = z[-1][0]
end
p z,fix,k

fix.each do |e|
  q[e] = "a"
end

s = z.pop
p q[s[1]] = ("z".ord - s[0] + k+1).chr
=end

q =q.map do |t|
 if "z".ord - t.ord  + 1 <= k && t != "a"
   k -= "z".ord - t.ord + 1
   "a"
 else
   t
 end
end
if k >0
  k = k % 26 
  #for i in 0..q.size-1
    q[-1] = (q[-1].ord + k).chr
    #k -= q[-1].ord 
    raise if q[-1].ord > "z".ord
  #end
end
puts q.join("")


Measured memory_bytes: 16252
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string a,b,out,tmp;
    cin >> a;
    cin >> b;
    //int m=max(a.size(),b.size());
    if(a.size()<b.size()){
      tmp=a;
      a=b;
      b=tmp;
    }
    //cout << a << endl;
    int si=-a.size()+b.size();
    for(int j=a.size()-1;j>=0;j--){
      if(j+si>=0){
	//cout << si << endl;
	a[j]+=b[j+si]-'0';
	//cout << a[j] << endl;
      }else{
	a[j]+=0;
	//cout << "!" << endl;
      }
      if(a[j]>'9'&&j!=0){
	a[j-1]++;
	a[j]-=10;
      }else if(a[j]>'9'&&j==0){
	a='1'+a;
	a[1]-=10;
	//for(int i=a.size();i>0;i--)
	//  a[i]=a[i-1];
	//a[1]-=10;
	//a[0]='1';
      }
    }
    if(a.size()>80)
      cout << "overflow" << endl;
    else
      cout << a << endl;
    //a='0';
  }

}

Measured memory_bytes: 1212
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void)
{
	int H,W;
	int i,j;

	while (1) {
		cin >> H;
		cin >> W;

		if ((H==0) && (W==0)) {
			break;
		}

		for (i = 0; i < H; i++) {
			for ( j = 0; j < W; j++) {
				if ((i>0) && (i<(H-1)) && (j>0) && (j<(W-1))) {
					cout << ".";
				}
				else {
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>

int aux(int,int,int,int,int);

int main(void){
    int p,q,a,n;

    while(scanf("%d %d %d %d",&p,&q,&a,&n),p,q,a,n)
      printf("%d\n",aux(1,p,q,a,n));

  return 0;
}

int aux(int last,int P,int Q,int A,int N){
  int count=0,y;
  if(P==0)return 1;
  if(N<=0)return 0;

  for(y=last;y<=A;y++)
    if(Q<=y*P)count+=aux(y,P*y-Q,Q*y,A/y,N-1);

  return count;
}

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


int main(){
    ios_base::sync_with_stdio(0);
    int N; // ile jest monetek
    vector <vector <long double> > DP; //jakie jest prawdopodobienstwo, ze bede miala dokladnie i orzelkow

    cin >> N;
    vector <long double> P;
    P.resize(N+1);
    DP.resize(N+1, vector <long double>(N/2 + 1, 0));
    // DP[i][j] i = ile rzutow j = ile orzelkow
    for (int i = 1; i <= N; i++){
        cin >> P[i];
    }
    DP[0][0] = 1;
    for (int i = 1; i <= N; i++){
        DP[i][0] = DP[i-1][0]*(1 - P[i]);
        for (int j = 1; j <= (N)/2; j++){
            DP[i][j] = DP[i-1][j]*(1 - P[i]) + DP[i-1][j-1]*P[i];
        }
    }

    // for (auto v : DP){
    //     cerr << "-----------------\n";
    //     for (auto co : v){
    //         cerr << co << " ";
    //     }
    // }
    // cerr << "--------------\n";
    long double Res = 0;
    vector <long double> R = DP.end()[-1];
    for (auto co : R){
        Res += co;
    }
    // cerr << "=====\n";
    
    cout << fixed << setprecision(11) << 1 - Res;

}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int n,m;
    cin >> n >> m;
    
   int sum = 0;
    int x;
    
    f(i,m)
    {
        cin >> x;
        sum+=x;
    }
    
    if(n < sum) cout << -1;
    else cout << n - sum;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3664
#include <iostream>

int main()
{
	int S;
	int h, m, s;

	std::cin >> S;
	if (S < 0 || S > 86400) return 0;

	h = S / (60 * 60);
	m = (S % (60 * 60)) / 60;
	s = (S % (60 * 60)) % 60;
	std::cout << h << ":" << m << ":" << s << std::endl;

	return 0;
}


Measured memory_bytes: 3088
N = int(input())

X = [None] * N
Y = [None] * N
H = [None] * N

x_max = 0
y_max = 0
h_max = 0
R = []

for n in range(N):
    X[n], Y[n], H[n] = map(int, input().split())
    if h_max <= H[n]:
        x_max, y_max, h_max = X[n], Y[n], H[n]

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True
        for n in range(N):
            if H[n] != 0:
                ch = H[n] + abs(X[n] - cx) + abs(Y[n] - cy)
        for n in range(N):
            if max(ch - abs(X[n] - cx) - abs(Y[n] - cy), 0) != H[n]:
                flag = False
                break
        if flag == True:
            R.append([cx, cy, ch])

print(R[0][0], R[0][1], R[0][2])


Measured memory_bytes: 3192
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,W = inpl()
wvs = [inpl() for _ in range(N)]
dp = [INF]*(10**5+5)
dp[0] = 0

for w,v in wvs:
    for i in reversed(range(10**5+5)):
        dp[i] = min(dp[i-v] + w,dp[i])
        if i == v:
            break
ans = 0
for i in range(10**5+5):
    if dp[i] <= W:
        ans = i

print(ans)


Measured memory_bytes: 117320
#include<bits/stdc++.h>
using namespace std;
long long  n,a[200005];
bool cmp(long long x, long long y)
{
	return x > y;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	    scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp );
	long long sum=0;
	for(int i=2;i<=(n-2)/2+1;++i)
	   sum+=2*a[i];
	sum+=a[1];
	if(n%2 ) sum+=a[(n-2)/2+2];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 5300
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PPQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define MOD 1000000007
using namespace std;
//
int N;
int main(){
  cin>>N;
  if(N%1000%111==0) cout<<"Yes"<<endl;
  else if(N/10%111==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int ans=0;
  int i=0;
  bool flag=true;
  while(i<N){
    if(flag){
      ans++;
      flag=false;
      i++;
    }else{
      if(S.at(i-1)!=S.at(i)){
        ans++;
        i++;
      }else{
        if(i==N-1){
          i++;
          continue;
        }
        ans++;
        flag=true;
        i+=2;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int n,m,i,j,x,a;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		a=0;
		scanf("%d",&m);
		for(i=n;i<=m;i++){
			x=i;
			while(x%2==0)x=x/2;
			while(x%3==0)x=x/3;
			while(x%5==0)x=x/5;
			if(x==1)a++;
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 408
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
    int minn=min(min(min(min(a,b),c),d),e);
  int maxx=max(max(max(max(a,b),c),d),e);
  if(maxx-minn<=k)cout<<"Yay!";
    else cout<<":(";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

int N, M;
int C[20];
int dp[50001][21];

int main() {
	cin >> N >> M;
	rep(i, M) cin >> C[i];

	rep(i, N+1) dp[i][0] = INFTY;
	dp[0][0] = 0;

	rep(m, M){
		int c = C[m];
		int mm = m+1;
		rep(i, N+1){
			if(i < c) dp[i][mm] = dp[i][mm-1];
			else{ dp[i][mm] = min(dp[i][mm-1], dp[i-c][mm]+1); }
		}
	}

	cout << dp[N][M] << endl;
}

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

#define ff first
#define ss second
#define maxn 2000006
#define pb push_back
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)

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

using namespace std;

vll gr[maxn];
vll parent(maxn);
vll counter(maxn);

void dfs(ll src) {

	for (auto child : gr[src]) {
		parent[child] = src;
		dfs(child);
	}

	return;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	ll n, q; cin >> n >> q;

	ll t = n;

	while (--t) {
		ll a, b; cin >> a >> b;
		gr[a].pb(b);
	}

	// f(i, 1, n) {
	// 	cout << i << "-->> ";
	// 	for (auto j : gr[i]) cout << j << ", ";
	// 	cout << endl;
	// }

	parent[1] = 0;

	dfs(1);

	while (q--) {
		ll p, x; cin >> p >> x;
		counter[p] += x;
	}

	f(i, 1, n) {
		counter[i] += counter[parent[i]];
	}

	f(i, 1, n) cout << counter[i] << " ";

	return 0;
}

Measured memory_bytes: 93056
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int a,b;

int main(){
    cin>>a>>b;
    int d=b-a;
    int sum=0;
    for(int i=1;i<=d-1;i++){
        sum+=i;
    }
    cout<<sum-a<<endl;
    return 0;
}

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

public class Main {
	public static int f(int a) {
		if(a%2 == 0) {
			return a/2;
		}else {
			return 3*a+1;
		}
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int index;
		sc.close();
		ArrayList<Integer> data  =new ArrayList<Integer>();
		while(true) {
			index = data.indexOf(s);
			data.add(s);
			if(index == -1) {
				s = f(s);
			}else {
				break;
			}
		}
		System.out.println(data.size());
	}
}


Measured memory_bytes: 22868
// インクルード(GCC only)
#include <bits/stdc++.h>

// 長い型名
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

// 省略記法
#define INF 1e9
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n), i=(i##_len-1); i>=0; ++i)
#define FOR(i,m,n) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sizei(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// デバッグ用
#ifdef LOCAL
    #define print(...) fprintf(stderr, __VA_ARGS__)
    #define printarray(x) rep(i,sizei(x)){cout << x[i] << endl;}
#else
    #define print(...) 42
    #define printarray(x) 42
#endif

#define SIZE 1000

int main(void)
{
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vector<LL> A(X), B(Y), C(Z);
  rep(i, X) cin >> A[i];
  rep(i, Y) cin >> B[i];
  rep(i, Z) cin >> C[i];

  // method 1
  // vector<LL> E;
  // rep(i, X) {
  //   rep(j, Y) {
  //     E.push_back(A[i] + B[j]);
  //   }
  // }
  // sort(all(E), greater<LL>());
  // sort(all(C), greater<LL>());
  //
  // vector<LL> ANS;
  // rep(i, min(X*Y, K)) {
  //   rep(j, min(Z, K)) {
  //     ANS.push_back(E[i] + C[j]);
  //   }
  // }
  // sort(all(ANS), greater<LL>());
  // printarray(ANS);
  //
  // rep(i, min(X*Y*Z, K)) {
  //   cout << ANS[i] << endl;
  // }

  // method 2
  sort(all(A), greater<LL>());
  sort(all(B), greater<LL>());
  sort(all(C), greater<LL>());

  vector<LL> ANS;

  rep(i, X) {
    rep(j, Y) {
      rep(k, Z) {
        if ((i + 1)*(j + 1)*(k + 1) <= K) ANS.push_back(A[i] + B[j] + C[k]);
        else break;
      }
    }
  }

  sort(all(ANS), greater<LL>());

  rep(i, K) {
    cout << ANS[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 1404
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL A, B;
	cin >> A >> B;
	cout << A * B << "\n";
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a[3];for(int i=0;i<3;i++)cin>>a[i];
   sort(a,a+3);
   int l=2*a[2]-(a[1]+a[0]);
   cout<<(l%2?(l+3)/2:l/2);
   
}

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

int main(){
	string d,e,f;
	char turn='a';
	cin>>d>>e>>f;
	vector<char>a,b,c;
	for(int i=d.size()-1;i>=0;i--){
		a.push_back(d[i]);
	}
	for(int i=e.size()-1;i>=0;i--){
		b.push_back(e[i]);
	}
	for(int i=f.size()-1;i>=0;i--){
		c.push_back(f[i]);
	}
	for(;;){
		if(turn=='a'){
			if(a.size()==0){
				cout<<'A'<<endl;
				return 0;
			}
			else{
				turn=a.at(a.size()-1);
			}
			a.pop_back();
		}
		if(turn=='b'){
			if(b.size()==0){
				cout<<'B'<<endl;
				return 0;
			}
			else{
				turn=b.at(b.size()-1);
			}
			b.pop_back();
		}
		if(turn=='c'){
			if(c.size()==0){
				cout<<'C'<<endl;
				return 0;
			}
			else{
				turn=c.at(c.size()-1);
			}
			c.pop_back();
		}
	}
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (2 * ab[i, :-c] + ab[i, c:]) % 998244353
        ab[i + 1, -c:] = (2 * ab[i, -c:] + ab[i, m]) % 998244353
    return ab[N, 0]


def func1():
    ab = np.zeros((N + 1, m1), dtype='int64')
    ab[0, m] = 1
    for i in range(N):
        c = a[i]
        ab[i + 1, :-c] = (ab[i, :-c] + ab[i, c:]) % 998244353 
        ab[i + 1, -c:] = ab[i, -c:]
    return ab[N, 0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Measured memory_bytes: 118256
#include <algorithm>
#include <stack>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()

string L;
bool input() {
    getline(cin, L);
    return L != ".";
}

bool Check() {
    stack<char> s;
    for (string::iterator i = L.begin(); i != L.end(); i++) {
        switch (*i) {
            case '(': 
                s.push(*i); 
                break;
            case ')': 
                if (s.empty() || s.top() != '(') return false;
                s.pop();
                break;
            case '[': 
                s.push(*i); 
                break;
            case ']':
                if (s.empty() || s.top() != '[') return false;
                s.pop();
                break;
        }
    }
    return s.empty();
}

void solve() {
    cout << (Check() ? "yes" : "no") << endl;
}

int main() {
    while (input()) solve();
    return 0;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
  ll N,ans,a=1,b=1,c=1;
  cin >> N;
  rep(i,N){
    a = (a*10)%MOD;
  }
  rep(i,N){
    b = (b*8)%MOD;
  }
  rep(i,N){
    c = (c*9)%MOD;
  }
  c=(c*2)%MOD;
  ans = mod((a+b)%MOD - (c%MOD), MOD);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int X, Y;
    cin >> X >> Y;
    cout << X + Y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a[3],  b[3], sum=0;
  for(int i = 0; i < 3; i++) {
    cin >> a[i] >> b[i];
    sum += (a[i] + b[i]);
  }
  if(sum == 15) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int t;
  int h;
  int m;
  int s;
  int c;
  std::cin >> t;
  h = t/3600;
  c = t-h*3600;
  m = c/60;
  s = c - m * 60;
  std::cout << h << ":" << m << ":" << s << std::endl;

  return 0;
}



Measured memory_bytes: 3088
import sys

line = sys.stdin.readline()
a = [ i for i in map(int, line.strip().split()) ]
b = abs(a[0] - a[1])
c = abs(a[1] - a[2])
d = abs(a[0] - a[2])
e = b + c
f = c + d
g = d + b
print(min(e,f,g))


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	int a,b,c,d,cnt=0;
	cin >> a >> b >> c >> d;
	
	
	for(int i=0;i<3001;i++){
		
		for(int j=0;j<3001;j++){
			
			if(d-(a*i+b*j) >=0 && (d-(a*i + b*j))%c == 0) cnt++;
			
			if((a*i + b*j) >= d)break;
		}
	}
	
	
	cout << cnt << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static boolean[][] map;
	static int[][] directions= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int ans = 0;
	static int[] nextSquare;
	static int w;
	static int h;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {

			 w = sc.nextInt();
			 h = sc.nextInt();

			if((w|h)==0) {
				break;
			}
			ans =0;

			map = new boolean[h][w];

			for(int i = 0; i < h; i++) {
				for(int j= 0; j < w; j++) {
					//陸ならtrue, 海ならfalse
					map[i][j] = (sc.nextInt() == 1);
				}
			}

			for(int i = 0; i < h; i++) {
				for(int j= 0; j < w; j++) {
					//左上から島を数える
					if(map[i][j]) {
						ans++;
						int[] nowSquare = {i,j};
						walkAround(nowSquare);
					};
				}
			}
			System.out.println(ans);
		}
	}

	static void walkAround(int[] nowSquare) {
		int nowH = nowSquare[0];
		int nowW = nowSquare[1];

		if(nowH <0 || nowH >= h || nowW < 0 || nowW >=w) {
			return;
		}

		if(map[nowH][nowW]==false) {
			return;
		}
		map[nowH][nowW] = false;
		for(int i = 0; i < 8; i++) {
			nextSquare = addArrayElms(nowSquare,directions[i]);
			walkAround(nextSquare);
		}


	}

	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}
}



Measured memory_bytes: 47088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const long long int MOD = 1000000007;
const int INF = 1000000000;

string s,t;

int main(){
    cin >> s >> t;
    for(int i = 0; i < 2; i++){
        int now = 0;
        bool ok = true;
        for(int j = i; j < s.size(); j += 2){
            if(now >= t.size()){
                ok = false;
                break;
            }
            while(t[now] != s[j]){
                now++;
                if(now == t.size()){
                    ok = false;
                    break;
                }
            }
            now++;
            if(!ok) break;
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

int main() {
    long long n, m;
    cin >> n >> m;

    if(n == 1 && m != 1) cout << m - 2 << endl;
    else if(n != 1 && m == 1) cout << n - 2 << endl;
    else if(n == 1 && m == 1) cout << 1 << endl;
    else cout << (n - 2) * (m - 2) << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets
v = [false] * 8
m = 0
gets.chomp.split(' ').map(&:to_i).each do |x|
  if x < 3200
    v[x / 400] = true
  else
    m += 1
  end
end

k = v.select {|b| b}.size
mn = [1, k].max
mx = k + m  # fuck
puts "#{mn} #{mx}"


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    ll sum = 0, s = 0;
    int ans = 0, cnt = 0;
    rep(i,n) cin >> a[i];
    vector<int> d;
    rep(i,n) { 
        cin >> b[i]; 
        if(a[i] > b[i])  { 
            d.push_back(a[i]-b[i]);
            s+=a[i]-b[i];
        }
        if(b[i] > a[i]) {
            sum+=b[i]-a[i];
            cnt++;
        }
    }
    if(s < sum) { cout << -1 << endl; return 0;}
    sort(all(d));
    reverse(all(d));
    ans = cnt;
    rep(i,d.size()) {
        if(sum<=0) break;
        sum-=d[i];
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4380
def main():
    S = input()
    num = S.count('S')
    if num==3:
        print('0')
    if num==2: 
        print('1')
    if num==1:
        if S[1]=='S':
            print('1')
        else:
            print('2')
    if num==0:
        print('3')
        


if __name__ == "__main__":
    main()


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

const int MAX_N = 2e5+10;
int a[MAX_N];
int N;

void solve()
{
    vector<int> b;
    for(int i=0;i<N;++i)b.push_back(a[i]);
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    for(int i=0;i<N;++i){
        if(a[i] == b[0]) cout << b[1] << "\n";
        else cout << b[0] << "\n";
    }
}

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

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
// Addition and Subtraction Easy
int main() {
  int a, b, x;
  char c;
  cin >> a >> c >> b;

  if (c == '+') {
    x = a + b;
  } else if (c == '-') {
    x = a - b;
  }

  cout << x << endl;
}

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

int main()
{

  long long N,D;
  cin >> N >> D;
  
  int count =0;
  
  vector<long long> X(N),Y(N);
  for(int i=0;i<N;i++)
  {
    cin >> X[i] >> Y[i];
    if( X[i]*X[i] + Y[i]*Y[i] <= D*D)
      count++;      
  }
  
  cout << count <<endl;
  
  return 0;
}

Measured memory_bytes: 6420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        final byte h = Byte.parseByte(tok.nextToken());
        final byte w = Byte.parseByte(tok.nextToken());

        char[][] mat = new char[h][w];
        boolean[] row = new boolean[h];
        boolean[] col = new boolean[w];

        for (byte i = 0; i < h; i++) {
            String str = br.readLine();
            for (byte j = 0; j < w; j++) {
                char c = str.charAt(j);
                mat[i][j] = c;
                if (c == '#') {
                    row[i] = true;
                    col[j] = true;
                }
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        for (byte i = 0; i < h; i++) {
            if (!row[i]) continue;
            for (byte j = 0; j < w; j++) {
                if (col[j]) {
                    out.print(mat[i][j]);
                }
            }
            out.print("\n");
        }
        out.flush();
    }
}


Measured memory_bytes: 21460
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, H[112345];

int main() {

	scanf("%d", &N);
	rep(i, N) scanf("%d", &H[i]);

	rep(i, N) {
		if (!i) H[i]--;
		else {
			if (H[i - 1] <= H[i]) {
				if (H[i - 1] < H[i]) H[i]--;
			}
			else {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int n,h,max = 1;
		n = sc.nextInt();
		h = sc.nextInt();

		long count = 0;
		Integer a[] = new Integer[n]; //何回でも
		Integer b[] = new Integer[n]; //一回だけ

		for(int i = 0; i < n; i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
		}

		for(int i = 0; i < n; i++) {
			max = Math.max(max,a[i]); //aのうち最大
		}

		Arrays.sort(b,Collections.reverseOrder());


		for(int i = 0; i < n && h > 0; i++) {
			if(b[i] >= max) {
				h -= b[i];
				count++;
			}else {
				break;
			}
		}

		if(h > 0) {

		count += Math.ceil(h/(double)max);
		}
		System.out.println(count);
	}


}


Measured memory_bytes: 86816
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =3001;
const int MOD =998244353;

  
  
signed main(){
  int k;
  cin>>k;
  while(k%2==0)k/=2;
  while(k%5==0)k/=5;
  if(k==1){
    cout<<1<<endl;
    return 0;
  }
  int d[k];
  fill(d,d+k,MOD);
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
  d[1]=1;
  que.push({1,1});
  while(!que.empty()){
    pair<int,int>p=que.top();
    que.pop();
    if(d[p.second]<p.first)continue;
    if(d[(p.second+1)%k]>p.first+1){
      d[(p.second+1)%k]=p.first+1;
      que.push({ d[(p.second+1)%k], (p.second+1)%k});
    }
    if(d[(p.second*10)%k]>p.first){
      d[(p.second*10)%k]=p.first;
      que.push({d[(p.second*10)%k],(p.second*10)%k});
    }
  }
  cout<<d[0]<<endl;
  return 0;


}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007

using namespace std;


int main(){

	/*data[i]: iに対して、小さい数*/
	map<lli,lli> data;
	map<lli,lli> before;

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	for(lli i=0;i<n;i++){
		for(lli j=0;j<n;j++){
			if(i==j)continue;
			if(a[i]>a[j]){
				if(i>j){
					before[i]++;
				}
				data[i]++;
			}
		}
	}

	lli sum=0;

	for(lli i=0;i<n;i++){
		if(k%2==0){
			sum += (before[i] * (k/2))%MOD * (k-1);
			sum %= MOD;

			sum += ((data[i]-before[i]) * (k/2))%MOD *(k+1);
			sum %= MOD;
		}
		else{
			sum += ((before[i] * k)%MOD) * ((k-1)/2);
			sum %= MOD;

			sum += ((data[i]-before[i]) *k)%MOD *(k+1)/2;
			sum %= MOD;
		}
	}
	cout<<sum%MOD<<endl;
	return 0;

}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	fill(kinds, kinds + 200001, INF);
	int n, k;
	cin >> n >> k;
	rep(i, n) {
		cin >> A[i];
		if (kinds[A[i]] == INF) kinds[A[i]] = 1;
		else kinds[A[i]]++;
	}
	sort(kinds, kinds + 200001);
	sort(A, A + n);
	int kind = 1;
	for (int i = 1; i < n; ++i) {
		if (A[i] > A[i - 1]) kind++;
	}
	if(kind<=k) cout << 0 << endl;
	else {
		rep(i, kind - k) {
			ans += kinds[i];
		}
		cout << ans << endl;
	}
	cin >> qqq;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout << (x) << endl;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    if (K == 1) {
        cout << 0 << endl;
    }
    else {
        cout << N - K << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	vector <char> N(4);
	vector <int> C(4);
	int i,j=0;
	cin >> N.at(0) >> N.at(1) >> N.at(2) >> N.at(3);
	for(i = 0;i < 4;i++) {
		C.at(i) = 0;
	}
	for(i = 0;i < 4;i++) {
		if(N.at(i) == '1') C.at(0) = 1;
		if(N.at(i) == '9') C.at(1) = 1;
		if(N.at(i) == '7') C.at(2) = 1;
		if(N.at(i) == '4') C.at(3) = 1;
	}
	if(C.at(0)==1 && C.at(1)==1 && C.at(2)==1 && C.at(3)==1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


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

using namespace std;
#define lint long long


int main() {
    string s;
    cin >> s;
    
    string t = "CODEFESTIVAL2016";
    int cnt = 0;
    for(int i = 0; i < 16;++i){
        if(s[i] != t[i]){
            ++cnt;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=50+5;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
    {
        return gcd(m%n,n);
    }
}
map<string,int>mp;
string s[N];
int x[N];
int pre[N];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i]>>x[i];
        mp[s[i]]=i;
    }
    string y;
    cin>>y;
    for(int i=1;i<=n;i++)
    {
        pre[mp[s[i]]]=pre[mp[s[i]]-1]+x[i];
    }
    cout<<pre[n]-pre[mp[y]]<<endl;

    
 
    
    
 
 
}

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

int main(){

        int colors[8][3] = {
                {0, 0, 0},
                {0, 0, 255},
                {0, 255, 0},
                {0, 255, 255},
                {255, 0, 0},
                {255, 0, 255},
                {255, 255, 0},
                {255, 255, 255}
        };

        char* colornum[8] = {
                "black",
                "blue",
                "lime",
                "aqua",
                "red",
                "fuchsia",
                "yellow",
                "white"
        };

        while(1){
                char code[8];
                scanf("%s", code);
                if(code[0]=='0') break;

                int i, j, rgb[] = {0, 0, 0};
                for(i=1; i<7; i++){
                        if('0'<=code[i] && code[i]<='9') rgb[(i-1)/2] += (code[i]-'0')*(1+15*(i%2));
                        else rgb[(i-1)/2] += (10+code[i]-'a')*(1+15*(i%2));
                }

                int minidx = 7;
                double mn = 1e11;
                for(i=7; i>=0; i--){
                        double d = 0;
                        for(j=0; j<3; j++) d += (rgb[j]-colors[i][j])*(rgb[j]-colors[i][j]);
                        d = sqrt(d);
                        if(d<mn){
                                mn = d;
                                minidx = i;
                        }
                }

                printf("%s\n", colornum[minidx]);
        }
        return 0;
}


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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef std::vector<ll> vec;
int n;
vec v;
ll ans;
inline void solve(vec & x) {
	ll v = x.back() - n; x.pop_back();
	for(ll & i : x) ++ i;
	x.insert(std::lower_bound(x.begin(), x.end(), v), v);
	++ ans;
}
inline ll _try(vec x) {
	for(int i = 0;i < x.size();++i) {
		ll v = x.back() - n; x.pop_back();
		for(ll & i : x) ++ i;
		if(x.size() && v > x.front()) return -1e18;
		x.insert(x.begin(), v);
	}
	return x.front();
}
inline void big_do(vec & x) {
	for(int j = 0;j < n;++j) {
		// std::cout << (j ? x[j - 1] : 0) + n - j << ' ' <<  _try(vec(x.begin() + j, x.end())) << std::endl;
		if((j ? x[j - 1] : 0) + n - j <= _try(vec(x.begin() + j, x.end()))) {
			const int pre_add = n - j, suf_dec = n - pre_add + 1;
			const ll cnt = (x[j] - (j ? x[j - 1] : 0)) / (pre_add + suf_dec);
			if(pre_add * j - suf_dec * (n - j) != -(n - j)) exit(1);
			ans += cnt * pre_add;
			for(int i = 0;i < j;++i) x[i] += pre_add * cnt;
			for(int i = j;i < n;++i) x[i] -= suf_dec * cnt;
			break;
		}
	}
}
const int S = 50;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) {
		ll x; cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for(;;) {
		if(*std::max_element(v.begin(), v.end()) < n) break;
		static int cnt = 0;
		++cnt % 2 ? big_do(v) : solve(v);
	}
	cout << ans << '\n';
}


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

using namespace std;
typedef long long ll;

const int maxn=2e5+5;

ll a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll uk=0;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(i%2){
			uk^=a[i]^a[i-1];
		}
	}
	for(int i=0; i<n; i++){
		cout << (uk^a[i]) << " ";
	}
	cout << '\n';
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int count = 0;
    for(int i = a; i <= b; ++i){
        int tmp = i;
        int reverse = 0;
        while(tmp != 0){
            int b = tmp % 10;
            reverse = reverse * 10 + b;
            tmp /= 10;
        }
        if(i == reverse) count++;
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  int N_num, sum=0;
  string N;
  cin >> N;

  N_num = atoi(N.c_str()); 
//  cout << N_num << endl;
//  cout << N << endl;
//  cout << N[0] << endl;
//  cout << N[1] << endl;

  for(int i=0; i < N.size(); i++ ){
    int A = N[i]-'0';
    sum += A;
//    cout << sum << endl;
  }
  if(N_num%sum==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n ; cin >> n ;
	vi v(n); re(v);
	vi tmp = v;
	sort(all(tmp));
	int a = tmp[n/2];
	int b = tmp[n/2-1];
	trav(i,v){
		if(i<=b) cout << a << endl ;
		else cout << b << endl;
	}
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 6280
a,b = map(int,input().split())
mod = 10**9+7
x = (2*a-b)//3
y = (2*b-a)//3

if (2*a-b)%3 != 0 or (2*b-a)%3 != 0 or 2*b < a or 2*a < b or (a+b)%3 != 0:
    print(0)
    exit()

def comb(n,r):
    fact = 1
    invfact = 1
    for i in range(r):
        fact *= n-i
        fact %= mod
        invfact *= i+1
        invfact %=mod
    return fact*pow(invfact,mod-2,mod)%mod

print(comb(x+y,y))

Measured memory_bytes: 9004
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <limits>

using namespace std;
using ll = long long;

int N;

ll func(const vector<ll>& a, ll b)
{
    ll res = 0;

    for(int i = 0; i < N; ++i) {
        res += abs(a[i] - b);
    }

    return res;
}

int main()
{
    cin >> N;

    vector<ll> a;

    for(int i = 0; i < N; ++i) {
        ll ai;
        cin >> ai;
        a.emplace_back(ai - (i+1));
    }

    sort(begin(a), end(a));

    ll b;

    if(N % 2 == 0) {
        b = (a[N / 2 - 1] + a[N / 2]) / 2.0;
    } else {
        b = a[N / 2];
    }

    ll ans1 = func(a, b - 1);
    ll ans2 = func(a, b - 0);
    ll ans3 = func(a, b + 1);

    ll ans = min(ans1, min(ans2, ans3));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    int x,y;
      set<int> possible;
      for(int i=1;i<=9;i++){
      for(int j=1;j<=9;j++){
      possible.insert(i*j);
      }
      }
      
      cin >> x;
      if(possible.count(x)==1) cout << "Yes";
      else cout << "No";
      return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<vector<int> > dp(H + 1, vector<int>(W, 0)); dp[0][0] = 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			for (int k = 0; k < 1 << (W - 1); ++k) {
				// Check if two horizontal lines are connecting
				// 2 つの横線がつながっていないか調べる
				bool ok = true;
				for (int l = 0; l < W - 2; ++l) {
					if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
						ok = false;
					}
				}
				if (ok) {
					if (j >= 1 && ((k >> (j - 1)) & 1)) {
						// The case which goes left
						// 左方向に横線をたどるケース
						dp[i + 1][j - 1] += dp[i][j];
						dp[i + 1][j - 1] %= MOD;
					}
					else if (j <= W - 2 && ((k >> j) & 1)) {
						// The case which goes right
						// 右方向に横線をたどるケース
						dp[i + 1][j + 1] += dp[i][j];
						dp[i + 1][j + 1] %= MOD;
					}
					else {
						// The case which goes straight
						// 横線をたどらないケース
						dp[i + 1][j] += dp[i][j];
						dp[i + 1][j] %= MOD;
					}
				}
			}
		}
	}
	cout << dp[H][K - 1] << '\n';
	return 0;
}


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

a = int(input())
l = [list(input().split()) for i in range(a)]
b = input()
c = 0
ll = []

for _,i in enumerate(l):
  if b == i[0]:
    c += 1
    break
  c += 1

del l[0:c]
for i in l:
    ll.append(i[1])

lll = [int(s) for s in ll]
print(sum(lll))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
using namespace std;

const int N = 2e5;
const int P = 998244353;
llong fact[N*4+3],finv[N*4+3];
char sa[N+3],sb[N+3],sc[N+3],sd[N+3];

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}
llong comb(llong x,llong y) {return x<0 || y<0 || x<y ? 0ll : fact[x]*finv[y]%P*finv[x-y]%P;}

llong solve(int n,int m,char s1[],char s2[],char s3[],char s4[])
{
	int cnt1 = 0,cnt2 = 0,cnt3 = 0,cnt4 = 0,cur3 = 0,cur4 = 0;
	for(int i=1; i<=n; i++) {cnt1 += s1[i]=='1',cnt2 += s2[i]=='1';}
	for(int i=1; i<=m; i++) {cnt3 += s3[i]=='1',cnt4 += s4[i]=='1';}
	llong tmp = 1ll;
	llong ret = 0ll;
	for(int i=1; i<=m; i++)
	{
		cur3 += s3[i]=='1'; cur4 += s4[i]=='1';
		if(s3[i]=='1' || s4[i]=='1')
		{
			if(s3[i]=='1' && s4[i]=='1') {tmp = tmp*2ll%P;}
			if(cnt2!=0) {ret = (ret+tmp*comb(cnt3+cnt2+cnt4-cur3-cur4-1,cnt2-1))%P;}
			else {ret = (ret+tmp*(cnt3+cnt4-cur3-cur4==0))%P;}
			if(cnt1!=0) {tmp = (tmp+comb(cur3+cur4+cnt1-1,cnt1-1))%P;}
			else {tmp = (tmp+(cur3+cur4==0))%P;}
		}
	}
	return ret;
}

int main()
{
	int n,m;
	fact[0] = 1ll;
	for(int i=1; i<=N*4; i++) fact[i] = fact[i-1]*i%P;
	finv[N*4] = quickpow(fact[N*4],P-2);
	for(int i=N*4-1; i>=0; i--) finv[i] = finv[i+1]*(i+1)%P;
	scanf("%d%d",&n,&m);
	scanf("%s%s%s%s",sa+1,sb+1,sc+1,sd+1);
	bool gg = false;
	for(int i=1; i<=n; i++) if(sa[i]=='1' || sb[i]=='1') gg = true;
	for(int i=1; i<=m; i++) if(sc[i]=='1' || sd[i]=='1') gg = true; 
	if(gg==false) {printf("1"); return 0;}
	llong ans = 0ll;
	ans += solve(n,m,sa,sb,sc,sd);
	ans += solve(m,n,sc,sd,sa,sb);
	ans %= P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 13056
import sys

N = int(input())
tasks = sorted([list(map(int,input().split())) \
        for _ in range(N)],key = lambda x:(x[1]))
time = 0

for i in range(N) :
    time += tasks[i][0]
    if time > tasks[i][1] :
        print("No")
        sys.exit()

print("Yes")





Measured memory_bytes: 55264
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#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
// utility
#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 T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N, M;
  string s;
  cin >> N >> M >> s;
  
  reverse(ALL(s));
  int now = 0;
  vector<int> ans;
  while(now < N+1){
    if(now+M+1 >= N+1){
      ans.push_back(N-now);
      break;
    }
    RREP(i, M+1){
      if(i == 0){
        cout << -1 << endl;
        return 0;
      }
      if(s[now+i] == '0'){
        ans.push_back(i);
        now += i;
        break;
      }
    }
  }

  reverse(ALL(ans));
  REP(i, ans.size()){
    cout << ans[i];
    SPBR(i, ans.size());
  }

  return 0;
}

Measured memory_bytes: 1528
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main( )
    {
        {
            long N = long.Parse( Console.ReadLine( ) );
            var A = Console.ReadLine( ).Split( ).Select( long.Parse ).ToArray( );
            var B = Console.ReadLine( ).Split( ).Select( long.Parse ).ToArray( );

            long a, b, cnt;
            long ans = 0;
            for ( long i = 0; i < N; i++ )
            {
                a = A[ i ];
                b = B[ i ];
                ans += cnt = Math.Min( a, b );
                ans += cnt = Math.Min( b - cnt, A[ i + 1 ] );
                A[ i + 1 ] -= cnt;

            }
            Console.WriteLine( ans );
        }
    }
}



Measured memory_bytes: 35892
gets.to_i.times {
  x1, y1, x2, y2, x3, y3 = gets.split.map &:to_f
  ax = x1 - x2
  ay = y1 - y2
  bx = x3 - x1
  by = y3 - y1
  sum = x1 * x1 + y1 * y1
  c1 = sum - x2 * x2 - y2 * y2
  c2 = sum - x3 * x3 - y3 * y3
  z = (ax * by - ay * bx) * 2
  px = (c1 * by + c2 * ay) / z
  py = -(c2 * ax + c1 * bx) / z
  r = ((px - x1)**2 + (py - y1)**2) ** 0.5
  puts sprintf("%.3f %.3f %.3f", px, py, r)
}

Measured memory_bytes: 8748