akhauriyash/Code-Regression huggingface dataset:
<?php
# 入力部
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%d %d", $n, $r);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $n);
// fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%s", $s2);
fscanf(STDIN, "%d %d %d", $a, $b, $c);


# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
// for ($i = $a; $i <= $b; $i++) {
//   if ($i % $k == 0) {
//     $r = "OK";
//   }
// }
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }
// $r = "Yes";
// if ($s == "AAA" || $s == "BBB") {
//   $r = "No";
// }
// if ($n % 2 == 0) {
//   $r = $n / 2;
// } else {
//   $r = ($n + 1) / 2;
// }
// if ($n < 10) {
//   $r += (10 - $n) * 100;
// }
$arr = array($a, $b, $c);
$arr = array_unique($arr);
if (count($arr) == 2) {
  $r = "Yes";
} else {
  $r = "No";
}
# 出力部
// echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";
// echo json_encode($arr) . "\n";
echo $r . "\n";


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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<long long,int> > team;
		int num,m1,m2,m3,m4,s1,s2,s3,s4;
		
		rep(i,n)
		{
			cin >> num >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;

			long long time = m1*60 + s1 + m2*60 + s2 + m3*60 + s3 + m4*60 + s4;
			team.push_back(make_pair(time,num));
		}

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

		cout << team[0].second << endl << team[1].second << endl << team[n-2].second << endl;
	}
	return 0;
}

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

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

	vector<vector<char>> a(h, vector<char>(w));
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a.at(i).at(j);
		}
	}

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (a.at(i).at(j) == '#')
			{
				row.at(i) = true;
				col.at(j) = true;
			}
		}
	}

	for (int i = 0; i < h; i++)
	{
		if (row.at(i))
		{
			for (int j = 0; j < w; j++)
			{
				if (col.at(j))
				{
					cout << a.at(i).at(j);
				}
			}
			cout << endl;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int K;
string S;
int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
vector<int>perm,inv;
void init_perm(){
	int x=2e6+1;perm.resize(x);inv.resize(x);
	perm[0]=1;
	REP(i,x+1)perm[i]=perm[i-1]*i%mod;
	inv[x]=mod_pow(perm[x],mod-2);
	for(int i=x-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}
signed main(){
	init_perm();
	cin>>K>>S;
	int N=K+len(S),M=len(S);
	int ans=0;
	for(int i=M;i<=N;i++){
		int p=nCk(N,i);
		int q=mod_pow(25,N-i);
		ans+=p*q%mod;ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 36564
A,B = map(int,input().split(" "))
ans = 0
if A >=3 and B >= 3:
    ans = A*B-(A*2 + B*2)+4
    print(ans)

if A == 1 and B!=1:
    print(B-2)
elif B == 1 and A != 1:
    print(A-2)
elif A == 1 and B ==1:
    print(1)
elif A == 2 and B >=2:
    print(0)
elif B == 2 and A >=2:
    print(0)

Measured memory_bytes: 3064
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
uvw = [LIST() for _ in range(N-1)]

graph = [[] for _ in range(N)]

for u, v, w in uvw:
	graph[u-1].append((v-1, w))
	graph[v-1].append((u-1, w))

#print(graph)

color = [-1]*N
color[0] = 0

def DFS(node):
	for i, w in graph[node]:
		if color[i] == -1:
			if w%2:
				color[i] = color[node]^1
			else:
				color[i] = color[node]
			DFS(i)

DFS(0)

#print(color)

for x in color:
	print(x)



Measured memory_bytes: 99940
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+7;
int main(void){
    int r;
    cin >> r;
    cout << r*6.28318530717958623200 << endl;
    return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int a,b,d,r;
    double f;
    cin >> a >> b;
    d = a/b;
    r = a%b;
    f = (double)a / b;
    cout << fixed;
    cout << setprecision(5) << d << " " << r << " " << f << "\n";
}


Measured memory_bytes: 3272
#include <stdio.h>

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main()
{
	int64_t N;
	std::cin >> N;
	
	std::cout << (((N % 1000) == 0) ? 0 : (1000 - (N % 1000))) << std::endl;

	return 0;
}


Measured memory_bytes: 3636
n=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(n):
    s=input()
    if s=='AC': ac+=1
    if s=='WA': wa+=1
    if s=='TLE': tle+=1
    if s=='RE': re+=1

print('AC x {0}'.format(ac))
print('WA x {0}'.format(wa))
print('TLE x {0}'.format(tle))
print('RE x {0}'.format(re))



Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int n; cin >> n;
    vector<long long> nums(n+1, 2);
    nums[0] = 0;
    nums[1] = 1;
    for (int i = 2; i<=n; ++i) {
        for (int j = i*2; j<=n; j += i) {
            nums[j]++;
        }
    }
    long long sum = 0;
    for (int i=1; i<=n; ++i) {
        sum += i * nums[i];
    }
    cout << sum << endl;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    
    rep(i,n){
        cin>>a[i];
    }
    SORT(a);
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(m):
    AA,BB=[int(i) for i in input().split()]
    a.append(AA)
    b.append(BB)
for i in range(n):
    cnt=0
    cnt=a.count(i+1)+b.count(i+1)
    print(cnt)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,k;cin >> n>>k;
    vector<vector<lint>> v(n,vector<lint>(2));
    REP(i, n) { cin >> v[i][0]>>v[i][1]; }
    sort(ALL(v));
    lint asum = 0;

    lint ans = 0;
    REP(i,n){
        asum += v[i][1];
        if(asum>=k){
            ans = v[i][0];
            break;
        }

    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
bool get(ll x)
{
	printf("? %lld\n", x);
	fflush(stdout);
	char z;
	scanf(" %c", &z);
	return z == 'Y';
}
void answer(ll x)
{
	printf("! %lld\n", x);
	fflush(stdout);
	exit(0);
}
int main()
{
	ll now = 1;
	for (int i = 0; i < 11; i++)
	{
		if (!get(now))break;
		now *= 10;
	}
	if (now == 100000000000LL)
	{
		ll t = 1;
		for (int i = 0; i < 11;i++)
		{
			if (get(t * 10 - 1))answer(t);
			t *= 10;
		}
	}
	else
	{
		ll beg = now / 10 + 1, end = now - 1;
		for (;;)
		{
			if (beg == end)break;
			ll med = (beg + end) / 2;
			if (get(med * 10))end = med;
			else beg = med + 1;
		}
		answer(beg);
	}
}

Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=2510;
const long long INF=1LL<<60;
int N,M,P,lin[maxn],len,rlin[maxn],rlen;
struct edge{
	int y,next,v;
}e[maxn*2],r[maxn*2];
inline void insert(int xx,int yy,int vv){
	e[++len].next=lin[xx];
	lin[xx]=len;
	e[len].y=yy;
	e[len].v=vv;
}
inline void rev_insert(int xx,int yy,int vv){
	r[++rlen].next=rlin[xx];
	rlin[xx]=rlen;
	r[rlen].y=yy;
	r[rlen].v=vv;
}
int q[10000000],head,tail,in[maxn];
bool vis[maxn];
long long dis[maxn];
long long spfa(){
	for(int i=1;i<=N;i++)
		dis[i]=-INF-1;
	head=tail=1;
	q[head]=1;
	vis[1]=1,in[1]=1,dis[1]=0;
	for(;head<=tail;head++){
		vis[q[head]]=0;
		for(int i=lin[q[head]];i;i=e[i].next)
			if(dis[e[i].y]<dis[q[head]]+e[i].v){
				dis[e[i].y]=dis[q[head]]+e[i].v;
				if(!vis[e[i].y]){
					vis[e[i].y]=1;
					in[e[i].y]++;
					if(in[e[i].y]<N)
						q[++tail]=e[i].y;
				}
			}
	}
	return dis[N];
}
int reach[maxn];
void rev_dfs(int x){
	reach[x]=1;
	for(int i=rlin[x];i;i=r[i].next)
		if(!reach[r[i].y])
			rev_dfs(r[i].y);
}
int main(){
	//freopen("in","r",stdin);
	N=read(),M=read(),P=read();
	while(M--){
		int t1=read(),t2=read(),t=read()-P;
		insert(t1,t2,t);
		rev_insert(t2,t1,t);
	}
	rev_dfs(N);
	long long ans=spfa();
	for(int i=1;i<=N;i++)
		if(in[i]>=N&&reach[i]==1)
			return printf("-1\n"),0;
	if(ans<0)
		ans=0;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 24960
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX*2]={};
  
  map<ll, ll> f;
  map<ll, ll> cnt;
  for(i=1; i<=N; i++) {
    cin >> a[i];
    f[a[i]]=1;
    cnt[a[i]]++;
  }
  sort(a, a+N+1);
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    if(a[i-1]==a[i]) continue;
    if(f[a[i]]==0) continue;
    for(j=a[i]*2; j<MAX*10; j+=a[i]) f[j]=0;
  }
  
  
  for(i=1; i<=N; i++) if(cnt[a[i]]==1 && f[a[i]]) ans++;
  pt(ans);
  
  
}


Measured memory_bytes: 80772
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int a,b,k;
    cin >> a >>b >> k;
    vector <int>ans;
    for(int i=0;i<k;i++){
        if(a+i <= b){
            ans.push_back(a+i);
        }
        if(b-i >= a){
            ans.push_back(b-i);
        }
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    for(int i = 0;i<min(2*k,b-a+1);i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a, b, c, d;

    scanf("%d %d %d", &a, &b, &c);

    if(a > b){
        d = a;
        a = b;
        b = d;
    }
    if(b > c){
        d = b;
        b = c;
        c = d;
    }
    if(a > b){
        d = a;
        a = b;
        b = d;
    }
    
    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef double ld;
typedef long long ll;
#define int ll
const ll mod=1e9+7;

int32_t main()
{
    SPEED;
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i];
    }
    int dp[k+1];
    memset(dp,0,sizeof(dp));
    for (int i = 0; i <= k; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if(i-a[j]>=0 && !dp[i-a[j]])
            {
                dp[i]=1;
            }
        }
    }
    if(dp[k]==1)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

ll modpow(ll a, ll t){
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret = (ret * a) % MOD;
        }
        a = (a * a) % MOD;
        t >>= 1;
    }
    return ret;
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();

    int cnt[4][100000] = {0};
    if(isupper(s[0])){
        cnt[s[0]-'A'][0] = 1;
    }else{
        cnt[3][0] = 1;
    }
    for(int i=1;i<n;i++){
        repp(j, 4) cnt[j][i] = cnt[j][i-1];
        if(isupper(s[i])){
            cnt[s[i]-'A'][i] += 1;
        }else{
            cnt[3][i] += 1;
        }
    }

    ll ans = 0LL;
    for(int i=1;i<n-1;i++){
        if(s[i] == 'A' || s[i] == 'C') continue;
        ll a = cnt[0][i-1], c = cnt[2][n-1] - cnt[2][i];
        ll qa = cnt[3][i-1], qc = cnt[3][n-1] - cnt[3][i];
        ll mp[3];
        mp[2] = ((qa+qc > 2LL)?modpow(3LL, qa+qc-2LL):1LL);
        mp[1] = ((qa+qc > 1LL)?(mp[2] * 3LL) % MOD:1LL);
        mp[0] = ((qa+qc > 0LL)?(mp[1] * 3LL) % MOD:1LL);
        (ans += ((a * c) % MOD) * mp[0])%= MOD;
        (ans += (a * qc * mp[1]) % MOD)  %= MOD;
        (ans += (qa * c * mp[1]) % MOD)  %= MOD;
        (ans += (qa * qc * mp[2]) % MOD)  %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,x,y,dif;
    long long int arr[1000000];
    long long int sum[1000000];
    long long int res[1000000];
    cin>>n;
    for(a=0;a<n;a++)
        cin>>arr[a];
    for(a=0;a<n;a++)
    {
        if(a!=0)
            sum[a]=sum[a-1]+arr[a];
        else
            sum[a]=arr[a];
    }
    for(a=0;a<n-1;a++)
    {
        x=sum[a];
        y=sum[n-1]-x;
        dif=x-y;
        if(dif<0)
            dif=dif*(-1);
        res[a]=dif;
    }
    long long int minn=res[0];
    for(a=1;a<n-1;a++)
    {
        if(minn>res[a])
            minn=res[a];
    }
    cout<<minn;

}

Measured memory_bytes: 11136
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(){

    val t = readLn()
    println(t.replace("?", "D"))
}

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

int  main()
{
	int n; cin >> n;
	if (n % 1000 == 0)
		cout << 0 << endl;
	else
		cout << 1000 - (n % 1000) << endl;
	return (0);
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
using namespace std;

long long int n, m, k;
long long int a[20010];
long long int c[20010];

int main(){
	scanf("%lld %lld %lld", &n, &m, &k);
	for(int i=1; i<=n; ++i) scanf("%lld", &a[i]);
	c[1] = k;
	for(int i=2; i<=n; ++i){
		long long int t = 1e18;
		long long int ma = 0;
		long long int mi = 1e18;
		for(int j=1; j<=m; ++j){
			if(i - j < 0) break;
			ma = max(ma, a[i-j+1]);
			mi = min(mi, a[i-j+1]);
			t = min(t, c[i-j] + j * (ma - mi) + k);
		}
		c[i] = t;
	}
	printf("%lld\n", c[n]);
/*	for(int i=1; i<=n; ++i) printf("%lld\t", c[i]);
	printf("\n");
*/
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    set<ll> st;
    map<ll, ll> mp;
    for(ll i = 0; i < n; i++){
        ll a,b;
        cin >> a >> b;
        mp[a] += b;
        st.insert(a);
    }
    ll cnt = 0;
    for(auto v: st){
        cnt += mp[v];
        if(cnt >= k){
            cout << v << endl;
            return 0;
        } 
    }
}

Measured memory_bytes: 7168
n, q = list(map(int, input().split()))
s = input()

w = [0]
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        w.append(w[i - 1] + 1)
    else:
        w.append(w[i - 1])

for i in range(q):
    l = list(map(int, input().split()))

    print(w[l[1] - 1] - w[l[0] - 1])

Measured memory_bytes: 6192
//
//  main.cpp
//  vjudge
//
//  Created by Sudipto Mondal on 7/9/20.
//  Copyright © 2020 Sudipto Mondal. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long int a,b,c;
    cin>>a>>b>>c;
    
    if((a+b+c)>=22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import fractions

n = int(input())
a = list(map(int, input().split()))

left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i+1] = fractions.gcd(left[i], a[i])
    right[n-i-1] = fractions.gcd(right[n-i], a[n-1-i]) 

ans = 0
for i in range(n):
    ans = max(ans, fractions.gcd(left[i], right[i+1]))
print(ans)

Measured memory_bytes: 16144
import java.util.*;

public class Main{
  
  	public static void main(String[] args){
      
      	Scanner sc = new Scanner(System.in);
      
      	int D = sc.nextInt();
      
      	if(D == 25)
          System.out.println("Christmas");
      	else if(D == 24)
          System.out.println("Christmas Eve");
      	else if(D == 23)
          System.out.println("Christmas Eve Eve");
      	else if(D == 22)
          System.out.println("Christmas Eve Eve Eve");
    }
}
      

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

const int maxn=2e5+10;
int n,fa[20][maxn],st[20][maxn],ans[maxn],log_2[maxn];
bool vis[maxn];
vector<int> g[maxn],stk;

void dfs1(int pos){
	st[0][pos]=pos;
	for(int i=1;i<20;++i){
		fa[i][pos]=fa[i-1][fa[i-1][pos]];
		st[i][pos]=max(st[i-1][pos],st[i-1][fa[i-1][pos]]);
	}
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos]){
			fa[0][g[pos][i]]=pos;
			dfs1(g[pos][i]);
		}
}
void dfs2(int pos){
	ans[pos]+=ans[fa[0][pos]];
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos])
			dfs2(g[pos][i]);
}
inline int rmq(int x,int y){
	if(x>y)
		return 0;
	int k=log_2[y-x+1];
	return max(st[k][stk[y]],st[k][stk[x-1+(1<<k)]]);
}
void dfs(int pos){
	stk.push_back(pos);
	if(pos!=1){
		int l=0,r=stk.size()-1;
		while(l<r){
			int mid=l+r>>1;
			if(rmq(0,mid-1)>rmq(mid+1,stk.size()-1))
				r=mid;
			else
				l=mid+1;
		}
		++ans[stk[l]];
	}
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos])
			dfs(g[pos][i]);
	stk.pop_back();
}

int main(){
	cin>>n;
	for(int i=1,u,v;i<n;++i){
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n;++i)
		log_2[i]=log(i)/log(2);
	dfs1(1);
	dfs(1);
	dfs2(1);
	for(int i=2;i<=n;++i)
		cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 59000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int k,x;
	cin>>k>>x;

	for(int i=x-k+1; i<x+k-1; i++){
		cout<<i<<" ";
	}
	cout<<x+k-1<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n==m) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;

bool is_odd_digit(int n) {
    int cnt = 0;
    while (n > 0) {
        n /= 10;
        cnt++;
    }
    return cnt % 2 == 1;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) if (is_odd_digit(i)) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3588
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	if (N / 10 == 9 || N % 10 == 9) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[10];
	for(int i=0;i<10;i++) a[i]=1;
	while(k--)
	{
	    int x;
	    cin>>x;
	    a[x]=0;
	}
	//cout<<n<<endl;
	for(int i=n;;)
	{
	    bool b=true;
	    int cp=i;
	    //cout<<i<<endl;
	    while(i)
	    {
	        int d=i%10;
	        if(!a[d])
	        {
	            b=false;
	            break;
	        }
	        i/=10;
	    }
	    if(b)
	    {
	        cout<<cp;
	        break;
	    }
	    i=cp+1;
	}
	
	return 0;
}

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

int main(){
  int K,S;
  cin>>K>>S;
  int count=0;
  
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
         if(0<=S-i-j and S-i-j<=K){
           count++;
         }
       
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
     int n, num, digit, rev = 0;
     cin >> num;
     n = num;
     do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if (n == rev)
         cout << " Yes";
     else
         cout << "No";
    return 0;
}

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

int main(){
  int N,Ncap,forTwait;
  cin >> N >> Ncap >> forTwait;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());

  int ans= 0;
  int Nwait= 0;
  int atTtop= 0;
  for(auto atTarrive:data){
    if(Nwait==0){ atTtop= atTarrive; }

    if(atTtop+ forTwait < atTarrive){
      ans++;
      Nwait= 1;
      atTtop= atTarrive;
    }
    else{
      Nwait++;
      if(Nwait==Ncap){
        ans++;
        Nwait= 0;
      }
    }
  }
  if(Nwait > 0){ ans++; }

  cout << ans << endl;
}

Measured memory_bytes: 640
long A,x[50],i,j,d[51][5001];main(n){for(scanf("%d%d",&n,&A);~scanf("%d",x+i);x[i++]-=A);d[0][A*=n]=1;for(i=-1;++i<n;)for(j=-1;j++<2*A;d[i+1][j]+=d[i][j])d[i+1][j]=j-x[i]<0||j-x[i]>2*A?0:d[i][j-x[i]];printf("%ld\n",d[n][A]-1);}

Measured memory_bytes: 2176
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)
/*
0120120
*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll K,T;
	string s;
	while(cin>>K>>T) {
		VI A(T);
		REP(i, T) cin>>A[i];
		sort(ALLR(A));
		ll ans = max(0LL, A[0]-1-(K-A[0]));
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char a[3]; scanf("%s",a);
  if (a[0]==a[1] && a[1]==a[2]) printf("No\n");
  else {
    for(int i=0; i<3; i++){
      if (a[i]=='A' || a[i]=='B'){
        if (i==2) printf("Yes\n");
        continue;
      }
      else printf("No\n");
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int ans = 0;
    for(int i = 1; i < N + 1; i += 2)
    {
        int cnt = 0;
        for(int j = 1; j < i + 1; j++)
        {
            if(i % j == 0)
            {
                cnt++;
            }
        }
        if(cnt == 8)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int top, S[1000];
 
 
void push(int x){
    top++;
    S[top] = x;
}
 
int pop(){
    top--;
    return S[top+1];
}
 
 
int main(void) {
    int a,b;
    top=0;
    char s[100];
    while( scanf("%s",s) != EOF){
        if( s[0]=='+'){
            a = pop();
            b = pop();
            push(a+b);
        } else if( s[0] == '-'){
            b=pop();
            a=pop();
            push(a-b);
        } else if( s[0] == '*'){
            a = pop();
            b= pop();
            push(a *b);
        } else{
            push(atoi(s));
        }
    }
     
    printf("%d\n",pop());
     
    return 0;
}

Measured memory_bytes: 548
n, C = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(C)]
c = [list(map(int, input().split())) for _ in range(n)]
a = [[0]*C for _ in range(3)]
for i in range(n):
    for j in range(n):
        a[(i+j)%3][c[i][j]-1] += 1
b = [[0]*C for _ in range(3)]
for i in range(3):
    for j in range(C):
        v = 0
        for k in range(C):
            v += a[i][k]*d[k][j]
        b[i][j] = v
r = 10**9
for i in range(C):
    for j in range(C):
        for k in range(C):
            if len({i,j,k}) == 3:
                r = min(r, b[0][i]+b[1][j]+b[2][k])
print(r)

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

char a[101][101];
int main(){
	int h,w;
	
	cin >> h >> w;
	for(int i = 0;i<h;i++){
		for(int j = 0;j < w;j++){
			cin >> a[i][j];
		}
	}
	
	for(int i = 0;i<h;i++){
		int n = 2;
		while(n--){
			for(int j = 0;j < w;j++){
				cout << a[i][j];
			}
			cout << endl;
		}
	}
}

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

using namespace std;
#define ll long long

const int N = 1000005;
int n, a[N], f[N<<2], g[N<<2], h[N<<2];
char s[N];
set<int> c, d;
void build(int l, int r, int t){
	if(l==r) return (void)(f[t]=g[t]=a[l]);
	int mid=(l+r)>>1, k=t<<1;
	build(l, mid, k), build(mid+1, r, k|1);
	f[t]=max(f[k], f[k|1]), g[t]=min(g[k], g[k|1]), h[t]=0;
}
int find(int l, int r, int t, int x){
	if(l==r) return l;
	int mid=(l+r)>>1, k=t<<1;
	if(h[t]) f[k]+=h[t], g[k]+=h[t], f[k|1]+=h[t], g[k|1]+=h[t], h[t]=0;
	if(f[k]>x) return find(l, mid, k, x);
	else return find(mid+1, r, k|1, x);
}
void change(int l, int r, int t, int L){
	if(L<=l) return (void)(f[t]-=2, g[t]-=2, h[t]-=2);
	int mid=(l+r)>>1, k=t<<1;
	if(h[t]) f[k]+=h[t], g[k]+=h[t], f[k|1]+=h[t], g[k|1]+=h[t], h[t]=0;
	if(L<=mid) change(l, mid, k, L);
	change(mid+1, r, k|1, L);
	f[t]=max(f[k], f[k|1]), g[t]=min(g[k], g[k|1]);
}
int main() {
	scanf("%s", s+1), n=strlen(s+1);
	for(int i=1; i<=n; ++i){
		a[i]=a[i-1]+(s[i]=='0'?-1:1);
		if(s[i]=='?') c.insert(i);
	}
	d=c;
	int ans=n;
	build(0, n, 1);
	for(int i=n;; i-=2){
		if(f[1]>i){
			int x=find(0, n, 1, i);
			auto it=c.upper_bound(x);
			if(it==c.begin()) break;
			change(0, n, 1, *--it);
			c.erase(it);
		}
		ans=min(ans, f[1]-g[1]);
	}
	build(0, n, 1);
	for(int i=n+1;; i-=2){
		if(f[1]>i){
			int x=find(0, n, 1, i);
			auto it=d.upper_bound(x);
			if(it==d.begin()) break;
			change(0, n, 1, *--it);
			d.erase(it);
		}
		ans=min(ans, f[1]-g[1]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 126904
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    A,B = inputMap()
    
    tmp = A+B
    print(tmp % 24)
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38768
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;i <= 0; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x); i++)
#define rreps(i,x) for(ll i = (ll)(x)-1; i <= 1; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));

    auto check2 = [&](ll x, ll idx){
        if(a[idx] == 0 && x > 0)return n-1;
        else if(a[idx] > 0){
            ll r = n, l = 0;
            if(a[l] * a[idx] >= x)return 0LL;
            while (r - l > 1){
                ll i = (r + l) / 2;
                if(a[i] * a[idx] < x)l = i;
                else r = i;
            }
            return r - (a[idx] * a[idx] < x ? 1 : 0);
        }
        else {
            ll l = -1, r = n-1;
            if(a[r] * a[idx] >= x)return 0LL;
            while(r - l > 1) {
                ll i = (l + r) / 2;
                if(a[i] * a[idx] < x)r = i;
                else l = i;
            }
            return n - r - (a[idx] * a[idx] < x ? 1 : 0);
        }
    };
    auto check = [&](ll x){
        ll cnt = 0;
        rep(i,n){
            cnt += check2(x, i);
        }
        // debug(x);
        // debug(cnt);
        cnt /= 2;
        if(cnt >= k)return true;
        else return false;
    };

    ll ok = INF, ng = -INF;
    while(abs(ok - ng) > 1){
        ll x = (ok + ng) / 2;
        if(check(x))ok = x;
        else ng = x;
    }
    cout << ng << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long q = sc.nextLong();
        long h = sc.nextLong();
        long s = sc.nextLong();
        long d = sc.nextLong();
        long n = sc.nextLong();
        long[] sl = {q*4,h*2,s};
        long[] dl = {q*8,h*4,s*2,d};
        Arrays.sort(sl);
        Arrays.sort(dl);
        System.out.println(n/2*dl[0] + n%2*sl[0]);
    }
}


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

H = list(map(int, input().split()))

S = [list(map(int, input().split())) for i in range(M)]

d=set(list(range(N)))

v=[]

for i in range(M):
    if H[S[i][0]-1]<H[S[i][1]-1]:
        v.append(S[i][0]-1)
    elif H[S[i][0]-1]>H[S[i][1]-1]:
        v.append(S[i][1]-1)
    elif H[S[i][0]-1]==H[S[i][1]-1]:
        v.append(S[i][0]-1)
        v.append(S[i][1] - 1)

u=set(v)

d=d-u

print(len(d))























Measured memory_bytes: 47264
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b > c+d){
    cout << "Left" << endl;
  }
  else if(a+b == c+d){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

using namespace std;
using Graph = vector<vector<int>>;

int main(void){
    int N,M;
    cin>>N>>M;

    Graph G(N);

    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(N,-1);
    queue<int> q;
    vector<int> pre(N,-1);

    dist[0] = 0;
    q.push(0);

    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int nv:G[v]){
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            q.push(nv);
            pre[nv] = v;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<N;i++){
        cout<<++pre[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10688
n = int( input() )
p = list( map( int, input().split()))
q = list( map( int, input().split()))

def factorial(n):
	if n == 1:
		return 1
	else:
		return n * factorial( n - 1 )

def calc_index( list_of_number: list ):
	lists = list(range(1, n+1))
	ans = 1
	for i in range( 1, n ):
		index = lists.index( list_of_number[ i - 1 ] )
		ans += factorial( n - i ) * ( index )
		lists.remove( list_of_number[ i - 1 ] )
	return ans
ans_p = calc_index( p )
ans_q = calc_index( q )

print( abs( ans_p - ans_q ))


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

namespace Aizu {
    public class OnlineJudge {
        static void Main() {
            while (Console.ReadLine() != "0") {
                var step = Console.ReadLine().Split();
                var count = 0;
                for (var i = 1; i < step.Length; ++i) {
                    if (step[i - 1][1] == step[i][1]) {
                        ++count; ++i;
                    }
                }

                Console.WriteLine(count);
            }
        }
    }
}



Measured memory_bytes: 9284
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;


template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    long long N, X, Y;
    cin >> N >> X >> Y;
    vector<long long> sum(N, 0);

    for(int k = 1; k <= N; ++k){
        for(int i = 1; i <= N - k; ++i){
            if(i >= Y){
                ++sum[k];
            }
            else if(i + k <= X){
                ++sum[k];
            }
            else{
                long long n = min<long long>(k, abs(X - i) + 1 + abs(Y - (i + k)));
                ++sum[n];
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b,c,k;

int main(void){
	scanf("%d%d%d",&a,&b,&c);
	scanf("%d",&k);
	int cnt=0;
	while(b<=a){
		cnt++;
		b*=2;
	}
	while(c<=b){
		cnt++;
		c*=2;
	}
	printf("%s\n",cnt<=k?"Yes":"No");
	return 0;
}


Measured memory_bytes: 3760
N = gets.to_i
MOD = 10 ** 9 + 7
S = gets.chomp 


ans = 1
if S[0] == 'W' || S[2 * N - 1] == 'W'
	puts '0'
	exit
end
1.upto(N) do |i|
	ans *= i
	ans %= MOD
end

check = true
cnt = 1
1.upto(2 * N - 1) do |i|
	if S[i] == S[i - 1] 
		check = !check
	end
	if check
		cnt += 1
	else
		ans *= cnt
		ans %= MOD
		cnt -= 1
	end
end
if cnt == 0
	puts ans
else
	puts '0'
end

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

bool divisor(int x) {
    int cnt = 0;
    int tmp = 1;
    while (tmp * tmp <= x) {
        if (x % tmp == 0) {
            if (tmp * tmp != x)
                cnt += 2;
            else
                cnt++;
        }
        tmp++;
    }
    if (cnt == 8)
        return true;
    else
        return false;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    rep2(i, 1, N + 1) {
        if ((i % 2) && divisor(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,cnt=0;
    cin>>n; 
    vector<ll> a(n),ball(n,0);
    rep(i,n) cin>>a[i];
    for(ll i=n;i>=1;i--){
        ll now=i,sum=0;
        while(1){
            now+=i;
            if(now>n) break;
            sum+=ball[now-1];
        }
        if(sum%2!=a[i-1]){
            ball[i-1]=1;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    rep(i,n) if(ball[i]) cout<<i+1<<endl;
    return 0;
}

Measured memory_bytes: 3968
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
vi dp;
ll fun(ll ind,vi v,ll n)
{
    if(ind==n-1)
    {
        return dp[ind]=0;
    }
    if(ind>n-1)
    {
        return -1;
    }
    if(dp[ind]!=-1)
    {
        return dp[ind];
    }
    ll l=LLONG_MAX,r=LLONG_MAX;
    if(fun(ind+1,v,n)!=-1)
    {
        l=abs(v[ind]-v[ind+1])+dp[ind+1];
    }
    if(fun(ind+2,v,n)!=-1)
    {
        r=abs(v[ind]-v[ind+2])+dp[ind+2];
    }
    return dp[ind]=min(l,r);
}
void solve()
{
    ll n;
    cin>>n;
    vi v(n),w(n,0);
    fr(i,0,n)
    {
        cin>>v[i];
    }
    if(n==1)
    {
        cout<<0;
        return;
    }
    w[0]=0;
    w[1]=abs(v[1]-v[0]);
    fr(i,2,n)
    {
        ll x=LLONG_MAX,y=LLONG_MAX;
        if(i-1>=0)
        {
            x=abs(v[i]-v[i-1]);
        }
        if(i-2>=0)
        {
            y=abs(v[i]-v[i-2]);
        }
        w[i]=min(x+w[i-1],y+w[i-2]);
    }
    cout<<w[n-1];
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/


Measured memory_bytes: 4696
"use strict"

function main(input) {
	
	const a = 2
	input  = parseInt(input, 10)
	let i = input

		if( i%a === 0 )
		{
			console.log( i )
		}
		else
		{

			console.log(i*a)
		}


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

Measured memory_bytes: 21064
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut b = a.clone();
    b.sort();
    b.reverse();
    let mmax = b.len() >= 2 && b[0] == b[1];

    for i in 0..a.len() {
        if !mmax && a[i] == b[0] {
            println!("{}", b[1]);
        } else {
            println!("{}", b[0]);
        }
    }
}


Measured memory_bytes: 9724
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
int N,Z,W;
int V[2005];
int dp[2][2005][2005];
int main()
{
    cin>>N>>Z>>W;
    for(int i=1;i<=N;i++)
        cin>>V[i];
    for(int i=0;i<=N;i++)
    {
        dp[0][i][N]=abs(V[N]-(i!=0 ? V[i]:Z));
        dp[0][N][i]=0;
        dp[1][N][i]=abs(V[N]-(i!=0 ? V[i]:W));
        dp[1][i][N]=1<<30;
    }
    for(int i=N-1;i>=0;i--)
    {
        for(int j=N-1;j>=0;j--)
        {
            dp[0][i][j]=max(dp[1][max(i,j)+1][j],dp[0][max(i,j)+1][j]);
            dp[1][i][j]=min(dp[0][i][max(i,j)+1],dp[1][i][max(i,j)+1]);
        }
    }
    cout<<dp[0][0][0];
    return 0;
}


Measured memory_bytes: 31616
import math
ans=0
m=[]
N=int(input())
rN=math.floor(math.sqrt(N))
for i in range(1,rN+1):
    if N%i==0:
        m.append(i)
        m.append(int(N/i))
    else:
        pass
m.sort()
m2=list(map(lambda x: x-1,m))
for i in m2:
    if i==0:
        pass
    else:
        a,b=divmod(N,i)
        if a==b:
            ans+=i
        else:
            pass
print(ans)

Measured memory_bytes: 3516
#include <stdio.h>

int main(){
	
	int n,i;
	char s[100];
	scanf("%d %s", &n,&s);
	
	if(n % 2 != 0){
		printf("No");
		return 0;
	}
	for(i = 0; i < n/2; i++){
		if(s[i] != s[n/2 + i]){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1704
K,A,B=map(int,input().split())
ans=0
if B-A<=2 or K+1<=A: #ぼったくり
  ans=K+1
else: #notぼったくり
  # A-1回ポケット叩いてA個のビスケットを用意する。A-1/Kつかう
  # B枚に交換してBの方が大きいので交換し続ける。それぞれ2/Kつかう
  # 最後に1回あまればビスケットを1枚増やしとく。1/Kつかう
  t=(K-A+1)//2 #交換する回数
  ans=B*t-A*(t-1)+(K-A+1)%2
print(ans)

Measured memory_bytes: 2940