akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define mp make_pair
#define fi first
#define se second
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
using namespace std;
typedef long long LL;
const int N=105;
int n,m,k,Mo,C[N+1][N+1],f[N+1][N+1][N+1][2];
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=(LL)a*a%Mo)
		if(b&1)s=(LL)s*a%Mo;
	return s;
}
int main() {
	scanf("%d%d%d%d",&n,&m,&k,&Mo);
	ref(i,0,N)C[i][0]=1;
	ref(i,1,N)ref(j,1,i)C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mo;
	f[0][0][0][0]=1;
	ref(x,0,k-1)ref(i,0,n)ref(j,0,m){
		int s=1,ss=(Mo+mi(x+1,m-j)-mi(x,m-j))%Mo;
		ss=(LL)ss*mi(k-x,j)%Mo;
		ref(l,0,n-i){
			(f[x][i+l][j][1]+=(LL)f[x][i][j][0]*C[n-i][l]%Mo*s%Mo)%=Mo;
			s=(LL)s*ss%Mo;
		}
		s=1;ss=(Mo+mi(k-x,i)-mi(k-x-1,i))%Mo;
		ss=(LL)ss*mi(x+1,n-i)%Mo;
		ref(l,0,m-j){
			(f[x+1][i][j+l][0]+=(LL)f[x][i][j][1]*C[m-j][l]%Mo*s%Mo)%=Mo;
			s=(LL)s*ss%Mo;
		}
	}
	printf("%d\n",f[k][n][m][0]);
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define ff(i,a,n) for(int i=a;i<n;i++)
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);ll k,a,b,c=0;
    cin>>k>>a>>b;
    ff(i,a,b+1)
    {
        if(i%k==0)
        {
            c+=1;break;
        }
    }
    if(c>0)
        cout<<"OK";
    else
        cout<<"NG";

    return 0;
}


Measured memory_bytes: 3692
#include <algorithm>
#include <cstdio>
#include <vector>
#include <tuple>

int readInt(void){
    char c;
    do{ c = getchar_unlocked(); } while(c < '0');
    int res = 0;
    do{res = 10 * res + c - '0'; c = getchar_unlocked();} while(c >= '0');
    return res;
}

int main(void){
    int n = readInt();
    std::vector<std::pair<int, int>> A(n);
    for(int i = 0; i < n; ++i){
        int x = readInt(); int l = readInt();
        A[i] = std::pair<int, int>(x - l, x + l);
    }

    int size = 0;
    {
        // 座標圧縮
        std::vector<std::pair<int, int>> Ap(2 * n);
        for(int i = 0; i < n; ++i){
            Ap[2 * i] = std::pair<int, int>(A[i].first, 2 * i);
            Ap[2 * i + 1] = std::pair<int, int>(A[i].second, 2 * i + 1);
        }
        std::sort(Ap.begin(), Ap.end());
        int idx = 0;
        while(idx < 2 * n){
            int cnt = 0;
            while(idx + cnt < 2 * n and Ap[idx].first == Ap[idx + cnt].first){
                int i = Ap[idx + cnt].second;
                if(i & 1) A[i >> 1].second = size;
                else A[i >> 1].first = size;
                cnt++;
            }
            size++;
            idx += cnt;
        }
    }
    std::sort(A.begin(), A.end());
    std::vector<int> DP(size, 0);
    DP[A[0].second] = 1;
    for(int i = 1; i < n; ++i){
        for(int j = A[i-1].first ; j < A[i].first; ++j) if(DP[j] > DP[j + 1]) DP[j + 1] = DP[j];
        int val = DP[A[i].first] + 1;
        if(DP[A[i].second] < val) DP[A[i].second] = val;
    }
    for(int i = A[n-1].first; i + 1 < size; ++i) if(DP[i] > DP[i+1]) DP[i+1] = DP[i];
    printf("%d\n", DP[size - 1]);
    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
int main()
{
	int s,m,h;
	scanf("%d",&s);
	h = s/3600;
	m = s/60-s/3600*60;
	printf("%d:%d:%d\n",h,m,s-h*3600-m*60);
	
	return 0;
}

Measured memory_bytes: 1860
//Mandelbrot: z(n+1) = (z(n))^2 + c
//Rick: I programmed you to believe that
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define PI 3.14159265359
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define tc(x) ll x; cin>>x; while(x--)
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define print(a)  for (auto x : a) cout << x << " "; cout << endl
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define setbits(a) __builtin_popcountll(a)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define P 998244353
#define Q 1000000006
#define inf 1e18
#define N 1000005
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(all(v), rng);



void solve(){

    ll n, sum=0;
    cin>>n;
    vl a(n);
    mll m;
    f(i,0,n){
        cin>>a[i];
        sum+=a[i];
        m[a[i]]++;
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        ll f = m[b];
        m[c] += f;
        m[b] = 0;
        sum += f*(c-b);
        cout<<sum<<endl;
    }

}

signed main() {
    teevra_gati
        
    solve();
    return 0;
}

Measured memory_bytes: 9996
#include<iostream>
using namespace std;
char mat[1001][1001];
long long int dp[1001][1001]={0};
#define mod 1000000007;
void noofways(int h,int w)
{ 	for(int i=0;i<h;i++)
    {
	  for(int j=0;j<w;j++)
	  {
	  	 if(i==0&&j==0)
	  	  dp[0][0]=1;
	  	  else
	  	  if(i==0)
	  	   { if(mat[i][j]=='#')
	  	      dp[i][j]=0;
	  	   	   else
	  	   	   dp[i][j]=dp[i][j-1]%mod;
      		}
      		else if(j==0)
      		{
      		if(mat[i][j]=='#')
	  	      dp[i][j]=0;
	  	   	   else
	  	   	   dp[i][j]=dp[i-1][j]%mod;
	  	   }
	  	   else
	  	       if(mat[i][j]=='#')
	  	       dp[i][j]=0;
	  	       else
	  	        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	 	 
	  }
    }
    cout<<dp[h-1][w-1];
}
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
	 for(int j=0;j<w;j++)
	 cin>>mat[i][j];
	noofways(h,w);
	
	
}

Measured memory_bytes: 9088
module CharMap = Map.Make (Char)

let alphabet =
  [ 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm';
    'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z']

let () =
  let a = read_line () in
  let trie = Array.make (String.length a + 1) CharMap.empty in
  for i = String.length a - 1 downto 0 do
    trie.(i) <- CharMap.add a.[i] (i + 1) trie.(i + 1)
  done;
  let dp = Array.make (String.length a + 1) (0, []) in
  for i = String.length a downto 0 do
    dp.(i) <- List.fold_right (fun c -> min @@
      match dp.(CharMap.find c trie.(i)) with
      | exception Not_found -> (1, [c])
      | (n, s) -> (1 + n, c :: s)) alphabet (max_int, [])
  done;
  List.iter print_char (snd dp.(0));
  print_newline ()


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

int main()
{  
    int n,comm,key;
    string color;
    map<string,int>s;
    cin>>n;
    REP(i,n)
    {
        cin>>comm;
        if(comm==0)
        {
            cin>>color>>key;
            s[color]=key;
        }
        if(comm==1)
        {
            cin>>color;
            if(s.find(color)!=s.end())
            {
                cout<<s[color]<<endl;
            }else cout<<0<<endl;
        }
        if(comm==2)
        {
            cin>>color;
            s.erase(color);
        }
    }
}



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

using namespace std;

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

const ll fin = 5*1e15;

ll cnt(ll d, ll rem) {
	if (d == 1) return 1;
	ll num = 1;
	while (1) {
		num *= d;
		if (num >= rem) return num;
	}
}


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

	string S;
	ll K;
	cin >> S >> K;

	int ones = 0;
	FO(i, S.size()) {
		if (S[i] != '1') break;
		++ones;
	}

	if (K <= ones) cout << "1" << endl;
	else cout << S[ones] << endl;

	// ll rem = k;
	// for (char c : S) {
	// 	int d = c-'0';
	// 	ll cc = cnt(d, rem);
	// 	cout << c << " " << cc << endl;
	// 	if (cc >= rem) {
	// 		cout << c << endl;
	// 		break;
	// 	}
	// 	rem -= cc;
	// }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd (int a, int b) {
  if (a%b == 0) {
    return(b);
  } else {
    return(gcd(b, a%b));
  }
}
int main() {
  int n, m;
  long long sum = 0;
  cin >> n;
  for (int a = 0; a < n; a++) {
    sum += a+1;
    if (n > 1) {
      for (int b = a+1; b < n; b++) {
        m = gcd(b+1,a+1);
        sum += 6*m;
        if (n > 2) {
          for (int c = b+1; c < n; c++) {
            sum += 6*gcd(c+1,m);
          }
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int a[200000];

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

	int x = 0;
	for (int i=0; i<N; i++) {
		cin >> a[i];
		x ^= a[i];
	}

	for (int i=0; i<N; i++) {
		if (i != 0) cout << " ";
		cout << (x^a[i]);
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 4288
# ABC070B

a, b, c, d = map(int, input().split())
if b <= c: # a-b c-d
    print(0)
elif a <= c <= b and c <= b <= d: # a-c-b-d
    print(b - c)
elif a <= c <= d <= b: # a-c-d-b
    print(d - c)
elif c <= a <= b <= d: # c-a-b-d
    print(b - a)
elif c <= a <= d <= b: # c-a-d-b
    print(d - a)
elif c <= a <= b <= d: # c-a-b-d
    print(b - a)
elif c <= d <= a <= b: # c-d a-b
    print(0)
else:
    print(a, b, c, d)


Measured memory_bytes: 3064
//C++ template-------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//define-------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++) //指定回数ループマクロ
#define reps(i, n) for (int i = 1; i < (int)(n); i++) //1-origin
#define rrep(i, n) for (int i = ((int)(n)-1); i>=0; i--) //逆順
#define rreps(i, n) for (int i= ((int)(n)); i>0; i--) //逆順1-origin
//typedef------------------------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
//const--------------------------------------------------------
const ll MOD = 1000000007;
const int INF = 1e9;
const double PI = acos(-1.0); //3.141592....
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
//main---------------------------------------------------------
int main() {
    string s, t;
    cin >> s >> t; //入力
    int lt = t.size(); //tの長さlt
    int ls = s.size();
    int l = ls - lt + 1;
    /* 重なっている文字が一番多いパターンに関して、
    重なっていない文字数を出力すればいい */
    int maxD = 0;
    rep(i,l) {
        int temp = 0;
        rep(j,lt) {
            if (s[i+j] == t[j]) temp++; 
        }
        maxD = max(maxD,temp);
    }
    cout << lt - maxD << endl; //カウントを出力
    return 0; //終了
}

Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main(){
    int A[150][150];
    int n1,n2,a,b;
    cin >> n1;
    for (int i = 0; i < n1; i++){
        cin >> a;
        cin >> n2;
        for (int j = 0; j < n2; j++){
            cin >> b;
            A[a-1][b-1] = 1;
        }
    }
    for (int i = 0; i < n1; i++){
        for (int j = 0; j < n1; j++){
            cout << A[i][j];
            if (j == n1 - 1){
                cout << endl;
            }
            else {
                cout << " ";
            }
        }
    }
}


Measured memory_bytes: 3156
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC171
{
    class MainClass
    {


        public static void Main(string[] args)
        {
            // s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            string s = ReadLine();
            if(char.IsUpper(s[0])){
                WriteLine('A');
            }else{
                WriteLine('a');
            }
        }
    }
}


Measured memory_bytes: 25876
s = input()
y = int(s[0:4])
m = int(s[5:7])


if y < 2019:
    print('Heisei')

elif y == 2019:

    if m < 5:
        print('Heisei')
    
    else:
        print('TBD')

else:
    print('TBD')

Measured memory_bytes: 2940
s = list(input())
t = list(input())
ans = 100000

for i in range(len(s) - (len(t) - 1)):
    diff = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            diff += 1
    ans = min(ans, diff)
print(ans)

Measured memory_bytes: 8976
n, m = map(int, input().split())
py = []
s = '000000'
for i in range(m):
    p, y = map(int, input().split())
    py.append([p, y, i])
py.sort(key=lambda py:(py[0],py[1]))

py[0].append(1)
for i in range(m-1):
    a = 1
    if py[i][0] == py[i+1][0]:
        py[i+1].append(py[i][3]+1)
    else:
        py[i+1].append(1)
        
py.sort(key=lambda py:(py[2]))

for j in range(len(py)):
    print((s+str(py[j][0]))[-6:]+(s+str(py[j][3]))[-6:])

Measured memory_bytes: 35480
import math
n,m,x = map(int,input().split())
book = [list(map(int,input().split())) for _ in range(n)]
best = math.inf

for i in range(2**n):
    und = [0]*m
    money = 0
    for j in range(n):
        if (i>>j) & 1:
            money += book[j][0]
            for k in range(m):
                und[k] += book[j][k+1]
    if all(s>=x for s in und) and best>money:
        best = money

if best==math.inf:
    print(-1)
else:
    print(best)

Measured memory_bytes: 9036
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

void solve() {
  invec<ll> A(5);
  ll r= 1;
  REP (i,5) {
    if (A[i] == 0) {
      cout << r << endl;
      return;
    }
    r++;
  }


}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3628
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = read().decode('utf8').rstrip()
# print(type(S))
# print(N//2)
# print(S)
# print(''.join(S[:N // 2]+S[:N//2]) )

ans = 'Yes' if S == S[:N // 2]+S[:N // 2] else 'No'
print(ans)


Measured memory_bytes: 2940
#include<cstdio>
#define int long long 
inline int max(int a,int b){return a>b?a:b;}
const int N=103,M=100003;
int n,m,w[N],v[N],dp[M],ans;
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)scanf("%lld%lld",w+i,v+i);
	for(int i=1;i<=n;i++)
	  for(int j=m;j>=w[i];j--)
		dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	for(int j=0;j<=m;j++)ans=max(ans,dp[j]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll r, d, x;
    cin >> r >> d >> x;
    REP(i,10){
        ll xx = r * x - d;
        cout << xx << endl;
        x = xx;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int UP = n / 100;
    int DOWN = n % 100;
    if(1 <= UP && UP <= 12){
        if(1 <= DOWN && DOWN <= 12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(1 <= DOWN && DOWN <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	int N = S.length();
	if(S[N-1] == '1' || S[0] == '0') {
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < N-1; i++) if(S[i] != S[N-2-i]) {
		cout << "-1\n";
		return 0;
	}
	vector< pair<int, int> > E;
	int r = 0;
	for(int i = 1; i < N; i++) if(S[i] == '1') {
		int j = i-1;
		int cnt = 0;
		while(S[j] == '0') {
			j--;
			cnt++;
		}
		for(j = 0; j <= cnt; j++) E.push_back({r+j, r+1+cnt});
		r = r+cnt+1;
	}
	E.push_back({r, N-1});
	for(int i = 0; i < N-1; i++) cout << E[i].ff+1 << " " << E[i].ss+1 << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

class Pg
{
    static void Main()
    {
        var height = new List<double>();
        for (string line; (line = Console.ReadLine()) != null; height.Add(double.Parse(line))) ;
        Console.WriteLine(height.Max() - height.Min());
    }
}


Measured memory_bytes: 16208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string S; cin>>S;
	cout<<(S.back()=='s' ? S+"es" : S+"s")<<"\n";
	return 0;
}

Measured memory_bytes: 3652
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static void exec(Scanner in, PrintStream out) {
		int N = in.nextInt();
		int[] a = new int[3 * N];
		for (int i = 0; i < 3 * N; i += 1) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		long sum = 0;
		for (int i = 0; i < N; i += 1) {
			sum += a[a.length - 2 - 2 * i];
		}
		out.println(sum);
	}

	public static void main(String[] args) {
		exec(new Scanner(System.in), System.out);
	}

}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
template<typename T>
struct BIT{
  ll n;
  ll k=1;
  vector<T>data;
  BIT(ll size):n(size){
    data.assign(n,0);
    while(k*2<=n)k*=2;
  }
  void add(ll a,T w){
    for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w;
  }
  T sum(ll a){
    T ret = 0;
    for(ll i=a+1;i>0;i-=i&-i)ret+=data[i-1];
    return ret;
  }
  T sum(ll a,ll b){return a>b?0:sum(b)-sum(a-1);}
  T operator[](ll pos){
    return sum(pos,pos);
  }
  ll lower_bound(ll x){
    ll ret=0;    
    for(ll i=k;i>0;i/=2){
      if(ret+i<=n&&data[ret+i-1]<x){
        x-=data[ret+i-1];
        ret+=i;
      }
    }
    return ret;
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,d,a;cin>>n>>d>>a;
  vector<P>p(n);
  rep(i,0,n)cin>>p[i].fi>>p[i].se;
  sort(ALL(p));
  BIT<ll>bit(n+1);
  rep(i,0,n){
    ll now=p[i].se-a*bit.sum(0,i);
    //cout<<p[i].fi spa p[i].se spa now spa res<<endl;
    ll idx=upper_bound(ALL(p),MP(p[i].fi+2*d,INF))-p.begin();
    ll x=(now+a-1)/a;
    if(x<=0)continue;
    res+=x;
    bit.add(i,x);
    bit.add(idx,-x);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>

using namespace std;

int goban[18][18] = { 0 };
int ans;

void check(int x,int y,int a,int b) {
	if (x == a&&y == b) { ans++; }
	else {
		if (goban[x + 1][y] == 1) {
			check(x + 1, y, a, b);
		}
		if (goban[x][y + 1] == 1) {
			check(x, y + 1, a, b);
		}
	}
}

int main(void) {
	while (1) {
		ans = 0;
		int a, b;
		cin >> a >> b;
		if (a == 0) break;
		int n;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) goban[i][j] = 1;
		}

		cin >> n;
		while (n) {
			int x, y;
			cin >> x>>y;
			goban[x][y] = 0;
			n--;
		}
		check(1,1,a,b);
		cout << ans << endl;
	}



}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXMASK=(1<<19);
const int MAXN=25;
const int mod=1e9+7;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int n,m,K,a[MAXN][MAXN],ok[MAXN];
int f[2][MAXN][MAXMASK],bin[25],id[MAXMASK];
int lowbit(int x){return x&-x;}
int main()
{
	bin[1]=1;for(int i=2;i<=20;i++)bin[i]=bin[i-1]<<1;
	for(int i=0;i<=18;i++)id[1<<i]=(i+1);
	n=read();m=read();K=read();
	for(int i=1;i<=K;i++)
	{
		int x=read(),y=read(),z=read();
		a[x][y]=z+1;
	}
	f[0][0][0]=1;n--;int now=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<n;j++)for(int k=0;k<bin[n+1];k++)if(f[now][j][k])
		{
			if(a[i][j+1])
			{
				if(a[i][j+1]==1&&!(k&bin[j+1]))ad(f[now][j+1][k],f[now][j][k]);
				else if(a[i][j+1]==2)
				{
					if(k&bin[j+1])ad(f[now][j+1][k],f[now][j][k]);
					else
					{
						int S=(k&((k>>j)<<j));
						int g=lowbit(S);
						if(!g)ad(f[now][j+1][k|bin[j+1]],f[now][j][k]);
						else ad(f[now][j+1][(k|bin[j+1])^g],f[now][j][k]);
					}
				}
			}
			else
			{
				ad(f[now][j+1][k],f[now][j][k]);
				if(!(k&bin[j+1]))
				{
					int S=(k&((k>>j)<<j));
					int g=lowbit(S);
					if(!g)ad(f[now][j+1][k|bin[j+1]],f[now][j][k]);
					else ad(f[now][j+1][(k|bin[j+1])^g],f[now][j][k]);
				}
			}
		}
		memset(f[now^1],0,sizeof(f[now^1]));
		for(int k=0;k<bin[n+1];k++)f[now^1][0][k]=f[now][n][k];
		now^=1;
	}
	int ans=0;
	for(int i=0;i<bin[n+1];i++)ad(ans,f[now][0][i]);
	pr2(ans);
	return 0;
}


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

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;

void show(){
  if (TEST){cout << endl;}
}

void show(string x){
  if (TEST){cout << x;}
}

void show(string x,bool enter){
  if (TEST){
    if (enter) cout << "<#> " << x << endl;
    else cout << x;
  }
}

void show(ll x){
  if (TEST){cout << x;}
}

void show(ll x,bool enter){
  if (TEST){
    if (enter) cout << "<#> " << x << endl;
    else cout << x;
  }
}


void show(p_ll p){
  if (TEST){
    cout << "{ ";
    show(p.first);
    cout << " ";
    show(p.second);
    cout << " }";
  }
}

void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << " ";
    }cout <<"<end>"<< endl;
  }
}

void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
    }
  }
}

void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
    }
  }
}

string S;
int main(){
  cin >> S;
  ll lose=0;
  for (ll i=0;i<S.length();i++){
    if (S[i]=='x')lose++;
  }
  if (lose>=8) cout << "NO" << endl;
  else cout << "YES" << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];
        ll ans = 0;
        rep(i, 0, N) {
                if (even(i) and odd(a[i])) ++ans;
        }
        cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long m = sc.nextLong();
		long rd = sc.nextLong();
		long rr = sc.nextLong();
		long cd = sc.nextLong();
		long cr = sc.nextLong();
		
		long d = (cd*100)/rd;
		while((d*rd)/100!=cd) d++;
		long r = (cr*100)/rr;
		while((r*rr)/100!=cr) r++;
		if(m-d-r<0) System.out.println(-1);
		else System.out.println(m-d-r);
	}

}

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

typedef long long ll;
typedef long double ld;

const int MOD = 998244353;

int add(int a, int b){
    return (a+b)%MOD;
}

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

int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}

pair <ll, ll> niz[200005];
map <ll, ll> u;
ll bit[200005];

void addbit(int x){
    while(x <= 200000){
        bit[x]++;
        x += x & -x;
    }
}

int getbit(int x){
    int res = 0;
    while(x){
        res += bit[x];
        x -= x & -x;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    vector <ll> vec;
    for(int i=1; i<=n; i++){
        cin >> niz[i].first >> niz[i].second;
        vec.push_back(niz[i].second);
    }
    sort(vec.begin(), vec.end());
    int cnt = 0;
    for(auto c : vec){
        if(!u[c]) u[c] = ++cnt;
    }
    sort(niz+1, niz+1+n);
    ll res = mul(n, pw(2, n));
    for(int i=1; i<=n; i++){
        niz[i].second = u[niz[i].second];
        res = add(res, MOD - pw(2, i-1));
        res = add(res, MOD - pw(2, n-i));
        res = add(res, MOD - pw(2, niz[i].second-1));
        res = add(res, MOD - pw(2, n-niz[i].second));
        int k = getbit(niz[i].second-1);
        res = add(res, pw(2, k));
        res = add(res, pw(2, i-1-k));
        res = add(res, pw(2, niz[i].second-1-k));
        res = add(res, pw(2, (n-niz[i].second) - (i-1-k)));
        res = add(res, MOD-1);
        addbit(niz[i].second);
    }
    cout << res;
    return 0;
}


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

int g[15][15];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      g[i][j] = -1; //なにも証言していない::-1
    }
  }
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int to, judge;
      cin >> to >> judge;
      to--;
      g[i][to] = judge;
    }
  }

  int ans = 0;

  // 1<<0 = 1; 1<<1 = 2; 1<<2 = 4,....
  //すなわち, 1<<n = 2^nになる。全部の状態量は2^nなのでこれで全探索できる。
  //bit全探索？
  for (int i = 0; i < (1<<n); i++) {
    vector<int> d(n); //各ビットが各ノードが正直者かどうかの状態を保持するようになっている
    for (int j = 0; j < n; j++) {
      if ((i>>j)&1) { //iのjビット目が1であるかどうか
        d[j] = 1; //1が立ってれば正直者
      }
    }

    bool ok = true;//もし矛盾が生じなければOK
    for (int j = 0; j < n; j++) {
      if (d[j]) {
        for (int k = 0; k < n; k++) {
          if (g[j][k] == -1) continue; //証言がない場合
          if (g[j][k] != d[k]) ok = false; //もし食い違う証言をしている場合はfalse
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
    //__builtin_popcount(i) : 2進数表記のときに1が何個存在するかをカウントする関数
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import collections

n=int(input())
adj=[]
for i in range(n):
      adj.append(list(map(int, input().split())))

Q=[]
Q=collections.deque()
Q.append(0)

D=[-1 for i in range(n)]
D[0]=0

while len(Q)>0:
    current=Q.popleft()
    for dst in range(n):
        for i in range(2,len(adj[current])):
            if adj[current][i]==dst+1 and D[dst]==-1:
                D[dst]=D[current]+1
                Q.append(dst)
for i in range(n):
    print(i+1,D[i])

Measured memory_bytes: 8008
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

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

int main()
{
        int X, Y, Z, K;
        cin >> X >> Y >> Z >> K;
        vector<ll> A(X + 1), B(Y + 1), C(Z + 1);

        for (int i = 0; i < X; i++)
        {
                cin >> A[i];
        }
        for (int i = 0; i < Y; i++)
        {
                cin >> B[i];
        }

        for (int i = 0; i < Z; i++)
        {
                cin >> C[i];
        }

        vector<ll> AB;
        for (int i = 0; i < X; i++)
        {
                for (int j = 0; j < Y; j++)
                {
                        AB.push_back(A[i] + B[j]);
                }
        }
        sort(AB.begin(), AB.end(), greater<ll>());

        vector<ll> ABC;
        for (int i = 0; i < min(K, (int)AB.size()); i++)
        {
                for (int j = 0; j < Z; j++)
                {
                        ABC.push_back(AB[i] + C[j]);
                }
        }
        sort(ABC.begin(), ABC.end(), greater<ll>());

        for (int i = 0; i < K; i++)
        {
                cout << ABC[i] << endl;
        }

        return 0;
}

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

int main(){
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = (double)w*h/2;
    int num;
    if (w == x * 2 && h == y * 2) num = 1;
    else num = 0;
    cout << ans << setprecision(10) << " " << num << endl;
}

Measured memory_bytes: 256
import datetime
from decimal import Decimal, ROUND_DOWN
import heapq
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
# n = int(input())
n, k = list(map(int, input().split()))
# A = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
# p = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))

M = 1000000007
f = [1]
g = [1]
for i in range(1, 2*n+1):
    f.append(i*f[i-1] % M)  # 階乗
    g.append(pow(f[i], -1, M))  # f[i]の逆元

for i in range(1, k+1):
    if n-k < i-1:
        print(0)
    else:
        a_com = f[n-k+1]*g[i] % M*g[n-k+1-i] % M
        b_com = f[k-1]*g[i-1] % M*g[k-i] % M
        print(a_com*b_com % M)


Measured memory_bytes: 10892
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

template <typename T>
std::unordered_map<size_t, T> group_count(std::vector<T>& v) {
	std::unordered_map<size_t, T> c;
	for(T& e : v) {
		c[e]++;
	}
	return c;
}

double memo[301][301][301];

double solve(int n, int c1, int c2, int c3) {
	if(memo[c1][c2][c3] >= 0) {
		return memo[c1][c2][c3];
	}
	if(c1 == 0 && c2 == 0 && c3 == 0) {
		return 0.0;
	}

	return memo[c1][c2][c3] =
			   ((c1 > 0 ? (solve(n, c1 - 1, c2, c3) * c1) : 0.0) +
				(c2 > 0 ? (solve(n, c1 + 1, c2 - 1, c3) * c2) : 0.0) +
				(c3 > 0 ? (solve(n, c1, c2 + 1, c3 - 1) * c3) : 0.0) + n) /
			   static_cast<double>(c1 + c2 + c3);
}

int main() {
	int n;
	cin >> n;
	VI a(n);
	REP(i, n) { cin >> a[i]; }
	unordered_map<size_t, int> cnt = group_count(a);
	FILL(memo, -1);
	cout << PRECISION(15) << solve(n, cnt[1], cnt[2], cnt[3]) << endl;
	return 0;
}


Measured memory_bytes: 216824
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(c-a+b>0)
	printf("%d",c-a+b);
	else
	printf("0");
	return 0;
 } 

Measured memory_bytes: 128
//1620
#include "bits/stdc++.h"
using namespace std;

void solve() {
    int N, H, a, max_a = 0, ans = 0;
    cin >> N >> H;
    vector<int> b(N);
    for (int i = 0; i < N; i++) {
        cin >> a >> b.at(i);
        max_a = max(max_a, a);
    }
    //cout << max_a << endl;
    sort(b.begin(), b.end());
    for (int i = N - 1; i >= 0; i--) {
        if (H <= 0) {
            H = 0;
            break;
        }
        if (b.at(i) < max_a) {
            break;
        }
        H -= b.at(i);
        ans++;
        //cout << H << " " << ans << endl;
    }
    ans += (H + max_a - 1) / max_a;
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 640
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, x, b[500029], r = 1, sum;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (b[0]) puts("No");
		else if (x >= 500020) puts("Yes");
		else {
			while (b[r]) r++;
			if (r <= x) {
				puts("Yes");
				int z = x; b[z]++, sum++;
				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;
				r = min(r, z + 1);
			}
			else {
				if (sum == x) puts("Yes"), b[0] = 1;
				else puts("No");
			}
		}
	}
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;

  if(a>b) {cout<<0; return 0;}
  if(a!=b&&n<2) {cout<<0; return 0;}

  ll min, max;
  min = a*(n-1)+b;
  max = a+b*(n-1);

  cout << max-min+1;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string board[60];
    int dx[8] = {1,1,0,-1,-1,-1,0,1};
    int dy[8] = {0,1,1,1,0,-1,-1,-1};
    int x,y;
    cin >> x >> y;
    rep(i,x){
        cin >> board[i];
    } 
    rep(i,x){
        rep(j,y){
            if(board[i][j] == '.'){
                int cnt=0;
                for(int k=0; k<8; k++){
                    int X = i + dx[k];
                    int Y = j + dy[k];
                    if(X>=0 && X < x && Y>= 0 && Y<y && board[X][Y] == '#') cnt++;
                }
                board[i][j] = '0' + cnt;
            }
        }
    }
    rep(i,x) cout << board[i] <<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7
 
if N < K:
    print(0)
else:
    ans = 0
    v = 1
    for i in range(K):
        if i % 2:
            ans -= pow(K-i, N, MOD) * v
        else:
            ans += pow(K-i, N, MOD) * v
        v = v * (K-i) * pow(i+1, MOD-2, MOD) % MOD
    print(ans % MOD)


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

const long long MOD = 1000000007;

long long mod_pow(long long x, long long y){
  return y ? mod_pow(x * x % MOD, y / 2) * (y % 2 ? x : 1) % MOD : 1;
}

long long combination(long long n, long long k){
  long long a = 1, b = 1;
  for(int i = n; i > k; --i){
    a = a * i % MOD;
    b = b * (n - i + 1) % MOD;
  }
  return a * mod_pow(b, MOD - 2) % MOD;
}

int main(){
  int x, y;
  cin >> x >> y;
  int xy = x + y;
  if(xy % 3 != 0){
    cout << 0 << endl;
    return 0;
  }
  int n = xy / 3; 
  x -= n;
  y -= n;
  if(x < 0 || y < 0){
    cout << 0 << endl;
    return 0;
  }
  cout << combination(n, x) << endl;
}

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

const int NMAX=110;

int color(int a) {
    if (1<=a && a<=399) return 0; //灰色
    else if (a<=799) return 1; //茶色
    else if (a<=1199) return 2; //緑色
    else if (a<=1599) return 3; //水色
    else if (a<=1999) return 4; //青色
    else if (a<=2399) return 5; //黄色
    else if (a<=2799) return 6; //橙色
    else if (a<=3199) return 7; //赤色
    else return 8; //なんでもok 
}
int main() {
    int N;
    int a[NMAX];
    cin >> N;
    for (int i=0; i<N; i++) cin >> a[i];

    //flags
    bool flag[10];
    int num = 0;
    for (int i=0; i<9; i++) flag[i]=false;
    for (int i=0; i<N; i++) {
        int x = color(a[i]);
        for(int j=0; j<9; j++) {
            if (x == j) flag[j] = true;
        }
        if (x==8) num++;
    }

    bool exista = true;
    for (int i=0; i<8; i++) {
        if (flag[i] == true) exista = false;
    }

    int min=0;
    int max=0;
    for (int i=0; i<8; i++)
        if (flag[i] == true) {
            min++; 
            max++;
        }

    if (exista) min = 1;
    max += num;

    cout << min << ' ' << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string S;
string ans[2] = { "ABC", "ARC" };
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
	rep(i, 0, 2) if (ans[i] != S) {
		cout << ans[i] << endl;
		return;
	}
}







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

const long long INF=1000000007; 

int main(){
    long int N;
    cin>>N;
    long long A[N];
    for (long int i=0;i<N;i++) cin>>A[i];
    long long sum=0,sum2=0;
    for (long int i=0;i<N;i++){
        sum+=A[i];
        sum2+=(A[i]*A[i])%INF;
        sum=sum%INF;
        sum2=sum2%INF;
    }
    sum=sum*sum;
    sum=sum%INF;
    long long ans=sum-sum2;
    if (ans<0) ans+=INF;
    if (ans%2==0){
        ans=ans/2;
        cout<<ans<<endl;
    }
    else{
        ans=(ans+INF)/2;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;
int main(){
    int x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
S = input()
counter = 0
ans = 0

for i in S:
    if i == "A" or i == "T" or i == "G" or i == "C":
        counter += 1
    else:
        if counter > ans:
            ans = counter
        counter = 0

if counter > ans:
    ans = counter
        
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	int c, d;
	int k;
	long long n, m;
	int s, t;
	long long  x, y, z;

	scanf("%lld", &n);

	for (long long i = 1; i <= 3500; i++){
		for (long long j = 1; j <= 3500; j++){
			x = 4 * i*j - (i*n) - (j*n);
			y = n*i*j;
			if (x > 0){
				if (y%x == 0){
					printf("%lld %lld %lld\n", i, j, y / x);

					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128