akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_bacm
#define mp mame_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int n, m;
    cin >> n >> m;
    int k, a;
    bool used[n][m] = {false};
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) used[i][j] = false;
    for (int i = 0; i < n; i++){
        cin >> k;
        for (int j = 0; j < k; j++){
            cin >> a;
            used[i][a-1] = true;
        }
    }
    int ans = 0;
    bool flag;
    for (int i = 0; i < m; i++){
        flag = true;
        for (int j = 0; j < n; j++){
            if (!used[j][i]){
                flag = false;
                break;
            }
        }
        if (flag) ans++;
    }
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


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

int main(){
  string s,ans="";
  cin >> s;
  r(i,s.size()){
    if(s.at(i)=='B'&&ans!="")ans.erase(ans.size()-1);
    if(s.at(i)=='1')ans+="1";
    if(s.at(i)=='0')ans+="0";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add_self(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int add(int a,int b){
	int c=a+b;
	if(c>=mod){
		c-=mod;
	}
	return c;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=2000005;
 
void solve(){
	int x,y;
	cin>>x>>y;
	ll sum=0;
	
	if(x==1&&y==1){
		cout<<300000*2+400000;
	}
	else{
		//~ 100000 200000, and 300000
		if(x==1){
			sum+=300000;
		}
		if(x==2){
			sum+=200000;
		}
		if(x==3){
			sum+=100000;
		}
		swap(x,y);
		if(x==1){
			sum+=300000;
		}
		if(x==2){
			sum+=200000;
		}
		if(x==3){
			sum+=100000;
		}
		cout<<sum;
		
	}
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println((1..n).map {
        var x = sc.nextInt()
        var count = 0
        while (x > 0 && x % 2 == 0) {
            x /= 2
            count++
        }
        count
    }.sum())
}

Measured memory_bytes: 37768
class mod_comb_k():
  def __init__(self, MAX_N = 10**6, mod = 10**9+7):
    self.fact = [1]
    self.fact_inv = [0] * (MAX_N + 4)
    self.mod = mod
    for i in range(MAX_N + 3):
      self.fact.append(self.fact[-1] * (i + 1) % self.mod)
    self.fact_inv[-1] = pow(self.fact[-1], self.mod - 2, self.mod)
    for i in range(MAX_N + 2, -1, -1):
      self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod
  def comb(self, n, k):
    if n < k:
      return 0
    else:return self.fact[n] * self.fact_inv[k] % self.mod * self.fact_inv[n - k] % self.mod
mod=10**9+7
c=mod_comb_k(mod=10**9+7)
n=int(input())
ans=0
for i in range(1,n//3+1):
  ans+=c.comb(n-3*i+i-1,i-1)
  ans%=mod
print(ans)

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

int main(){
    string in;
    string p,q;
    int ma=0;
    map<string,int>mp;

    while(cin>>in){
        if(in.size()>q.size())q=in;
        mp[in]++;
        if(ma<mp[in]){
            ma=mp[in];
            p=in;
        }
    }
    cout<<p<<" "<<q<<endl;
}

Measured memory_bytes: 1196
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(:5.10);
use utf8;

my @num = 0..999;

# 桁チェック
my $keta;
{
    my $line = <STDIN>;
    my @line = split(/\s+/, $line);
    $keta = $line[0];
}
@num = grep {/^.{$keta}$/} @num;

# 制約チェック
while(<STDIN>){
    my @seiyaku = split(/\s+/);
    my @regex;
    push(@regex, ".") for 1..$keta;
    $regex[$seiyaku[0]-1] = $seiyaku[1];
    my $regstr =  join("",@regex);
    @num = grep {/$regstr/} @num;
}

# 最小値
if (@num+0 == 0){
    say -1;
}
else {
    my $min = 999;
    for(@num){
        $min = $_ if $_ < $min;
    }
    say $min;
}


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

int main(){
    int n;
    cin >> n;
    int g,k;
    if(n%2==0){
        g=n/2;
        k=n/2;
    }else{
        k=n/2+1;
        g=n/2;
    }
    cout << k*g << endl;
}

Measured memory_bytes: 256
//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define gc(a) scanf("%s",a+1)
#define rep(p,n,i) for(RE ll i=p;i<=n;++i)
#define go(x) for(ll i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE ll i=n;i>=p;--i)
#define pii pair<ll,ll> 
#define mk make_pair
#define RE register
#define P 1000000007
#define S second
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ull unsigned long long
#define mod 998244353
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
    register ll x=0,f=1;register char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const ll MAXN=200010;
ll n,ans,top;
ll f[MAXN],g[MAXN],s[MAXN];
struct wy
{
	ll x,y;
	inline ll friend operator <(wy a,wy b){return a.x<b.x;}
}t[MAXN];
int main()
{
	//freopen("1.in","r",stdin);
	get(n);
	rep(1,n,i)
	{
		ll get(x);ll get(y);
		t[i]=(wy){x,x+y-1};
	}
	sort(t+1,t+1+n);
	g[n+1]=1;
	fep(n,1,i)
	{
		f[i]=i;
		while(top&&t[i].y>=t[s[top]].x)
		{
			f[i]=max(f[i],f[s[top]]);
			--top;
		}
		s[++top]=i;
		g[i]=(g[i+1]+g[f[i]+1])%mod;
	}
	putl(g[1]);
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n, d; cin >> n >> d;
  int x[n][d];
  rep(i, n) rep(j, d) cin >> x[i][j];
  int ans = 0;
  double g = 0;
  rep(i,n-1){
    for(int j=i+1; j<n; j++){
      g = 0;
      rep(k,d){
        g += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      g = sqrt(g);
      rep(i, sqrt(16000)+1) if(g == i) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e18 + 7)
using namespace std;

long long num[55], n;

long long get()
{
    long long res = 0;
    while(1)
    {
        long long mx = -inf, id;
        for(int i = 1;i <= n;i++)
        {
            if(mx < num[i])
                mx = num[i], id = i;
        }
        if(mx <= n - 1)
            break;
        long long cnt = (mx - n + 1) / n;
        if((mx - n + 1) % n)
            cnt++;
        num[id] -= cnt * n;
        for(int i = 1;i <= n;i++)
        {
            if(i == id)
                continue;
            num[i] += cnt;
        }
        res += cnt;
    }
    return res;
}

int main()
{
    scanf("%lld", &n);
    for(int i = 1;i <= n;i++)
        scanf("%lld", &num[i]);
    printf("%lld\n", get());
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <functional> // std::greater <int> ()
#define inf 1000000000000000001

typedef long long ll;
typedef long double ld;
using namespace std;

//variables
ll n, p, ans=1;
ll prime, dem;
bool check=0;

//functions
void factor(ll x){
	ll k=2;
	while(x!=1){
		if(x%k==0){
			prime=k;
			dem=0;
			while(x%k==0){
				x=x/k;
				dem++;
				if(dem%n==0){
					ans*=prime;
				}
			}
		}
		if(k*k>x){
			return;
		}
		k++;
	}
}

void input(){
	cin >> n >> p;
}

void solve(){
	ll temp;
	if(n==1){
		check=1;
		return;
	}
	factor(p);
}

void output(){
	if(check){
		cout << p;
		return;
	}
	cout << ans;
	return;
}

int main(){
//  freopen(".INP", "r", stdin);
//  freopen(".OUT", "w", stdout);
	input();
	solve();
	output();
	return 0;
}
//  Author: NamSPro

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

void check (int a[], int b[], int & hit, int & blow )
{
	rep (i, 4 ){
		rep (j, 4 ){
			if (a[i] == b[j] ){
				if (i == j ) hit++;
				else blow++;
			} // end if
		} // end rep
	} // end rep
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.HB", "r", stdin );

	int a[4],b[4];
	while (scanf ("%d%d%d%d", &a[0], &a[1], &a[2], &a[3] ) != EOF ){
		scanf ("%d%d%d%d", &b[0], &b[1], &b[2], &b[3] );
		int hit = 0, blow = 0;
		check (a, b, hit, blow );
		printf ("%d %d\n", hit, blow );
	} // end while
		
	return 0;
}

Measured memory_bytes: 1188
def quick_sort(list):
    stand=list[0]
    over=[]
    same=[]
    under=[]
    for i in list:
        if(i>stand):
            over.append(i)
        elif(i<stand):
            under.append(i)
        else:
            same.append(i)
    if(len(over)>1):
        over=quick_sort(over)
    else:
        pass
    if(len(under)>1):
        under=quick_sort(under)
    else:
        pass

    return over+same+under

N=int(input())
A=list(map(int,input().split()))
A=quick_sort(A)
ans="YES"
if(len(A)>1):
    for i in range(len(A)):
        if(A[i-1]==A[i]):
            ans="NO"
            break
        else:
            pass
else:
    pass
print(ans)

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

using namespace std;

const long long N = 2e5 + 5, M = 998244353;
long long n, m, a[N];
long long ans = 1;

long long fpow(long long x, long long y)
{
    long long ret = min(1LL, x);
    while (y)
    {
        if (y & 1) ret = (1LL * ret * x) % M;
        x = (1LL * x * x) % M;
        y /= 2;
    }
    return ret;
}

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

    long long n;
    cin >> n;
    for (long long i = 0; i < n; i++)
    {
        long long x;
        cin >> x;

        if (i == 0 && x != 0)
        {
            cout << 0;
            return 0;
        }

        a[x]++;
        m = max(m, x);
    }

    if (a[0] != 1)
    {
        cout << 0 << "\n";
        return 0;
    }

    for (int i = 0; i <= m; i++)
    {
        if (a[i] == 0)
        {
            cout << 0;
            return 0;
        }
    }

    for (long long i = 1; i < m; i++)
    {
        ans = (1LL * ans * fpow(a[i], a[i + 1])) % M;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 1024
import sys

MOD = 998244353

def main():
    N, S = map(int, input().split())
    X = [int(x) for x in sys.stdin.readline().split()]

    # dp = np.zeros((N+1)*(S+1), dtype=np.int).reshape((N+1),(S+1))
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]

    dp[0][0] = 1

    for i in range(N):
        xi = X[i]
        # xi を U に加えない場合
        for j in range(S+1):
            dp[i+1][j] += dp[i][j]*2  # T に加える／加えない
            dp[i+1][j] %= MOD
            # xi を U に加える場合
            if j+xi > S: continue
            dp[i+1][j+xi] += dp[i][j]
            dp[i+1][j+xi] %= MOD

    print(dp[N][S] % MOD)

main()

Measured memory_bytes: 146740
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  long n,w;
  cin>>n>>w;
  vector<long> dp(100001,w+1);
  dp[0]=0;
  long val=0;
  for(int i=0;i<n;i++)
  {
    long we,va;
    cin>>we>>va;
    val+=va;
    for(int j=val+1;j>=va;j--)
    {
      if(min(dp[j],dp[j-va]+we)<=w)dp[j]=min(dp[j],dp[j-va]+we);
    }

  }
  int res=0;
  for(int i=100000;i>-1;i--)
  {
    if(dp[i]!=w+1){res=i;break;}
  }
  cout<<res;
  return 0;

}

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

int lcs(string X,string Y)
{
    int c[1051][1051];
    int maxv=0;
    int m=X.size();
    int n=Y.size();
    X=' '+X;
    Y=' '+Y;
    for(int i=0;i<=m;i++)c[i][0]=0;
    for(int j=1;j<=n;j++)c[0][j]=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(X[i]==Y[j])  c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i][j-1],c[i-1][j]);
            maxv=max(maxv,c[i][j]);
        }
    }
    return maxv;
}

int main()
{
    string s1,s2;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
 	return 0;
}


Measured memory_bytes: 7216
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string yes = "YES", no = "NO";
    vi v(4);
    vi u = {1, 4, 7, 9};
    rep(i, 4) cin >> v[i];
    sort(all(v));
    if(v == u) cout << yes << endl;
    else cout << no << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
int n,l,i;
cin>>n>>l;
vector<string > v(n);
for(i=0;i<n;i++)
cin>>v[i];
sort(v.begin(),v.end());
string s="";
for(i=0;i<n;i++)
s+=v[i];
cout<<s<<endl;
 
return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define rep(i, n) for(int i = 0; i < n; i++)
const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
  string s;
  cin >> s;
  if(s.at(s.size() - 1) == 's') {
    cout << s + "es" << endl;
  }
  else {
    cout << s + 's' << endl;
  }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long X, long long Y){
    vector<vector<int>> distances(N+1, vector<int>(N+1));
    vector<vector<int>> edges(N+1);
    rep(i,1,N) {
        edges[i].emplace_back(i+1);
        edges[i+1].emplace_back(i);
    }
    edges[X].emplace_back(Y);
    edges[Y].emplace_back(X);

    rep(i,1,N+1) {
        queue<int> que;
        que.push(i);
        while (!que.empty()) {
            for (const int next : edges[que.front()]) {
                if (distances[i][next] != 0) continue;
                distances[i][next] = distances[i][que.front()] + 1;
                que.push(next);
            }
            que.pop();
        }
    }
    vector<int> cnt(N);
    rep(i,1,N+1) {
        rep(j,i+1,N+1) {
            cnt[distances[i][j]]++;
        }
    }
    rep(k,1,N) {
        cout << cnt[k] << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 16128
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int a , b , res;
	scanf("%d %d",&a , &b);
	res = max(a + b , a - b);
	res = max(a * b , res);
	printf("%d\n",res);
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int count = 0;
    rep(i, 3) if(s[i] == t[i]) count++;
    cout << count;
}


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

int main(){
    double N,M;
    cin >> N >> M;
    double ans;
    // 1回で通る確率は1/2^M
    double p = 1.0/pow(2,M);
    // 1回の提出にかかる時間は1900*M+100*(N-M)
    double et = 1900*M+100*(N-M);
    // ans = et + (1-p)*ans を解く
    ans = et/p;
    cout << (ll)ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  
map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


void solve(void)
{
  int N;
  cin>>N;
  int X;
  cin>>X;
  map<int,int> mp = prime_factor(X);
  map<int,int> mpp;
  for (int i = 0; i < mp.size(); i++)
  {
    static auto itr = mp.begin();
    if(itr->second >= N)
    {
      mpp[itr->first] = itr->second/N;
    }
      itr++;
  }
  int ANS = 1;
  for (int i = 0; i < mpp.size(); i++)
  {
    static auto itr = mpp.begin();
    ANS *= pow(itr->first,itr->second);
    itr++;
  }
  cout<<ANS<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

i64 S;

i64 f(i64 k){
  int d = 0;
  {
    i64 temp = k;
    while(temp > 0){
      d++;
      temp /= 10;
    }
  }

  i64 ans = 0;
  {
    i64 nine = 9;
    for(int i = 1;i <= d - 1;i++){
      ans += nine * i;
      nine *= 10;
    }
  }


  {
    i64 ten = 1;
    for(int i = 1;i <= d - 1;i++){
      {
        i64 t = ten + (ten % 3 == 0 ? 0 : 3 - ten % 3);
        ans -= ((ten * 10 - 1 - t + 3) / 3) * i;
      }
      {
        i64 t = ten + (ten % 5 == 0 ? 0 : 5 - ten % 5);
        ans -= ((ten * 10 - 1 - t + 5) / 5) * i;
      }
      {
        i64 t = ten + (ten % 15 == 0 ? 0 : 15 - ten % 15);
        ans += ((ten * 10 - 1 - t + 15) / 15) * i;
      }
      ten *= 10;
    }

    ans += (k / 3) * 4;
    ans += (k / 5) * 4;
    ans += (k - ten + 1) * d;

    {
      i64 t = ten + (ten % 3 == 0 ? 0 : 3 - ten % 3);
      ans -= ((k - t + 3) / 3) * d;
    }
    {
      i64 t = ten + (ten % 5 == 0 ? 0 : 5 - ten % 5);
      ans -= ((k - t + 5) / 5) * d;
    }
    {
      i64 t = ten + (ten % 15 == 0 ? 0 : 15 - ten % 15);
      ans += ((k - t + 15) / 15) * d;
    }
  }

  return ans;
}

i64 solve(){

  i64 ok = 0;
  i64 ng = 1e18;

  while(ng - ok > 1){
    i64 mid = (ok + ng) / 2;
    if(f(mid) < S){
      ok = mid;
    }
    else{
      ng = mid;
    }

  }
  return ok;
}

int main(){

  string s = "";

  string st[] = {"","Fizz","Buzz","FizzBuzz"};

  cin >> S;

  i64 k = solve();

  i64 now = S - f(k);

  k++;

  while(s.size() <= 20 + now){
    int b = (k % 3 == 0) | ((k % 5 == 0) << 1);
    if(b == 0){
      s += to_string(k);
    }
    else{
      s += st[b];
    }
    k++;

  }

  cout << s.substr(now - 1,20) << endl;

}



Measured memory_bytes: 3260
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
const ll inf =1e17;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",&a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
//#define N 100010
const int S=20;
int gcd(int a,int b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}


int main(){
	int n,temp;
    string s1;
    cin>>s1;
    string s2="7";
    int pos=s1.find(s2);
    if(pos!=string::npos) printf("Yes\n");
    else printf("No\n");
    return 0;
}



Measured memory_bytes: 3608
using System;
using System.Collections.Generic;

delegate T Function<T>(T v1, T v2);

class SegTree<T>
{

    public int Count { get; }
    
    int n_layer;
    int[] segsize;
    T[][] data;

    Function<T> function;
    
    public SegTree(int N, Function<T> function, T fill=default(T))
    {
        Count=N;

        this.function=function;
        
        n_layer=1;
        for(int k=1; k<N; k<<=1) n_layer+=1;

        segsize = new int[n_layer];
        data = new T[n_layer][];
        for(int l=0; l<n_layer; ++l) {
            segsize[l] = 1<<(n_layer-1-l);
            data[l] = new T[1<<l];
            for(int j=0; j<(1<<l); ++j) data[l][j]=fill;
        }
    }
    
    public void Update(int index, T value) {
        data[n_layer-1][index] = value;
        
        for(int l=n_layer-2; l>=0; --l) {
            index = index/2;
            data[l][index] = function(data[l+1][index*2], data[l+1][index*2+1]);
        }
    }

    public T Query(int ibgn, int iend, int l=0) {
        int ssize = segsize[l];
        if(ibgn%ssize==0 && iend-ibgn==ssize) return data[l][ibgn/ssize];

        int imid = ibgn - ibgn%ssize + ssize/2;
        if(iend<=imid || imid<=ibgn) return Query(ibgn, iend, l+1);
        return function(Query(ibgn, imid, l+1), Query(imid, iend, l+1));
    }
    

    public void Print()
    {
        Console.WriteLine($"Count   : {Count}");
        Console.WriteLine($"n_layer : {n_layer}");
        for(int l=0; l<n_layer; ++l) {
            Console.WriteLine($"[{l}] "+string.Join(" ", data[l]));
        }
    }
}


class Program
{
    static void Main()
    {
        var str = Console.ReadLine().Split(" ");
        var N = int.Parse(str[0]);
        var Q = int.Parse(str[1]);

        var C = new int[N];
        str = Console.ReadLine().Split(" ");
        for(int i=0; i<N; ++i) C[i] = int.Parse(str[i]);
        
        var LR = new List<List<int>>();
        for(int q=0; q<Q; ++q) {
            str = Console.ReadLine().Split(" ");
            int l = int.Parse(str[0]);
            int r = int.Parse(str[1]);

            LR.Add(new List<int>{q, l, r});
        }

        LR.Sort((x, y) => x[2]-y[2]);

        var I = new int[N+1];
        for(int i=0; i<I.Length; ++i) I[i] = -1;
        
        var st = new SegTree<int>(N, (x, y) => x+y, 0);

        var ans = new int[Q];
        int j = 0;
        for(int iq=0; iq<Q; ++iq) {
            int q = LR[iq][0];
            int l = LR[iq][1];
            int r = LR[iq][2];

            for(; j<r; ++j) {
                int c = C[j];

                int iprev = I[c];
                I[c] = j;

                if(iprev!=-1) st.Update(iprev, 0);
                st.Update(j, 1);
            }
            ans[q] = st.Query(l-1,r);
        }

        Console.WriteLine(String.Join("\n", ans));
        
    }
}


Measured memory_bytes: 137212
def main():
    n, m = list(map(int, input().split()))
    lr = []
    for _ in range(m):
        l, r = list(map(int, input().split()))
        lr.append((l, r))

    lmax, rmin = lr[0]
    for l, r in lr:
        if l > lmax:
            lmax = l
        if r < rmin:
            rmin = r

    if lmax > rmin:
        print(0)
    else:
        print(rmin - lmax + 1)


main()

Measured memory_bytes: 16588
#include<cstdio>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll t[1000+5],a[1000+5];
ll n,p,q,m1,m2,k1,k2,e1,e2;
ll ans;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&t[i],&a[i]);//比例
	for(int i=1;i<=n;i++)
	{
		ll x=t[i],y=a[i];
		if(x<p||y<q)
		{
			k1=p-x;
			k2=q-y;
			e1=k1/x;
			e2=k2/y;
			
			if(e1*x!=k1)
				m1=e1+2;
			else
				m1=p/x;
				
			if(e2*y!=k2)
				m2=e2+2;
			else
				m2=q/y;
			if(x<p&&y>=q)
			{
				x*=m1;
				y*=m1;
			}
			else if(x>=p&&y<q)
			{
				x*=m2;
				y*=m2;
			}
			else
			{
				x*=max(m1,m2);
				y*=max(m1,m2);
			}
		}
		//printf("%d: k1:%lld k2:%lld e1:%lld e2:%lld m1:%lld m2:%lld x:%lld y:%lld\n",i,k1,k2,e1,e2,m1,m2,x,y);
		p=x;
		q=y;
		ans=x+y;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#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() {
    ll n;
    cin >> n;
    cout << n * (n-1) / 2 << endl;
}

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

  int n,k;
  int sum = 1;
  int flag = 0;

  cin >> n >> k;

  for ( int i = 0; i < n; i++ ) {
    if ( flag == 0 ) {
      if ( sum * 2 >= sum + k ) {
	flag = 1;
	sum += k;
      } else {
	sum *= 2;
      }
    } else if ( flag == 1 ) {
      sum += k;
    }
  }

  cout << sum << endl;

  return 0;

}


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

namespace AtCoder.Abc
{
    class B_171_MixJuice
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var NK = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long N = NK[0];
            long K = NK[1];

            // 整数配列の入力
            var p = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            Array.Sort(p);

            long result = 0;

            for (int i = 0; i < K; i++)
            {
                result += p[i];
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28516
#include<cstdio>
const int N=2003;
int n,m,i,j,x,p[N][N],h[N];
int q[N],s,e,L[N],R[N];
int ans;
char c[N][N];
int max(int x,int y){
	return x>y?x:y;
}
void init(){
	scanf("%d%d",&n,&m);
	ans=max(n,m);
	for(i=1;i<=n;i++){
		scanf("%s",c[i]+1);
		for(j=1;j<=m;j++)
			p[i][j]=c[i][j]=='.';
	}
	n--;m--;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			p[i][j]=(p[i][j]+p[i][j+1]+p[i+1][j]+p[i+1][j+1]+1)%2;
}
void work(){
	for(i=1;i<=m;i++)h[i]=1;
	for(x=1;x<=n;x++){
		for(i=1;i<=m;i++){
			if(p[x][i]==1)
				h[i]++;
			else
				h[i]=1;
		}
		q[s=e=0]=0;
		for(i=1;i<=m;i++){
			while(h[q[e]]>=h[i])
				e--;
			L[i]=q[e];
			q[++e]=i;
		}
		q[s=e=0]=m+1;
		for(i=m;i;i--){
			while(h[q[e]]>=h[i])
				e--;
			R[i]=q[e];
			q[++e]=i;
		}
		for(i=1;i<=m;i++)
			ans=max(ans,(R[i]-L[i])*h[i]);
	}
	printf("%d",ans);
}
int main(){
	init();
	work();
	return 0;
}

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

int main() {
    int n;
    int min, max_profit;
    max_profit = 0x80000001;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int temp = 0;
        cin >> temp;
        if (i == 0) {  // initialize
            min = temp;
            continue;
        }
        if (temp - min > max_profit) {
            max_profit = temp - min;
        }
        if (temp < min) {
            min = temp;
        }
    }
    cout << max_profit << endl;
    return 0;
}



Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 0;
		int A = sc.nextInt();
		int[] arrayInt = new int[A];

		for(int i = 0; i < A; i++) {
			int Num = sc.nextInt();
			arrayInt[i] = Num;
		}

		for(int j = A-1; 0 < j; j--) {
			System.out.print(arrayInt[j]+" ");
		}
		System.out.println(arrayInt[0]);
	}
}

Measured memory_bytes: 26344
# 幅優先探索による全探索
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def bfs(N):
    """
    param N:文字列の長さ

    """
    S = "abcdefghij"
    result = []
    queue = deque(["a"])
    
    while queue:
        s = queue.popleft()
        if len(s) == N:
            result.append(s + "\n")
            continue
        else:
            for i in S[:len(set(s))+1]:
                queue.append(s + i)
    
    return result


def main():
    N = int(readline())

    ans = bfs(N)
    print("".join(ans))


if __name__ == "__main__":
    main()


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

int main(){
  char a;
  cin >> a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3512
import java.util.*;
import java.io.*;

class Main {

  static int[][][] residence = new int[4][3][10];
  static int m = 0;

  public static void main(String[] args) {
    int[] v = new int[4];
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    init();
    sc.nextLine();
    for (int i = 0; i < n; i++) {
      // line???????????§split???????????¨?±??????¨????????°?????±?????´??°????????????
      String[] s = sc.nextLine().split(" ");
      for (int j = 0; j < 4; j++) {
        v[j] = Integer.parseInt(s[j]);
      }
      residence[v[0] - 1][v[1] - 1][v[2] - 1] = residence[v[0] - 1][v[1] - 1][v[2] - 1] + v[3];
    }
    output();
  }

  static void init() {
    for (int[][] building : residence) { for (int[] floor : building) {
       for (int room : floor) { room = 0; } } }
  }

  static void output() {
    for (int[][] building : residence) {
      m++;
      for (int[] floor : building) { for (int room : floor) { System.out.print(" " + room); }
        System.out.println(); }
      if (m != 4) System.out.println("####################");
    }
  }

}

Measured memory_bytes: 20776
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
const lli N = 2e5 + 10;
const lli offset = 6;
lli BIT[N + 10];
void update(lli idx, lli val) {
	while (idx < N) {
		BIT[idx] = max(BIT[idx], val);
		idx += (idx & (-idx));
	}
}
lli query(lli idx) {
	lli ret = 0;
	while (idx > 0) {
		ret = max(BIT[idx], ret);
		idx -= (idx & (-idx));
	}
	return ret;
}

void solve() {
	lli n;
	cin >> n;
	lli ret = 0;
	vi dp(n + 1);
	vi val(n);
	vi h(n);
	for (lli i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (lli i = 0; i < n; i++) {
		cin >> val[i];
	}

	for (lli i = 0; i < n; i++) {

		dp[h[i]] = val[i] + query(offset + h[i] - 1);
		ret = max(dp[h[i]], ret);
		update(offset + h[i], dp[h[i]]);

	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 2e5;

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

	int n,m;
	cin>>n>>m;
	vector<vector<int>> con(m);
	for(int i=0;i<m;i++)
	{
		int k;
		cin>>k;
		con[i].resize(k);
		for(auto& x:con[i])
		{
			cin>>x;
			x--;
		}
	}
	vector<int> fstate(m);
	for(auto& x:fstate)
		cin>>x;

	int ans = 0;
	for(int state=0;state<(1<<n);state++)
	{
		int num_on = 0;
		for(int bno = 0;bno<m;bno++)
		{
			int swi_on = 0;
			for(auto x:con[bno])
				if((state>>x)&1)
					swi_on++;
			num_on += (swi_on%2==fstate[bno]);
		}
		ans += (num_on==m);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a,a+3);
    
    int s1,s2,s3;
    
    s1=a[1]-a[0]+a[2]-a[0];
    s2=a[2]-a[1];
    
    if((a[1]-a[0])%2==1){
        s2+=2;
    }
    
    s2+=(a[1]-a[0])/2;
    
    
    s3=(a[2]-a[0])/2 + (a[2]-a[1])/2;
    if((a[2]-a[0])%2==1 && (a[2]-a[1])%2==1){
        s3++;
    }else if((a[2]-a[0])%2==1 || (a[2]-a[1])%2==1){
        s3+=2;
    }
    
    cout<<min(s1,min(s2,s3))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n)for(int i=0;i<n;i++)
#define REPR(i,n)for(int i=n;i>=0;i--)
#define FOR(i,m,n)for(int i=m;i<n;i++)
#define INF 999999999
#define llong long long

using namespace std;

int main(){
	string s;
	cin>>s;
	int max=0;
	int flag=0;

	REP(i,s.size()){
		FOR(j,i,s.size()){
		flag=0;
		FOR(k,i,j+1){
			if(s[k]!='A' && s[k]!='C' && s[k]!='G' && s[k]!='T'){
				flag=1;
			}
		}
		if(flag==0 && max<j-i+1){
			max=j-i+1;
			}
		}
	}

	cout<<max<<endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

// [min, _], [_, max]
ll calc1(V<ll> x, V<ll> y, const int &n) {
    ll xmn = inf, xmx = -inf, ymn = inf, ymx = -inf;
    rep(i, n) {
        if(x[i] > y[i]) swap(x[i], y[i]);
        chmin(xmn, x[i]);
        chmax(xmx, x[i]);
        chmin(ymn, y[i]);
        chmax(ymx, y[i]);
    }
    return (xmx - xmn) * (ymx - ymn);
}

// [min, max], [_, _]
ll calc2(V<ll> x, V<ll> y, const int &n) {
    V<int> p(n);
    multiset<ll> st;
    ll mn = inf, mx = -inf;
    rep(i, n) {
        p[i] = i;
        if(x[i] > y[i]) swap(x[i], y[i]);
        chmin(mn, x[i]);
        chmax(mx, y[i]);
        st.insert(x[i]);
    }
    sort(ALL(p), [&](int a, int b) { return x[a] < x[b]; });
    ll res = (mx - mn) * (*st.rbegin() - *st.begin());
    for(int i : p) {
        st.erase(st.find(x[i]));
        st.insert(y[i]);
        chmin(res, (mx - mn) * (*st.rbegin() - *st.begin()));
    }
    return res;
}

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

    int n;
    cin >> n;
    V<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    cout << min(calc1(x, y, n), calc2(x, y, n)) << endl;

    return 0;
}

Measured memory_bytes: 18688
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k0 = 0;
		int k1 = 0;
		while(sc.hasNext()) {
			String s = sc.next();
			String[] n = s.split(",");
			int a = Integer.parseInt(n[0]);
			int b = Integer.parseInt(n[1]);
			int c = Integer.parseInt(n[2]);
			if(a * a + b * b == c * c && a == b) continue;
			if(a * a + b * b == c * c && a != b) {
				k0++;
			}else if(a == b){
				k1++;
			}
		}
		sc.close();
		System.out.println(k0);
		System.out.println(k1);
	}
}


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


template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};










int N;

struct conn {
	int next_node;
	int count;
};

vector<conn> conns;
vector<int> edgerefs[200000];


// 部分木のノード数を計算
int dfs( int node, int parent_node ){
	int count = 0;
	for ( auto it : edgerefs[node] ){ // node -> next_node を調べる
		conn &c  = conns[it  ];
		conn &cr = conns[it^1];
		if ( c.next_node != parent_node ){
			if ( c.count == -1 )
				c.count = dfs( c.next_node, node );
			if ( cr.count == -1 )
				cr.count = N - c.count;
			count += c.count;
		}
	}
	return count+1;
}


int main(){
	cin >> N;
	
	conns.resize( (N-1)*2 );
	for ( int i = 0; i < N-1; i++ ){
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		int iab = i*2+0;
		int iba = i*2+1;
		
		conns[iab] = {b,-1};
		conns[iba] = {a,-1};
		edgerefs[a].push_back(iab);
		edgerefs[b].push_back(iba);
	}
	
	dfs(0, -1);
	
//	for ( int i = 0; i < N; i++ ){
//		for ( auto it : edgerefs[i] ){
//			conn& c = conns[it];
//			conn& cr = conns[it^1];
//			cout << it << " : " << i << "->" << c.next_node << " count=" << c.count << endl;
//		}
//	}
	
	using mint = modint<1000000007>;
	vector<mint> pow2(N+1);
	{
		mint a = 1;
		for ( int i = 0; i <= N; i++ ){
			pow2[i] = a;
			a *= 2;
		}
	}
	
	mint result = 0; // 期待値 * 2^N

	for ( int i = 0; i < N; i++ ){
		//  穴あきの頂点である == そこから出る2つの辺の先に黒が1つ以上ある
		// i->j0, i->j1, i->j2
		// j0以降が全て白の確率 : pj0
		// iが穴でない確率 = p(iが黒) + p(iが白)*( tmp ) // tmp = pj0*pj1*pj2 + !pj0*pj1*pj2 + pj0*!pj1*pj2 + pj0*pj1*!pj2
		// iが穴である確率 = p(iが白)*!( tmp )
		
		if ( edgerefs[i].size() >= 2 ){
			mint t = 1; // t = tmp * 2^(N-1)
			for ( auto it : edgerefs[i] ){
				conn &c  = conns[it  ];
				t += pow2[c.count]-1;
			}
			result += (pow2[N-1] - t);
		}
	}

	
	result /= pow2[N];
	cout << result.value() << endl;
	
	return 0;
}



Measured memory_bytes: 27008
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
    int N;
    cin >> N;
    cout << 180 * (N - 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    ll ans = 0;
    rep(i,N){
        cin>>A>>B;
        ans += B - A + 1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	int n;
	ll k;
	cin >> n >> k;

	vector<int> mapping(n + 1);
	for (int i = 1; i <= n; i++)
	{
		cin >> mapping[i];
	}

	vector<ll> visit_log(n + 1, -1);
	int res = 1;
	for (ll j = 0; j < k; j++)
	{
		visit_log[res] = j;

		int next_res = mapping[res];
		if (visit_log[next_res] != -1)
		{
			ll cycle = j - visit_log[next_res] + 1;
			ll remaining = k - j;
			ll remaining_after_cut = remaining % cycle;
			k = j + remaining_after_cut;
		}
		if (j < k)
			res = next_res;
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

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

int main(){
    int N;  ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<int> cnt(61,0);
    for(int i=0; i<N; i++){
        int j=0;
        ll a = A[i];
        while(a>0){
            if(a%2==1) cnt[j]++;
            a/=2;
            j++;
        }
    }
    
    ll X = 0;
    for(ll i=60; i>=0; i--){
        if((N%2==0 && cnt[i]<N/2) || (N%2==1 && cnt[i]<=N/2)){
            ll p = 1;
            ll ind = i;
            while(ind>0){
                p*=2;
                ind--;
            }
            if(X + p <= K){
                X += p;
            }
        }
    }
    ll ans = 0;
    for(int i=0; i<N; i++){
        ans += X^A[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;

namespace abc130_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var input2 = Console.ReadLine();

            var items1 = input1.Split(' ');
            var items2 = input2.Split(' ');

            var n = 0;
            if (items1.Length > 0)
            {
                if (!int.TryParse(items1[0], out n))
                {
                    n = 0;
                }
            }
            var x = 0;
            if (items1.Length > 1)
            {
                if (!int.TryParse(items1[1], out x))
                {
                    x = 0;
                }
            }
            var l = new int[n];
            for (int i = 0; i < items2.Length; i++)
            {
                if (!int.TryParse(items2[i], out l[i]))
                {
                    l[i] = 0;
                }
            }

            var d = 0;
            var answer = 1;
            for (int i = 0; i < l.Length; i++)
            {
                d += l[i];
                if (d > x)
                {
                    break;
                }
                answer++;
            }

            Console.WriteLine($"{answer}");
        }
    }
}


Measured memory_bytes: 13140