akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;
const int N=310;

int C[N][N],fact[N];
int f[N],g[N];

int n,k,MOD;

inline void inc(int a,int &b){b=(a+b)%MOD;}

int main()
{
	scanf("%d%d%d",&n,&k,&MOD);

	for(int i=0;i<N;i++)C[i][0]=1;
	for(int i=1;i<N;i++)
		for(int j=1;j<N;j++)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
	fact[0]=1;
	for(int i=1;i<N;i++)fact[i]=(ll)fact[i-1]*i%MOD;

	g[1]=1;

	for(int val=k-1;~val;val--)
	{
		memset(f,0,sizeof(f));
		f[0]=1;

		for(int i=1;i<=n;i++)
			for(int j=1;j<=i;j++)
				inc((ll)g[j]*f[i-j]%MOD*C[i-1][j-1]%MOD,f[i]);

		for(int i=n+1;i;i--)f[i]=f[i-1],f[i-1]=0;
		for(int i=1;i<=n+1;i++)
			inc(f[i],g[i]);

//		for(int i=1;i<=n+1;i++)
//			printf("%d ",f[i]);
//		printf("\n");
	}

	printf("%d\n",f[n+1]);

	return 0;
}


Measured memory_bytes: 640
s = int(input())

def f(n):
    if n%2 == 0:
        return n//2
    elif n%2 != 0:
        return 3*n + 1

a = [s]
for x in range(10000):
    i = a[-1]
    a.append(f(i))

if s == 1 or s == 2:
    print("4")
else:
    print(a.index(4)+4)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
#define ll long long
 vector<pair<ll,ll>>v;
 ll n,k,p;
 ll go(ll i,ll p)
 {
     if(p==0)
     {
         return 0;
     }
     if(p<0)
     {
         return INT_MIN;
     }
     ll res=INT_MIN;
     res=max(go(i+1,p-v[i].second)+v[i].first,go(i+1,p));
     return res;
 }
 bool check(string s)
 {
     string s1=s;
     reverse(s1.begin(),s1.end());
     if(s1==s)
     return true;
     else
     return false;
 }
int main() {
    
    ll s;
    cin>>s;
     
         cout<<fixed<<setprecision(12)<<(1.0*s/3*s/3*s/3);
    
    
}


Measured memory_bytes: 256
while True:
    (n,m) = map(int,input().split())
    if n == 0 and m == 0:
        break
    iss = list(map(int, input().split()))
    best = max([ (iss[i] + iss[j] if not ( i == j) and iss[i] + iss[j] <= m else -1) for i in range(0,n) for j in range(0,n) ])
    if(best < 0):
        print("NONE")
    else:
        print(best)



Measured memory_bytes: 47176
R = input()
A = int(R.split(' ')[0])
B = int(R.split(' ')[1])
C = int(R.split(' ')[2])
D = int(R.split(' ')[3])

while True :
    C = C - B
    if C <= 0 :
        print("Yes")
        break
    A = A -D
    if A <= 0 :
        print("No")
        break

Measured memory_bytes: 9092
# -*- coding: utf-8 -*-
"""
A - Ice Tea Store
https://atcoder.jp/contests/agc019/tasks/agc019_a

"""
import sys


def solve(Q, H, S, D, N):
    # 2L単位の最安値で買えるだけ買った後、(もしあれば)端数の1Lを処理する
    q, r = divmod(N, 2)         # 2L単位で購入する場合の必要ユニット数と端数
    d_prices = sorted([Q*8, H*4, S*2, D]) #  2L単位で購入する場合の価格
    ans = q * d_prices[0]
    s_prices = sorted([Q*4, H*2, S]) #  1L単位で購入する場合の価格
    ans += r * s_prices[0]
    return ans


def main(args):
    Q, H, S, D = map(int, input().split())
    N = int(input())
    ans = solve(Q, H, S, D, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int m = max(max(a,b),c);
  string ans;
  if(m==a+b+c-m) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int X, Y,a,b,c,d,p;
	fscanf(stdin, "%d%d%d%d%d", &a, &b, &c, &d, &p);
	X = a*p;
	Y = b + (p <= c ? 0 : p - c)*d;
	fprintf(stdout, "%d\n", X > Y ? Y : X);
	return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(All(a));
    ll ans = a[a.size() - 1] - a[0];
    c(ans);
    ed;
    return 0;
}

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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pow q1850918q205
#define pb push_back

#define K 3000001

int n;

string x[K];

int p1[K], p2[K], ok = 1;

vector<pair<int, int> > A[2];



int construct(int id) {
	if (A[id].size() == 0) return 0;
	
	sort(A[id].begin(), A[id].end());
	
	int pow = 0;
	
	for (int i = A[id].size() - 1; i >= 0; i--) {
		int elem = A[id][i].first;
		int add = A[id][i].second;
		
		if (elem < -pow) {
		//	cout << elem << " " << pow << endl;
			ok = 0;
			return 0;
		}
		
		pow += add;
	}
	
	return pow;
}

int main() {
	scanf("%d", &n);
	
	FOE(i, 1, n) cin >> x[i];
	
	FOE(i, 1, n) {
		int pot = 0;
		int pot2 = 0;
		int le = x[i].length();
		
		int l1 = 0, l2 = 0;
		
		FOR(j, 0, le) {
			if (x[i][j] == '(') pot++;
			else pot--;
			
			l1 = min(l1, pot);
		}
		
		FOD(j, le - 1, 0) {
			if (x[i][j] == '(') pot2--;
			else pot2++;
			
			l2 = min(l2, pot2);
		}
		
		p2[i] = pot;
		
		if (p2[i] <= 0) {
			p1[i] = l2;
			p2[i] *= -1;
			A[1].pb(mp(p1[i], p2[i]));	
		} else {
			p1[i] = l1;
			A[0].pb(mp(p1[i], p2[i]));
		}
		
	//	printf("(%d, %d)\n", l1, l2);
	//	printf("%d: %d, %d\n", i, p1[i], p2[i]);
	}
	
	int x1 = construct(0);
	int x2 = construct(1);
	
//	cout << x1 << " " << x2 << endl;
	
	if (ok && (x1 == x2)) {
		puts("Yes");	
	} else {
		puts("No");	
	}
}

Measured memory_bytes: 112924
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      while(sc.hasNext()){
         str = sc.nextLine();
         arr = str.split(" ");
         int a = Integer.parseInt(arr[0]);
         int b = Integer.parseInt(arr[1]);
      
         System.out.println((int)Math.log10(a+b)+1);
      }
   }//main
}//class

Measured memory_bytes: 26104
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] data = new int[n];
        double sum = 0.0;
        int ave = 0;
        
        for(int i=0; i<n; i++){
            data[i] = sc.nextInt();
            sum += data[i];
        }
        
        ave = (int)(Math.round(sum/n));
        sum = 0;
        
        for(int i=0; i<n; i++){
            if(data[i]!=ave){
                sum += (data[i]-ave) * (data[i]-ave); 
            }
        }
        
        System.out.println((int)(sum));
        
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

int linearSearch(int A[],int m,int key){
	int i = 0;
	A[m] = key;
	while (A[i]!=key) {
		i++;
		if(i==m) return 0;
	}
	return 1;
}

int main(void){
	int m,n,i,key;
	int A[10000+1];
	int count =0;
	
	scanf("%d",&m);
	
	for(i=0;i<m;i++){
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&key);
		count= count+ linearSearch(A,m,key);
	}
	
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 2128
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math/big"
	"os"
	"strconv"
)

func main() {
	inf := big.NewInt(int64(1e18))
	n := readInt()
	a := make([]int64, n)
	for i := range a {
		a[i] = readInt64()
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	ans := big.NewInt(1)
	for i := range a {
		ans.Mul(ans, big.NewInt(a[i]))
		if ans.Cmp(inf) == 1 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

int dp[10001];
int val[101];

int main (void) {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
	dp[0] = 1;
	for (int j = 1; j <= n; j++) {
		for (int i = 10000; i >= val[j]; i--) {
			dp[i] |= dp[i - val[j]];
		}
	}
	for (int i = 10000; i >= 0; i--) {
		if (i % 10 == 0) continue;
		if (dp[i]) {
			printf("%d\n", i);
			return 0;
		}
	}
	printf("0\n");
	return 0;
}

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

int main() {
	std::string n;
	std::cin >> n;
	if (n.size() == 1) {
		std::cout << n << std::endl;
		return 0;
	}

	bool isCorner = true;
	for (int i = 1; i < n.size(); ++i)
		if (n[i] != '9')
			isCorner = false;

	std::cout << (n.size() - 1) * 9 + (n[0] - '0') - (isCorner ? 0 : 1) << std::endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1e9+7;
ll N;
ll inv[2000000];
ll FactorialInv[2000000];
ll Factorial[2000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    Factorial[0] = 1;
    for(int i = 2; i < 2000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll patterns[1000500];
int main() {
    //cout.precision(10);
    cin >> N;
    N--;
    if(N == 1) {
        cout << 1 << endl;
        return 0;
    }
    init_combination();
    ll ans = 0;
    ll sum = 0;
    for(ll i = 2; i <= N; i++) {
        patterns[i] = combination(i - 1, N - i);
        patterns[i] *= Factorial[i];
        patterns[i] %= mod;
        patterns[i] *= Factorial[N - i];
        patterns[i] %= mod;
        patterns[i] += mod - sum;
        patterns[i] %= mod;
        sum = (sum + patterns[i]) % mod;
        ans = (ans + patterns[i] * i) % mod;
        //cerr << i << " " << patterns[i] << endl;
    }
    //cerr << " " << sum << " " << Factorial[N] << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 54912
#include <iostream>

int main(){
    int right = 0, left = 0;
    int n;
    std::cin >> n;

    while(n--){
        char in;
        std::cin >> in;
        if('(' == in){
            int num;
            std::cin >> num;
            //if(right == 0) left += num;
            //else if(right < num){
              //  num -= right;
                //right = 0;
                //left += num;
            //}
            //else right -= num;
            left += num;
        }
        
        if(')' == in){
            int num;
            std::cin >> num;
            if(left == 0) right += num;
            else if(left < num){
                num -= left;
                left = 0;
                right += num;
            }
            else left -= num;
        }
    }
    
    if(right == 0 && left == 0) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;

    return 0;
}

Measured memory_bytes: 1156
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

counter = Counter(A)
res =[]

for word,cnt in counter.most_common():
    if 4 <= cnt:
        res.append(word)
        res.append(word)
    elif 2 <= cnt:
        res.append(word)

res = sorted(res)[::-1]
if len(res) < 2:
    print(0)
else:
    print(res[0]*res[1])
    


Measured memory_bytes: 21668
#include <stdio.h>

int main(void) {
	int a, b, d, r;
	double da, db, f;
	scanf("%d %d", &a, &b);
	da = a; db = b;
	d = a/b;
	r = a%b;
	f = da/db;
	printf("%d %d %f", d, r, f);
	return 0;
}

Measured memory_bytes: 636
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int a[N], b[N], p[N], q[N], r[N];
double ret[N];

void mul(int p[], int q[], int r[], int n) {
  for (int i = 0; i < n; ++i) {
    r[i] = q[p[i]];
  }
}

int main() {
  int n, m;
  int64 k;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    b[i] = a[i + 1] - a[i];
    p[i] = i;
    q[i] = i;
  }
  scanf("%d%lld", &m, &k);
  while (m--) {
    int x;
    scanf("%d", &x);
    x -= 2;
    swap(p[x], p[x + 1]);
  }
  for (; k; k >>= 1) {
    if (k & 1) {
      mul(p, q, r, n - 1);
      copy(r, r + n - 1, q);
    }
    mul(p, p, r, n - 1);
    copy(r, r + n - 1, p);
  }
  ret[0] = a[0];
  ret[n - 1] = a[n - 1];
  for (int i = 1; i < n - 1; ++i) {
    ret[i] = ret[i - 1] + b[q[i - 1]];
  }
  for (int i = 0; i < n; ++i) {
    printf("%.10f\n", ret[i]);
  }

  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    N %= 10;
    string ret = N == 3 ? "bon" : (N == 0 || N == 1 || N == 6 || N == 8 ?
                 "pon" : "hon");
    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e7;
const int inf=1e9;
int main(){
	int K,N;cin>>K>>N;
	int A[N]; int m = 0;
	rep(i,0,N) cin>>A[i];
	rep(i,0,N-1) m = max(m , A[i+1]-A[i]);
	m = max(m , K - A[N-1] + A[0]);
	cout<<K - m<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b; cin >> a >> b;
    if(b % a == 0) cout << b+a << endl;
    else cout << b-a << endl;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int ret = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int now = 1;
        while (now <= d) {
            ret++;
            now += a;
        }
    }
    cout << ret + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll mod = 998244353;
const int N = 300000 + 100;
using namespace std;
ll n,inv[N],fc[N],K,ans,A,B;;
ll q_pow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b>>=1LL;
    }
    return ans;
}
ll C(ll n,ll m) {
    return ((fc[n]*inv[n-m])%mod*inv[m])%mod;
}
int main() {
    scanf("%lld%lld%lld%lld",&n,&A,&B,&K);
    fc[0]=1;for(int i=1;i<=n;++i)fc[i]=(fc[i-1]*i)%mod;
    inv[n] = q_pow(fc[n],mod-2);
    for(ll i=n-1;i>=0;--i)inv[i]=(inv[i+1]*(i+1))%mod;
    for(ll a=0;a<=n;++a) {
        ll b = (K-A*a)/B;
        if(b<0||b>n)continue;
        if((K-A*a)%B)continue;
        ans += (C(n,a)*C(n,b))%mod;
        ans %= mod;
    }
    cout << ans <<'\n';
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int MAXS = 500000;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
long long fact[MAXS];
void makef() {
    fact[0] = 1;
    for (long long i = 1; i < MAXS-1; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
}

signed main(){
    makef();
    long long n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    long long res = fact[n];
    res *= fact[m];
    res %= mod;
    if(n==m){
        res*=2;
        res%=mod;
    }
    cout<<res<<endl;

    

}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int d; cin >> d;
    cout << "Christmas";
    if(d!=25){
        for(int i=d; i<25; i++){
            cout << " Eve";
        }
    }
    cout  << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int atcoder(){
    //入力
    int n;
    cin >> n;
    ll ansa = 0;
    ll ansb = 0;
    ll a[110000]={};
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    ll tmpsum = 0;
    
    //処理
    for(auto i=0; i<n; ++i){
        tmpsum += a[i];
        if(i%2==0){
            if(tmpsum<=0){
                ansa += -tmpsum+1;
                tmpsum = 1;
            }
        }else{
            if(tmpsum>=0){
                ansa += tmpsum+1;
                tmpsum = -1;
            }
        }
    }
    
    tmpsum = 0;
    for(auto i=0; i<n; ++i){
        tmpsum += a[i];
        if(i%2!=0){
            if(tmpsum<=0){
                ansb += -tmpsum+1;
                tmpsum = 1;
            }
        }else{
            if(tmpsum>=0){
                ansb += tmpsum+1;
                tmpsum = -1;
            }
        }
    }
    
    //出力
    cout << min(ansa,ansb) << ENT;
    return 0;
}

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


Measured memory_bytes: 1152
console.log(main(require("fs").readFileSync("/dev/stdin","utf8")));
function main(inp){
  inp = inp.split("\n").map(a=>+a);
  var n = inp[0];
  var s = [];
  for(var i = 0; i < n; i++)s[i] = inp[i+1];
  s.sort((a,b)=>a-b);
  var ans = 0;
  var m = n + 1 >> 1;
  for(i = 0; i < m; i++){
    ans -= s[i] * 2;
  }
  for(; i < n; i++){
    ans += s[i] * 2;
  }
  if(n % 2 === 0)return ans - s[m] + s[m-1];
  if(s[m-1]+s[m-2] > s[m-1]*3-s[m])return ans + s[m-1] + s[m-2];
  else return ans + s[m-1]*3 - s[m];
}

Measured memory_bytes: 42320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll gcd(ll a,ll b){
    if (a < b) swap(a, b);
    ll r = a % b;
    while(r){
        a = b, b = r;
        r = a % b;
    }
    return b;
}
int main() {
    init();
    ll K, Q;
    cin >> K >> Q;
    vl D(K);
    rep(i, K) cin >> D[i];

    while(Q--){
        ll N, X, M;
        cin >> N >> X >> M;
        ll ans = 0;
        N--;

        vl Dm(K);
        rep(i, K) Dm[i] = (D[i] % M == 0 ? M : D[i] % M);
        ll sumDm = 0;
        rep(i, K) sumDm += Dm[i];

        ll sum = X % M, loop = N / K, rem = N % K;
        sum += sumDm * loop;
        rep(i,K){
            if (i < rem) sum += Dm[i];
        }
        ans = N - sum / M;

        cout << ans << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

typedef long long ll;



int main() {
    string S;
    cin >> S;
    // 人数
    vector<int> cnt(S.size(),0);
    // 人iが最終的にいる場所
    vector<int> pos(S.size(),-1);
    // 後ろからRについて見る
    REPR(i,S.size()-2) {
        if (S[i]=='L') continue;
        if (S[i]=='R' && S[i+1]=='R') {
            pos[i] = (S[pos[i+1]] == 'L') ? pos[i+1]-1 : pos[i+1]+1;
            cnt[pos[i]]++;
            continue;
        }
        // みぎはL
        if (S[i] == 'R') {
            pos[i] = i;
            cnt[pos[i]]++;
        }
    }
    // 前からLについて見る
    FOR(i,1,S.size()) {
        if (S[i]=='R') continue;
        if (S[i]=='L' && S[i-1]=='L') {
            pos[i] = (S[pos[i-1]] == 'R') ? pos[i-1]+1 : pos[i-1]-1;
            cnt[pos[i]]++;
            continue;
        }
        // 左はR
        if (S[i] == 'L') {
            pos[i] = i;
            cnt[pos[i]]++;
        }
    }
    REP(i,S.size()-1) {
        cout << cnt[i] << " ";
    }
    cout << cnt[S.size()-1] << endl;

    return 0;
}


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

#define read(num) scanf("%d", &num)
#define readll(num) scanf("%lld", &num)
#define read2(num1, num2) scanf("%d%d", &num1, &num2)
#define read3(num1, num2, num3) scanf("%d%d%d", &num1, &num2, &num3)
#define reads(str) scanf("%s", str)
#define readc(ch) scanf("%c", &ch)

#define pb push_back
#define mp make_pair

#define pii pair<int, int>
#define vi vector<int>
#define ll long long


int main()
{
    ll n;
    cin>>n;
    ll c[n+1]={0};
    int x;
    for(int i=2;i<=n;i++){
        cin>>x;
        if(x!=i){
            c[x]++;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<c[i]<<endl;
    }
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll n;cin>>n;
    cout<<3*n*n<<endl;
    
    return 0;
}







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

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size() == 2)
      cout << "Yes";
    else
      cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) int(lower_bound(all(s),x)-s.begin())
#define ub(s,x) int(upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

int n;
vector<int> a;

// kを増やすべきかどうか
bool check(int x, int k){
    if (n-k <= n/2) return false;
    if (n-k*2-1 < 0) return false;
    return abs(a[n-k*2-1]-x) <= abs(a[n-k-1]-x);
}

int main(void){
    int q;
    cin >> n >> q;
    a.resize(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1), t_sum(n+1);
    rep(i,n){
        sum[i+1] = sum[i] + a[i];
        if (i % 2 != n % 2) {
            t_sum[i+1] = t_sum[i] + a[i];
        } else {
            t_sum[i+1] = t_sum[i];
        }
    }
    rep(_,q){
        int x;
        cin >> x;
        int l = 0, r = 1e9;
        while (l + 1 < r) {
            int m = (l+r)/2;
            if (check(x, m)) l = m;
            else r = m;
        }
        int k = r;
        // debug(x);
        // debug(k);

        // int lob = lb(a,x-l), upb = ub(a,x+l);
        // int k = upb - lob;
        // int m = min(n-k, upb);
        cout << sum[n]-sum[n-k] + t_sum[max(n-2*k,0)]<< endl;
    }

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	ll a, b, c, d, ans1, ans2, ans3, ans4;
	cin >> a >> b >> c >> d;
	ans1 = a * c;
	ans2 = a * d;
	ans3 = b * c;
	ans4 = b * d;
	ans1 = max(ans1, ans2);
	ans2 = max(ans3, ans4);
	cout << max(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

    ll ans = x / 11 * 2;

    if ( x % 11 > 6 ) {
        ans += 2;
    }
    else if ( x % 11 > 0 ) {
        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
[abc127] E - Cell Distance
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const ll MOD = 1e9 + 7;

ll N, M;
ll K;

ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x) % m;
}

ll fac(int n) {
    ll ret = 1;
    for (int i = 2; i <= n; i++) {
        (ret *= i) %= MOD;
    }
    return ret;
}

ll solve() {
    ll c = (fac(N * M - 2) * mod_inv(fac(N * M - K) * fac(K - 2) % MOD, MOD)) %
           MOD;

    ll ans = 0;
    for (ll d = 1; d < N; d++) {
        ll a = ((((d * (N - d) % MOD) * (M * M % MOD)) % MOD) * c) % MOD;
        (ans += a) %= MOD;
    }
    for (ll d = 1; d < M; d++) {
        ll a = ((((d * (M - d) % MOD) * (N * N % MOD)) % MOD) * c) % MOD;
        (ans += a) %= MOD;
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    } 
    sort(a,a+n);
    ll ma=0,mi=0;
    n--;k--;
    for(int i=0;i<=n;i++){
        mi+=a[i]*com(n-i,k);
        ma+=a[i]*com(i,k);
        mi%=mod;ma%=mod;
    }
    cout << (((ma-mi)%mod)+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 5760
N, T = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort()

ans = 0
dp = [[0 for _ in range(3005)] for _ in range(3005)]
for i in range(N):
    a, b = AB[i]
    for j in range(T):
        # iを使わないパターン
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        # iを使うパターン
        nj = j + a
        if nj < T:
            dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + b)
    now = dp[i][T - 1] + b
    ans = max(ans, now)

print(ans)


Measured memory_bytes: 123736
#include <cstdio>
#include <vector>
static const int MAXN = 3e5 + 4;
static const int MAXM = 1e5 + 3;

int n, m;
int l[MAXN], r[MAXN];

namespace fwk {
    int f[MAXM] = { 0 };
    inline void add(int pos, int inc) { for (; pos < MAXM; pos += (pos & -pos)) f[pos] += inc; }
    inline int sum(int rg) { int ans = 0; for (; rg; rg -= (rg & -rg)) ans += f[rg]; return ans; }
}

int ans[MAXM] = { 0 };
std::vector<int> len[MAXM];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%d%d", &l[i], &r[i]);

    for (int i = 0; i < n; ++i) ans[r[i] - l[i] + 1] += 1;
    for (int i = m - 1; i >= 1; --i) ans[i] += ans[i + 1];

    for (int i = 0; i < n; ++i) len[r[i] - l[i] + 1].push_back(i);
    for (int i = 1; i <= m; ++i) {
        for (int j = i; j <= m; j += i)
            ans[i] += fwk::sum(j);
        for (int p : len[i]) {
            fwk::add(l[p], +1);
            fwk::add(r[p] + 1, -1);
        }
    }

    for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
    scanf("%lld%lld",&x,&y);
    if(x==0||y==0)
    {
        if(x>y)
        {
            cout<<abs(x-y)+1<<endl;
            exit(0);
        }
        cout<<abs(x-y)<<endl;
        exit(0);
    }
    if(x>0&&y>0)
    {
        if(x<y)
        cout<<abs(x-y)<<endl;
        else
        cout<<abs(x-y)+2<<endl;
    }
    if(x>0&&y<0||x<0&&y>0)cout<<abs(abs(x)-abs(y))+1<<endl;
    if(x<0&&y<0)
    {
        if(x==y)cout<<0<<endl;
        if(x>y)cout<<abs(abs(x)-abs(y))+2<<endl;
        if(x<y)cout<<abs(abs(x)-abs(y))<<endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

	int ans = INT_MAX;
	for (int i = 1; i < n; i++) {
		int a = i;
		int b = n - i;

		string strA = to_string(a);
		string strB = to_string(b);

		int scoreA = accumulate(begin(strA), end(strA), 0, [](int score, char c) {
			return score + (int)(c - '0');
		});

		int scoreB = accumulate(begin(strB), end(strB), 0, [](int score, char c) {
			return score + (int)(c - '0');
		});

		ans = min(ans, scoreA + scoreB);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  ll ans = 1;
  rep1(i,n){
    ans = (ans*i)%1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//けんさんの写経やで
//うんちっち
#include <bits/stdc++.h>

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> n >> m ;
	ll c[n] , p[n];
	rep(i,n) cin >> p[i] >> c[i];


	ll res = 1<<29;
	for(int bit = 0 ; bit < (1<<n) ; bit ++){
		ll sum = 0 , num = 0 ;
		for(int i = 0 ; i < n ; i ++){
			if(bit &(1<<i)) sum += c[i] + p[i] * 100 *(i+1), num += p[i];
		}
		if( sum >= m ) res = min (res,num);
		else {
			for(int i = n -1 ; i >= 0 ; i--){
				if(bit &(1 << i)) continue;
					for(int j = 0 ; j < p[i] ; j ++){
						if(sum >= m) break;
						sum += 100*(i+1);
						++ num;
					}
			}
			res = min(res, num);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a >= b && a >= c){
        printf("%d\n",a*10+b+c);
    }
    else if(b >= a && b >= c){
        printf("%d\n",b*10+a+c);
    }
    else if(c >= a && c >= b){
        printf("%d\n",c*10+a+b);
    }
    return 0;
}

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = int(readline())
    As = list(map(int, readline().split()))
    Bs = list(map(int, readline().split()))
    Cs = list(map(int, readline().split()))

    ans = 0
    for a, a_next in zip(As, As[1:]):
        ans += Bs[a-1]
        if a_next - a == 1:
            ans += Cs[a-1]
    ans += Bs[As[-1]-1]
    print(ans)


if __name__ == '__main__':
    main()


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

char map[13][13];
int da[] = {1, 0, -1, 0};
int db[] = {0, 1, 0, -1};

void dfs(int a, int b){
	if(a < 0 || a >= 12 || b < 0 || b >= 12 || map[a][b] == '0')	return;
	map[a][b] = '0';
	for(int i = 0; i < 4; i++){
		dfs(a + da[i], b + db[i]);
	}
	return;
}

int main(void){
	while(true){
		int cnt = 0;
		
		for(int i = 0; i < 12; i++){
			if(scanf("%s", map[i]) == EOF)	return 0;
		}

		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if(map[i][j] == '1'){
					dfs(i, j);
					cnt++;
				}
			}
		}
		printf("%d\n", cnt);
	}
  return 0;
}

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

using namespace std;

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

    double sum = 0;
    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        sum += 1 / a;
    }

    cout << fixed << setprecision(10);
    cout << 1 / sum << endl;
    return 0;
}


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

int main(){
	int a,b;
	cin>>a>>b;
	if(a<b) cout<<"a < b"<<endl;
	if(a>b) cout<<"a > b"<<endl;
	if(a==b) cout<<"a == b"<<endl;
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, P> pp;

int main(){
	ll N, K, R, S, P; cin >> N >> K >> R >> S >> P;
	string T; cin >> T;
	vector<char> g[K];
	for(int i=0; i<N; i++){
		g[i%K].push_back(T[i]);
	}
	ll ans = 0;
	for(int i=0; i<K; i++){
		char prev;
		int cnt = 0;
		for(int j=0; j<g[i].size(); j++){
			if(j==0){
				cnt++;
				prev = g[i][j];
			}else{
				if(prev==g[i][j]) cnt++;
				else{
					if(prev == 'r') ans += P*((cnt+1)/2);
					if(prev == 's') ans += R*((cnt+1)/2);
					if(prev == 'p') ans += S*((cnt+1)/2);
					cnt=1;
					prev=g[i][j];
				}
			}
		}
		if(prev == 'r') ans += P*((cnt+1)/2);
		if(prev == 's') ans += R*((cnt+1)/2);
		if(prev == 'p') ans += S*((cnt+1)/2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5120
n, x=map(int, input().split())
L=[i for i in map(int, input().split())]
counter=1
place=0
for i in range(n):
    place+=L[i]
    if place<=x and i!=n-1:
        counter+=1
    elif place>x:
        print(counter)
        break
    elif place<=x and i==n-1:
        counter+=1
        print(counter)

Measured memory_bytes: 3064
from operator import itemgetter
h, w, n = map(int, input().split())
coord = [list(map(int, input().split())) for i in range(n)]

co_sort = sorted(sorted(coord), key = itemgetter(1))
c = h
r = 0
for co in co_sort:
  if co[0] - 1- r >= co[1]:
    c = min(c, co[0]-1)
  elif co[0] - r == co[1]:
    r += 1

print(c)
    

Measured memory_bytes: 58828
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool finder(int first, int last, int s);
vector<int>v;

int main(void){
    int s,count=1;
    v.push_back(-1);
    cin >> s;
    while(true){
        if(finder(0, v.size(), s))  //見つかったら
            break;
        else{
            v.push_back(s);
            sort(v.begin(), v.end());
            count++;
        }
        if(s%2 == 0){
            s = s/2;
        }
        else{
            s = 3*s+1;
        }
    }
    cout<< count << endl;
    return 0;
}

bool finder(int first, int last, int s){
    int now = (first + last)/2;
    if(last < first)    return false;
    else if(s < v[now])
        finder(first, now-1, s);
    else if(v[now] < s)
        finder(now+1, last, s);
    else return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>	
#include<algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int > vi;
typedef vector<vi> vvi;

int main() {
	int n, m;
	cin >> n >> m;
	vvi e(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	int q;
	cin >> q;
	vvi A(11, vi(n,-1));
	vi C(q);
	for (int i = 0; i < q; i++) {
		int v, d, c;
		cin >> v >> d >> c;
		v--;
		A[d][v] = i;
		C[i] = c;
	}
	for (int d = 10; d > 0; d--) {
		for (int v = 0; v< n; v++) {
			int clr = A[d][v];
			for (int i = 0; i < e[v].size(); i++) {
				int nv = e[v][i];
				A[d - 1][nv] = max(A[d - 1][nv], clr);
			}
			A[d - 1][v] = max(A[d - 1][v], clr);
		}
	}
	for (int i = 0; i < n; i++) {
		int clr;
		if (A[0][i] == -1) {
			clr = 0;
		}
		else {
			clr = C[A[0][i]];
		}
		cout << clr << endl;
	}

	return 0;
}

Measured memory_bytes: 11248
function Main(input) {
    ar = input[0].split(" ");
    var x = Number(ar[0]);
    var a = Number(ar[1]);
    if (x < a) {
        console.log("0");
    }
    else {
        console.log("10");
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

const ll MOD=1e9+7;
ll f[444][444],sum[444][444];
int n,c,a[444],b[444];

ll fpow(ll a,ll p){
	ll res=1LL;
	while(p){
		if(p&1LL) res=res*a%MOD;
		a=a*a%MOD;
		p>>=1LL;
	}
	return res;
}

ll dp(int cur,int remain){
	if(cur==n){
		if(remain==0) return 1LL;
		else return 0LL;
	}
	ll &res=f[cur][remain];
	if(~res) return res;
	res=0LL;
	for(int k=0;k<=remain;++k) (res+=sum[cur][k]*dp(cur+1,remain-k)%MOD)%=MOD;
	return res; 
}

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>c;
	for(int i=0;i<n;++i) cin>>a[i];
	for(int i=0;i<n;++i) cin>>b[i];
	for(int i=0;i<n;++i) for(int k=0;k<=c;++k) for(int j=a[i];j<=b[i];++j) (sum[i][k]+=fpow(j,k))%=MOD;
	memset(f,-1,sizeof f);
	cout<<dp(0,c);
}

Measured memory_bytes: 3200
function bomb(){
   var ans=0;
   var dx=[0,-1,1,0];
   var dy=[-1,0,0,1];
   var obj={};
   var ary=[[1,1,0]];
   while(true){
      if(ary.length==0)break;
      var leaf=ary.shift();
      var x=leaf[0];
      var y=leaf[1];
      var cnt=leaf[2];
      if(x==w*2-1 && y==h*2-1){ans=(cnt+2)/2;break;}
      for(var i=0;i<4;i++){
         var X=x+dx[i];
         var Y=y+dy[i];
         if(X<=0 || Y<=0 || X>=w*2 || Y>=h*2)continue;
         if(yx[Y][X]==1)continue;
         if(obj.hasOwnProperty(X+","+Y)==false){
            ary.push([X,Y,cnt+1]);
            obj[X+","+Y]=true;
         }
      }
   }
   return ans;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var wh=arr.shift().split(" ").map(Number);
   if(wh.join(" ")=="0 0")break;
   var w=wh[0];
   var h=wh[1];
   var yx=[];
   for(var i=0;i<=h*2;i++){
      yx[i]=[];
      for(var j=0;j<=w*2;j++){
         yx[i][j]=0;
      }
   }
   for(var i=0;i<(h*2)-1;i++){
      var data=arr.shift().replace(/ /g,"");
      if(i%2==0){
         data=data;
         var ary=data.split("");
         ary.forEach(function(value,index){
            if(value=="1"){
               yx[i+0][index*2+2]=1;
               yx[i+1][index*2+2]=1;
               yx[i+2][index*2+2]=1;
            }
         });
      }else{
         var ary=data.split("");
         ary.forEach(function(value,index){
            if(value=="1"){
               yx[i+1][index*2+0]=1;
               yx[i+1][index*2+1]=1;
               yx[i+1][index*2+2]=1;
            }
         });
      }
   }
   console.log(bomb());
}

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

#define rep(i, n) for(int i=0;i<(int)n;i++)
int INF=1e9;

int main() {
  int H, N;
  cin >> H >> N;
  int A[N], B[N];
  int dp[N+1][H+1];
  rep(i, N) {
    cin >> A[i] >> B[i];
    dp[i+1][0]=0;
    rep(j, H) dp[i][j+1]=INF;
  }
  rep(j,H) dp[0][j+1]=INF;
  dp[0][0]=0;
  rep(i, N) {
    rep(j, H) {
      if(j+1>=A[i]) dp[i+1][j+1]=min(dp[i][j+1], dp[i+1][j+1-A[i]]+B[i]);
      else dp[i+1][j+1]=min(dp[i][j+1], B[i]);
    }
  }
  cout << dp[N][H] << endl;
}

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

int main()
{
    set<int>s;
    int T,num=0;
    cin>>T;
    while(T--)
    {
        int flag,x;
        cin>>flag>>x;
        if(flag==0)
        {
            auto it=s.insert(x);
            if(it.second==1)
                num++;
            cout<<num<<endl;
        }
        else
        {
            auto it=s.find(x);
            if(it==s.end())
            {
                cout<<0<<endl;
            }
            else cout<<1<<endl;
        }
    }
  //  cout << "Hello world!" << endl;
    return 0;
}



Measured memory_bytes: 12464
// https://atcoder.jp/contests/agc036/tasks/agc036_a

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const double EPS = 1e-9;
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1000000007;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll s, x, y;
    cin >> s;
    y = ceil(((double)s / INF));
    x = y * INF - s;
    cout << "0 0 1000000000 1 " << x << " " << y << endl;

    return 0;
}


Measured memory_bytes: 256