akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	LLI n;
	cin >> n;
	vector<LLI> a(n + 1);

	REP(i, n + 1)
	{
		cin >> a[i];
	}


	vector<LLI> ok(n + 1);

	LLI r = 1;
	REP(i, n + 1)
	{
		if (r < a[i])
		{
			cout << -1;
			return 0;
		}

		ok[i] = r;
		r -= a[i];
		r *= 2;if (1e18L < r)r = 1e18L;
	}


	LLI cnt = 0;
	LLI node = 0;
	for (LLI i = n; 0 <= i; i--)
	{
		LLI rep = node / 2;
		node += a[i];


		node = node - _min(rep, _max(node - ok[i], 0));

		//for (LLI j = 0; j < rep; j++)
		//{
		//	if (ok[i] < node)
		//	{
		//		node--;
		//	}
		//}
		cnt += node;

	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <stdio.h>
typedef long long ll;
using namespace std;
int n, k, q;
int main(void)
{
    //入力
    cin >> n;
    cin >> k;
    cin >> q;
    int a[q + 10], player[n+10];

    for (int i = 0; i < q; i++)
    {
        cin >> a[i];
    }
    //一人の得点の設定
    for (int i = 1; i <= n; i++)
    {
        player[i] = 0;
    }
    //処理
    for (int i = 0; i < q; i++)
    {
        player[a[i]] += 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (k - (q - player[i]) >= 1)
        {
            cout << "Yes"
                 << endl;
        }
        else
        {
            cout << "No"
                 << endl;
        }
    }
}

Measured memory_bytes: 1408
package main

import (
	"fmt"
)

func main() {

	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	var result int
	result = C - (A - B)
	if result >= 0 {
		fmt.Println(C - (A - B))
	} else {
		fmt.Println("0")
	}

}


Measured memory_bytes: 1832
sx,sy,tx,ty = map(int, input().split())

dx = tx-sx
dy = ty-sy

a = dx*'R'+dy*'U'+dx*'L'+dy*'D'
b = 'D'+(dx+1)*'R'+(dy+1)*'U'+'L'+'U'+(dx+1)*'L'+(dy+1)*'D'+'R'

print(a+b)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
    LL m,n;
    while(~scanf("%lld%lld",&m,&n))
    {
        if(m>n) swap(m,n);
        if(m==1)
        {
            if(n==1) printf("1\n");
            else
            printf("%lld\n",n-2);
        }
        else
        {
            LL res=(n-2)*(m-2);
            printf("%lld\n",res);
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 4e5 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int arr[N], vis[N], vis2[N];
vector<int> adj[N], cur;
vector<vector<int>> comps;

void dfs(int node) {
  if(vis[node])
    return;
  vis[node] = 1;
  cur.push_back(node);
  for(auto it: adj[node]) {
    if(vis[it]) continue;
    dfs(it);
  }
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    if(!vis[i]) {
      cur.clear();
      dfs(i);
      comps.push_back(cur);
    }
  }
  ll ans = 0;
  for(auto it: comps) {
//    for(auto ii: it) cout << ii << ' ';
//    cout << endl;
    set<int> st;
    for(int ii: it)
      st.insert(ii);
    for(int ii: it) {
      vis2[ii] = 1;
      if(st.find(arr[ii]) != st.end())
        ++ans;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 24952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const int maxn=200010;
int a[maxn];
ll sum[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		a[i]-=i;
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	ll ans=1ll<<62;
	for(int i=1;i<=n;i++)
		ans=min(ans,(ll)a[i]*i-sum[i]+(sum[n]-sum[i])-(ll)a[i]*(n-i));
	printf("%lld\n",ans);
	return 0;
}

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

int n;
long long dp[55][3030];
long long ans;
int x[60];
int A;

int main()
{
	memset(dp,-1,sizeof dp);
	scanf("%d %d",&n,&A);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
 }
	for(int i=0;i<n;i++)
		for(int j=i+1;j>=0;--j)
			for(int t=0;t<3000;t++)
			{
				if(j==0)
				{
					if(dp[1][x[i]]==-1)	dp[1][x[i]]=1;
					else dp[1][x[i]]++;
					break;
				}
				else
				{
					if(dp[j][t]==-1)	continue;
					if(dp[j+1][t+x[i]]==-1)	dp[j+1][t+x[i]]=dp[j][t];
					else dp[j+1][t+x[i]]+=dp[j][t];
				}
			}
	unsigned	long long ans=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<3000;j++)
		{
			if(dp[i][j]==-1) continue;
			if(j%i==0&&j/i==A) ans+=dp[i][j];
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int arr[100000];
    arr[9999]=0;
    arr[10000]=0;
    for(int i=10001;i<=99999;i++){
        string s=to_string(i);
        if(s[0]==s[4] && s[1]==s[3]){
            arr[i]=arr[i-1]+1;
        }
        else{
            arr[i]=arr[i-1];
        }
    }
    //cout<<arr[11009]<<' '<<arr[11332]<<endl;

    int a,b;
    cin>>a>>b;
    cout<<arr[b]-arr[a-1]<<endl;

    return 0;
}


Measured memory_bytes: 4104
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50

const int MAX_N=2e5;
LL bit[MAX_N+1],n;

LL sum(int i){
    LL s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}


LL add(int i,LL x){
    while(i<=n){
        bit[i]+=x;
        i+=i&-i;
    }
    return 0;
}


int main(){
    int N;
    cin>>N;
    n=N;
    CLR(bit);
    REP(i,N){
        LL a;
        cin>>a;
        add(i+1,a);     
    }
    LL al=sum(N);
    LL mini=(LL)1e15;
    //cout<<al<<endl;
    FOR(i,1,N){
        mini=min(abs((al-sum(i))-sum(i)),mini);
    }
    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
import numpy as np


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    t, a = nm()
    H = nl()
    D = list(map(lambda x: abs(a - (t - x * 0.006)), H))
    print(D.index(min(D)) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27108
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    int N; cin >> N;
    vecl A(N);
    REP(i,N) cin >> A[i];
    ll ans = 1e9;
    for(ll x = -100; x <= 100; x++) {
        ll total = 0;
        REP(i,N) {
            total += (x-A[i])*(x-A[i]);
        }
        chmin(ans,total);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {

    int n;
    cin>>n;
    if(n%2==0)
        cout<<n/2-1;
    else
        cout<<n/2;



}

Measured memory_bytes: 3624
N = int(input())
syougen = [[]*N for _ in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(s) for s in input().split()]
        syougen[i].append((x,y))

def judge(bit):
    for i in range(N):
        if not bit & (1<<i):
            continue
        for x, y in syougen[i]:
            if y == 1 and not bit & (1<<x-1):
                return False
            if y == 0 and bit & (1<<x-1):
                return False
    return True

ans = 0
for bit in range(2**N):
    if judge(bit):
        res = 0
        for i in range(N):
            if bit & (1<<i):
                res += 1
        ans = max(res, ans)
        
print(ans)




Measured memory_bytes: 46364
#!/bin/sh
read day
if [  $day = 'SUN' ] ; then
echo 7
elif [  $day = 'MON' ] ; then 
echo 6
elif [  $day = 'TUE' ] ; then
echo 5
elif [  $day = 'WED' ] ; then
echo 4
elif [  $day = 'THU' ] ; then
echo 3
elif [  $day = 'FRI' ] ; then
echo 2
else
echo 1
fi

Measured memory_bytes: 376
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,x = na()
L = na()
ans = 0
a = 0

for i in L:
    ans+=1
    a+=i
    if a > x:
        break
    if ans == n:
        ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> day{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string S;
    cin >> S;
    int ans=0;
    rep(i,7){
        if(S==day[i]){
            ans=7-i;
            break;
        }
    }
    cout<<ans<<endl;
 //   system("pause");
    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int H, W, N;
set<pair<int, int>> B, cand;

void add(int i, int j) {
   if (i >= 0 && i < H-2 && j >= 0 && j < W-2) {
      cand.insert({i, j});
   }
}

int main() {
   cin >> H >> W >> N;
   rep (i, N) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      B.insert({a, b});
      rep (i, 3) {
         rep (j, 3) {
            add(a-i, b-j);
         }
      }
   }

   vec<ll> ans(10);
   ans[0] = 1LL * (H-2) * (W-2);
   for (auto c : cand) {
      int y = c.first, x = c.second;
      int cnt = 0;
      rep (i, 3) {
         rep (j, 3) {
            if (B.find({y+i, x+j}) != B.end()) {
               cnt++;
            }
         }
      }
      ans[cnt]++;
      ans[0]--;
   }

   for (ll x : ans) {
      cout << x << endl;
   }

   return 0;
}

Measured memory_bytes: 47104
from itertools import accumulate


# エラトステネスの篩
# is_prime := 1~nが素数か否か
# table := 2~nのうち素数
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


Q = int(input())
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

max_R = max(R)
is_prime, table = sieve(max_R)

check = [0]*(max_R + 1)
for i in range(0, max_R + 1):
    if (i % 2 == 1):
        if (is_prime[i-1] and is_prime[(i+1)//2-1]):
            check[i] = 1

# 累積和
check = [0] + check
check = list(accumulate(check))

for i in range(Q):
    print(check[R[i] + 1] - check[L[i]])

Measured memory_bytes: 21760
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int a[5];
int b;
int main()
{
	b=10;
	rep(i,5)
	{
		cin>>a[i];
		if(a[i]%10!=0)
		{
			if(b>a[i]%10)b=a[i]%10;
			a[i]=(a[i]/10+1)*10;
			
		}
	}
	rep(i,4)
	{
		a[4]+=a[i];
	}
	cout<<a[4]-(10-b)<<endl;
	return 0;
}

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

int main(void){
    int k, q;
    cin >> k >> q;
    vector<ll> d(k);
    rep(i, k) cin >> d[i];
    
    rep(i, q) {
        ll n, x, m;
        cin >> n >> x >> m;
        
        ll ans = n-1;
        ll zero_count = 0;
        ll a_end = x%m;
        rep(j, k) {
            //cout << (n-1)%k << " " << j << endl;
            if ((n-1) % k > j) {
                a_end += d[j]%m * ((n-1)/k + 1);
                if (d[j] % m == 0)
                    zero_count += (n-1)/k + 1;
            }
            else {
                a_end += d[j]%m * ((n-1)/k);
                if (d[j] % m == 0)
                    zero_count += (n-1)/k;
            }
        }
        //cout << a_end << endl;
        ans -= zero_count;
        ans -= (a_end / m);
        cout << ans << endl;
    }
}

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

typedef long long LL;

LL a[55];
int main()
{
    LL k;
    cin>>k;
    LL n = k / 50;
    k %= 50;
    a[1]=49+n+k*50;
    for(int i = 1; i <= 50; i++) a[i] = 49 + n;
    for(int j = 1; j <= k; j++)
    {
        for(int i = 1; i <= 50; i++)
        {
            if(i == j) a[i] += 50;
            else a[i]--;
        }
    }
    cout << "50" << endl;
    for(int i = 1; i <= 50; i++) cout << a[i] << " ";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 400
#define mod 998244353
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,ans,a[MN+5],b[MN+5],f[MN+5][MN+5],p[MN+5],inv[MN+5],Inv[MN+5];
int main()
{
    n=read();p[0]=p[1]=inv[0]=inv[1]=Inv[0]=Inv[1]=1;
    for(int i=2;i<=MN;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=MN;++i) Inv[i]=1LL*Inv[i-1]*inv[i]%mod;
    for(int i=1;i<=n;++i) a[i]=read(),b[i]=read();
    f[0][0]=mod-1;int s=0,S=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=s;j>=0;--j) for(int k=S;k>=0;--k)
        {
            int v=mod-f[j][k];
            for(int l=0;l<b[i];++l)
            {
                int x=1LL*v*Inv[l]%mod;v=1LL*v*a[i]%mod;
                f[j+a[i]][k+l]=(f[j+a[i]][k+l]+x)%mod;
            }
        }
        s+=a[i];S+=b[i];
    }
    for(int i=1;i<=s;++i) for(int j=0,t=1;j<=S;++j)
    {
        ans=(ans+1LL*f[i][j]*t%mod*p[j]%mod*inv[i]%mod*s)%mod;
        t=1LL*t*inv[i]%mod;
    }
    cout<<ans;
    return 0;
}

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

int main() {
  ll N;
  cin >> N;
  if (N%2 != 0) {
    cout << 0 << endl;
    return 0;
  }
  N /= 2;
  ll ans = 0;
  for (ll i = 1; i <= 30; i++) ans += N/ll(powl(5,i));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	long mod = 1000000007;
	long count[n];
	for (int i = 0; i < n; i++) {
		count[i] = 0;
	}
	long answer;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			if (count[0] == 0) {
				answer = 3;
			} else if (count[0] == 1) {
				answer *= 2;
			} else if (count[0] > 2) {
				printf("0\n");
				return 0;
			}
			count[0]++;
		} else {
			if (count[a[i]] == 0) {
				if (count[a[i]-1] == 0) {
					printf("0\n");
					return 0;
				}
				answer *= count[a[i]-1];
			} else if (count[a[i]] == 1) {
				if (count[a[i]-1] <= 1) {
					printf("0\n");
					return 0;
				}
				answer *= count[a[i]-1]-1;
			} else if (count[a[i]] == 2){
				if (count[a[i]-1] <= 2) {
					printf("0\n");
					return 0;
				}
			} else {
				printf("0\n");
				return 0;
			}
			count[a[i]]++;
			answer %= mod;
		}
	}
	printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    double ans = 0, res;
    int N;
    cin >>N;
    while(N){
        cin >> res;
        ans += 1.0/res; 
      --N;
    }
    cout << 1/ans;
 }




Measured memory_bytes: 256
#include <cstdio>
int main() {
	int n; scanf("%d", &n);
	int arr[4] = { 0 };
	while (n--) {
		char str[10]; scanf("%s", str);
		switch (str[0]) {
		case 'A': ++arr[0]; break;
		case 'W': ++arr[1]; break;
		case 'T': ++arr[2]; break;
		case 'R': ++arr[3]; break;
		}
	}
	printf("AC x %d\n", arr[0]);
	printf("WA x %d\n", arr[1]);
	printf("TLE x %d\n", arr[2]);
	printf("RE x %d\n", arr[3]);
	return 0;
}

Measured memory_bytes: 3180
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------
bool g[55][55],vis[55];
int n,m;
void dfs(int i){
    vis[i]=1;
    rep(j,n){
        if(g[i][j]==0)continue;
        if(vis[j]==1)continue;
        dfs(j);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    cin>>n>>m;
    vi a(m),b(m);
    rep(i,m){
       cin>>a[i]>>b[i];
       a[i]--,b[i]--;
       g[a[i]][b[i]]=g[b[i]][a[i]]=1;
    }
    int ans=0;
    rep(i,m){
       g[a[i]][b[i]]=g[b[i]][a[i]]=0;
       rep(j,n)vis[j]=0;
       dfs(0);
       bool bridge=0;
       rep(j,n)if(vis[j]==0)bridge=1;
       if(bridge)ans++;
       g[a[i]][b[i]]=g[b[i]][a[i]]=1;
    }
    cout<<ans<<enl;

    return 0;
}


Measured memory_bytes: 3648
// abc134c: Exception Handling
#include <stdio.h>

#define upto(i,s,e,d) for(int i=(s);i<=(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>=(e);i-=(d))
#define in(n) scanf("%d",n)
#define out(d) printf("%d\n",d)

int search(int k, int *a, int n){
  int l=0,r=n,m;
  while(l<r){ m=(l+r)/2; if(a[m]<k) r=m; else l=m+1; }
  return l;
}

int main(){
  int n;in(&n);
  int gn = 1, g[n];in(g);
  upto(i,1,n-1,1){
    int a;in(&a);
    int j = search(a,g,gn);
    g[ j<gn? j: gn++ ] = a;
  }
  out(gn);
  return 0;
}

Measured memory_bytes: 512
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
char str[N];
int dp[N][13];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%s", str + 1);
	int n = strlen(str + 1);
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		int l = 0, r = 9;
		if (str[i + 1] != '?') l = r = str[i + 1] - '0';
		for (int j = 0; j < 13; j++)
		{
			for (int k = l; k <= r; k++)
			{
				int o = (j * 10 + k) % 13;
				int &tmp = dp[i + 1][o] += dp[i][j];
				if (tmp >= INF)
					tmp -= INF;
			}
		}
	}
	cout << dp[n][5] << endl;
	return 0;
}


Measured memory_bytes: 8448
use std::io::Read;
use std::ascii::AsciiExt;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let s = s.to_ascii_lowercase();
    let chars = (b'a'..b'{').map(char::from);
    let mut a = vec![0;chars.len()];
    for c in s.chars() {
        if c.is_alphabetic() {
            let i = (c as usize) - 97;
            a[i] += 1;
        }
    }
    for (i,c) in chars.enumerate() {
       println!("{} : {}", c, a[i]); 
    }
}



Measured memory_bytes: 5028
import sys
import numpy as np
import numba
from numba import jit

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


def main(x1, x2, y1, y2):
    a = x1 + y1 * 1j
    b = x2 + y2 * 1j
    c = b + (b-a) * 1j
    d = a + (a-b) * (-1j)
    print(int(c.real), int(c.imag), int(d.real), int(d.imag))

x1, y1, x2, y2 = map(int, readline().split())
main(x1, x2, y1, y2)


Measured memory_bytes: 91596
#include <stdio.h>

int main(void){
  int a,i,n,min,max;
  long int sum;
  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    scanf("%d",&a);
    if(i == 1){
      min = a;
      max = a;
      sum = a;
    }
    else{
      if(min > a)min = a;
      if(max < a)max = a;
      sum += a;
    }
  }
  printf("%d %d %ld\n",min,max,sum);
  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define        ll          long long int
#define        sz          200010
#define        fast        ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define        sc1(a)      scanf("%lld",&a)
#define        sc2(a,b)    scanf("%lld %lld",&a,&b)
#define        pb          push_back
#define        pn          printf("No\n")
#define        py          printf("Yes\n")
#define        op(a)       printf("%lld\n",a)

using namespace std;



int main()
{

    ll n,k,i,j,p,d,x;
    set<ll>st;

    cin>>n>>k;
    while(k--)
    {
        cin>>p;
        while(p--)
        {
            cin>>x;
            st.insert(x);
        }
    }

    cout<<n-st.size()<<endl;


    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define fill(x, v) memset(x, v, sizeof(x))
const ll mod = 1000000007;
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
//--------dsu----------
vector<int> volume(1000000);
vector<int> parent(1000000);

void initialise_dsu()
{
    for (int i = 0; i < volume.size(); i++)
        volume[i] = 1;
    for (int i = 0; i < parent.size(); i++)
        parent[i] = i;
}

int find_par(int v)
{
    return (v == parent[v] ? v : parent[v] = find_par(parent[v]));
}

void union_sets(int a, int b)
{
    a = find_par(a);
    b = find_par(b);
    if (a != b)
    {
        if (volume[a] < volume[b])
            swap(a, b);
        parent[b] = a;
        volume[a] += volume[b];
    }
}

int power(int x, unsigned int y, int p)
{
    int res = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
//-------------------------
string arr;
map<pair<char, char>, char> mpsym;

int main()
{
    ios;

    ll n;
    cin >> n;
    vector<ll> arr(n + 1), count(n + 1);
    for (int i = 2; i <= n; i++)
    {
        ll x;
        cin >> x;
        arr[x]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << arr[i] << endl;
    }
}

Measured memory_bytes: 14292
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
bool isDigit(char c){return '0'<=c&&c<='9';}
template<typename T> void remove(std::vector<T>& vector,unsigned int index){vector.erase(vector.begin()+index);}
//priority_queue<int, vi, greater<int> > que;//æ˜‡é †

using namespace std;

const int mod=1e9+7;


signed main(){
    SPEED;
    vi a(2,0),b(2,0),c(2,0),d(2,0);
    double l,r;
    while(scanf("%lf%lf",&l,&r) != EOF)
    {
        if(1.1<=l)++a[0];
        else if(0.6<=l&&l<1.1)++b[0];
        else if(0.2<=l&&l<0.6)++c[0];
        else ++d[0];

        if(1.1<=r)++a[1];
        else if(0.6<=r&&r<1.1)++b[1];
        else if(0.2<=r&&r<0.6)++c[1];
        else ++d[1];
    }
    cout << a[0] << " " << a[1] << endl;
    cout << b[0] << " " << b[1] << endl;
    cout << c[0] << " " << c[1] << endl;
    cout << d[0] << " " << d[1] << endl;
}



Measured memory_bytes: 3252
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
for n in range(N):
    ys=N-1-n
    machi=N-n
    if A[machi]>B[ys]:
        c=c+B[ys]
    else:
        c=c+A[machi]
        B[ys]=B[ys]-A[machi]
        if A[machi-1]>B[ys]:
            c=c+B[ys]
            A[machi-1]=A[machi-1]-B[ys]
        else:
            c=c+A[machi-1]
            B[ys]=B[ys]-A[machi-1]
            A[machi-1]=0
print(c)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll X;cin>>X;
    ll ans=0;
    ll ans2=0;
    for(int i=1;i<=X;i++){
        ans+=i;
        if(ans>=X){
            ans2=i;
            break;
        }
    }
    cout<<ans2<<endl;
}

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

int main() {

  int N, K;
  cin >> N >> K;
  int ans = 0;
  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x >= K) {
      ans++;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 384
n,t = list(map(int,input().split()))
in_time = list()
           
for i in range(n):
    a,b =  list(map(int,input().split()))
    if t >= b:
        in_time.append(a)

if len(in_time) == 0:
    print("TLE")
else:
    print(min(in_time))

Measured memory_bytes: 3060
#!/usr/bin/env python3
def primes(n):
    m = 1297
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and i % 5 == 2][:n]


print(*primes(int(input())))


Measured memory_bytes: 63524
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 100000

long long a[MAX+1];

void solve() {
    int n;
    long long ai, bi, k, cnt;
    cin >> n >> k;
    cnt = 0;
    for (int i=0; i<n; ++i) {
        cin >> ai >> bi;
        a[ai] += bi;
    }
    for (int i =1 ; i <= MAX; ++i) {
        cnt += a[i];
        if (cnt >= k) {
            cout << i;
            return;
        }
    }

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3940
L = list(map(int, input().split()))

cnt = 0
while max(L)-min(L) > 1:
  L[L.index(min(L))] += 2
  cnt +=1
L.sort()
if L[0] == L[1] != L[2]:
  cnt += 1
elif L[0] != L[1]:
  cnt += 2
print (cnt)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    string s ;
    cin>>s;
    if(s == "SUN")
        cout<<7<<endl;
    else if(s == "MON")
        cout<<6<<endl;
    else if(s == "TUE")
        cout<<5<<endl;
    else if(s == "WED")
        cout<<4<<endl;
    else if(s == "THU")
        cout<<3<<endl;
    else if(s == "FRI")
        cout<<2<<endl;
    else
        cout<<1<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    ll w,h,x,y;
    cin>>w>>h>>x>>y;


    cout<<(((double)(w*h))/2)<<" ";
    if(2*x == w && 2*y == h) cout<<1;
    else cout<<0;


    return 0;
}   

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

int n;
char s[6003];
std::string parts[3003];
int main()
{
	scanf("%d %s",&n,s);
	int i = 0, j = 0;
	while(i < 2 * n) {
		std::string max;
		int sum = 0;
		int type = s[i] - 'a';
		std::vector<int> va, vb;
		do {
			if(s[i] == 'a') {
				++sum;
				va.push_back(i);
			} else {
				--sum;
				vb.push_back(i);
			}
			++i;
		} while(sum != 0);
		if(type == 0) {
			while(!va.empty()) {
				assert(va[0] < vb[0]);
				max += "ab";
				int j = vb[0];
				while(!va.empty() && va[0] < j) {
					va.erase(va.begin());
					vb.erase(vb.begin());
				}
			}
		} else {
			int s = va.size();
			for(int k = 0;k < s;++k) {
				std::string cur;
				int a = k, b = k;
				while(a < s || b < s) {
					if(b == s || (a != s && va[a] < vb[b])) {
						cur.push_back('a');
						++a;
					} else {
						cur.push_back('b');
						++b;
					}
				}
				if(cur > max) max = cur;
			}
		}
		parts[j++] = max;
	}
	std::string max, ans;
	for(int k = j-1;k >= 0;--k) {
		if(parts[k] >= max) {
			max = parts[k];
		}
		if(std::mismatch(parts[k].begin(),parts[k].end(),max.begin()).first == parts[k].end()) {
			ans = parts[k] + ans;
		}
	}
	printf("%s\n", ans.c_str());
		
}


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

int N, Q;
const int INF = INT_MAX;
struct LazySegmentTree {
private:
    int n;
    vector<int> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    cin >> N >> Q;
    LazySegmentTree seg( vector<int>(N, INF) );
    for(int i=0; i<Q; i++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.find(s, t+1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a,b; cin>> a >> b;
    vector<string> v;
    rep(i,a){
        string str; cin >> str;
        int count = 0;
        rep(j,b){
            if(str[j]!='.'){
                count += 1;
            }
        }
        if(count!=0){
            v.push_back(str);
        }
    }

    rep(i,v[0].size()){
        int count = 0;
        rep(j,v.size()){
            if(v[j][i]!='.'){
                count += 1;
            }
        }
        if(count==0){
            rep(k,v.size()){
                v[k][i]=0;
            }
        }
    }
    rep(i,v.size()){
        rep(j,b){
            if(v[i][j]!=0){
                cout << v[i][j];
            }
        }
        cout << endl;
    }


    return 0;
}

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

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

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

    ll che = 10e8 + 7;
    ll ans = 1;

    map<int, int> m;
    int cou = 0;
    m[0] = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == 0){
            ans *= (3 - cou);
            cou++;
            m[a[i]]++;
        }else{
            ans *= m[a[i] - 1];
            m[a[i] - 1]--;
            auto itr = m.find(a[i]);
            if(itr == m.end()){
                m[a[i]] = 1;
            }else{
                m[a[i]]++;
            }
        }

        ans %= che;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8676
N,M=map(int, input().split())

A=[]
B=[]
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)

C=[]
D=[]
for i in range(M):
    c,d=map(int, input().split())
    C.append(c)
    D.append(d)

T=[]
S=[]
for i in range(N):
    for j in range(M):
        T.append(abs(A[i]-C[j])+abs(B[i]-D[j]))
    S.append(T.index(min(T))+1)
    T=[]

for i in range(N):
    print(S[i])


Measured memory_bytes: 3064
def fun(n, m):
    key = 1
    n -= m
    key += n / (m - 1)
    if int(key) == key:
        return int(key)
    else:
        return int(key) + 1
    
N, K = map(int, input().split())
A = list(map(int, input().split()))
key = N / (K - 1)
print(fun(N, K))


Measured memory_bytes: 14008
using System;
using System.Linq;

namespace DLamp
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力 H/W の取得
            var inputsHW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = inputsHW[0];
            var w = inputsHW[1];

            var map = new bool[h][];
            var rows = new MapLine[h];
            var columns = new MapLine[w];
            for (var i = 0; i < h; i++)
            {
                var row = Console.ReadLine().ToCharArray().Select(c => c == '#').ToArray();
                map[i] = row;
                rows[i] = new MapLine(row);
            }

            for (var i = 0; i < w; i++)
            {
                var column = map.Select(row => row[i]).ToArray();
                columns[i] = new MapLine(column);
            }

            // 各マスでの照らし出されるマス数を計算
            var maxCount = 0;
            for (var i = 0; i < h; i++)
            {
                for (var j = 0; j < w; j++)
                {
                    if (map[i][j]) continue;

                    var lightCount = rows[i].Scores[j] + columns[j].Scores[i] - 1;
                    if (maxCount < lightCount) maxCount = lightCount;
                }
            }

            // 解答の出力
            Console.WriteLine(maxCount);
        }
    }

    class MapLine
    {
        int[] _walls;
        public readonly int[] Scores;

        public MapLine(bool[] elements)
        {
            _walls = elements.Select((e, i) => Tuple.Create(e, i)).Where(t => t.Item1).Select(t => t.Item2).ToArray();

            Scores = new int[elements.Length];
            foreach (var wall in _walls) Scores[wall] = 0;
            for (var i = 0; i < _walls.Length + 1; i++)
            {
                var wall = i != _walls.Length ? _walls[i] : elements.Length;
                var prev = i != 0 ? _walls[i - 1] : -1;

                var score = wall - prev - 1;
                for (var j = prev + 1; j < wall; j++)
                {
                    Scores[j] = score;
                }
            }
        }
    }
}


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

using namespace std;

int main(){
	int x, n;
	map <int, bool> mp;
	scanf("%d %d", &x, &n);
	for (int i = 0; i < n; i++){
		int c;
		scanf("%d", &c);
		mp[c] = true;
	}
	for (int i = x, j = x; true; i++, j--){
		if (!mp[j]){
			printf("%d\n", j);
			return 0;
		}
		if (!mp[i]){
			printf("%d\n", i);
			return 0;
		}
	}
}


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

using namespace std;

int N, M, R;

int r[10];
int dist[210][210];

void AddEdge(int from, int to, int cost) {
  dist[from][to] = cost;
  dist[to][from] = cost;
}

void WarshallFloyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

int Cost(const vector<int> &order) {
  int totalCost = 0;
  for (int i = 0; i + 1 < R; i++) {
    totalCost += dist[order[i]][order[i + 1]];
  }
  return totalCost;
}

int main() {
  cin >> N >> M >> R;
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }

  fill(&dist[0][0], (int *)(dist + 210), 1e9);
  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    AddEdge(A, B, C);
  }

  WarshallFloyd();

  vector<int> order;
  for (int i = 0; i < R; i++) order.push_back(r[i]);
  sort(order.begin(), order.end());

  int minCost = Cost(order);
  do {
    minCost = min(minCost, Cost(order));
  } while (next_permutation(order.begin(), order.end()));
  cout << minCost << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define sqr(x) ((x)*(x))
 
using namespace std;
const double eps = 1e-9;
const int INF = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int MAXN =(int)1e6;
 
int main() {
    int n, k;
    cin >> n >> k;
    vector <ll> a(n), b(n);
    vector <int> good(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] <= k) {
            sum += b[i];
            good[i] = 1;
        }
    }
 
    ll ans = 0;
    for (ll i = 30; (1 << i) >= 0; --i) {
        int cur = (bool)((1 << i) & k);
        if (cur == 0) {
            for (int j = 0; j < n; ++j) {
                if (good[j] && ((a[j] >> i) & 1)) {
                    good[j] = 0;
                    sum -= b[j];
                }
            }
        } else {
            ll cur_bad = 0;
            for (int j = 0; j < n; ++j) {
                if (good[j] && ((a[j] >> i) & 1)) {
                    cur_bad += b[j];
                }
            }
            ans = max(ans, sum - cur_bad);
        }
    }
    ans = max(ans, sum);
    cout << ans;
 
    return 0;
}

Measured memory_bytes: 2176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, x, t := nextInt3()

	ans := t * ((n - 1 + x) / x)
	puts(ans)
}


Measured memory_bytes: 1780
#include<stdio.h>

int main()
{
  int n;
  int sum;
  int ans=0;
  int i;
  char s[300001];
  scanf("%d",&n);
  scanf("%s",s);
  for(i=1;i<n;i++){
    if(s[i]=='E') ans++;
  }
  sum=ans;
  for(i=1;i<n;i++){
    if(s[i]=='E') sum--;
    if(s[i-1]=='W') sum++;
    if(sum<ans) ans=sum;
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 2028