akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
int N,M;
const LL up=1000LL*1000LL*1000LL+1;
LL l[200][200];
LL s[200][200];
void relax(LL mat[200][200])
{
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
			}
		}
	}
}
LL buf[2][200];
inline void clear(LL *b)
{
	for(int i=0;i<N;i++){
		b[i]=up;
	}
}
void exec()
{
	scanf("%d%d",&N,&M);
	if(N==0&&M==0){
		exit(0);
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			l[i][j]=s[i][j]=up;
		}
		l[i][i]=s[i][i]=0;
	}

	for(int i=0;i<M;i++){
		int x,y,t;
		char sl[2];
		scanf("%d%d%d%1s",&x,&y,&t,sl);
		x--;
		y--;
		if(sl[0]=='L'){
			if(l[x][y]>t){
				l[x][y]=l[y][x]=t;
			}
		}
		else
		{
			if(s[x][y]>t){
				s[x][y]=s[y][x]=t;
			}
		}
	}

	relax(l);
	relax(s);


	/*
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			if(l[i][j]!=up)
				//cout << i+1 << ", " << j+1 << ": " << l[i][j] << endl;
		}

	}
	//cout << endl;
	for(int i=0;i<N;i++){
		for(int j=i;j<N;j++){
			if(s[i][j]!=up)
				//cout << i+1 << ", " << j+1 << ": " << s[i][j] << endl;
		}
	}
	//cout << endl;
*/
	int R;
	scanf("%d",&R);
	int z;
	int zz;
	scanf("%d",&z);
	z--;
	LL *cur=buf[0];
	LL *nex=buf[1];
	clear(cur);
	cur[z]=0;
	zz=z;
	for(int i=1;i<R;i++){
		clear(nex);
		scanf("%d",&z);
		z--;
		for(int b=0;b<N;b++){
			if(l[zz][b]==up){
				continue;
			}
			for(int e=0;e<N;e++){
				if(l[e][z]==up||s[b][e]==up){
					continue;
				}
				if(b==e){
					nex[e]=min(nex[e],cur[b]+l[zz][z]);
				}
				else
				{
					nex[e]=min(nex[e],cur[b]+l[zz][b]+s[b][e]+l[e][z]);
				}
			}
		}
		/*
		//cout << z+1 << endl;
		for(int i=0;i<N;i++){
			if (nex[i]!=up)
				//cout << i+1 << ": " << nex[i] << endl;
		}
		//cout << endl;
		*/
		zz=z;
		swap(nex,cur);
	}
	LL ret=up;
	for(int i=0;i<N;i++){
		ret=min(cur[i],ret);
	}
	printf("%lld\n",ret);
}
int main()
{
	while(true){
		exec();
	}
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	string a, b, c;
	cin >> a >> b >> c;
	cout << "A" << b[0] << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
//abc155_c.cpp
//Sat Apr  4 20:49:25 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;

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

	map<string,int> mp;
	int m = 0;
	for (int i=0;i<n;i++){
		string s;
		cin >> s;
		auto itr = mp.find(s);
		if (itr != mp.end()){
			mp[s]++;
		}else {
			mp[s] = 1;
		}
		m = max(m,mp[s]);
	}

	vector<string> ans;
	for (auto itr = mp.begin();itr!=mp.end();itr++){
		if (itr->second==m){
			ans.push_back(itr->first);
		}
	}

	sort(ans.begin(),ans.end());

	for (int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 26868
import collections
N,A,B=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
l=[]
frac=[1]*51
modfrac=[1]*51
avg=0
for i in range(1,51):
    frac[i]=frac[i-1]*i
for i in range(A):
    l.append(v[i])
avg=(sum(l)/len(l))
mi=min(l)
cnt=0
c1 = collections.Counter(l)
c2 = collections.Counter(v)
if len(set(l))==1:
    n=c2[mi]
    for i in range(A,min(B+1,n+1)):
        up=1
        down=1
        for j in range(1,i+1):#nCi
            up=up*(n-i+j)
            down=down*j
        cnt=cnt+(up//down)
else:
    n=c2[mi]
    r=c1[mi]
    up=1
    down=1
    for i in range(1,r+1):
        up=up*(n+1-i)
        down=down*i
    cnt=(up//down)
print(avg)
print(cnt)

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = 0; i < N; i++ ) cin >> B[i];
    priority_queue<ll> q;
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] > B[i] ) q.push(A[i]-B[i]);
    }
    ll ans = 0, f = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( A[i] < B[i] ) {
            ans++;
            while ( !q.empty() && f < B[i]-A[i] ) {
                f += q.top();
                q.pop();
                ans++;
            }
            if ( q.empty() && f < B[i]-A[i] ) return -1;
            f -= B[i]-A[i];
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2428
#include <iostream>

using namespace std;

main(){
    int A,B,fee;

    fee = 0; 

    cin >> A >> B;

    if(A>=6)
    {
        fee += B/2;
    }

    if(A>=13)
    {
        fee += B/2;
    }

    cout << fee << endl;


}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    vector<bool> f(26);
    for (int i = 0; i < (int)s.size(); i++) {
        f[s[i] - 'a'] = 1;
    }

    bool found = 0;
    for (int i = 0; i < 26; i++) {
        if (!f[i]) {
            cout << (char)('a' + i) << endl;
            found = 1;
            break;
        }
    }

    if (!found) {
        cout << "None" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int N, W;
    cin >> N >> W;
    vector<pair<ll,ll>> items(N + 1);
    for (int i = 1; i <= N; i++) cin >> items[i].first >> items[i].second;
    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= W; j++) {
            if (j - items[i].first >= 0) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - items[i].first] + items[i].second);
            else dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

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

int main() {
	int x, a, b; scanf("%d%d%d", &x, &a, &b);
	if (b - a <= 0)puts("delicious");
	else if (b - a <= x)puts("safe");
	else puts("dangerous");
}

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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  int res = 0, k = 1;
  for (int i = 0; i < N; i++) {
    if (A[i] == k) k++;
    else res++;
  }
  if (res == N) cout << -1 << endl;
  else cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n; cin >> n;
  string res1, res2;
  const string d1 = ".#.#";
  const string d2 = "..##";

  for(int i = 0; ; i++){
    res1 = res1 + "X";
    res2 = res2 + "X";
    int j = 0;
    for(;j < 4; j++){
      res1[res1.size()-1] = d1[j];
      res2[res2.size()-1] = d2[j];
      cout << res1 << endl << res2 << endl;
      string ans; cin >> ans;
      if(ans == "T"){ break; }
      if(ans == "end"){ return 0; }
    }
    if(j >= 4){ break; }
  }
  res1 = res1.substr(0,res1.size()-1);
  res2 = res2.substr(0,res2.size()-1);
  for(int i = 0; ; i++){
    res1 = "X" + res1;
    res2 = "X" + res2;
    int j = 0;
    for(;j < 4; j++){
      res1[0] = d1[j];
      res2[0] = d2[j];
      cout << res1 << endl << res2 << endl;
      string ans; cin >> ans;
      if(ans == "T"){ break; }
      if(ans == "end"){ return 0; }
    }
  }
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 解説PDF後
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long ans = solve(n, k);
        System.out.println(ans);
    }

    static long solve(int N, int K) {
        long ans = 0;
        long tmpOdd = 0;
        long tmpEve1 = 0;
        long tmpEve2 = 0;
        for (int a = 1; a <= N; a++) {
            long modK = a % K;
            if (K % 2 == 0) {
                // 偶数の場合

                if (modK == 0) {
                    // 1. a,b,cがそれぞれ、Kでちょうど割り切れる
                    // ex) K=2 [a=2, b=2, c=2]
                    tmpEve1++;
                }

                if (modK == K / 2) {
                    // 2. a,b,cがそれぞれ、Kで割った余りがちょうど K /2
                    // ex) K=2 [a=1, b=3, c=1]
                    tmpEve2++;
                }

            } else {
                // 偶数の場合
                if (modK == 0) {
                    // 1. a,b,cがそれぞれ、Kでちょうど割り切れる
                    // ex) K=3 [a=3, b=3, c=3]
                    tmpOdd++;
                }
            }
        }

        if (K % 2 == 0) {
            // 各値がKでちょうど割り切れる場合と、K/2の場合を加算する
            ans = (long) (Math.pow(tmpEve1, 3) + Math.pow(tmpEve2, 3));
        } else {
            // 全ての値がちょうど割り切れる場合のパターンをa,b,cで3乗する
            ans = tmpOdd * tmpOdd * tmpOdd;
        }

        return ans;
    }
}



Measured memory_bytes: 21716
N = int(input())
T = 0
t = 0
ans = []
for i in range(N-1):
    C, S, F = map(int, input().split())
    for j in range(len(ans)):
        if ans[j] <= S:
            ans[j] = S+C
        elif ans[j]%F != 0:
            ans[j] = ans[j]+F-(ans[j] % F)+C
        else:
            ans[j] += C
    ans.append(S+C)
for a in ans:
    print(a)
print(0)


Measured memory_bytes: 8960
#include<iostream>
            #include<stdio.h>
            //#include <bits/stdc++.h>
            #include<vector>
            #include<algorithm>
            #include<string>
            #include<math.h>
            #include<sstream>
            #include<set>
            #include<map>
            using namespace std;
            #define INF 10000000;
            #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
            #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
            #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
            #define vec(type,n) vector<type>(n)
            #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
         
          
          
            int main(){
              int n,k,r,s,p;
              cin >> n>>k>>r>>s>>p;
              string t;
              cin >>t;

              rep(i,n-k){
                if(t[i] == t[i+k])t[i+k] = 'X';
              }

              int sum = 0;
              rep(i,n){
                if(t[i] == 'r')sum +=p;
                if(t[i] == 's')sum +=r;
                if(t[i] == 'p')sum +=s;
              }
              cout <<sum;
            }

Measured memory_bytes: 512
S = str(input())
T = str(input())

s = len(S)
t = len(T)

count = 0
for i in range (0, s-t+1):
	V = S[i:i+t]
	temp  = 0
	for j in range (0, t):
		if V[j]==T[j]:
			temp+=1
	count = max(count, temp)

print(t-count)

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

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

    int N;
    int x; int y;

    cin >> N;
    int d[N];
    for(int i=0; i<N; i++) cin >> d[i];

    int total = 0;

    for(int i=0;i<N;i++){
        for(int j=i+1; j<N; j++){
            total += d[i] * d[j];
        }
    }
    cout << total;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,q;
    string s;
    cin>>n>>s>>q;
    vector<set<int>> t(26);
    rep(i,n){
        int x=s[i]-'a';
        t[x].emplace(i);
    }
    rep(i,q){
        ll tp;cin>>tp;
        if(tp==1){
            //j文字目をcに置き換える
            int j;char c;cin>>j>>c;j--;
            int pre=s[j]-'a',now=c-'a';
            t[pre].erase(j);
            s[j]=c;
            t[now].emplace(j);
        }else{
            //l文字目からr文字目まで何種類の文字が使われているのかを調べる
            ll l,r;cin>>l>>r;l--;r--;
            ll res=0;
            rep(j,26){
                auto itr1=t[j].lower_bound(l);
                auto itr2=t[j].lower_bound(r+1);
                if(itr1!=itr2)res++;
            }
            cout<<res<<endl;
        }
    }
}

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

using namespace std;

int m, n, t, k;

int main() {
    ios_base::sync_with_stdio(false);
    int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> k;
    cout << ar[k-1] << endl;
}



Measured memory_bytes: 256
from functools import reduce
n,k=map(int,input().split())
a=list(map(int,input().split()))
d1,d2=a[:n-k],a[k:n]
dd=list(map(lambda x,y:'Yes' if y>x else 'No',d1,d2))
for i in range(len(dd)):print(dd[i])

Measured memory_bytes: 32176
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int num = 1;
    int count = 0;
    while(num < b) {
      num += (a - 1);
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int c[1001][1001];
  string x,y;
  int n; cin >> n;
  while(n>0){
    n--;
    
    //文字列の入力
    cin >> x;
    cin >> y;

    //入力した文字列の長さをもとめる
    int lenx = x.size();
    int leny = y.size();
 
    //初期条件
    for(int i = 1; i <= lenx; i++){
      c[i][0] = 0;
    }
    
    //初期条件
    for(int j = 1; j <= leny; j++){
      c[0][j] = 0;
    }


    //LCS
    for(int i = 1; i <= lenx; i++){
      for(int j = 1; j <= leny; j++){
	//着目している文字が等しいとき
    if(x[i-1]==y[j-1]){
      c[i][j] = c[i-1][j-1] + 1;
      //着目している文字が等しくないときは
      //表の左と上の小さいほうを出力
    }else if(c[i-1][j] >= c[i][j-1]){
      c[i][j] = c[i-1][j];
    }else{
      c[i][j] = c[i][j-1];
    }
      }
    }
    
    //出力
    cout << c[lenx][leny] << endl;
  }
  return 0;
}

Measured memory_bytes: 5116
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Char (digitToInt)

main :: IO ()
main = do
  s <- getLine
  unless (s == "0") $ do
    putStrLn $ solve s
    main

solve :: String -> String
solve s = fst $ minimumBy (\x y -> dc c (snd x) `compare` dc c (snd y)) colors
  where
    c = toColor s

hexToInt :: String -> Int
hexToInt s = foldl (\a x -> a * 16 + x) 0 $ map digitToInt s

colors :: [(String,(Int,Int,Int))]
colors = [("black",(0,0,0)),("blue",(0,0,255)),
          ("lime",(0,255,0)),("aqua",(0,255,255)),
          ("red",(255,0,0)),("fuchsia",(255,0,255)),
          ("yellow",(255,255,0)),("white",(255,255,255))]

dc :: (Int,Int,Int) -> (Int,Int,Int) -> Int
dc (r,g,b) (rk,gk,bk) = (r - rk) ^ 2 + (g - gk) ^ 2 + (b - bk) ^ 2

toColor :: String -> (Int,Int,Int)
toColor s = (hexToInt r, hexToInt g, hexToInt b)
  where
    r = take 2 . tail $ s
    g = take 2 . drop 3 $ s
    b = drop 5 s

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

int main()
{
    int n;
    cin>>n;
    unordered_map<string,int> mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    string a;
    for(int i=1;i<=n;i++)
    {
      cin>>a;
      mp[a]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	UL n;
	cin >> n;
	VV<UL> x(n);
	VV<bool> y(n);
	REP(i, n) {
		int a, x0, y0;
		cin >> a;
		REP(j, a) {
			cin >> x0 >> y0;
			x0--;
			x[i].emplace_back(x0);
			y[i].emplace_back(y0);
		}
	}

	UL ans = 0;
	REP(i, 1u << n) {
		bitset<15> bit(i);
		bool able = true;

		REP(j, n) {
			if (bit[j]) {
				REP(k, x[j].size()) {
					if (bit[x[j][k]] != y[j][k]) {
						able = false;
						break;
					}
				}
			}
			if (!able) {
				break;
			}
		}

		if (able) {
			ans = max(ans, static_cast<UL>(bit.count()));
		}
	}

	col(ans);
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int w=nxt(),h=nxt(),n=nxt();
    int x1=0,y1=0,x2=w,y2=h;
    for(int i=0;i<n;i++)
    {
        int x=nxt(),y=nxt(),a=nxt();
        if(a==1)
        {
            x1=max(x1,x);
        }
        else if(a==2)
        {
            x2=min(x2,x);
        }
        else if(a==3)
        {
            y1=max(y1,y);
        }
        else
        {
            y2=min(y2,y);
        }
    }
    if(x1>=x2||y1>=y2)
        cout<<"0\n";
    else
        cout<<(x2-x1)*(y2-y1)<<endl;

    
    return 0;   
}




 
 


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int m = min(A, B);
    int c=0;
    for(int i=m; i>=1; --i) {
        if( A%i==0 && B%i==0 )
            c++;
        if(c==K) {
            cout << i;
            return 0;
        }
    }
    cout << 0;
}


Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


int main(void) {
    ll N;
    cin>>N;
    string S;
    cin>>S;
    ll ans = 0;
    rep(i,0,N-2) {
        if (S[i] == 'A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout<<ans<<endl;





   return 0;
}

Measured memory_bytes: 256
mod=10**9+7
N=int(input())
M=1
y=[1 for k in range(N)]
for k in range(2,N+1):
    for j in range(2,k+1):
        if k==1:
            break
        if k%j ==0:
            count=0
            while k%j==0:
                k=k//j
                count+=1
            y[j-1]+=count
ans=1
for k in range(len(y)):
    ans=ans*y[k]%mod
print(ans)

Measured memory_bytes: 3064
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [String; n],
    }
    let mut a = a
        .into_iter()
        .map(|ai| {
            let s = ai.split('.').collect::<Vec<_>>();
            if s.len() == 1 {
                (s[0].parse::<usize>().ok().unwrap(), 0)
            } else {
                (
                    format!("{}{}", s[0], s[1]).parse::<usize>().ok().unwrap(),
                    s[1].len(),
                )
            }
        })
        .collect::<Vec<_>>();
    a.sort_by_key(|&(_, k)| k);
    // eprintln!("{:?}", a);

    let mut factors = HashMap::new();
    for i in 0..n {
        let (mut x, k) = a[i];
        let mut two = 0;
        while x % 2 == 0 {
            two += 1;
            x /= 2;
        }
        let mut five = 0;
        while x % 5 == 0 {
            five += 1;
            x /= 5;
        }
        *factors.entry((two, five, k)).or_insert(0) += 1;
    }

    let factors = factors.into_iter().collect::<Vec<_>>();
    eprintln!("{:?}", factors);
    let m = factors.len();
    let mut result = 0usize;
    for i in 0..m {
        let ((fi, gi, ki), ci) = factors[i];
        if fi >= ki && gi >= ki {
            result += ci * (ci - 1) / 2;
        }
    }
    for i in 0..m {
        let ((fi, gi, ki), ci) = factors[i];
        for j in 0..i {
            let ((fj, gj, kj), cj) = factors[j];
            if fi + fj >= ki + kj && gi + gj >= ki + kj {
                result += ci * cj
            }
        }
    }
    println!("{}", result);
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<int> cnt(M);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int K;  cin >> K;
    vector<int> km(K);
    for (int j = 0; j < K; j++) {
      cin >> km.at(j);
    }
    for (int j = 0; j < M; j++) {
      for (int k = 0; k < K; k++) {
        if (j + 1 == km.at(k)) {
          cnt.at(j)++;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if(cnt.at(i) == N) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
                String S[] = new String [N];
                String Str = "Two";
                 for(int i=0;i<N;i++){
                  S[i] = sc.next();
                 }
                 for(int i=0;i<N;i++){
                    if(S[i].equals("Y")){
                      Str = "Four";
                      break;
                    }
                    else
                      Str = "Three";
                  }
                System.out.println(Str);
	}
}

Measured memory_bytes: 21844
# B - Crane and Turtle

x,y = list(map(int, input().split()))

a = 2*x - y/2
b = (y-2*x)/2

#print(a,b)

if a>=0 and b>=0 and a%1!=0.5 and b%1!=0.5:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    bool b[328][328] = {};
    ll d[328][328] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> d[i][j], z += d[i][j];
    for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (d[i][j] > d[i][k] + d[k][j]) {cout << -1; return 0;}
    //for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cout << i << ' ' << j << ' ' << k << ' ' << d[i][j] << ' ' << d[i][k] << ' ' << d[k][j] << ' ' << (i != k && j != k && i != j && d[i][j] == d[i][k] + d[k][j]) << '\n';
    for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != k && j != k && d[i][j] == d[i][k] + d[k][j]) b[i][j] = 1;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (b[i][j]) z -= d[i][j];
    cout << z / 2;
    /*
     2 4 10
     1 4 11
     2 3 13
     3 5 13
     4 5 17
     1 3 18
     */
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
set<int> adj[100001];
int a[100001],b[100001];
ll c[100001];
ll ans=0;
ll d[100001];
int shutu[100001]={};
int main(){
	int N;
	scan(N);
	rep(i,N-1){
		scan(a[i]>>b[i]);
		a[i]--; b[i]--;
		adj[a[i]].insert(b[i]);
		adj[b[i]].insert(a[i]);
	}
	rep(i,N) scan(c[i]);
	sort(c,c+N);
	/*rep(i,N-1){
		SI.insert({adj[i].size(),i});
	}*/
	rep(i,N){
		shutu[i]=adj[i].size();
	}
	/*for(int i=0;i<N&&(!SI.empty());i++){
		auto itr=SI.begin();
		int mins=(*itr).first,v=(*itr).second;
		SI.erase(itr);
		ans+=(ll)shutu[v]*c[i];
		d[v]=c[i];
		alre[v]=1;
		shutu[v]=0;
		vpint tmp;
		rep(j,adj[v].size()){
			int u=adj[v][j];
			if(alre[u]) continue;
			SI.erase({shutu[u],u});
			if(shutu[u]>0) shutu[u]--;
			tmp.push_back({shutu[u],u});
		}
		rep(j,tmp.size()){
			SI.insert(tmp[j]);
		}
	}*/
	rep(i,N-1) ans+=c[i];
	queue<int> v1;
	rep(i,N) if(shutu[i]==1) v1.push(i);
	rep(i,N){
		int u=v1.front();
		v1.pop();
		d[u]=c[i];
		if(i==N-1) break;
		auto vitr=adj[u].begin();
		int v=(*vitr);
		adj[v].erase(u);
		adj[u].erase(v);
		shutu[u]--;
		shutu[v]--;
		if(shutu[v]==1) v1.push(v);
		//printf("i:%d u:%d v:%d d[u]:%lld shutu[v]:%d size:%d\n",i,u+1,v+1,d[u],shutu[v],(int)v1.size());
	}
	prin(ans);
	rep(i,N){
		printf("%lld ",d[i]);
	}
	kaigyo;
	return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <stdint.h>

typedef unsigned __int128 uint128_t;

uint64_t s[2] = {0xFEDCBA9876543210, 0x0123456789ABCDEF};

uint64_t xorshift128plus(void) {
  uint64_t x = s[0];
  uint64_t const y = s[1];
  s[0] = y;
  x ^= x << 23;
  s[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
  return s[1] + y;
}

uint64_t modpow(uint64_t a, uint64_t n, uint64_t m){
  uint64_t r;
  for(r=1;n;n/=2){
    if(n&1) r = (uint128_t) r * a % m;
    a = (uint128_t) a * a % m;
  }
  return r;
}

int is_prime(uint64_t n){
  int i, j, r;
  uint64_t d;
  if(n == 2) return 1;
  if(!(n & 1)) return 0;
  r = __builtin_ctz(n-1);
  d = (n-1) >> r;
  for(i=0;i<1000;i++){
    uint64_t a = 2 + xorshift128plus() % (n-3);
    uint64_t t = modpow(a, d, n);
    if(t == 1) continue;
    for(j=0;t!=n-1;j++){
      if(j == r-1) return 0;
      t = (uint128_t) t * t % n;
      if(t == 1) return 0;
    }
  }
  return 1;
}

int main(){
  int x;
  scanf("%d", &x);
  while(1){
    if(is_prime(x)){
      printf("%d\n", x);
      return 0;
    }
    x++;
  }
  return 0;
}


Measured memory_bytes: 256
#template
def inputlist(): return [int(j) for j in input().split()]
#template
from collections import Counter
N = int(input())
A = inputlist()
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = inputlist()
A_sum = sum(A)
dic = Counter(A)
for i in range(Q):
    A_sum += (C[i]-B[i])*dic[B[i]]
    print(A_sum)
    dic[C[i]] += dic[B[i]]
    dic[B[i]] = 0

Measured memory_bytes: 29920
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  string s;
  int ans = 0;
  cin >> s;
  for(int i=0;i<s.size()/2;i++){
    if(s[i]!=s[s.size()-1-i]) ans++;
  }
  cout<< ans <<endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    // cin.sync_with_stdio(false);
    int n, k;
    while(cin >> n >> k, n) {
        ll d = 0, i = 1;

        while(true) {
            if (d < n && n <= d + i * pow(10, i - 1) * 9) {
                int num = (n - d) / i + (((n - d) % i) ? 1 : 0) + (int)pow(10, i - 1) - 1;
                int p = i * (num - (int)pow(10, i - 1) + 1) - (n - d) + 1;
                if (k >= p) {
                    cout << to_string(num).substr(i - p);
                    num++;
                    k -= p;
                    while(to_string(num).size() <= k) {
                        k -= to_string(num).size();
                        cout << to_string(num);
                        num++;
                    }
                    if (k) cout << to_string(num).substr(0, k);
                } else {
                    cout << to_string(num).substr(i - p, k);
                }
                cout << endl;
                break;
            } else {
                d += i * pow(10, i - 1) * 9;
                i++;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3376
#include "bits/stdc++.h"
using namespace std;

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

int main() {
	int n, m, k; cin >> n >> m >> k;
	vector<int> row(n, 0);
	vector<int> col(m, 0);

	vector<vector<int>> adj(n, vector<int>());

	while(k--) {
		int x, y; cin >> x >> y;
		x--;
		y--;
		row[x]++;
		col[y]++;
		adj[x].push_back(y);
	}

	int row_max = *max_element(row.begin(), row.end());
	int col_max = *max_element(col.begin(), col.end());

	int mx_col_cnt = 0;
	for(int i = 0; i < m; ++i) {
		if(col[i] == col_max) {
			mx_col_cnt++;
		}
	}

	bool found = false;
	for(int i = 0; i < n; ++i) {
		if(row[i] != row_max) continue;
		int cnt = 0;
		for(auto j : adj[i]) {
			cnt += col[j] == col_max;
		}
		if(cnt < mx_col_cnt) 
			found = true;
		if(found)
			break;
	}

	cout << (found ? (row_max + col_max) : (row_max + col_max - 1)) << '\n';

	return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    REP(z, k + 1) {
        REP(y, k + 1) {
            int x = s - z - y;
            if(x >= 0 && x <= k) cnt++;
        }
    }
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
function main(input) {
  const a = input.split('\n')[1].split(' ').map(Number);

  if(a.some(x => x === 0)){
    console.log('0');
    return;
  }

  let c = 1;
  for(let i=0; i< a.length; i++){
    if(( BigInt(a[i]) * BigInt(c) ) > 1000000000000000000) {
      console.log('-1');
      return;
    }
    c = BigInt(a[i]) * BigInt(c);
  }

  console.log(c.toString());
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 45868
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    vll x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    ll sumx = 0, sumy = 0;
    rep(i,n){
        sumx += i * x[i] % mod;
        sumx %= mod;
        sumx += mod - ((n - 1 - i) * x[i] % mod);
        sumx %= mod;
    }
    rep(i, m)
    {
        sumy += i * y[i] % mod;
        sumy %= mod;
        sumy += mod - ((m - 1 - i) * y[i] % mod);
        sumy %= mod;
    }
    cout << sumx * sumy % mod << ENDL;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    vector<int> a(32);
    rep(i, 3)a[i] = 1;
    a[3] = 2;
    a[4] = 1;
    a[5] = 2;
    a[6] = 1;
    a[7] = 5;
    a[8] = a[9] = 2;
    a[10] = 1;
    a[11] = 5;
    a[12] = 1;
    a[13] = 2;
    a[14] = 1;
    a[15] = 14;
    a[16] = a[18] = 1;
    a[17] = a[19] = 5;
    a[20] = a[21] = 2;
    a[22] = 1;
    a[23] = 15;
    a[24] = a[25] = 2;
    a[26] = 5;
    a[27] = a[39] = 4;
    a[28] = a[30] = 1;
    a[31] = 51;
    int k;
    cin >> k;
    k--;
    cout << a[k] << endl;
}   

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, std::vector<long long> a, std::vector<long long> b) {
  const ll maxBit = 30;
  vl bitNums(maxBit);
  rep(k, 0, maxBit) {
    vl aTmp;
    vl bTmp;
    rep(n, 0, N) {
      aTmp.push_back(a[n] % (ll)pow(2, k + 1));
      bTmp.push_back(b[n] % (ll)pow(2, k + 1));
    }
    sort(all(aTmp));
    sort(all(bTmp));

    ll t = pow(2, k);
    rep(n, 0, N) {
      auto l = lower_bound(all(bTmp), t - aTmp[n]);
      auto r = lower_bound(all(bTmp), 2 * t - aTmp[n]);
      bitNums[k] += r - l;

      l = lower_bound(all(bTmp), 3 * t - aTmp[n]);
      r = lower_bound(all(bTmp), 4 * t - aTmp[n]);
      bitNums[k] += r - l;
    }
    bitNums[k] %= 2;
  }

  ll ans = 0;
  rep(k, 0, maxBit) {
    if (bitNums[k] == 1) {
      ans += pow(2, k);
    }
  }
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  std::vector<long long> b(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &b[i]);
  }
  solve(N, std::move(a), std::move(b));
  return 0;
}


Measured memory_bytes: 8408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mod 998244353

using namespace std;
typedef long long ll;
const int MAXN = 2000005;
int n,a[MAXN],b[MAXN];
char str[MAXN];
ll f[MAXN];
inline void solve(int x)
{
	ll res = 0;
	for(int i = 1; i<=x/2; i++)
		res = (res*2+a[i])%mod;
	res = (res+1)%mod;
	for(int i = 1, j = 0; i<=n; i += x/2, j++)
		for(int k = i; k<=i+x/2-1; k++)
			b[k] = a[k-i+1]^(j&1);
	bool flag = true;
	for(int i = 1; i<=n; i++)
	{
		if(b[i]>a[i])
			flag = false;
	    else if(b[i]<a[i])
	    	break;
	}
	if(!flag)
		res = (res+mod-1)%mod;
	f[x] = res;
}

int main()
{
	cin >> n >> str+1;
	for(int i = 1; i<=n; i++)
		a[i] = str[i]-'0';
	for(int i = 1; i<=2*n; i++)
		if(2*n%i==0&&n%i!=0)
			solve(i);
	for(int i = 1; i<=2*n; i++)
		if(2*n%i==0&&n%i!=0)
			for(int j = 2*i; j<=2*n; j += i)
				if(2*n%j==0&&n%j!=0)
					f[j] = (f[j]-f[i]+mod)%mod;
	ll ans = 0;
	for(int i = 1; i<=2*n; i++)
		ans = (ans+f[i]*i)%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

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

	return gcd(b, a%b);
}

int main()
{
	ll n,ans=0;
	string s;

	cin >> n;

	forll(i, 0, n)
	{
		forll(j, 0, n)
		{
			ll buf = gcd(max(i+1,j+1), min(i + 1,j + 1));

			forll(k, 0, n)
			{
				ans += gcd(max(buf, k + 1), min(buf, k + 1));
			}
		}
	}


	cout << ans << endl;

}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {

    int N;
    int a;
    int b;

    cin>>N;

    a = N/100;
    b = N - (a*111);

    if(b<=0)
        cout<<a*111<<endl;
    else
        cout<<(a+1)*111<<endl;


    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  bool judge = true;

  rep(i, N){
    if(S[i] != S[(N-i)-1]){
      judge = false;
      break;
    }

  }
  rep(i, (N-1)/2){
    if(S.at(i) != S.at((N-1)/2-i-1)){
      judge = false;
      break;
    }
  }
  if(judge)cout << "Yes" << endl;
  else cout << "No" << endl;

return 0;
}




Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B = list(map(str, input().split()))
A = int(A)
B = 100*int(B[0])+10*int(B[2])+int(B[3])

print(A*B//100)

Measured memory_bytes: 65556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    char a[n][n],b[m][m];
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
        }
    }
    rep(i,m){
        rep(j,m){
            cin>>b[i][j];
        }
    }

    if(n==m){
        bool ok=true;
        rep(i,n){
            rep(j,n){
                if(a[i][j]!=b[i][j]) ok=false;
            }
        }
        if(ok) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }

    rep(i,n-m){
        rep(j,n-m){
            bool ok=true;
            rep(k,m){
                rep(l,m){
                    if(a[i+k][j+l]!=b[k][l]) ok=false;
                }
            }
            if(ok){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return 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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e18+1;

int main()
{
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans=INF;
    rep(i,1e5+1){
        ans=min(ans,2*c*i+a*max(0LL,x-i)+b*max(0LL,y-i));
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
using System;
class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int A = int.Parse(input[1]);
    int B = int.Parse(input[2]);
    
    int train = N * A;
    int taxi = B;
    
    Console.WriteLine(Math.Min(train, taxi));
  }
}

Measured memory_bytes: 11092
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            if (n % 2 == 1) {
                Console.WriteLine(0);
                return;
            }
            
            n /= 2;
            var k = 5L;
            var ans = 0L;
            while (n / k > 0) {
                ans += n / k;
                k *= 5;
            }
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
						For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
typedef vector <int> vi;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=500005,mod=1e9+7,INF=1e9;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
int del(int x,int y){
	return x-y<0?x-y+mod:x-y;
}
int n;
struct Node{
	int b,k;
	int id;
	int L,R;
}a[N];
bool cmpK(Node a,Node b){
	return a.k!=b.k?a.k<b.k:a.b<b.b;
}
bool cmpB(Node a,Node b){
	return a.b<b.b;
}
bool cmpL(Node a,Node b){
	return a.L!=b.L?a.L<b.L:a.R<b.R;
}
int dp[N],s[N];
int main(){
	n=read();
	For(i,1,n)
		a[i].b=read(),a[i].k=read();
	sort(a+1,a+n+1,cmpK);
	For(i,1,n)
		a[i].id=i;
	sort(a+1,a+n+1,cmpB);
	a[0].R=0,a[n+1].L=INF;
	For(i,1,n)
		a[i].R=max(a[i-1].R,a[i].id);
	Fod(i,n,1)
		a[i].L=min(a[i+1].L,a[i].id);
	sort(a+1,a+n+1,cmpL);
	dp[0]=s[0]=1;
	for (int i=1,j=0;i<=n;i++){
		while (j<a[i].R){
			j++;
			Add(s[j]=s[j-1],dp[j]);
		}
		Add(dp[a[i].R],del(s[a[i].R],a[i].L>1?s[a[i].L-2]:0));
		Add(s[j]=s[j-1],dp[j]);
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		sc.close();

		long ans = 0;
		if (N * 2 > M) {
			ans = M / 2;
		} else {
			ans = N + (M - 2 * N) / 4;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764