akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

ll dp[3001][3001][4];



int main(){

    int R,C;
    ll K;
    cin>>R>>C;
    cin>>K;

    vector<vector<ll> > a(R+1,vector<ll>(C+1,0));

    ll r,c,v;

    for(int i=0;i<K;++i){
        cin>>r>>c>>v;
        a[r][c]=v;
    }

    

    for(int i=1;i<=R;++i){
        for(int j=1;j<=C;++j){
            ll val=0;
            for(int k=0;k<4;++k){
                val=max(dp[i-1][j][k],val);
            }

            if(a[i][j]>0){
                dp[i][j][0]=max(dp[i][j-1][0],val);
                dp[i][j][1]=max(max(dp[i][j-1][0]+a[i][j],dp[i][j-1][1]),val+a[i][j]);
                dp[i][j][2]=max(dp[i][j-1][1]+a[i][j],dp[i][j-1][2]);
                dp[i][j][3]=max(dp[i][j-1][2]+a[i][j],dp[i][j-1][3]);
            }else{
                dp[i][j][0]=max(dp[i][j-1][0],val);
                dp[i][j][1]=dp[i][j-1][1];
                dp[i][j][2]=dp[i][j-1][2];
                dp[i][j][3]=dp[i][j-1][3];
            }


        }

    }

    ll ans=0;

    for(int i=0;i!=4;++i){
        ans=max(dp[R][C][i],ans);
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 354896
#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 pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
// can always split into half
void solve(){
    double w,h,x,y; cin >> w >> h >> x >> y;
    cout << fixed << setprecision(7) << w*h/2 << " ";
    if(2*x == w && 2*y == h) cout << 1;
    else cout << 0;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3772
#include<stdio.h>
#include<math.h>

int main()
{
 int x[4];
 int y[4];
 double xd[4];
 double yd[4];
 double pi=3.14159265358979;
 double temp;
 double tempf;
 double tempc;
 int i;

 scanf("%d %d %d %d",&x[0],&y[0],&x[1],&y[1]);
 for(i=0;i<2;i++)
 { 
  xd[i]=1.0*x[i]-1.0*x[0];
  yd[i]=1.0*y[i]-1.0*y[0];
 }

 xd[3]=cos(0.5*pi)*xd[1]-sin(0.5*pi)*yd[1];
 yd[3]=sin(0.5*pi)*xd[1]+cos(0.5*pi)*yd[1];
 xd[2]=xd[3]+xd[1];
 yd[2]=yd[3]+yd[1];

 for(i=0;i<2;i++)
 {
  temp=xd[i+2]+x[0];
  tempf=fabs(floor(temp)-temp);
  tempc=fabs(ceil(temp)-temp);
  if(tempf>tempc)
  {
   x[i+2]=ceil(temp);
  }else{
   x[i+2]=floor(temp);
  }
 }
 for(i=0;i<2;i++)
 {
  temp=yd[i+2]+y[0];
  tempf=fabs(floor(temp)-temp);
  tempc=fabs(ceil(temp)-temp);
  if(tempf>tempc)
  {
   y[i+2]=ceil(temp);
  }else{
   y[i+2]=floor(temp);
  }
 }

 printf("%d %d %d %d\n",x[2],y[2],x[3],y[3]);
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int sumdigit(int n){
  int sum = 0;
  while(n){
    sum += n % 10;
    n = n / 10;
  }
  
  return sum;
}
 
int main(void){
  int N,a,b;
  cin >> N >> a >> b;
  
  int ans = 0;
  
  for(int i=1;i<=N;i++){
    if(sumdigit(i)  >= a && sumdigit(i) <= b)
      ans += i;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    res_n_cases = 0
    
    for a in range(0,A+1):
        for b in range(0,B+1):
            for c in range(0,C+1):
                value = a*500 + b*100 + c*50
                if value == X:
                   res_n_cases += 1 
    print(res_n_cases)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
my $n = <>;
my %d = ();

for (;0 < $n; $n--) {
    my $k = <>;
    if (!defined($d{$k})) {
        $d{$k} = 1;
    } else {
        $d{$k}++;
    }
}

my $m = -1;
foreach my $k (reverse sort {$d{$a} <=> $d{$b} || $b cmp $a} keys %d) {
    if ($d{$k} < $m) {
        last;
    }
    print $k;
    $m = $d{$k};
}

Measured memory_bytes: 38884
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    B=sorted(A)
    left=B[N//2-1]
    right=B[N//2]

    for i in range(N):
        if A[i]<=left:
            print(right)
        else:
            print(left)

if __name__=="__main__":
    main()

Measured memory_bytes: 25476
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<time.h>
#include<typeinfo>
#include <cstdlib>
#include<stdio.h>

using namespace std;

#define ll long long
#define MOD 1000000007

int main(){
	int n;
	vector<pair<int, ll> > es[100001];
	cin >> n;
	ll u,v,w;
	for(int i = 0;i < n-1;i++){
		cin >> u >> v >> w;
		u--;v--;
		es[u].push_back(make_pair(v,w));
		es[v].push_back(make_pair(u,w));
	}
	ll memo[100001];
	fill_n(memo,100001,-1);
	queue<pair<int, ll> > que;
	que.push(make_pair(0,0));
	while(que.size()){
		int at = que.front().first;
		ll cost = que.front().second;
		que.pop();
		if(memo[at]!=-1)continue;
		memo[at] = cost;
		for(int i = 0;i < es[at].size();i++){
			que.push(make_pair(es[at][i].first,es[at][i].second+cost));
		}
	}
	for(int i = 0;i < n;i++){
		cout << (memo[i]%2) << endl;
	}
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n, k;
void solve(){
	cin >> n >> k;
	
	i64 ans = 0;
	for(i64 i = k+1; i <= n; i++){
		ans += n/i*(i-k) + max(0LL,n%i-max(k,1LL)+1);
		//cout << ans << endl;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
  int main(){
  while(1){
   int t,n,i,x[11],y[11];
     scanf("%d",&t);
     if(t==0){
        break;
        }
      scanf("%d",&n);
     int sum=0;
       for(i=0;i<n;i++){
          scanf("%d%d",&x[i],&y[i]);
            sum += y[i]-x[i];
              }
           if(t<=sum){
             printf("OK\n");
                }else{
                  printf("%d\n",t-sum);
                  } 
}
return 0;
}
                    

Measured memory_bytes: 612
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=1e5+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

struct node
{
  ll w,s,v;
};

ll n;
node a[N];
ll dp[1005][N];

bool comp(node l,node r)
{
  return l.w+l.s<r.w+r.s;
}

ll F(ll idx,ll prev)
{
  ll maxi=0;
  if(idx==n){return 0;}
  if(dp[idx][prev]!=-1){return dp[idx][prev];}
  if(prev<=a[idx].s)
  {
    maxi=max(maxi,F(idx+1,prev));
    maxi=max(maxi,a[idx].v+F(idx+1,prev+a[idx].w));
  }
  else{maxi=max(maxi,F(idx+1,prev));}
  return dp[idx][prev]=maxi;
}

int main()
{
  cin>>n;
  ms(dp,-1);
  for(ll i=0;i<n;i++){cin>>a[i].w>>a[i].s>>a[i].v;}
  sort(a,a+n,comp);
  cout<<F(0,0)<<endl;
}


Measured memory_bytes: 786688
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	

	int a, b, c;
	cin >> a >> b >> c;
	cout << a + b + c - max(a, max(b, c));
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main(){
  char c; cin>>c;
  switch(c){
  case 'a':
  case 'i':
  case 'u':
  case 'e':
  case 'o':
    cout<<"vowel"<<endl;
    break;
  default:
    cout<<"consonant"<<endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 string s;
 cin>>s;
 sort(s.begin(),s.end());
 for(int i=0;i<s.size();i++){
   if(s[i]==s[i+1]){cout<<"no"<<endl;return 0;}
 }
 cout<<"yes"<<endl;
 return 0;
}

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


void print_array(int *x, int n)
{
	for (int k = 0; k < n; ++k)
	{
		if (k == n- 1)
		{
			printf("%d\n", x[k]);
		}
		else
		{
			printf("%d ", x[k]);
		}
	}
}


int main(int argc, char const *argv[])
{
	int input_size, min, count = 0;
	cin >> input_size;

	int array[input_size];

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

	//=====  SelectionSort =====//
	for (int i = 0; i < input_size; ++i)
	{
		// i は配列の中の未ソート部分の先頭を表す
		min = i;
		for (int j = i; j < input_size; ++j)
		{
			if(array[j] < array[min])
			{
				min = j;
			}
		}
		if(min != i) count++;
		int temp = array[min];
		array[min] = array[i];
		array[i] = temp;
	}
	print_array(array, input_size);
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N, K, ans = 0;
cin >> N >> K;
vector<int> ball(N + 1, 0), A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
for (int i : A) ball[i]++;
sort(ball.begin(), ball.end());
for (int i = 0; i < N + 1 - K; ++i) ans += ball[i];
cout << ans << endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long mod = 1000000007;

template<typename T>
void max_self(T& a, T b)
{
	a = max(a, b);
}
template<typename T>
void add_self(T& a, T b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}
template<typename T>
void sub_self(T& a, T b)
{
	a -= b;
	if (a < 0)
		a += mod;
}

// dp[i][j] - number of ways to distribute i candies to j kids

int main()
{ 
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int m;
	cin >> m;
	ll d = 0, s = 0;
	for (int i = 0; i < m; i++)
	{
		ll cc, cd;
		cin >> cd >> cc;
		d += cc;
		s += cd * cc;
	}
	cout << (d - 1) + (s - 1) / 9;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
def nsin(x,n):
    if(int(x/n)):
        return nsin(int(x/n),n)+str(x%n)
    return str(x%n)

def to357(s):
    s = s.replace('3', '7')
    s = s.replace('2', '5')
    s = s.replace('1', '3')
    return s

ans = 0
for i in range(1, N + 1):
    num_3 = nsin(i, 4)
    if '0' in num_3 or '1' not in num_3 or '2' not in num_3 or '3' not in num_3:
        continue

    num_10 = int(to357(num_3))
    if num_10 > N:
        break

    ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int n, cnt = 0, i;
    scanf("%d", &n);
    char s[n + 1];
    scanf("%s", s);
    for(i = 0; i < n - 1; i++){
        if(i == 0){
            cnt++;
        }else if(s[i] != s[i - 1]){
            cnt++;
        }
        
    }
    if(i == n - 1 && s[i] != s[i - 1]){
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> k >> n;
    vl A;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }

    A.push_back(A[0] + k);

    vl B;
    ans = 0;
    rep(i, n) { ans = max(ans, A[i + 1] - A[i]); }

    cout << k-ans << endl;
}

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

using namespace std;

#define int long long
#define test int t;cin>>t;while(t--)

int32_t main()
{
    int n;string s;
    cin>>n>>s;
    if(n<3200)
        cout<<"red"<<endl;
    else
        cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ans := 0
	for i := 1; i <= n; i++ {
		t, c := i, 0
		for t > 0 {
			t /= 10
			c++
		}
		if c%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int c=0,d=0,e=0,f=0;
for(int i=0;i<4;i++){
 int a[i],b[i];
  cin>>a[i]>>b[i];
  if(a[i]==1||b[i]==1)
    c+=1;
  if(a[i]==2||b[i]==2)
    d+=1;
  if(a[i]==3||b[i]==3)
    e+=1;
  if(a[i]==4||b[i]==4)
    f+=1;
}
  if(c>=3||d>=3||e>=3||f>=3)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}

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

int main() {
  int a, b, c, ma, mi, med;
  cin >> a >> b >> c;
  ma = max(max(a, b),c);
  mi = min(min(a, b),c);
  med = a + b + c - mi - ma;
  cout << ma * 10 + mi + med;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f; 
using namespace std;

int n, f[N][27], pos[N], nxt[N], g[N][27], sum[N][27]; 
char s[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	scanf("%s", s + 1), n = strlen(s + 1); 
	for(int tmp, i = n + 1; i >= 1; i--)
	{
		for(int j = 1; j <= 26; j++)
		{
			if(s[i] == 'a' + j - 1)
			{
				tmp = INF; 
				for(int k = 26; k; k--)
					if(f[i + 1][k] <= tmp) tmp = f[i + 1][k], nxt[i] = g[i + 1][k]; 
				f[i][j] = tmp + 1, g[i][j] = i, sum[i][j] = sum[i + 1][j] + 1; 
			}
			else f[i][j] = f[i + 1][j], g[i][j] = g[i + 1][j], sum[i][j] = sum[i + 1][j]; 
		}
		pos[s[i] - 'a' + 1] = i; 
	}
	for(int i = 1; i <= 26; i++) if(!pos[i]) { putchar('a' + i - 1), puts(""); return 0; }
	int tmp = INF, id = 0; 
	for(int i = 26; i >= 1; i--) if(f[pos[i]][i] <= tmp) tmp = f[pos[i]][i], id = i; 
	id = pos[id]; 
	while(id)
	{
		putchar(s[id]); 
		if(!nxt[id]) break;
		id = nxt[id]; 
	}
	for(int i = 1; i <= 26; i++)
		if(!sum[id + 1][i]) { putchar('a' + i - 1), puts(""); return 0; }
	return 0; 
}


Measured memory_bytes: 68024
#include <iostream>

using namespace std;

 
int main(){
    long long n;
    long long m;
    cin >> n >> m;
 
    long long ans=1;
 
    if((m-n)>1||(n-m)>1){
        cout << "0" << endl;
        return 0;
    }
 
 
    for(long long i=1;i<=n;i++){
        ans = i * ans;
        ans = ans % (1000000000 + 7);
    }
    for(long long i=1;i<=m;i++){
        ans = i * ans;
        ans = ans % (1000000000 + 7);
    }   
    if(n - m == 0){
        ans = ans * 2;
    }
    ans = ans % (1000000000 + 7);
    cout << ans << endl;
    return 0;
 
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private int[] a = new int[10];
	private double v1, v2;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			String[] str = scan.nextLine().split(",");
			
			int dis = 0;
			
			for (int i = 0; i < 10; i++) {
				a[i] = Integer.parseInt(str[i]); 
				dis += a[i];
			}
			
			v1 = Double.parseDouble(str[10]);
			v2 = Double.parseDouble(str[11]);
			
			double pos = v1 * dis / (v1 + v2);
			//System.out.println(pos);
			
			int cal = 0, ans = 0;
			for (int i = 0; i < 10; i++) {
				if (cal + a[i] >= pos) {
					ans = i+1;
					break;
				}
				cal += a[i];
			}
			
			System.out.println(ans);
			
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int64 sum(int32 x){
  return (int64)(1+x) * x / 2;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> a(n);
  int64 asum = 0;
  REP(i,n){
    cin >> a[i];
    asum += a[i];
  }
  if(asum % sum(n) != 0){
    YES(false);
    return 0;
  }
  int64 m = asum / sum(n);
  vector<int32> d(n);
  REP(i,n)d[i] = a[(i+1)%n] - a[i];
  REP(i,n)d[i] -= m;
  bool flg = true;
  REP(i,n){
    if(d[i] > 0 || d[i] % n)flg = false;
  }
  YES(flg);
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
P = [int(p) for p in input().split()]
Q = [int(q) for q in input().split()]

fact = [1] * (N+1)
for i in range(2,N+1):
    fact[i] = fact[i-1]*i


def dic_num(S):
    keta = 0
    num = 0
    S_set = set()
    for i in range(len(S)):
        minor = 0
        for j in S_set:
            if S[keta] > j:
                minor = minor + 1
        num += (S[keta] - 1 - minor) * fact[len(S)-keta-1]
        S_set.add(S[keta])
        keta += 1

    return num+1


print(abs(dic_num(P)-dic_num(Q)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7; //99844353;
const int N = 1e5;
void YN(bool z){cout << (z ? "YES" : "NO") << endl; exit(0);}
int n;
ll c[N];
V<int> e[N];
ll dfs(int a, int p){
  if(sz(e[a])==1) return c[a];
  ll s = 0, ma = -1;
  for(int b:e[a]) if(p!=b){
    ll t = dfs(b, a);
    s += t;
    maxs(ma, t);
  }
  if(c[a]<max(ma, s-s/2) || s<c[a]) YN(false);
  return c[a]*2-s;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> c[i];
  FOR(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  if(n==2) YN(c[0]==c[1]);
  FOR(i, 0, n) if(sz(e[i])>1) YN(!dfs(i, -1));
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
		#include<unordered_map>	
		#include<unordered_set>
		#define pb emplace_back
		#define rt(v) return cout<<v,0
		#define sz(v) (int)(v.size())
		#define all(a) a.begin(),a.end()
		#define endl '\n'
		#define space " "
		typedef long long ll;
		typedef unsigned long long ull;
		const int N = 10 + 1e5;
		const int mod = 1e9 + 7;
		/*

		███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
		████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
		██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
		██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
		██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
		╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

		*/
		//
		int m1[150][150];
		int m2[150][150];
		using namespace std;
		void Ferrari() {
			ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
		}
		
		int main() {
			Ferrari();
			int n, k; cin >> n >> k;
			set<int>st;
			for (int i = 0; i < k; ++i) {
				int y; cin >> y;
				while (y--) {
					int a; cin >> a;
					st.insert(a);
				}
			}
			cout << n - st.size();
			return 0;
		}
		   

	


		/* stuff you should look for
			* keepin sharp mind.
			* int overflow, array bounds.
			* special cases (n=1?), set tle , make sure you understand the proble correctly.
			* don`t stuck in a problem.
			* test the idea on samples.
			*/

Measured memory_bytes: 3664
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

SU = [0] * (len(A)+1)

for i in range(N):
    SU[i+1] = SU[i] + A[i]

ans = 0
for i in range(N):
    ans += A[i] * (SU[N]-SU[i+1]) % MOD

print(ans%MOD)

Measured memory_bytes: 94152
l,r=map(int, input().split())

mod_l = l % 2019
mod_r = r % 2019

if (r - l >= 2019) or (mod_r < mod_l):
  print('0')
else:
  rem = 2018
  for i in range(mod_l, mod_r):
    for j in range(i+1, mod_r+1):
      if rem < (i*j)%2019:
        continue
      else:
          rem = (i*j)%2019

  print(rem)

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

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

const ll INF = 1LL<<60;

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> price(n, vector<ll>(3));
    rep(i, n) rep(j, 3) cin >> price[i][j];

    vector<vector<ll>> dp(n + 1, vector<ll>(3, 0));

    for(int i = 1; i <= n; i++) {
        rep(j, 3) {
            rep(k, 3) {
                if(j != k) chmax(dp[i][k], dp[i - 1][j] + price[i - 1][k]);
            }
        }
    }

    ll ans = 0;
    rep(i, 3) {
        ans = max(ans, dp[n][i]);
    }

    cout << ans << endl;

    return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define ALL(v) v.begin(), v.end()

const int MAX = 1e5+10;
int N;
vi D, c, p;
vii P;
vi children[MAX];

ii dfs(int n) {
    int cnt = 0;
    ll res = 0;
    FORE (ch, children[n]) {
        ii r = dfs(ch);
        cnt += r.first;
        res += r.second;
    }
    res += cnt;
    return MP(cnt+1, res);
}

int main () {
    cin >> N;
    D = vi(N);
    c = vi(N, 1);
    p = vi(N, -1);
    REP (i, N) {
        cin >> D[i];
        P.PB(MP(D[i], i+1));
    }
    sort(ALL(D));
    sort(ALL(P));
    FORR (i, 1, N) {
        ll d = D[i] - N + 2*c[i];
        auto it = lower_bound(ALL(D),d);
        if (it == D.end() || *it != d) {
            cout << -1 << endl;
            return 0;
        }
        int j = it-D.begin();
        c[j] += c[i];
        p[i] = j;
        children[j].PB(i);
    }
    if (dfs(0).second != D[0]) {
        cout << -1 << endl;
        return 0;
    }
    REP (i, N) if (p[i] != -1) {
        cout << P[p[i]].second << " " << P[i].second << "\n";
    }
}

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

using namespace std;

typedef long long ll;
//const ll MOD = 1000000007;

int main() {
  int N,Q;
  cin>>N>>Q;
  vector<tuple<ll, ll, ll>> ST;
  vector<ll> D(Q);
  for (int i = 0; i < N; i++) {
    ll s,t,x;
    cin>>s>>t>>x;
    ST.emplace_back(s - x, 1, x);
    ST.emplace_back(t - x, -1, x);
  }
  for (int i = 0; i < Q; i++) cin>>D[i];
  sort(ST.begin(),ST.end());
  multiset <ll> st;
  vector<ll> ans(Q,-1);
  ll cnt = 0;
  for (int i = 0; i < 2 * N; i++) {
    bool ok = false;
    ll time = get<0>(ST[i]);
    ll type = get<1>(ST[i]);
    ll x = get<2>(ST[i]);
    while(time > D[cnt]) {
      if (st.empty()) ans[cnt] = -1;
      else ans[cnt] = *st.begin();
      cnt++;
      if (cnt == Q) {
        ok = true;
        break;
      }
    }
    if (type == 1) {
      st.insert(x);
    } else st.erase(x);
    if (ok) break;
  }
  for (int i = 0; i < Q; i++) cout<<ans[i]<<endl;
  return 0;
}

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

using namespace std;

int a[30],b[30];
int main() {

    string s,t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < (int)s.size(); ++i)
        ans += s[i] != t[i];
    cout << ans << "\n";


    return 0;
}


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

int main() {
	string S;
	cin >> S;
	bool Cexisted = false;
	for (int i = 0; i < S.length(); i++) {
		if (i == 0) {
			if (S[i] != 'A') {
				cout << "WA" << endl;
				return 0;
			}
		}
		else {
			if (i == 1 || i == S.length() - 1) {
				if (S[i] < 'a' || S[i]>'z') {
					cout << "WA" << endl;
					return 0;
				}
			}
			else {
				if ((S[i] < 'a' && S[i]>'z' && S[i] != 'C') || (S[i] == 'C' && Cexisted)) {
					cout << "WA" << endl;
					return 0;
				}
				if (S[i] == 'C') Cexisted = true;
			}
		}
	}
	cout << (Cexisted ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
/*input
3 3
1 2 1
1 3 1
2 3 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=305;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

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

int dis[maxn][maxn];
vector<pair<pii,int>> edge;

int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) REP(j,n){
		dis[i][j]=(i==j)?0:INF;
	}
	REP(i,m){
		int u,v,d;
		cin>>u>>v>>d;
		u--;v--;
		edge.eb(MP(u,v),d);
		dis[u][v]=dis[v][u]=d;
	}

	REP(j,n) REP(i,n) REP(k,n){
		dis[i][k]=min(dis[i][k],dis[i][j]+dis[j][k]);
	}
	// REP(i,n) REP(j,n) cout<<dis[i][j]<<" \n"[j==n-1];

	int cnt=0;
	for(auto i:edge){
		if(dis[i.F.F][i.F.S]!=i.S) cnt++;
	}
	cout<<cnt<<'\n';

	return 0;
}


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

class Program
{
    static void Main()
    {
        var S = Console.ReadLine();
        var l0 = S.Count(c => c == '0');
        var l1 = S.Count(c => c == '1');
        Console.WriteLine(2 * Math.Min(l0, l1));
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i, n){
    cin >> vec.at(i);
  }
  sort(vec.rbegin(), vec.rend());
  int x = 101, cnt = 0;
  rep(i, n){
    if(vec.at(i)<x){
      cnt++;
      x = vec.at(i);
    }
  }
  cout << cnt << endl;



    




}



Measured memory_bytes: 256
import std.stdio, std.array, std.conv, std.string, std.algorithm;

void main() {
  string[] input = split(readln());
  int[] a = new int[3];

  for (int i = 0; i < 3; ++i) {
    a[i] = to!int(input[i]);
  }

  sort(a);
  // sort!("a < b")(a);
  for (int i = 0; i < 3; ++i) {
    write(a[i]);
    write(i == 2 ? "\n" : " ");
  }
}

Measured memory_bytes: 2500
import java.util.Scanner;  

  public class Main {
          public static void main(String[] args){
        
        Scanner input = new Scanner(System.in);
        int masuk=input.nextInt();
        int total=0;
        for (int a=1;a<=masuk;a++){
            total+=a;
        }
        System.out.println(total);
}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
using ull = unsigned long long;

int Digits(ull n){
	int res = 1;
	while(n /= 10){
		res++;
	}
	return res;
}

int main(){
	ull N;
	scanf("%llu", &N);
	int answer = Digits(N);
	for (ull i = 2; i*i <= N; ++i){
		if(!(N % i)) answer = min(answer, max(Digits(i), Digits(N/i)));
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <thread>
#include <chrono>

using namespace std;

int main(void){
	string s;
	cin >> s;
	if(s.length()==2){
		cout << s << endl;
	}else{
		reverse(s.begin(), s.end());
		cout << s << endl;
	}
	return 0;
}

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

int main(void)
{

	/*int c,r;
	int i,j;
	int a[102][102];
	
	cin >> c >> r;
	
	for( i = 0; i <= r + 1; i++){
		for( j = 0; j <= c + 1; j++){
			a[i][j] = 0;
		}
	}
	
	for (i = 1; i <= r; i++){
		for(j =1; j<= c; j++){
			cin >> a[i][j];
			a[i][c+1] += a[i][j];
			a[r+1][j] += a[i][j];
			a[r+1][c+1] += a[i][j];
		}
	}
	
	for (i = 1; i <= r + 1; i++){
		for (j = 1; j <= c + 1; j++){
			if (j != 1) cout << " ";
			cout << a[i][j];
		}
		cout << endl;
	}
	
	return 0;
}
	





#include <iostream>
using namespace std;
 
int main(){*/
    int i, j, r, c;
    int array[102][102];
 
    cin >> r >> c;
 
    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            array[i][j] = 0;
        }
    }
 
    for (i = 1; i <= r; i++){
        for (j = 1; j <= c; j++){
            cin >> array[i][j];
            array[i][c+1] += array[i][j];
            array[r+1][j] += array[i][j];
            array[r+1][c+1] += array[i][j];
        }
    }
 
    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            if (j != 1) cout << " ";
            cout << array[i][j];
        }
        cout << endl;
    }
 
    return 0;
}

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

#define MAXN (100010)

int n, k, x[MAXN];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", x + i);
    }
    int ans = INT_MAX;
    for (int j = 1; j <= n - k + 1; ++j) {
        int l = x[j];
        int r = x[j + k - 1];
        int s = abs(l - r) + std::min(abs(l), abs(r));
        ans = std::min(ans, s);
    }
    printf("%d", ans);
    return 0;
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            
            Array.Sort(imp);
            //Console.Write(imp[2]);
            int a = int.Parse(imp[2]);
            int b = int.Parse(imp[1]);
            int c = int.Parse(imp[0]);
            if (a==b&&b==c)
            {
                Console.Write("Yes");
            }
            else
            {
                Console.Write("No");
            }
            
            //System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 13408
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      
      // 判定
      String result = "";
      int digit1 = N % 10;
      if(digit1 == 3){
        result = "bon";
      }else if(digit1 == 0 || digit1 == 1 || digit1 == 6 || digit1 == 8){
        result = "pon";
      }else{
        result = "hon";
      }
      
      // 出力
      System.out.println(result);
    }

}

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

int gcd(int a, int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
}
int GCD(int a, int b, int c)
{
  return gcd(a,gcd(b,c));
}
int main(void)
{
  int n,i,j,k;
  long long int ans = 0;
  cin>>n;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      for(k=1;k<=n;k++)
        ans += GCD(i,j,k);
  cout<<ans<<endl;
 return 0; 
}

Measured memory_bytes: 3604
def solve(string):
    x, k, d = map(int, string.split())
    x = abs(x)
    if k % 2:
        x = min(x - d, x + d, key=abs)
        k -= 1
    k, d = k // 2, d * 2
    if x < k * d:
        return str(min(x % d, abs((x % d) - d)))
    else:
        return str(x - k * d)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int maxn = 200010;

ll NumberOfzeros(ll n){
    ll ans = 0;
    ll val = (ll)10;
    while(n >= val){
        ans += (n / val);
        val *= 5;
    }
    return ans;
}


int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll n; cin >> n;
    if(n & 1){
        cout << 0 << '\n';
        return 0;
    }
    cout << NumberOfzeros(n) << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A[3][3]; 
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> A[i][j]; 
		}
	}
	bool B[3][3] = {}; 
	int N; cin >> N; 
	for(int t = 0; t < N; t++){
		int b; cin >> b; 
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				if(A[i][j] == b) B[i][j] = true; 
			}
		}
	}
	for(int i = 0; i < 3; i++){
		if(B[i][0] && B[i][1] && B[i][2]){
			cout << "Yes" << endl; return 0; 
		}
	}
	for(int i = 0; i < 3; i++){
		if(B[0][i] && B[1][i] && B[2][i]){
			cout << "Yes" << endl; return 0; 
		}
	}
	if(B[0][0] && B[1][1] && B[2][2]){
		cout << "Yes" << endl; return 0; 
	}
	if(B[0][2] && B[1][1] && B[2][0]){
		cout << "Yes" << endl; return 0; 
	}
	cout << "No" << endl;  
}

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

long long n, l = 2, r = 2;
long long a[100010];

int main()
{
	scanf("%lld", &n);
	for(register int i = 1; i <= n; ++i){
		scanf("%lld", &a[i]);
	}
	for(register int i = n; i >= 1; --i){
		if(l % a[i] != 0) l = l / a[i] * a[i] + a[i];
		r = r / a[i] * a[i] + a[i] - 1;
		if(l > r) break;
	}
	if(l > r) puts("-1");
	else printf("%lld %lld\n", l, r);
	return 0;
} 

Measured memory_bytes: 1024
import collections
N = int(input())
S = [input() for i in range(N)]
S = sorted(S)


C = collections.Counter(S)

M = C.most_common()
V = C.values()
MAX = max(V)

for i in range(len(M)):
    if M[i][1] == MAX:
        print(M[i][0])


Measured memory_bytes: 159824
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vi data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    sort(data.begin(), data.end());
    int ans = 20000001;
    for (int i = data[0]; i <= data[N - 1]; i++) {
        int sum = 0;
        for (int x : data) {
            int a = (i - x) * (i - x);
            sum += a;
        }
        if (ans > sum) {
            ans = sum;
        }
        else {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Measured memory_bytes: 6148
//shipc2018masters_d.cpp
//Sun May 17 14:10:56 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

struct edge {ll to, cost;};

vector<edge> G1[100100];
ll d1[100100];
ll v,e;

void dijkstra1 (ll s){
	priority_queue<P, vector<P>, greater<P>> pq; //小さい順 
	//sからの最短距離の配列を初期化
	fill (d1,d1+v,LLINF);
	//sからsへの最短距離は当然0
	d1[s] = 0;
	//C++11以降はmake_pairの代わりに下記の書き方が可能
	pq.push(P(0,s));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		ll vtemp = p.second;
		if (d1[vtemp] < p.first){
			continue;
		}
		for (ll i=0;i<G1[vtemp].size();i++){
			edge e = G1[vtemp][i];
			if (d1[e.to] > d1[vtemp] + e.cost){
				d1[e.to] = d1[vtemp] + e.cost;
				pq.push(P(d1[e.to],e.to));
			}
		}
	}
}

vector<edge> G2[100100];
ll d2[100100];

void dijkstra2 (ll s){
	priority_queue<P, vector<P>, greater<P>> pq; //小さい順 
	//sからの最短距離の配列を初期化
	fill (d2,d2+v,LLINF);
	//sからsへの最短距離は当然0
	d2[s] = 0;
	//C++11以降はmake_pairの代わりに下記の書き方が可能
	pq.push(P(0,s));
	while(!pq.empty()){
		P p = pq.top();
		pq.pop();
		ll vtemp = p.second;
		if (d2[vtemp] < p.first){
			continue;
		}
		for (ll i=0;i<G2[vtemp].size();i++){
			edge e = G2[vtemp][i];
			if (d2[e.to] > d2[vtemp] + e.cost){
				d2[e.to] = d2[vtemp] + e.cost;
				pq.push(P(d2[e.to],e.to));
			}
		}
	}
}

int main(){
	cin >> v >> e;
	ll s,t;
	cin >> s >> t;
	s--;t--;

	for (ll i=0;i<e;i++){
		ll a,b,c,d;
		cin >> a >> b >> c >> d;
		a--;b--;
		edge e1;
		e1.to = b;
		e1.cost = c;
		G1[a].push_back(e1);
		edge e2;
		e2.to = a;
		e2.cost = c;
		G1[b].push_back(e2);
		edge e3;
		e3.to = b;
		e3.cost = d;
		G2[a].push_back(e3);
		edge e4;
		e4.to = a;
		e4.cost = d;
		G2[b].push_back(e4);
	}

	dijkstra1(s);
	dijkstra2(t);

	ll total[v];
	fill(total,total+v,LLINF);
	total[v-1] = d1[v-1]+d2[v-1];
	for (ll i = v-2;i>=0;i--){
		total[i] = d1[i]+d2[i];
		total[i] = min(total[i],total[i+1]);
	}

	for (ll i=0;i<v;i++){
		cout << 1000000000000000-total[i] << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 19472
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define DescSort(a) sort(a.begin(),a.end(),std::greater<LL>())
#define Sort(a) sort(a.begin(),a.end())

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	LL ans = 0;

	cin >> N >> M;

	vector<LL>X((UI)M);

	for (int i = 0; i < M; i++) {
		cin >> X.at(i);
	}

	Sort(X);

	vector<LL>L((UI)M - 1, 0);	// 差分

	for (int i = 1; i < M; i++) {
		L[i - 1] = X[i] - X[i - 1];
	}

	Sort(L);

	for (UI i = 0; i < M - N; i++) {
		ans += L[i];
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1792
int t,n,m,l,i,j,a,b,k,P[1001],T[1001],Q[2001],C[2001][2001],V[2001],d[1001][1001];
int match(s){int i=l;for(;i<l+l;i++)if(C[s][i]&&!V[i])if(V[i]=1,Q[i]<0||match(Q[i]))return Q[s]=i,Q[i]=s,1;return 0;}
main(){
  for(;scanf("%d%d%d",&n,&m,&l),l;printf("%d\n",l-t)){
	memset(C,0,sizeof(C));memset(Q,0xff,sizeof(Q));
	memset(d,11,sizeof(d));for(i=0;i<n;i++)d[i][i]=0;
    //for(i=0;i<n;i++)for(j=0;j<n;j++)d[i][j]=i==j?0:99999;
    for(i=0;i<m;i++)scanf("%d%d%d",&a,&b,&k),d[a][b]=d[b][a]=k;
	for(i=0;i<l;i++)scanf("%d%d",P+i,T+i);
	//warshall-floyd
	for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
	for(i=0;i<l;i++)for(j=0;j<l;j++)if(i!=j&&d[P[i]][P[j]]<99999&&T[i]+d[P[i]][P[j]]<=T[j])C[i][l+j]=C[l+j][i]=1;
    for(t=i=0;i<l;i++)memset(&V,0,sizeof(V)),t+=match(i);
  }
  return 0;
}

Measured memory_bytes: 20200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
  	int flag =0;
  	cin>>a>>b;
  	if(b.length()==a.length()+1)
    {
  		for(int i=0;i<a.length();i++)
        {
        	if(a[i]!=b[i])
            {
				flag=1;
              	break;
            }
          if(flag)
            	break;
        }
    }
  	if(flag==1)
      cout<<"No";
  	else
      cout<<"Yes";
}


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


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

    map<string, int> dict{};
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        dict[s]++;
    }

    cout << "AC x " << dict["AC"] << endl;
    cout << "WA x " << dict["WA"] << endl;
    cout << "TLE x " << dict["TLE"] << endl;
    cout << "RE x " << dict["RE"] << endl;

    return 0;
}


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

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

pii gcd(int a, int b, int c = 0) {
  return b == 0 ? pii(a, c) : gcd(b, a % b, c + 1);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a, b;
  while (cin >> a >> b, a) {
    if (a < b) swap(a, b);
    pii g = gcd(a, b);
    cout << g.first << " " << g.second << endl;
  }

  return 0;
}


Measured memory_bytes: 3096