akhauriyash/Code-Regression huggingface dataset:
//https://www.youtube.com/watch?v=8LusJS5-AGo
//https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10/
#include<bits/stdc++.h>
#define int long long
#define scf(n) scanf("%lld",&n)
#define rep1(n) for(int i=1;i<=n;i++)
#define prf(n) printf("%lld",n)
#define sci(n) scanf("%lld",&n)
#define pri(n) printf("%lld",n)

#define nl printf("\n")
#define spc printf(" ")
#define file freopen("in.txt","rt",stdin)
#define pii pair<int,int>
#define piii pair<pii,int>
#define MOD 10000007
using namespace std;

/*bool sortBySec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/
void faster(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/******************************************/
int dp[109][100009];
int cost[109];
int weight[109];
int32_t main()
{
    /***********************************/
#ifdef ONPC
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    //faster();
    /*********************************/
    int capacity,n;
    int c = 0;

    cin>>n>>capacity;
    for(int i=1; i<=n; i++)
    {
        cin>>weight[i]>>cost[i];
    }
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=capacity; j++)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(j>=weight[i])
            {
                dp[i][j] = max(cost[i]+dp[i-1][j-weight[i]],dp[i-1][j]);
            }
            else
            {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout<<dp[n][capacity]<<endl;


    return 0;
}


Measured memory_bytes: 80128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int num1[100005],num2[100005];
int n,a,mx,mxo1,mxo2,mxe1,mxe2,po1,po2,pe1,pe2;
int main()
{
	n=in();
	for (int i=1;i<=n;++i) {
		a=in();
		if (i&1) ++num1[a];
		else ++num2[a];mx=max(mx,a);
	}
	for (int i=1;i<=mx;++i){
		if (num1[i]>mxo1) mxo2=mxo1,po2=po1,mxo1=num1[i],po1=i;
		else if (num1[i]>mxo2)  mxo2=num1[i],po2=i;
		if (num2[i]>mxe1) mxe2=mxe1,pe2=pe1,mxe1=num2[i],pe1=i;
		else if (num2[i]>mxe2)  mxe2=num2[i],pe2=i;
	}
	if (po1==pe1) printf("%d",n-max(mxo1+mxe2,mxe1+mxo2));
	else printf("%d",n-mxo1-mxe1);
	return 0;
}

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll big = 10e10 + 11 ;

int  main (  ) {

    FASTIO ;

    string s1 , s2 ;
    cin >> s1 >> s2 ;

    int a , b ;
    cin >> a >> b ;

    string  u ;
    cin >> u ;

    if( u == s1 )a-- ;
    else  b-- ;

    cout << a << " " << b ;



    return  0 ;
}



Measured memory_bytes: 256
#! /usr/bin/env python

import sys

def check(inputstring) :

    check_string = [['keyence'],
                    ['k','eyence'],
                    ['ke','yence'],
                    ['key','ence'],
                    ['keye','nce'],
                    ['keyen','ce'],
                    ['keyenc','e'],
                    ['keyence']]

    if check_string[0][0] == inputstring[0:7] :
        return "YES"

    for i in range(1, 7) :
        if check_string[i][0] == inputstring[0:len(check_string[i][0])] and check_string[i][1] == inputstring[-len(check_string[i][1]):] :
            return "YES"

    if check_string[7][0] == inputstring[-7:] :
        return "YES"


    return "NO"

if __name__ == '__main__' :
    line = sys.stdin.readline()

    print(check(line.rstrip()))

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

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

	llong ret = 0;
	llong before = 0;
	llong cnt = 1;
	for (int &&i = 1, &&n = s.size(); i < n; ++i) {
		if (s[i-1] == s[i]) {
			++cnt;
		} else {
			if (s[i-1] == '<') {
				ret += cnt * (cnt+1) / 2;
				before = cnt;
			} else {
				ret += cnt * (cnt-1) / 2;
				if (before < cnt) {
					ret += cnt - before;
				}
				before = 0;
			}

			cnt = 1;
		}
	}
	if (s.back() == '<') {
		ret += cnt * (cnt+1) / 2;
		before = cnt;
	} else {
		ret += cnt * (cnt-1) / 2;
		if (before < cnt) {
			ret += cnt - before;
		}
		before = 0;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,m;
long long a[300010];
int main() 
{
    cin>>n;
    for(int i=1;i<=n*3;i++)
    cin>>a[i];
    sort(a+1,a+n*3+1);
    for(int i=(n*3)-1;i>=n+1;i-=2)
    m+=a[i];
    cout<<m;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MAX (ll)(3e5 + 7)
#define INF (ll)(1e5 + 7)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 20

using namespace std;
using ll = long long;

int main () {
	int n, m;
	cin >> n >> m;
	cout << ((n) * (n - 1) + (m * (m - 1))) / 2 << "\n";
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[][] a = new int[101][101];
		
		int r = scan.nextInt();
		int c = scan.nextInt();
		
		for(int i=0; i<=r; i++){
		for(int q=0; q<=c; q++){
			a[i][q] = 0;}}
		
		for(int i=0; i<r; i++){
		for(int q=0; q<c; q++){
			a[i][q] = scan.nextInt();
			a[i][c] += a[i][q];
			a[r][q] += a[i][q];
			a[r][c] += a[i][q];}}
			
		for(int i=0; i<=r; i++){
		for(int q=0; q<=c; q++){
			System.out.print(a[i][q]);
			if(q!=c){
				System.out.print(" ");}}
			System.out.print("\n");}
	}
}


Measured memory_bytes: 42564
from bisect import bisect_right
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
for i in range(1, N+1):
    a[i] = a[i-1]+A[i-1]
for i in range(1, M+1):
    b[i] = b[i-1]+B[i-1]
ans = 0
for i in range(N+1):
    if a[i]>K:
        break
    j = bisect_right(b, K-a[i]) - 1
    ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 47372
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  double_t N; cin >> N;
  auto ans = 2*N * 3.14159265359;
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 3800
import sys


def answer():
    input = sys.stdin.readline
    x, y = map(int, input().split())

    def reward(x):
        if x==1:
            return 300000
        elif x==2:
            return 200000
        elif x==3:
            return 100000
        return 0

    total = 0
    total += reward(x)
    total += reward(y)
    if x == y == 1:
        total += 400000

    print(total)


if __name__ == '__main__':
    answer()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e5 + 10;

int a[maxN][3];
int dp[maxN][3];
int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int inf = 1 << 30;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }
  for (int j = 0; j < 3; ++j)
    dp[1][j] = a[1][j];
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int t = 0; t < 3; ++t) {
        if (t != j)
          dp[i+1][t] = max(dp[i+1][t], dp[i][j] + a[i+1][t]);
      }
    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]});
return 0;
}


Measured memory_bytes: 5932
s = gets.chomp                           
                                         
a = 0                                    
b = 0                                    
s.size.times do |i|                      
  a += 1 if (i.odd? ? "0" : "1") != s[i] 
  b += 1 if (i.odd? ? "1" : "0") != s[i] 
end                                      
                                         
puts a < b ? a : b                       


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 1002;
int N, M;
int S, T, X, Y;
string G[MAX_N];
const int dx[]={1,-1,0,0}, dy[]={0,0,1,-1};
int vis[MAX_N][MAX_N];
vector<pair<int,int>> prv, nxt;
int a;
map<int, vector<pair<int,int>>> order;

void dfs(int x, int y)
{
	if(vis[X][Y]!=-1) return;
	vis[x][y]=a;
	order[a].eb(x,y);
	for(int i=0;i<4;++i){
		const int nx=x+dx[i];
		const int ny=y+dy[i];
		if(nx>=0&&nx<N&&ny>=0&&ny<M&&vis[nx][ny]==-1&&G[nx][ny]!='#'){
			dfs(nx,ny);
		}
	}
}

void solve()
{
	S--,T--,X--,Y--;
	a = 0;
	memset(vis,-1,sizeof(vis));
	dfs(S,T);
	if(vis[X][Y]==0){
	    cout<<0;
	    return;
	}
	for(;;){
		a++;
		bool update=false;
		for(const auto& p : order[a-1]){
			const int x=p.first, y=p.second;
			for(int r=-2;r<=2;++r)for(int c=-2;c<=2;++c){
				const int nx=x+r, ny=y+c;
				if(nx>=0&&nx<N&&ny>=0&&ny<M&&vis[nx][ny]==-1&&G[nx][ny]!='#'){
					update=true;
					dfs(nx,ny);
					if(vis[X][Y]!=-1) goto out;
				}
			}
		}
		if(!update || vis[X][Y]!=-1)break;
	}
out:
	if(vis[X][Y]==-1) cout<<-1;
	else cout<<a;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N >> M;
	cin >> S >> T;
	cin >> X >> Y;
	for(int i=0;i<N;++i) cin >> G[i];
	solve();
	return 0;
}

Measured memory_bytes: 26644
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int costs[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool usable[10];


int main()
{
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        usable[a] = true;
    }

    vector<int> dp(N + 1, INT_MIN);
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 9; j > 0; j--) {
            if (usable[j] && i - costs[j] >= 0) {
                dp[i] = max(dp[i], dp[i - costs[j]] + 1);
            }
        }
    }

    int t = N;
    while (t) {
        for (int i = 9; i > 0; i--) {
            if (usable[i] && t - costs[i] >= 0 && dp[t - costs[i]] + 1 == dp[t]) {
                cout << i;
                t -= costs[i];
                break;
            }
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include<regex>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define int long long
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%lld",&a)
#define pf(a) printf("%lld ",a)
using namespace std;
int dp[10000005][3];
char a[10000005];
signed main()
{
    
    a[0] = '0';
    scanf("%s", a + 1);
    int len = strlen(a + 1);
    dp[len][0] = (a[len] - '0');
    dp[len][1] = 10 - (a[len] - '0');
    for (int i = len - 1; i >= 0; i--)
    {
        dp[i][0] = min(dp[i + 1][0] + (a[i] - '0'), dp[i + 1][1] + (a[i] - '0') + 1);
        dp[i][1] = min(dp[i + 1][0] + 10 - (a[i] - '0'), dp[i + 1][1] + 10 - (a[i] - '0' + 1));
    }
   pf(min(dp[0][0], dp[0][1]));
    return 0;
}








Measured memory_bytes: 26880
/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.0.2"
+/

import std.algorithm, std.range, std.stdio, std.math, std.conv, core.bitop;

// import dcomp.scanner;
// import dcomp.algorithm;

int n;
struct Edge {
    int to;
    long dist;
}
Edge[][] g;
long md;

T[N] toS(T, int N)(T[N] data){ return data; }

long[2][] dfs(int p) {
    if (g[p].empty) {
        return [[0L, 0L]];
    }
    Edge le = g[p][0], re = g[p][1];
    auto lt = dfs(le.to);
    auto rt = dfs(re.to);
    if (lt.length > rt.length) {
        swap(le, re);
        swap(lt, rt);
    }
    long ld = le.dist, rd = re.dist;
//    long[2][] ans;
    auto buf = Appender!(long[2][])();
    buf.reserve(lt.length*2);
    foreach (co; lt) {
        //co[1] + ld + rd + rco[0] <= md
        int idx = binSearch!((i){return co[1]+ld+rd+rt[i][0] > md;})(-1L, rt.length).to!int-1;
        if (idx == -1) continue;
        buf.put([co[0]+ld, rt[idx][1]+rd].toS);
        buf.put([rt[idx][1]+rd, co[0]+ld].toS);
    }
    auto ans = buf.data;
    sort(ans);
    if (ans.empty) return ans;
    long ma = 10L^^15;
    int co = 0;
    foreach (e; ans) {
        if (ma <= e[1]) continue;
        ma = min(ma, e[1]);
        ans[co] = e;
        co++;
    }
    return ans[0..co];
}

//md以下にできるか？
bool solve(long _md) {
    md = _md;
    return !dfs(0).empty;
}

int main() {
    auto sc = new Scanner();
    int n;
    sc.read(n);
    g = new Edge[][](n);
    foreach (i; 1..n) {
        int a; long b;
        sc.read(a, b); a--;
        g[a] ~= Edge(i, b);
    }

    writeln(binSearch!solve(-1L, 10L^^12));
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/algorithm.d */
// module dcomp.algorithm;

//[0,0,0,...,1,1,1]で、初めて1となる場所を探す。pred(l) == 0, pred(r) == 1と仮定
T binSearch(alias pred, T)(T l, T r) {
    while (r-l > 1) {
        T md = (l+r)/2;
        if (!pred(md)) l = md;
        else r = md;
    }
    return r;
}


Measured memory_bytes: 45308
#include<bits/stdc++.h>
using namespace std;
int A[201];
int main(){
	int a,b,i,w=0,m=1e9,p;
	cin>>a>>b;
	for(i=1;i<=a;i++){
		A[i]=b+i-1,w+=A[i];
		if(abs(A[i])<m)p=i,m=abs(A[i]);
	}
	cout<<w-A[p];
}

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	string S, T;
	cin >> S >> T;
	bool flag = true;
    for (int i=0; i < S.size(); i++) {
		if(S[i] != T[i]) {
			flag = false;
		}
	}
	if (flag) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  ll M;
  
  cin >>N>>M;
  if(N<=M) {
  if((N==1)&&(M==1)) {
    cout<<1<<endl;
  }
else if((N==1) &&(M!=1)) {
  cout<<M-2<<endl;
}
  else {
    cout<<(N-2)*(M-2)<<endl;
  }
  }
  
  
  
  
  
  else if(M<N) {
    if((M==1)&&(N!=1)) {
      cout<<N-2<<endl;
    }
    else {
      cout<<(N-2)*(M-2)<<endl;
    }
  }
    
    
    
    
    
    
    
    
    
}
  


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Mod 1000000000 + 7
#define Maxn 1000000 + 100
typedef long long ll;
using namespace std;
bool cmp(int x,int y)
{
    return x < y;
}

int gcd(int x,int y)
{
    return 0;
}

ll quick_mod()
{
    return 0;
}

int n;
int main()
{
    cin>>n;
    cout<<48 - n<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int


int solve( ){
 

 int a,b,n;
 cin>>a>>b>>n;

cout<<min(b/a,n);



return 0;
}
int main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  

  
  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;
   while(t--)
     {solve();
     }

         time_req = clock() - time_req;
   // cout << "Processor time taken is "
      // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}


Measured memory_bytes: 256
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int s, w;
signed main()
{
	cin >> s >> w;

	if (s <= w) {
		cout << "unsafe" << endl;
	} else {
		cout << "safe" << endl;
	}

	return 0;
}


Measured memory_bytes: 3640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

 //最大公約数求める関数
auto my_gcd(auto n , auto m){
  if(n < m){
    auto tmp = n;
    n = m;
    m = tmp;
  }
  auto l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
ll A,B,C,D ; cin >> A >> B >> C >> D;
ll n = (A  - 1)/ C;
ll m = B / C;
ll l = (A -1) / D;
ll o = B / D;
ll x = C / my_gcd(C,D);
ll y = D / my_gcd(C,D);
ll p = (A-1) / (my_gcd(C,D) * x * y); 
ll q = B / (my_gcd(C,D) * x * y); 

/*cout << n << endl;
cout << m << endl;
cout << l << endl;
cout << o << endl;
cout << x << endl;
cout << y << endl;
cout << p << endl;
cout << q << endl;*/
cout << B - A + 1-( m - n + o - l - q + p)<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);



int main()
{
    long long int N, K, S; std::cin >> N >> K >> S;
    if(S+1<=1000000000)
    {
        // S!=1000000000
        for(int i=0; i<K; i++)
            std::cout << S << " ";
        for(int i=K; i<N; i++)
            std::cout << S+1 << " ";
        std::cout << "\n";
    }
    else
    {
        for(int i=0; i<K; i++)
            std::cout << S << " ";
        for(int i=K; i<N; i++)
            std::cout << 1 << " ";
        std::cout << "\n";
    }
    return 0;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 100 * 1000 + 9;

int n, m;
multiset<ll> se;
vector<ll> job[maxN];

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

	cin >> n >> m;

	for(int i = 1; i <= n; i++){
		ll a, b;  cin >> a >> b;
		job[a].push_back(b);
	}
	
	ll fRes = 0;
	for(int i = 1; i <= m; i++){
		for(int j = 0, L = job[i].size(); j < L; j++){
			se.insert(job[i][j]);
		}

		if(!se.empty()){
			multiset<ll>::iterator it = se.end();
			it--;
			fRes += *it;
			se.erase(it);
		}
	}
	
	cout << fRes << '\n';

	return 0;
}

Measured memory_bytes: 8320
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    cout << (x == 0 ? 1 : 0) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

int main(){
  char s[3]={};
  for(int i=0;i<3;i++)
  	std::cin>>s[i];
  if(s[2]==0){
    std::cout<<s[0]<<s[1];
  }else
  for(int i=2;i>=0;--i){
  	std::cout<<s[i];
  }
  return 0;
}

Measured memory_bytes: 256
def kannondou(x):
    dp = [0]*(x+1)
    dp[0] = 1
    for i in range(1, x+1):
        for j in range(1, 4):
            if 0 <= i - j:
                dp[i] += dp[i-j]
    return dp[-1]//3650 + 1

while True:
    a = int(input())
    if a == 0:
        break
    print(kannondou(a)) 


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

int main() {
  std::string S;
  std::cin >> S;
  int prev = (S[0] - 48) * 10 + (S[1] - 48);
  int next = (S[2] - 48) * 10 + (S[3] - 48);

  bool prev_flag = false;
  bool next_flag = false;

  if ((0 < prev) && (prev < 13)) {
    prev_flag = true;
  }
  if ((0 < next) && (next < 13)) {
    next_flag = true;
  }

  std::string result;

  if (prev_flag & next_flag) {
    result = "AMBIGUOUS";
  } else if (prev_flag) {
    result = "MMYY";
  } else if (next_flag) {
    result = "YYMM";
  } else {
    result = "NA";
  }

  std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
const ll INF=1ll<<58;
#define MAXN 200011
ll fa[MAXN];
struct DSU
{
	ll fa[MAXN];
	void build(ll n){for(ll i=1;i<=n;++i)fa[i]=i;}
	ll find(ll x)
	{
		if(fa[x]==x)return x;
		return fa[x]=find(fa[x]);
	}
	void uni(ll u,ll v)
	{
		u=find(u),v=find(v);
		fa[u]=v;
	}
}s;
bool a[MAXN];
ll cnt0[MAXN],cnt1[MAXN];
struct one
{
	ll x;
	bool operator <(const one& t)const
	{
		ll x1=cnt1[x],x0=cnt0[x],y1=cnt1[t.x],y0=cnt0[t.x];
		return x1*y0<y1*x0||(x1*y0==y1*x0&&x>t.x);
	}
};
std::set<one>st;
int main()
{
	ll n=read(),ans=0;
	s.build(n);
	for(ll i=2;i<=n;++i)fa[i]=read();
	ll x=read();
	cnt0[1]=!x,cnt1[1]=x;
	for(ll i=2;i<=n;++i)x=read(),cnt0[i]=!x,cnt1[i]=x,st.insert({i});
	while(st.size())
	{
		ll u=s.find(st.begin()->x);
		ll f=s.find(fa[u]);
		st.erase({u}),st.erase({f});
		ans+=cnt1[f]*cnt0[u];
		cnt1[f]+=cnt1[u],cnt0[f]+=cnt0[u];
		s.uni(u,f);
		if(f!=1)st.insert({f});
	}
	std::cout<<ans;
	return 0;
}

Measured memory_bytes: 19240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,k,a[N],cov[N];

int main() {
	cin>>n>>k;
	for(int i=1;i<=n;i++) a[i]=gi();
	while(k--) {
		memset(cov,0,sizeof(cov));
		for(int i=1;i<=n;i++) {
			++cov[max(1,i-a[i])];
			--cov[min(n,i+a[i])+1];
		}
		bool all=1;
		for(int i=1;i<=n;i++) cov[i]+=cov[i-1],a[i]=cov[i],all&=(a[i]==n);
		if(all) break;
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<' ';
	return 0;
}


Measured memory_bytes: 5192
#include<iostream>

using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2!=0){
        cout << "No";
        return 0;
    }
    for(int i=0; i<=x; i++){
        if(y==4*x-2*i){
            cout <<"Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3636
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

ans=0
for i in range(1,int(input())+1):
    if i%2==1:
        if len(make_divisors(i))==8:
            ans+=1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}


const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18; //(+1までok)
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

const int N_max=100000;

int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N,C,s,t,c,temT[N_max*2+2],T[N_max*2+2],result=0;
	vector<P> ve[31];


	cin>>N>>C;
	REP(i,N){
		cin>>s>>t>>c;
		ve[c].pb(P(s,t));
	}

	REP(i,N_max*2+2) T[i]=0;

	FOR(i,1,C+1){
		REP(j,N_max*2+2) temT[j]=0;
		REP(j,ve[i].size()){
			temT[ve[i][j].first*2-1]++;
			temT[ve[i][j].second*2]--;
		}
		FOR(j,1,N_max*2+2){
			temT[j]+=temT[j-1];
			if(temT[j]>0) T[j]++;
		}
	}
	FOR(i,1,N_max*2+2) chmax(result,T[i]);
	print(result);
	return 0;
}





Measured memory_bytes: 3072
import sys

n, k = map(int, input().split())
a = list(map(int, input().split()))

if k == 0:
    print(max(a))
    sys.exit()

def check(t):
    if t == 0:
        return False
    ans = 0
    for ai in a:
        if ai > t:
            ans += ai // t
    return ans <= k

l = 0
r = 10 ** 9 + 1

while r - l > 1:
    mid = (r + l) // 2
    if check(mid):
        r = mid
    else:
        l = mid

if check(l):
    print(l)
else:
    print(r)



Measured memory_bytes: 30976
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
#define MOD 1'000'000'007
using namespace std;
typedef long long ll;
typedef long double ld;

int Q;
int l[100000];
int r[100000];
int prime[100001];
int cnt[100001];

int main(){
    cin>>Q;
    rep(i,Q) cin>>l[i]>>r[i];

    repn(i,100000){
        repn(j,100000/i){
            prime[i*j]++;
        }
    }
    
    repn(i,100000){
        cnt[i]=cnt[i-1];
        if(prime[i]==2 && prime[(i+1)/2]==2) cnt[i]++;
    }

    rep(i,Q){
        int ans=cnt[r[i]]-cnt[l[i]-1];
        cout<<ans<<endl;
    }
}

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

#define ll long
#define ld long double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod	%1000000007
#define FOR(I,N) for(I=0;I<N;++I)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pi 3.141592653

ll n,a[23][23];
ll dp[3000000];
queue<pair<ll,ll>> que;
void solve()
{
	pair<ll,ll> x=que.front();	que.pop();
	ll i,k=x.F;
	ll mask=x.S;
	FOR(i,n)
	{
		if((mask&(1<<i))==0 && a[k][i]==1)
		{
			if(k+1<n && dp[mask|(1<<i)]==0)
				que.push(mp(k+1,mask|(1<<i)));
			dp[mask|(1<<i)] = (dp[mask|(1<<i)] + dp[mask])mod;			
		}
	}
}

int main()
{
	//IOS;
	memset(dp,0,sizeof(ll)*(3000000));
	ll i,j;
	cin>>n;
	dp[0]=1;
	FOR(i,n)
	{
		FOR(j,n)
		{
			cin>>a[i][j];
		}
	}
	que.push(mp(0,0));
	while(que.empty()==0)
	{
		solve();
	}
	j=0;
	FOR(i,n)
	j = j|1<<i;
	cout<<dp[j];
}

Measured memory_bytes: 30084
#include <iostream>

 

using namespace std;

 

int main() 
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0 && x+r <= w && y+r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
       


Measured memory_bytes: 3116
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/24/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 1e18;

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

  int N,M; cin>>N>>M;
  struct Node {
    int p; ll c;
    Node(int p, ll c) : p(p), c(c) {}
    bool operator>(const Node& x) const {return c > x.c;}
  };
  vector<Node> graph[N];
  for (int i = N-1; i > 0; i--)
    graph[i].emplace_back(i-1, 0);
  for (int i = 0; i < M; i++) {
    int l,r,c; cin>>l>>r>>c;
    l--; r--;
    graph[l].emplace_back(r,c);
  }
  auto dijkstra = [&]() {
    priority_queue<Node, vector<Node>, greater<>> qs;
    vector<ll> dis(N, INF);
    qs.emplace(0, 0);
    while (not qs.empty()) {
      Node q = qs.top(); qs.pop();
      if (dis[q.p] < q.c)
        continue;
      for (Node t : graph[q.p]) {
        auto c = q.c+t.c;
        if (dis[t.p] <= c)
          continue;
        dis[t.p] = c;
        if (t.p < N-1)
          qs.emplace(t.p, c);
      }
    }
    return dis[N-1];
  };
  auto ans = dijkstra();
  cout << (ans==INF?-1:ans) << endl;

  return 0;
}


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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> v(n);
    for(int i = 0;i < n;i++) cin >> v.at(i);
    int max_d = 0;
    for(int i = 0; i < n;i++){
        int d = 0;
        if(i == n - 1) d = k - v.at(i) + v.at(0);
        else d =(v.at(i+1) - v.at(i));
        max_d = max(max_d,d);
        
    }
    int ans = k - (max_d);
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int i = 1;
  do {
   int x=i;
   if (x%3==0){
    System.out.print(" " + i);
   } 
    else {
    do{
     if(x%10==3){
      System.out.print(" " + i);
      break;
     }
     x /= 10;
    } while (x != 0);
   }
  } while (++i <= n);
  System.out.println();
 }
}

Measured memory_bytes: 28688
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000];
int n;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int right = a[n / 2];
    int left = a[n / 2 - 1];
    cout << right - left << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define il inline
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 200005
#define MAXM 
#define mod 1000000007
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(register int i = x; i <= y; ++i)
#define repd(i, x, y) for(register int i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".my", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
ll n, A, B, C;
ll f[MAXN], invf[MAXN];
ll fpow(ll x, ll y) {
	ll ret = 1;
	while(y) {
		if(y & 1) ret = ret * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ret;
}
const int Inv = fpow(100, mod-2);
ll Ch(ll x, ll y) {
	return f[x] * invf[y] % mod * invf[x - y] % mod;
}
int main() {
	read(n, A, B, C);
	int ta = A, tb = B;
	A = A * fpow(ta + tb, mod - 2) % mod, B = B * fpow(ta + tb, mod - 2) % mod, C = C * Inv % mod;
	// A = A * Inv % mod, B = B * Inv % mod, C = C * Inv % mod;
	f[0] = 1;
	rep(i, 1, n * 2) f[i] = f[i-1] * i % mod;
	invf[n * 2] = fpow(f[n * 2], mod - 2);
	repd(i, n * 2, 1) invf[i-1] = invf[i] * i % mod;
	ll ans = 0;
	rep(i, n, n * 2 - 1) {
		ans = (ans + i * Ch(i-1, n-1) % mod * (fpow(A, n) * fpow(B, i - n) % mod + fpow(A, i - n) * fpow(B, n) % mod)) % mod;
		// cout << i << ' ' << Ch(i-1, n-1) << ' ' << fpow(A, n) * fpow(B, i-n) % mod << ' ' << fpow(A, i-n) * fpow(B, n) % mod << endl;
	}
	// cout << ans << endl;
	ans = ans * fpow(1 - C + mod, mod - 2) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class ATenki
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == t[i])
                {
                    count++;
                }
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+7;
#define mo 998244353
#define ll long long
ll inv[MAXN<<2],fac[MAXN<<2],n,m,ans;
char U[MAXN],D[MAXN],L[MAXN],R[MAXN];
inline ll Cn(ll k,ll b){return (ll)fac[k]*inv[b]%mo*inv[k-b]%mo;}
inline void solve(int n,int m,char *L,char *R,char *U,char *D)
{
	ll tmp=0;
	ll cl,cr,cu,cd,nowu,nowd,u,d;
	cl=cr=cu=cd=nowu=nowd=u=d=0;
	for(int i=1;i<=n;i++) cl+=L[i]-'0',cr+=R[i]-'0';
	for(int i=1;i<=m;i++) cd+=D[i]-'0',cu+=U[i]-'0';
	if(cl+cd+cr+cu==0){cout<<"1";exit(0);}
	tmp=1;
	for(int i=1;i<=m;i++){
		nowu+=(u=U[i]-'0');nowd+=(d=D[i]-'0');
		if(u||d){
			if(u&&d) tmp=tmp*2%mo;
			if(cr!=0) ans=(ans+tmp*Cn(cr+cu+cd-nowu-nowd-1,cr-1))%mo;
			else ans=(ans+tmp*(cu+cd-nowu-nowd==0))%mo;
			if(cl!=0) tmp=(tmp+Cn(cl+nowu+nowd-1,cl-1))%mo;
			else tmp=(tmp+(nowu+nowd==0))%mo;
		}
	}
}
int main()
{
	cin>>n>>m;
	fac[0]=1;inv[1]=inv[0]=1;
	for(int i=1;i<=4*MAXN-10;i++) fac[i]=fac[i-1]*i%mo;
	for(int i=2;i<=4*MAXN-10;i++) inv[i]=(mo-mo/i)*inv[mo%i]%mo;
	for(int i=2;i<=4*MAXN-10;i++) inv[i]=(ll)inv[i]*inv[i-1]%mo;
	scanf("%s%s%s%s",L+1,R+1,U+1,D+1);
	solve(n,m,L,R,U,D);solve(m,n,U,D,L,R);
	cout<<ans<<endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define ps push
#define fr front
typedef pair<int,int> pii;

#define MAX_N 100000

int ord[MAX_N],low[MAX_N];
vector<int> g[MAX_N];
bool f[MAX_N];
vector<pii> ans;

void dfs(int u,int v,int k){
	f[v]=true;
	ord[v]=k;
	low[v]=ord[v];
	for(int j=0;j<g[v].size();++j){
		int w=g[v][j];
		if(w==u) continue;
		else if(f[w]) low[v]=min(low[v],ord[w]);
		else{
			dfs(v,w,k+1);
			low[v]=min(low[v],low[w]);
			if(ord[v]<low[w]) ans.pb(mp(min(v,w),max(v,w)));
		}
	}
}

int main(){
	int n,e;
	scanf("%d%d",&n,&e);
	vector<pii> es;
	for(int j=0;j<e;++j){
		int v,w;
		scanf("%d%d",&v,&w);
		g[v].pb(w);
		g[w].pb(v);
	}
	fill(f,f+n,false);
	dfs(0,0,0);
	sort(ans.begin(),ans.end());
	for(int j=0;j<ans.size();++j) printf("%d %d\n",ans[j].fi,ans[j].sc); 
}

Measured memory_bytes: 7192
import math

A, B = map(int, input().split())

while B > 0:
    A, B = B, A % B
N = A

ans = 1
i = 2
while i * i <= N:
    if N % i == 0:
        while N % i == 0:
            N //= i
        ans += 1
    i += 1
if N > 1:
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

int main(){
  int n,S[10000],q,T[500],i,j,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2108
/*
つかれた～～～～
*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

const int N = 310;
ll dp[N][N], dp2[N][N];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k, m; cin >> n >> k >> m;
  for(int i = 0; i <= 301; i++) dp[i][0] = dp[0][i] = dp[1][i] = 1;
  for(int i = 2; i <= 301; i++) {
    for(int j = 1; j <= 301; j++) {
      dp[i][j] = (dp[i][j-1] * i % m + dp[i-1][j]) % m;
    }
  }
  for(int i = 0; i <= 300; i++) dp2[0][i] = dp2[i][1] = 1;
  for(int i = 1; i <= n; i++) {
    for(int j = 2; j <= k; j++) {
      for(int l = 0; l <= i; l++) {
        dp2[i][j] = (dp2[i][j] + dp2[l][j - 1] * dp[l + 1][i - l] % m) % m;
        dump(l+1, j-l, dp[l+1][j-l]);
      }
    }
  }
  cout << dp2[n][k] << endl;
}


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

const int N=500005; 

using namespace std;

int n,m,mark,p[N],qq[N],deg[N];
pair<int,int> q[N];

struct edge{
	int u,v,nxt; 
}e[N<<1]; int adj[N],tail; 

void addedge(int u,int v){ e[++tail]=(edge){u,v,adj[u]}; adj[u]=tail; }

set<int> s; 
set<int>::iterator it; 
priority_queue< int, vector<int>, greater<int> > pq; 

bool cmp(pair<int,int> a, pair<int,int> b){ return a.first>b.first; }

int main(){
	int x,y; 
	cin>>n>>m;
	for(int i=1; i<=n; ++i) cin>>p[i]; 
	for(int i=1; i<=n; ++i) qq[p[i]]=q[p[i]].first=i, q[p[i]].second=p[i]; 
	tail=0; for(int i=1; i<=n; ++i) adj[i]=-1; 
	sort(q+1,q+n+1); s.clear(); 
	for(int i=1; i<=n; ++i){
		if(i-m>=1) s.erase(q[i-m].second);
		it=s.upper_bound(q[i].second);
		if(it!=s.end()) addedge(q[i].first,qq[*it]), ++deg[qq[*it]]; 
 		s.insert(q[i].second); 
	}
	sort(q+1,q+n+1,cmp); s.clear(); 
	for(int i=1; i<=n; ++i){
		if(i-m>=1) s.erase(q[i-m].second);
		it=s.upper_bound(q[i].second);
		if(it!=s.end()) addedge(q[i].first,qq[*it]), ++deg[qq[*it]]; 
 		s.insert(q[i].second); 
	}
	for(int i=1; i<=n; ++i) if(!deg[i]) pq.push(i); 
	for(int i=1; i<=n; ++i){
		x=pq.top(); pq.pop(); 
		p[x]=i; 
		for(int k=adj[x]; k!=-1; k=e[k].nxt){
			y=e[k].v; 
			--deg[y]; 
			if(!deg[y]) pq.push(y); 
		}
	} 
	for(int i=1; i<=n; ++i) cout<<p[i]<<endl; 
	return 0; 
}

Measured memory_bytes: 50432
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,M,K;
  cin>>N>>M>>K;
  vector<ll>A(N);
  vector<ll>B(M);
  for(ll i=0;i<N;i++)cin>>A[i];
  for(ll i=0;i<M;i++)cin>>B[i];
  
  vector<ll>C(M+1,0);
  for(ll i=0;i<M;i++){
    C[i+1]=C[i]+B[i];
  }

  int t=0;
  int ans=0;
  for(int i=0;i<=N;i++){//配列Aのほうが何個なのかを決めつけ
    if(i!=0){
      t+=A[i-1];
    }
    if(t>K)break;
    int L=-1;
    int R=M+1;
    while(R-L>1){
      int Mid=(R+L)/2;
      if(t+C[Mid]<=K){
        L=Mid;
      }else{
        R=Mid;
      }
    }
    ans=max(ans,i+L);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 7988
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

int main()
{
	LL a, b;
	cin >> a >> b;

	LL ans = 0;
	if (b == 1) {
		ans = 0;
	}
	else {
		if ((b-1)%(a-1) == 0) {
			ans = (b-1)/(a-1);
		}
		else {
			ans = (b-1)/(a-1) + 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
diff=[0 for _ in range(N+1)]
for _ in range(M):
    L,R=map(int,input().split())
    diff[L-1]+=1
    diff[R]-=1
ans=0
x=0
for i in range(N):
    x+=diff[i]
    if x==M:
        ans+=1
print(ans)


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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b)
		cout << 0 << "\n";
	else if (a == b)
		cout << 1 << "\n";
	else {
		if (n == 1)
			cout << 0 << "\n";
		else {
			n -= 2;
			cout << n * b - n * a + 1 << "\n";
		}
	}
	return 0;
}




Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for ii in range(int(n**0.5)):
        i = ii+1
        if (n % i == 0):
            divisors.append(i)
            if( i != n // i):
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

s = sum(a)

divs = make_divisors(s)
divs.sort(reverse=True)

#print(divs)
divstimes = len(divs)

for i in range(divstimes):
    nowd = divs[i]
    rems = [a[j]%nowd for j in range(n)]
    rems.sort(reverse=True)
    time = sum(rems)//nowd
    #print(rems)
    #print(time)
    total = sum(rems[time:n])
    #print("tot",sum(rems[time:n]))
    #print()
    if(total <= k):
        ans = nowd
        break
    
    
print(ans)





Measured memory_bytes: 42076
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    way = [[] for _ in range(n+1)]
    for i in range(m):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)
    nms = [set([1]),set()]
    lst = [(1,0)]
    while lst:
        li,ti = lst.pop()
        for j in way[li]:
            if j in nms[ti]:
                print(n*(n-1)//2-m)
                exit()
            elif not j in nms[1-ti]:
                nms[1-ti].add(j)
                lst.append((j,1-ti))
#    print(nms)
    l0 = len(nms[0])
    l1 = len(nms[1])
    print(l0*l1-m)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 102008