akhauriyash/Code-Regression huggingface dataset:
from collections import deque

n, x, y = map(int, input().split())
adj = [[] for _ in range(n + 1)]

for i in range(1, n):
    adj[i].append(i + 1)
    adj[i + 1].append(i)

adj[x].append(y)
adj[y].append(x)

def bfs(root):
    visited = [0] * (n + 1)
    q = deque([root])

    while q:
        x = q.popleft()
        for y in adj[x]:
            if visited[y] == 0:
                visited[y] = visited[x] + 1
                q.append(y)
    
    return visited

result = [0] * (n + 1)

for i in range(1, n + 1):
    data = bfs(i)
    for j in range(i + 1, n + 1):
        result[data[j]] += 1

for i in range(1, n):
    print(result[i])

Measured memory_bytes: 50140
n = int(input())
a=list()
sum=0
for i in range(n):
  x = int(input())
  sum+=x
  if(x%10!=0):
    a.append(x)

if(sum%10==0 and len(a)>0):
  sum-=min(a)

if(sum%10==0):
  print(0)
else:
  print(sum)


Measured memory_bytes: 3060
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;
import java.awt.Point;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		// 迷路を受け取る
		String[][] map = new String[h][w];
		String[][] copy = new String[h][w];
		for (int i = 0; i < map.length; i++) {
			map[i] = in.next().split("");
			copy[i] = Arrays.copyOf(map[i], map[i].length);
		}
		// スタートを決める
		int max = 0;
		for (int l = 0; l < w; l++) {
			for (int m = 0; m < h; m++) {
				Point start = new Point(l, m);
				int move = bfs(h, w, start, map);
				if (max < move) {
					max = move;
				}
				for (int i = 0; i < map.length; i++) {
					map[i] = Arrays.copyOf(copy[i], copy[i].length);
				}
			}
		}
		System.out.println(max);
	}

	static int bfs(int h, int w, Point start, String[][] map) {
		// Queueを用意し、スタート地点を入れる
		ArrayDeque<Point> dq = new ArrayDeque<>();
		dq.add(start);
		// 各地点のスタート地点からの距離を記録する二次元配列
		int[][] moves = new int[h][w];

		if(map[(int) start.getY()][(int) start.getX()].equals("#")){
			return -1;
		}
		// スタート地点を"#"で埋めて、探索済みにする
		map[(int) start.getY()][(int) start.getX()] = "#";

		// 4方向
		Point[] D4 = { new Point(0, -1), new Point(1, 0), new Point(0, 1), new Point(-1, 0) };

		int max = 0;
		// 幅優先探索
		while (dq.size() > 0) {
			Point p = dq.removeFirst();
			for (int i = 0; i < 4; i++) {
				int x = (int) p.getX() + (int) D4[i].getX();
				int y = (int) p.getY() + (int) D4[i].getY();

				if (x > -1 && x < w && y > -1 && y < h && map[y][x].equals(".")) {

					// "."であれば探索可能なので、Queueの末尾に追加する
					dq.addLast(new Point(x, y));

					// 探索が終わった座標を"#"で埋めて、次回以降探索しないようにする
					map[y][x] = "#";

					// 座標pからpの四方の座標への移動距離は、pまでの移動距離+1
					moves[y][x] = moves[(int) p.getY()][(int) p.getX()] + 1;
					if(max < moves[y][x]){
						max = moves[y][x];
					}
				}
			}
		}
		return max;
	}
}


Measured memory_bytes: 28792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string>st(n);
  vector<string>st2;
  for(int i=0;i<n;i++){
    cin >> st[i];
  }
  st2=st;
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(st[j][1]<st[j-1][1])
	swap(st[j],st[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    cout << st[i];
    if(i+1!=n)
      cout << " ";
  }
  cout << endl;
  cout << "Stable"<< endl;
  //
  int f=0;
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(st2[j][1]<st2[minj][1])
	minj=j;
    }
    if(i!=minj){
      swap(st2[i],st2[minj]);
    }
  }
  for(int i=0;i<n;i++){
    cout << st2[i];
    if(st2[i]!=st[i])f=1;
    if(i+1!=n)cout << " ";
  }
  cout << endl;
  if(f)cout << "Not stable" << endl;
  else cout << "Stable" << endl;
  return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(void){
    // Your code here!
    int n;
    cin >> n;
    long long int ans=0;
    
    for(int i=1;i<n;i++){
        for(int j=1;j*j<=(n-i);j++){
            if((n-i) % j == 0){
                //cout << i << " " << j << endl;
                if(j*j == (n-i)){
                    ans++;
                }else{
                    ans += 2;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    
    
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int k, a, b; cin >> k >> a >> b;
    if(b / k - (a - 1)/k > 0) cout << "OK" << endl;
    else cout <<"NG" << endl;
}

Measured memory_bytes: 3624
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

ppi=3.14159265358979

def main():
	a = int(input())
	print(a*2*ppi)
	#b , c = IN()
	#s = input()
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62004
fun main(arg: Array<String>) {
    val (H, W, K) = listOfInt()
    val S = Array(H) { next().map { it - '0' }.toIntArray() }
    val INF = 1001001001
    var ans = INF
    for (b in 0 until (1 shl (H - 1))) {
        var G = 0
        val gr = IntArray(H)
        for (h in 0 until H) {
            gr[h] = G
            if (((b shr h) and 1) == 1) G += 1
        }
        G += 1
        val c = Array(G) { IntArray(W) }
        for (h in 0 until H) for (w in 0 until W) c[gr[h]][w] += S[h][w]
        var num = G - 1
        val now = IntArray(G)
        fun add(w: Int): Boolean {
            for (g in 0 until G) now[g] += c[g][w]
            for (g in 0 until G) if (now[g] > K) return false
            return true
        }
        for (w in 0 until W) {
            if (!add(w)) {
                num += 1
                for (g in 0 until G) now[g] = 0
                if (!add(w)) {
                    num = INF
                    break
                }
            }
        }
        ans = Math.min(ans, num)
    }
    println(ans)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 50300
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B;
  cin >> A >> B;
  A -= 2; B -= 2;

  int N = 100;
  vector<string> s(N);
  REP(i, N) s[i].resize(N);

  REP(i, N) REP(j, N){
    if(i < N/2) s[i][j] = '.';
    else s[i][j] = '#';
  }

  for(int i = 1; B >= 0; i += 2) for(int j = 1; j < N; j += 2){
    if(B >= 0){
      s[i][j] = '#';
      B--;
    }
  }
  for(int i = N/2+1; A >= 0; i += 2) for(int j = 1; j < N; j += 2){
    if(A >= 0){
      s[i][j] = '.';
      A--;
    }
  }

  cout << "100 100" << "\n";
  REP(i, N) cout << s[i] << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=20;
int a[N],e[N][N];
int main (){
	memset (e,-1,sizeof(e));
	int n;scanf ("%d",&n);
	for (int i=1,m;i<=n;i++){
		scanf ("%d",&m);
		for (int j=1;j<=m;j++){
			int x,y;scanf ("%d%d",&x,&y);
			e[i][x]=y;
		}
	}
	int ans=0;
	for (int s=1;s<(1<<n);s++){
		int cnt=0;for (int i=1;i<=n;i++) cnt+=((s&(1<<(i-1)))!=0);
		for (int i=1;i<=n;i++){
			if (s&(1<<(i-1))){
				for (int j=1;j<=n;j++){
					if (s&(1<<(j-1))){
						if (e[i][j]==0) cnt=0;
					}else {
						if (e[i][j]==1) cnt=0;
					}
				}
			}
		}
		ans=max(ans,cnt);
	}
	printf ("%d",ans);
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
Ques = [ list(map(int, input().split())) for _ in range(Q) ]

Nums = [ i for i in range(M) ]
ans = -1
for v in combinations_with_replacement(Nums, N):
    cnt = 0
    for que in Ques:
        if v[que[1]-1]-v[que[0]-1] == que[2]: cnt += que[3]
    ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 73468
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int f[100][100];
int A,B;
char str[3]=".#";
int main(){
	cin >> A >> B;
	for(int i=0;i<47;i++){
		for(int j=47;j<94;j++){
			f[i][j]=1;
		}
	}
	for(int i=0;i<B-1;i++){
		int a = i/23;
		int b = i%23;
		f[2*a+1][2*b+1]=1;
	}
	for(int i=0;i<A-1;i++){
		int a = i/23;
		int b = i%23;
		f[2*a+1][2*b+1+47]=0;
	}
	cout << 47 << ' ' << 94 << endl;
	for(int i=0;i<47;i++){
		for(int j=0;j<94;j++){
			printf("%c",str[f[i][j]]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}



Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku
long long modpow(long long x,long long n) {
    long long result = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            result = (result * x) % mod;
        }
        x = (x * x) % mod;
        n >>= 1;
    }
 
    return result;
}

#define N 1000

long long x[N+1],y[N+1];

void make_fact_table(int n){
	int i;
	x[0]=y[0]=1;
	for(i=1;i<=n;i++){
		x[i]=(long long)(x[i-1]*i)%mod;
		y[i]=modpow(x[i],mod-2);
	}
}

long long mod_nCr(int n, int r){
	return x[n]*y[n-r]%mod*y[r]%mod;
}

int main(void){
	int a=in(),b=in(),c=in(),d=in();
	print(min(a,b)+min(c,d));
	return 0;
}

Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))

b = {}
ans = 0
for i, v in enumerate(a):
    if v > i+1:
        b[i+1] = v
    elif v < i+1:
        if v in b and b[v] == i+1:
            ans += 1
print(ans)


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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N; cin >> N;
    vector<int> A(N); cin >> A;
    
    int ans = 0;
    int mi = INT_MAX, ma = INT_MIN;
    for (const auto a:A) {
        mi = min(mi, a);
        ma = max(ma, a);
    }
    ans = abs(mi -ma);
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

N,Q=map(int,input().split())
graph=[[]for _ in range(N)]
point=[0]*N
for _ in range(N-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for _ in range(Q):
    a,b=map(int,input().split())
    a=a-1
    point[a]=point[a]+b

def dfs(now,prev=-1):
    for next in graph[now]:
        if next==prev:
            continue
        point[next]=point[next]+point[now]
        dfs(next,now)
dfs(0)
print(*point)

Measured memory_bytes: 268464
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    int cnt[4] = {0};
    rep(i, n) {
        string s;
        cin >> s;
        if (s == "AC") {
            ++cnt[0];
        }
        else if (s == "WA") {
            ++cnt[1];
        }
        else if (s == "TLE") {
            ++cnt[2];
        }
        else {
            ++cnt[3];
        }
    }
    rep(i, 4) {
        if (i == 0) {
            cout << "AC x " << cnt[0] << endl;
        }
        else if (i == 1) {
            cout << "WA x " << cnt[1] << endl;
        }
        else if (i == 2) {
            cout << "TLE x " << cnt[2] << endl;
        }
        else {
            cout << "RE x " << cnt[3] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio> 
#include<algorithm>
using namespace std; 
long long read()
{
	long long a=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){ if (ch=='-') f=-1;ch=getchar(); }
	while (ch>='0' && ch<='9') { a=a*10+ch-48;ch=getchar(); }
	return a*f;
}
long long a,b,c,d;
int main()
{
	a=read();
	b=read();
	c=read();
	d=read();
	printf("%lld",max(a*c,max(a*d,max(b*c,b*d))));
	return 0;
}

Measured memory_bytes: 1600
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


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

const int N = 110000;
const int MOD = 998244353;

inline int modExp(int a, int n, int mod) {
	int ret = 1;
	while (n) {
		if (n & 1) ret = (long long)ret * a % mod;
		a = (long long)a * a % mod;
		n >>= 1;
	}
	return ret;
}

int fact[N], rfact[N], bit[N];
int xxx[N];

inline int calc_C(int n, int m) {
	if (n < m) return 0;
	return (long long)fact[n] * rfact[m] % MOD * rfact[n - m] % MOD;
}

inline int calc_H(int n, int m) {
	return calc_C(n + m - 1, m);
}

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	fact[0] = rfact[0] = bit[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = (long long)fact[i - 1] * i % MOD;
	for (int i = 1; i < N; i++) rfact[i] = (long long)rfact[i - 1] * modExp(i, MOD - 2, MOD) % MOD; 
	for (int i = 1; i < N; i++) bit[i] = (long long)bit[i - 1] * 2 % MOD;
	
	int k, n; cin >> k >> n;
	
	for (int i = 1; i <= k; i++) for (int j = i + 1; j <= k; j++) xxx[i + j]++;
	
	for (int i = 2; i <= 2 * k; i++) {
		int ans = 0, nn = xxx[i], mm = k - xxx[i] * 2;
		if (i % 2 == 0) mm--;
		for (int j = 0; j <= nn; j++) {
			if (n - j < 0) break;
			(ans += (long long)calc_C(nn, j) * bit[j] % MOD * calc_H(j + mm, n - j) % MOD) >= MOD && (ans -= MOD);
			if (i % 2 == 0) {
				if (n - 1 - j >= 0) {
					(ans += (long long)calc_C(nn, j) * bit[j] % MOD * calc_H(j + mm, n - 1 - j) % MOD) >= MOD && (ans -= MOD);
				}
			}
		}
		cout << ans << "\n";
	}
	
	return 0;
}


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

int main()
{
   int A,B;
   char op;
   cin>>A>>op>>B;
   if(op=='+'){
       cout<<A+B<<endl;
   }
   else{
       cout<<A-B<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long int ll;
using namespace std;
//分割数
ll n;
const int MAX_N = 200010;
const int M = 1000000007;

ll f[MAX_N], rf[MAX_N];
ll inv(ll x)
{
    ll res = 1;
    ll k = M - 2;
    ll y = x;
    while (k)
    {
        if (k & 1)
            res = (res * y) % M;
        y = (y * y) % M;
        k /= 2;
    }
    return res;
}
void init()
{
    f[0] = 1;
    rep(i, 1, MAX_N) f[i] = (f[i - 1] * i) % M;
    rep(i, 0, MAX_N) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k)
{
    ll a = f[n];      // = n!
    ll b = rf[n - k]; // = (n-k)!
    ll c = rf[k];     // = k!

    ll bc = (b * c) % M;

    return (a * bc) % M;
}

int main()
{
    init();
    ll k, m;
    cin >> n >> m >> k;
    ll x = 0;
    ll y = 0;
    REP(i, m)
    {
        ll t = (i * (m - i)) % M;
        t = (t * ((n * n) % M)) % M;
        x += t;
        x %= M;
    }
    x *= C(n * m - 2, k - 2);
    x %= M;
    REP(i, n)
    {
        ll t = (i * (n - i)) % M;
        t = (t * ((m * m) % M)) % M;
        y += t;
        y %= M;
    }
    y *= C(n * m - 2, k - 2);
    cout << (x + y) % M << endl;
}

Measured memory_bytes: 3328
# coding: utf-8

import collections


def solve():
    n = int(input())
    qo = collections.deque()
    qe = collections.deque()

    for i, a in enumerate(map(int, input().split())):
        if i % 2 == 0:
            qe.append(a)
        else:
            qo.append(a)

    r = []

    if n % 2 == 0:
        while qo:
            r.append(qo.pop())
        while qe:
            r.append(qe.popleft())
    else:
        while qe:
            r.append(qe.pop())
        while qo:
            r.append(qo.popleft())
    print(" ".join(map(str, r)))


solve()


Measured memory_bytes: 29124
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def C(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def P(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


P = int(input())
c = Combi(P-1, P)
A = list(map(int,input().split()))
ans = [0 for i in range(P)]
for i in range(P):
    if A[i] != 0:
        ans[0] += 1
        for j in range(P):
            ans[j] -= c.C(P-1, j)*pow(-i, P-1-j,P) 
for i in range(P):
    ans[i] %= P
print(*ans)

Measured memory_bytes: 74772
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}



int main(){
  ll n; cin >> n; vl num(n);
  
  rep(i,n) cin >> num[i];
  
  ll ans1 = 0; ll ans2 = 0;
  ll now1 = 0; ll now2 = 0;
  
  rep(i,n){

    now1 += num[i]; now2 += num[i];
    
    if(i % 2 == 0 and now1 <= 0){
      ans1 += 1-now1;
      now1 = 1;
    }
    else if(i % 2 == 1 and now1 >= 0){
      ans1 += now1+1;
      now1 = -1;
    }
    
    if(i % 2 == 1 and now2 <= 0){
      ans2 += 1-now2;
      now2 = 1;
    }
    else if(i % 2 == 0 and now2 >= 0){
      ans2 += now2+1;
      now2 = -1;
    }
    
  }
   
  cout << min(ans1,ans2) << endl;
    
  
}

Measured memory_bytes: 4032
# A - Product
# 2つの整数 a × b が偶数か奇数かを判定する。

# 整数 a b の入力
a, b = map(int, input().split())
# print(a, b)

# a × b　を value に代入
value = a * b
# print(value)

# value が 奇数 か 偶数 かを判定する
if value % 2 == 0:
    # print('guusuu')
    answer = 'Even'
else:
    # print('kisuu')
    answer = 'Odd'

# 結果の表示
print(answer)


Measured memory_bytes: 9148
#include <stdio.h>

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

Measured memory_bytes: 596
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC_List = x = [list(map(int, input().split())) for i in range(Q)]
int_list = [0 for _ in range(10**5+1)]
sum = 0
for i in A:
    int_list[i] += 1
    sum += i

for B, C in BC_List:
    sum = sum + (C-B) * int_list[B]
    int_list[C] += int_list[B]
    int_list[B] = 0
    print(sum)

Measured memory_bytes: 32800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int popRow(vvint &g, int y, int w, int k, int p)
{
    vint row = g[y];
    int score = 0;
    int add = pow(2, p);

    int li = 0, l = row[0];
    rep(i, w)
    {
        if (row[i] != l)
        {
            l = row[i];
            li = i;
            continue;
        }

        if (i - li >= k - 1)
        {
            for (int j = i; j >= li && g[y][j]; j--)
            {
                score += add * g[y][j];
                g[y][j] = 0;
            }
        }
    }

    return score;
}

int pop(vvint &g, int h, int w, int k, int p)
{
    int score = 0;
    rep(y, h)
    {
        score += popRow(g, y, w, k, p);
    }
    return score;
}

void shift(vvint &g, int h, int w)
{
    for (int y = h - 2; y >= 0; y--)
        rep(x, w)
        {
            int d = 1;
            while (y + d < h && g[y + d][x] == 0)
            {
                g[y + d][x] = g[y + d - 1][x];
                g[y + d - 1][x] = 0;
                d++;
            }
        }
}

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vvint g(h, vint(w));
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, w) g[i][j] = s[j] - '0';
    }

    vvint back = g;

    int ans = 0;
    rep(y, h) rep(x, w)
    {
        int now = 0;
        int p = 0;
        g[y][x] = 0;
        while (true)
        {
            shift(g, h, w);
            int newScore = pop(g, h, w, k, p);
            now += newScore;
            ++p;
            if (newScore == 0)
                break;
        }
        g = back;
        ans = max(now, ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 200020 
typedef long long ll;
inline int read(){
	int 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<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N];
ll ans,sum,now;
inline ll Abs(ll x){
	return x>=0?x:-x;
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		sum+=a[i];
	}
	ans=2e18;
	for(int i=1;i<n;++i){
		now+=a[i];
		ans=min(ans,Abs(sum-now-now));
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 4424
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

using ld = long double;

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

    ll a, b, c;
    cin>>a>>b>>c;

    if (c - a - b < 0) cout<<"No"<<endl;
    else {
        if (4 * a * b < (c  - a - b) * (c - a - b)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    char s[100001], c[5];
    int q, t, f;
    scanf("%s%d", s, &q);

    int sCnt = strlen(s), headCnt = 0, tailCnt = 0, rev = 0;
    char head[200001], tail[200001];
    rep(i, q)
    {
        scanf("%d", &t);
        if (t == 1)
            if (rev)
                rev = 0;
            else
                rev = 1;
        else
        {
            scanf("%d%s", &f, c);
            if ((rev == 0 && f == 1) || (rev == 1 && f == 2))
            {
                head[headCnt] = c[0];
                head[headCnt + 1] = '\0';
                headCnt++;
            }
            else if ((rev == 0 && f == 2) || (rev == 1 && f == 1))
            {
                tail[tailCnt] = c[0];
                tail[tailCnt + 1] = '\0';
                tailCnt++;
            }
        }
    }

    if (rev)
    {
        for (int i = tailCnt; i > 0; i--)
            putchar((unsigned char)tail[i - 1]);
        for (int i = sCnt; i > 0; i--)
            putchar((unsigned char)s[i - 1]);
        puts(head);
    }
    else
    {
        for (int i = headCnt; i > 0; i--)
            putchar((unsigned char)head[i - 1]);
        printf("%s", s);
        puts(tail);
    }
    return 0;
}

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

using namespace std;


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

	int t;cin>>t;

	vector<int> h(t);
	for(int i=0;i<t;i++)
        cin>>h[i];

    vector<int> dp(t);

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);

    for(int i=2;i<t;i++){
        int first = abs(h[i]-h[i-2])+dp[i-2];
        int second = abs(h[i]-h[i-1])+dp[i-1];
        dp[i]=min(first,second);
    }

    cout<<dp[t-1]<<'\n';

	return 0;
}


Measured memory_bytes: 3948
#define ll long long int
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
const ll y = 1000;
const ll INF = y*y*y*y*y*y;
int main() {
	int n;
	cin >> n;
	vector <vector <int>> a(n+1, vector <int>(3));
	for (int i = 1; i <= n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	vector <vector <int>> dp(n + 1, vector <int> (3));
	for (int i = 1; i <= n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2];
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 11136
let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let K = input[1]
let H = readLine()!.split(separator: " ").map { Int($0)! }.sorted()

var sum = 0
var i = 0
while i < H.count - K {
  sum += H[i]
  i += 1
}
print(sum)


Measured memory_bytes: 21856
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n==1)
	{
		cout<<m;
		return 0;
	}
	int ma=1;
	for(int i=1;i<=m/n+1;i++){
		if(m%i==0&&m/i>=n&&i>ma)
		   ma=i;
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<long long int, int> P;

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.first < secondElof.first;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<P> shop(n);

    for (int i = 0; i < n; ++i) {
        cin >> shop[i].first >> shop[i].second;
    }

    sort(shop.begin(), shop.end(), pairCompare);

    long long int money = 0;
    int num = m;

    int end;
    for (int i = 0; i < n; ++i) {
        if ((num - shop[i].second) <= 0) {
            end = i;
            break;
        } else {
            num -= shop[i].second;
            money += shop[i].first * shop[i].second;
        }
    }

    for (int j = 0; j < shop[end].second; ++j) {
        if (num == 0) {
            break;
        } else {
            money += shop[end].first;
            num--;
        }
    }
    
    cout << money << endl;
}

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

using namespace std;

long long dp[200000];

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

	int n;

	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	for(int i = 0; i < 200000; ++i){
		dp[i] = 0;
	}

	dp[1] = abs(h[0] - h[1]);

	for(int i = 2; i < n; ++i)
	{
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 2176
MOD = 10 ** 9 + 7
N, K = gets.split.map(&:to_i)

ans = 0
left_sum = 0
right_sum = 0
l = 0
r = N

(1..N + 1).each do |n|
  left_sum += l
  right_sum += r

  if K <= n
    ans += (right_sum - left_sum + 1)
    ans %= MOD
  end

  l += 1
  r -= 1
end

puts ans


Measured memory_bytes: 14320
import sys
N = int(input())
List = []
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    List.append([tmp_b,tmp_a])
List.sort()
Sum_a= 0

for i in range(N):
    Sum_a += List[i][1]
    if Sum_a > List[i][0]:
        print('No')
        sys.exit()
print('Yes')

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

  int N,num[3][200],score[200],counter;

  for(int i=0 ; i < 200 ; i++){
    score[i]=0;
  }
  
  cin >>N;

  for(int i=0 ; i < N ;i++){
    for(int j=0 ; j < 3 ; j++){
      cin >>num[j][i];
    }
  }
  
  for(int i=0 ; i < 3 ;i++){
    for(int j=0 ; j < N ;j++){
      counter=0;
      for(int k=0 ; k < N ; k++){
	
	if( j == k )continue;
	
	if(num[i][j] == num[i][k])counter++;
	
      }

	if(counter == 0){
	  score[j]+=num[i][j];	  
	}
    
    }
  }

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

  return 0;
}

Measured memory_bytes: 1164
h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]

place=[(0,0) for _ in range(h*w+1)]

for r in range(h):
    for c in range(w):
        place[a[r][c]]=(r,c)

dp=[0]*(w*h+1)


for r in range(1,w*h+1):
    if r-d<1:
        continue

    r1,c1=place[r-d]
    r2,c2=place[r]

    dp[r]=dp[r-d]+abs(r1-r2)+abs(c1-c2)

for _ in range(int(input())):
    l,r=map(int,input().split())

    print(dp[r]-dp[l])

Measured memory_bytes: 82540
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S, W = map(int, readline().split())
    if S<=W:
        print('unsafe')
    else:
        print('safe')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9232
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[][] k = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {-1, 1, 1}, {-1, -1, 1}, {-1, 1, -1}, {1, -1, -1}, {-1, -1, -1}};
        long[][] sum = new long[8][n];

        for (int i = 0; i < n; i++) {
            long x = sc.nextLong(), y = sc.nextLong(), z = sc.nextLong();
            for (int v = 0; v < 8; v++) {
                sum[v][i] = x * k[v][0] + y * k[v][1] + z * k[v][2];
            }
        }

        long ans = 0;
        for (int v = 0; v < 8; v++) {
            Arrays.sort(sum[v]);
            long lower = 0, upper = 0;
            for (int i = 0, c = n - 1; i < m; i++, c--) {
                lower += sum[v][i];
                upper += sum[v][c];
            }
            ans = Math.max(ans, Math.max(Math.abs(lower), Math.abs(upper)));
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 26428
#include <stdio.h>

void FuncShowArray(int array[], int head, int tail);
void FuncSwapInt(int *a, int *b);
int FuncSelectionSortInt(int a[], const int len);

int main(void)
{
	int n, num[128];
	int count;
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &num[i]);
	count = FuncSelectionSortInt(num, n);
	FuncShowArray(num, 0, n);
	printf("%d\n", count);

	return 0;
}

int FuncSelectionSortInt(int a[], const int len)
{
	int count = 0;
	int mini;
	int flag = 0;
	int temp;
	int i, j;

	for (i = 0; i < len; i++) {
		mini = i;

		flag = 0;
		for (j = i; j < len; j++) {
			if (a[j] < a[mini]) {
				mini = j;
				flag = 1;
			}
		}
		
		FuncSwapInt(&a[i], &a[mini]);

		if (flag == 1) count++;
	}

	return (count);
}

void FuncSwapInt(int *a, int *b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

void FuncShowArray(int array[], int head, int tail)
{
	int i;
	
	for (i = head; i < tail; i++){
	  if (i > head) putchar(' ');
      printf("%d", array[i]);
	}
	putchar('\n');
}

Measured memory_bytes: 604
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

p = p[0:x]
q = q[0:y]

apple = p + q + r
apple.sort(reverse=True)

print(sum(apple[:x + y]))


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

int main() {
	long A, B, K; cin >> A >> B >> K;
	for(int i=0; i<K; ++i){
	    if(i%2){
	       B=(B-(B%2))/2;
	       A += B;
	    }else{
	       A=(A-(A%2))/2;
	       B += A;
	    }
	}
	cout << A << ' ' << B << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))

int
main(int argc, char *argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\n", Max(a + b, Max(a - b, a * b)));
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define max 10000
#define NIL -1

struct Node{
  int p;
  int l;
  int r;
};

struct Node T[max];
int n;

void preParse(int u){
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}


void postParse(int u){
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,r,l,root;

  scanf("%d",&n);
  for(i=0 ; i<n ; i++) T[i].p = NIL;

  for(i=0 ; i<n ; i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  for(i=0 ; i<n ; i++) if(T[i].p == NIL) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int n;
void solve()
{
    cin>>n;

    if (n%2 || n < 2)
    {
        cout << "0\n";
        return;
    }
    int tw = 0;
    for (int i = 2; i <= n; i *= 2)
    {
        tw += n / i;
    }
    int fv = 0;
    for (int i = 5; i*2 <= n; i*= 5)
    {
        fv += n / (i*2);
    }
    cout << min(tw, fv) << '\n';
}


//
signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	string s;
	cin >> s;
	int N = 0, E = 0, W = 0, S = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s.at(i) == 'N')N++;
		else if (s.at(i) == 'E')E++;
		else if (s.at(i) == 'W')W++;
		else if (s.at(i) == 'S')S++;
	}
	if ((!(N * S) && N + S) || (!(E * W) && E + W))cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

class BIT:
    def __init__(self, n=0):
        self.n = n
        self.d = [0] * (n+1)
    
    def add(self, i, x=1):
        i = int(i+1) # index begin 1
        while i <= self.n:
            self.d[i] += x
            i += i&-i # add LSB
    
    def sum(self, i=None):
        x = 0
        i = int( i+1 if not (i is None) else self.n )
        while i > 0:
            x += self.d[i]
            i -= i&-i # sub LSB
        return x

n, q = list(map(int, input().split()))
c = list(map(int, input().split()))
dprint("n, q =", n, q)
dprint("c =", c)

# check colors pair index (s,t)
st = [0] * (n+1)
col_last = [0] * (n+1)
for i in range(n):
    t = i + 1
    col = c[i]
    s = col_last[col]
    if s > 0:
        st[s] = t
    col_last[col] = t
dprint("st =", st)

# input querys (l,r)
lr = [None] * n
qs = list()
sorted_qs = list()
for i in range(q):
    l, r = list(map(int, input().split()))
    qs.append((i,l,r)) 
sorted_qs = sorted(qs, key=lambda q: q[1], reverse=True)
dprint("qs =", qs)
dprint("sorted_qs =", sorted_qs)

i_qs = 0
x = n
d = BIT(n+1)
qs_ans = [0] * len(qs)
for i_qs in range(len(sorted_qs)):
    i, l, r = sorted_qs[i_qs]
    dprint("i, l, r", i, l, r)
    while (x >= l):
        if st[x] > 0:
            d.add(st[x])
            dprint("add x(s), t =", x, st[x])
        x -= 1
    qs_ans[i] = (r-l+1)-d.sum(r)

for ans in qs_ans:
    print(ans)


Measured memory_bytes: 239412
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
	cin >> N >> K;
	vector<bool> ok(10,1);
	int ans = N;
	rep(i,K){
		int a;
		cin >> a;
		ok[a] = 0;
	}
	bool ng = 1;
	ans = N-1;
	while(ng){
		ng = 0;
		ans++;
		int tmp = ans;
		while(tmp){
			int x = tmp%10;
			tmp/=10;
			if(ok[x]==0){
				ng=1;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter

S = sys.stdin.readline().strip()
counter = Counter(S)
counter = sorted(counter.items(), key=lambda x: x[1])
# print(counter)

if len(counter) == 1:
    if counter[0][1] == 1:
        print("YES")
    else:
        print("NO")
elif len(counter) == 2:
    if counter[0][1] == 1 and counter[1][1] == 1:
        print("YES")
    else:
        print("NO")
else:
    if counter[0][1] + 1 < counter[2][1]:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for (int i = 0; i < m; i++)
        cin >> s[i] >> c[i];
    
    bool isOk;
    for (int i = 0; i < 1000; i++) {
        isOk = true;
        if (!((n == 1 && i < 10) || (n == 2 && 10 <= i && i < 100) || (n == 3 && 100 <= i))) {
            isOk = false;
            continue;
        }
        
        vector<int> d;
        int num = i;
        do {
            d.push_back(num % 10);
            num /= 10;
        } while (num > 0);
        
        for (int i = 0; i < m; i++) {
            if (d[d.size() - s[i]] != c[i])
                isOk = false;
        }
        
        if (isOk) {
            cout << i << endl;
            break;
        }
    }
    
    if (!isOk)
        cout << -1 << endl;
    
    return 0;
}


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

using namespace std;

int alphabet[26];

int main(){
string s; cin >> s; int n = (int) s.size();
  
  memset(alphabet, 0, sizeof( alphabet));
  
  for(int i = 0; i < n; i++){
    alphabet[ s[i] - 'a'] ++;}
  
  if( n < 26){
    for(int i = 0; i < 26; i++){
      if( alphabet[i] == 0){ s = s + (char)( 'a' + i); break;}}
        
        // here is the problematic point; break;
    
    cout << s << endl; return 0;}
  
  else{ // int the case of s.size() == 26
    
    int i = 25;
  
      while( i >= 1 && s[i] < s[i-1]){ i--;}
    
    if( i == 0){ cout << -1 << endl; return 0;}
    
    string t = s.substr( i, n- i);
   char c = s[i-1]; char u = 'z';
    for(int j = 0; j < (int) t.size(); j++){
      if( t[j] > c){ u = min( u, t[j]);}}
    
    string w = s.substr(0,i-1);
    w = w + u;
    cout <<w << endl; return 0;}

  
  return 0;}
    

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

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

    cout << (int(log(N) / log(K)) + 1) << endl;
    return 0;
}

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

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


  int min = 0, max = 0, tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    if (min > tmp || min == 0) min = tmp;
    if (max < tmp) max = tmp;
  }

  cout << max - min << endl;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,m,d,ans=0;cin>>m>>d;
	for(i=10;i<=d;i++){
		int tu=(i/10)*(i%10);
		
		if(i/10>=2&&i%10>=2&&1<=tu&&tu<=m){ans++;}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int a, b;
    std::cin >> a >> b;

    if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
        std::cout << a * b << std::endl;
    } else {
        std::cout << "-1" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
m = 55555
l = []
p = [True for i in range(m+1)]
p[0] = False
p[1] = False
ans = []
l = []
for i in range(2, m):
  if len(ans) >= n:
    break
  if p[i] == False:
    continue
  l.append(i)
  if i % 5 == 1:
    ans.append(i)
  j = i*2
  while j < m:
    p[j] = False
    j += i

print(' '.join(map(str, ans)))

Measured memory_bytes: 3608