akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
#define ull unsigned long long
#define ld long double
#define uint unsigned int
struct debug {
debug() {cerr << "[LINE:" << __LINE__ << "]";}
~debug() {cerr << "\n";}template<class C> debug& operator<<(C c) {cerr << c;return *this;}
};
#define var(x) " [" << #x << ": " << x << "]"

int n;

void tc() {
    cin >> n;
    ll a[n];
    for(int i=0; i<n; ++i) {
        cin >> a[i];
    }
    sort(a, a+n);
    int ans=0;
    for(int i=0; i<n; ++i) {
        for(int j=i+1; j<n; ++j) {
            if(a[j]!=a[i]) {
                for(int k=j+1; k<n; ++k) {
                    if(a[k]!=a[j]&&a[k]<a[i]+a[j])
                        ans++;
                }
            }
        }
    }
    cout << ans << "\n";
}

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

    tc();
    return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    const int m = n % 10;
    switch (m)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    }
}


Measured memory_bytes: 3620
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

distance (x,y) (x',y') = abs (x-x') + abs (y-y')

movable (t,p) (t',p') = dist<=time && even dist == even time
  where
    dist = distance p p'
    time = t' - t



main = do
    x <- getInt
    a <- getInt
    b <- getInt
    print $ (x - a) `mod` b

Measured memory_bytes: 508
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=abs(score//10)
etemp=1
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.9:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(5)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)

Measured memory_bytes: 10404
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

vtxs = [[] for i in range(n)]
dist = [0 for i in range(n)]
visit = [0 for i in range(n)]

for i in range(n-1):
    a,b,c = getList()
    vtxs[a-1].append((b-1 ,c))
    vtxs[b-1].append((a-1 ,c))

ques, k = getList()

from collections import deque
q = deque([k-1])
visit[k-1] = 1
while(q):
    cur = q.popleft()
    cdist = dist[cur]
    for nx in vtxs[cur]:
        nxa, nxc = nx
        if visit[nxa] == 0:
            dist[nxa] = cdist + nxc
            visit[nxa] = 1
            q.append(nxa)

for i in range(ques):
    x, y = getList()
    print(dist[x-1] + dist[y-1])

Measured memory_bytes: 74800
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    auto n = 0;
    cin >> n;

    vector<string> str;
    for (auto i = 0 ; i < n ; ++i) {
        string s;
        cin >> s;
        str.push_back(s);
    }

    // 各文字列をソートし、出現回数を数える
    uint64_t count = 0;
    map<string, uint64_t> m;
    for (auto& s: str) {
        sort(s.begin(), s.end());
        if (m.count(s) == 0) {
            // 新しく発見したので初期化
            m[s] = 0;
        }
        else {
            // 既に登場しているのでインクリメント
            m[s] += 1;
            count += m[s];
        }
    }

    cout << count;
    return 0;
}

Measured memory_bytes: 10608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t;
	string s;
	cin>>s;
	if(s[s.length()-1]=='s')
	s+="es";
	else s+="s";
	cout<<s;
}

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

int n, a, k=1;
int main() {
	cin>> n;
	for(int i=0; i<n; i++) {
		scanf("%d", &a);
		if(a==k) k++;
	}
	cout<< (k>1? n-k+1: -1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)( 1e9 + 7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef pair<float,float> ff;
typedef vector<ff> vff;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;

const int N=2e5+5;
int par[N];
int root(int v){return par[v] < 0 ? v : (par[v] = root(par[v]));}
void merge(int x,int y){	
        if((x = root(x)) == (y = root(y)) )    return ;
	if(par[y] < par[x])	
		swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

int32_t main()
{
	IOS
	int n;cin>>n;
	int cnt=1,prev=0;
	int mx=1;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		if(x>prev)
		{
			cnt=1;
		}
		else cnt++;
		prev=x;
		mx=max(cnt,mx);
	}
	cout<<max(mx-1,0LL)<<endl;
		
			
	
		
	
}
 
 


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

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

ll f(ll x, ll c, ll d) {
    return x-x/c-x/d+x/lcm(c,d);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll n_c, n_d, n_cd;
    ll lc = lcm(c,d);
    ll ans = f(b,c,d) - f(a-1,c,d);
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    ll h,w,m,hi,wi;
    scanf("%lli %lli %lli",&h,&w,&m);
    ll hcount[h],wcount[w],hitem[m],witem[m];
    fr(i,0,h) {hcount[i] = 0;}
    fr(i,0,w) {wcount[i] = 0;}
    fr(i,0,m) {hitem[i] = 0; witem[i] = 0;}
    fr(i,0,m){
        scanf("%lli %lli",&hi,&wi);
        hcount[hi-1]++;
        wcount[wi-1]++;
        hitem[i] = hi-1;
        witem[i] = wi-1;
    }
    ll hmax=0,hmaxcount=0,wmax=0,wmaxcount=0,itemmax=0,itemmaxcount=0;
    fr(i,0,h){
        if(hmax<hcount[i]) {
            hmax = hcount[i];
        }
    }
    fr(i,0,h){
        if (hmax == hcount[i]) {
            hmaxcount++;
        }
    }    
    fr(i,0,w){
        if(wmax<wcount[i]) {
            wmax = wcount[i];
        }
    }
    fr(i,0,w){
        if (wmax == wcount[i]) {
            wmaxcount++;
        }
    }
    fr(i,0,m){
        if(itemmax<hcount[hitem[i]]+wcount[witem[i]]) {
            itemmax = hcount[hitem[i]]+wcount[witem[i]];
        }
    }
    fr(i,0,m){
        if (itemmax == hcount[hitem[i]]+wcount[witem[i]]) {
            itemmaxcount++;
        }
    }
    if(itemmax == hmax+wmax && itemmaxcount == hmaxcount*wmaxcount)
    {printf("%lli",hmax+wmax-1);}  
    else {printf("%lli",hmax+wmax);}  
    return 0;
}

Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("in.txt", "r", stdin);
	int a, b;
	cin >> a >> b;
	if(a*500 >= b) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}

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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    map<pair<int, int>, int> c;
    for (int i = 0; i < n; i++) {
        double x;
        scanf("%lf", &x);
        long long a = llround(x * 1e9);
        int twos = 0;
        while (a % 2 == 0) {
            a /= 2;
            twos++;
        }
        int fives = 0;
        while (a % 5 == 0) {
            a /= 5;
            fives++;
        }
        c[{twos, fives}] += 1;
    }
    long long answer = 0;
    for (pair<pair<int, int>, int> p1 : c) {
        for (pair<pair<int, int>, int> p2 : c) {
            if (p1.first.first + p2.first.first >= 18 && p1.first.second + p2.first.second >= 18) {
                if (p1 < p2) {
                    answer += (long long)p1.second * p2.second;
                } else if (p1 == p2) {
                    answer += (long long)p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    for (char i = 'a'; i <= 'z'; i++) {
        if (s+i == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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


int main(){
    int n;cin>>n;
    int data[10][10] ={0};
    ll sum =0;
    for(int i =1;i<=n;++i){
        string x = to_string(i);
        int len = x.size();
        ll first = (i/(int)pow(10,len-1))%10;
        ll second =i%10;
        data[first][second]++;

    }
    for(int i=1;i<10;++i ){
        for(int j = 1;j<10;++j){
            sum+=data[i][j]* data[j][i];
        }

    }
    cout <<sum<<endl;

}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  queue<int> q;
  rep(i, s.size()) {
    if (q.empty()) {
      q.push(s[i]);
    } else {
      if (q.front() == s[i]) {
        q.push(s[i]);
      } else {
        q.pop();
      }
    }
  }
  cout << s.size() - q.size() << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long >
#define ll long long
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 100000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
int mod(int x,int y)
{
  int s;
  s = abs(x)/y;
  if(x<0)s--;
  return x-y*s;
}
int dir8[2][8] = {{1,-1,0,0,1,-1,1,-1},{0,0,1,-1,1,-1,-1,1}};
int dir4[2][4] = {{1,-1,0,0},{0,0,1,-1}};
int m,n,row,col;
double p[3000];
double memo[3000][3000];
double dp(int i,int h)
{
  if(i >= n)
  {
    if(h > n-h)return 1.0;
    return 0.0;
  }
  if(memo[i][h]!=-1.0)return memo[i][h];
  double p1 = p[i] * dp(i+1,h+1);
  double p2 = (1.0-p[i])*dp(i+1,h);
  memo[i][h] = p1+p2;
  return memo[i][h];
}
void solve()
{
  for(int w=0;w<3000;w++)
  {
    for(int q=0;q<3000;q++)memo[w][q] = -1.0;
  }
  scanf("%d",&n);
  for(int w=0;w<n;w++)scanf("%lf",&p[w]);
  double ans = dp(0,0);
  printf("%.10lf\n",ans);

}
void test()
{
  int t;
//  scanf("%d",&t);
  t  = 1;
  for(int test=1;test<=t;test++)
  {
    solve();
  }
}
int main()
{
  test();
  return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define scanf(...) scanf(__VA_ARGS__)?:0
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <PII, int> PPI;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
#define maxn 305
int tab[maxn][maxn], n, m;
char s[maxn][maxn];

inline int solve(int k) {
	int t1[maxn], t2[maxn];
	FOR(i, 1, n) t1[i] = tab[i][k];
	FOR(i, 1, n) t2[i] = tab[i][k + 1];

	int koszt[maxn][maxn], dp[maxn][maxn];
	FOR(i, 0, n)
	  FOR(j, 0, n) koszt[i][j] = 0, dp[i][j] = inf;
	dp[n][n] = 0;
	//koszt[i][j] -> koszt operacji zrobienia czegos jesli bylo jeszcze i numerkow z t1 oraz j numerkow z t2
	FOR(i, 1, n)
	  FOR(j, 1, n) koszt[i][j] = koszt[i-1][j-1] + (t1[i] == t2[j]);
	  
	for (int i=n; i>=0; --i)
	  for (int j=n; j>=0; --j)
	  {
		  if (dp[i][j] == 0) continue;
		  if (i + 1 <= n) dp[i][j] = min(dp[i][j], dp[i + 1][j] + koszt[i + 1][j]);
		  if (j + 1 <= n) dp[i][j] = min(dp[i][j], dp[i][j + 1] + koszt[i][j + 1]);
	  }
	return dp[0][0];
}

int main() {
	scanf("%d%d", &n, &m);
	FOR(i, 1, n) scanf("%s", s[i] + 1);
	FOR(i, 1, n)
	  FOR(j, 1, m) tab[i][j] = s[i][j] - 'a' + 1;
	
	int wyn = 0;
	FOR(i ,1, m-1) wyn += solve(i);
	cout << wyn;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int f(int x) {
	while (10 <= x)
		x /= 10;
	return x;
}
int g(int x) {
	return x % 10;
}
int n;
ll t[10][10];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		t[f(i)][g(i)]++;
	ll count = 0;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			count += t[i][j] * t[j][i];
	printf("%d\n", count);
}

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

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

int main(void)
{
	int x, sum = 0;
	scanf("%d", &x);

	for (int i = 1; i <= x; i++)
	{
		for (int j = 1; j <= x; j++)
		{
			for (int k = 1; k <= x; k++)
			{
				sum += gcd(gcd(i, j), k);
			}
		}
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 1724
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define long long int





int findNumberOfTriangles(vector<int> arr, int n)  
{  
    
    sort(arr.begin(),arr.end());  
  
    int count = 0;  
   
    for (int i = 0; i < n - 2; ++i)  
    {  
        
        int k = i + 2;  
  
       
        for (int j = i + 1; j < n; ++j)  
        {  
            
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
  
            
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
}  
  
int main()
{
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }
    int count=0;
    
    cout<<findNumberOfTriangles(v,n)<<endl;
    return 0;


}

Measured memory_bytes: 256
let split = Str.split (Str.regexp_string " ");;

let (d1,d2,d3,d4) =
  let n = read_int () in
  let list1 = read_line () |> split |> List.map float_of_string and
      list2 = read_line () |> split |> List.map float_of_string in
  let rec loop (w,x,y,z) = function
      i when i = n -> (w,x,y,z)
    | i -> let t = abs_float ((List.nth list1 i)-.(List.nth list2 i)) in
           loop (w +. t, x +. t**2., y +. t**3., if t> z then t else z) (i+1)in
  loop (0.,0.,0.,0.) 0;;

let () = Printf.printf "%f\n%f\n%f\n%f\n" d1 (d2**0.5) (d3**(1./.3.)) d4;;

Measured memory_bytes: 2488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair <int,int> ii ;
typedef vector < ii > vii ;
typedef vector < vii > viii ;
#define rep(i,n)                   for( ll i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++) 
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define db double 
#define fi first
#define se second
const ll mod =1000000007;

int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	int n; cin>>n;
  	double p[n+1];
  	repu(i,1,n) cin>>p[i];
  	double dp[n+1][n+1];
  	memset(dp,0.0, sizeof dp);
  	dp[0][0]=1;
  	repu(i,1,n) {
  		dp[0][i]=(1-p[i])*dp[0][i-1];
  		repu(j,1,n) {
  			dp[j][i]=(p[i]*dp[j-1][i-1])+((1-p[i])*dp[j][i-1]);
  		}
  	}
  	double ans=0;
  	repu(i,n/2+1,n)  ans+=dp[i][n];
  	cout<<setprecision(9)<<ans<<endl;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<P> VP;
const int INF = 1LL<<60;
const int MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
  str S;
  cin>>S;
  bool n=false,w=false,s=false,e=false;
  rep(i,S.length()){
    if(S[i]=='N')n=true;
    if(S[i]=='S')s=true;
    if(S[i]=='W')w=true;
    if(S[i]=='E')e=true;
  }
  if(n&&s&&w&&e)cout<<"Yes"<<endl;
  else if(n&&s&&!w&&!e)out("Yes");
  else if(!n&&!s&&w&&e)out("Yes");
  else out("No");
  
  
  
  return 0;
}



Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Debug.Trace

import           Data.List             (group, sort)

f :: Int -> B.ByteString -> [[B.ByteString]]
f k = group . sort . concatMap B.inits . take (k + 1) . sort . B.tails

main :: IO ()
main = do
    s <- B.getLine
    k <- readLn :: IO Int
    let gs = (f k s) !! k
    B.putStrLn $ head gs


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;

#define fi first
#define se second

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

const ll inf = ll(1e18);
//const int MOD = (1e9 + 7);

int main() 
{

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
		clock_t start = clock();
	#endif
	cout.setf(ios::fixed), cout.precision(20);
	//code begins here

	ll a,b,c;
	cin >> a>>b >> c;
	if(a+b+c>=22) cout<<"bust"<<"\n";
	else cout<<"win"<<"\n";
	
	
	//End of code 
	#ifdef DEBUG_
		cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999

struct cost{
	string name;
	double eff;
	
	bool operator<(const cost& a) const{
		if(eff != a.eff) return eff > a.eff;
		if(name != a.name) return name < a.name;
	}
};
	
int main(){
	double p, a, b, c, d, e, f, s, m;
	int n, i, j;
	string l;
	cost ls[51];
	while(1){
		cin >> n;
		if(!n) break;
		for(i=0;i<n;i++){
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			ls[i].name = l;
			ls[i].eff = (s*f*m-p)/(a+b+c+(d+e)*m);
		}
		sort(&ls[0], &ls[n]);
		for(i=0;i<n;i++){
			cout << ls[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<int> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

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


struct Edge {
    int to, cap, rev;
    Edge(int _to, int _cap, int _rev) {
        to = _to; cap = _cap; rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
    G[from].push_back(Edge(to, cap, G[to].size()));
    if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}


class UnionFind {
 vector<int> data;
 int num;
public:
 UnionFind(int size) : data(size, -1), num(size) { }
 bool unionSet(int x, int y) {
  x = root(x); y = root(y);
  if (x != y) {
   if (data[y] < data[x]) swap(x, y);
   data[x] += data[y]; data[y] = x;
   num--;
  }
  return x != y;
 }
 bool findSet(int x, int y) {
  return root(x) == root(y);
 }
 int root(int x) {
  return data[x] < 0 ? x : data[x] = root(data[x]);
 }
 int size(int x) {
  return -data[root(x)];
 }
 int numSet() {
  return num;
 }
};

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

	ll n;
	cin>>n;

	vector<P> xy(n);
	Matrix ys(101010),xs(101010);
	REP(i,n){
		ll x,y;
		cin>>x>>y;
		xy[i]={x,y};
		xs[y].push_back(x);//あるyに対するx
		ys[x].push_back(y);//あるxに対するy
	} 
	sort(all(xy));

	UnionFind uni(101010);
	
	REP(i, n){
		ll x=xy[i].first;
		ll y=xy[i].second;
		uni.unionSet(x,xs[y][0]);
	}

	vector<set<ll>> st(101010);//あるxとつながってるグループに対するy
	vector<ll> num(101010,0);//あるxにつながってるグループに対するyの数
	REP(x,101010){
		for(auto y:ys[x]){
			ll root = uni.root(x);
			if(st[root].find(y)==st[root].end()){
				//まだないyの場合は追加
				st[root].insert(y);
				num[root]++;
			}
		}
	}

	ll ans=0;
	REP(x,101010){
		ans+=num[uni.root(x)];
	}

	ans-=n;

	cout<<ans<<en;

    return 0;
}

Measured memory_bytes: 17920
s = input()
t = input()

ans = []

for i in range(0, len(s) - len(t) + 1):
  score = 0
  # sをtと同じ文字列分、切り取る
  u = s[i:i + len(t)]
  for j in range(len(t)):
    # 切り取った文字列のsとtが同じかどうか比較する
    if u[j] != t[j]:
      score += 1
  ans.append(score)

print(min(ans))


Measured memory_bytes: 8992
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n, l, sum = 0, del = inf;
	cin >> n >> l;
	for (int i = l; i < l + n; ++i)
		sum += i;
	int ans = -1;
	for (int i = l; i < l + n; ++i) {
		if (abs(sum - (sum - i)) < del)
			del = abs(sum - (sum - i)), ans = i;
	}
	cout << sum - ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
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;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  char C;
  cin >> C;
  if(C >= 'a') cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3652
import math

list=list((int(input()) for i in range(5)))
min=10
index=0
result=0
for i in range(len(list)):
    if min > list[i]%10 and list[i]%10 !=0:
        min=list[i]%10
        index=i
for i in range(len(list)):
    if i != index:
        result+=math.ceil(list[i]/10)*10
result+=list[index]
print(result)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {


      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int ans = 1;
            int modulo = 7;
            while(modulo%n != 0){
                  modulo = (modulo *10 + 7)%n;
                  ans++;
                  if(ans >=n+2){
                        ans  = -1;
                        break;

                  }            }
            System.out.println(ans);

      }


}


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

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

    if (n % 2 == 0) cout << n / 2 << endl;
    if (n % 2 !=  0) cout << n / 2 + 1 << endl;

    return 0;
    
}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# strlist = "abcdefghijklmnopqrstuvwxyz"
k,n = map(int,input().split())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

ans = k+10
for i in range(n):
    if i == 0:
        migi = arrA[n-1]-arrA[0]
        hidari = k - (arrA[1]-arrA[0])
        ans = min(migi,hidari,ans)
    elif i == n-1:
        migi = k -(arrA[n-1] - arrA[n-2])
        hidari = arrA[n-1]-arrA[0]
        ans = min(migi,hidari,ans)
    else:
        migi = arrA[i-1] + k-arrA[i]
        hidari = k-(arrA[i+1]-arrA[i])
        ans = min(migi,hidari,ans)

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 26444
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int M = 2019;
		int N = S.Length;
		long tot = 0;
		long[] dp = new long[M];
		var a = new int[N];
		for(int i=0;i<N;i++) a[i] = S[i] - '0';
		
		dp[a[0]] = 1;
		for(int i=1;i<N;i++){
			var ndp = new long[M];
			ndp[a[i]] = 1;
			for(int k=0;k<2019;k++){
				int nk = (k * 10 + a[i]) % 2019;
				ndp[nk] += dp[k];
			}
			tot += ndp[0];
			dp = ndp;
		}
		
		Console.WriteLine(tot);
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 40240
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n)
  cin >> p[i];
  
  if(n%2 == 0){
    printf("%f", 1/2.0);
  }
  else{
    printf("%f", ((n-1)/2.0+1)/n);
  }
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

using namespace std;

int main(){
  double a,b,n;
  long long ans;
  cin >> a >> b >> n;
  if(b<=n){
    ans = (long long)(a * (b-1) / b);
  }else{
    ans = (long long)(a * n / b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
#define MAX 500001
#define SENTINEL 1e9+1

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) { L[i] = A[left + i]; }
    for (i = 0; i < n2; i++) { R[i] = A[mid + i]; }
    L[n1] = R[n2] = SENTINEL;

    i = 0; j = 0;
    for (k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        }
        else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right) {
    if (left+1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main() {
    int A[MAX], n, i;
    cnt = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    mergeSort(A, n, 0, n);

    for (i = 0; i < n; i++) {
        printf("%d", A[i]);
        printf( (i == n-1) ? "\n" : " ");
    }

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 5592
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
N = int(input())
B = {int(input()) for _ in range(N)}
A = a1+a2+a3
ijk = [ [0,1,2], [3,4,5], [6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]


end = False
for i,j,k in ijk:
    if {A[i], A[j], A[k]} <= B:
        print('Yes')
        end = True
        break
    else:
        continue
if not end:        
    print('No')



Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

signed main(){
    int n;
    cin >> n;
    set<string> m, a, r, c, h;
    rep(i, n){
        string s;
        cin >> s;
        switch(s[0]){
            case 'M': m.insert(s); break;
            case 'A': a.insert(s); break;
            case 'R': r.insert(s); break;
            case 'C': c.insert(s); break;
            case 'H': h.insert(s); break;
            default: break;
        }
    }

    int sum = 0;
    sum += m.size() * a.size() * r.size();
    sum += m.size() * a.size() * c.size();
    sum += m.size() * a.size() * h.size();
    sum += m.size() * r.size() * c.size();
    sum += m.size() * r.size() * h.size();
    sum += m.size() * c.size() * h.size();
    sum += a.size() * r.size() * c.size();
    sum += a.size() * r.size() * h.size();
    sum += a.size() * c.size() * h.size();
    sum += r.size() * c.size() * h.size();

    int num = 0;
    num += (m.size() > 0)? 1: 0;
    num += (a.size() > 0)? 1: 0;
    num += (r.size() > 0)? 1: 0;
    num += (c.size() > 0)? 1: 0;
    num += (h.size() > 0)? 1: 0;
    
    int itr_max = facctorialMethod(num) / 6;

    cout << sum /* * itr_max  */<< endl;

}

Measured memory_bytes: 11236
def sol(lis):
    m = lis[0]
    ans = []
    for i in range(len(lis)):
        if lis[i]<m:
            ans.append(m-lis[i])
            lis[i] = m
        elif  lis[i]!=m:
            m = max(m,lis[i])
    print(sum(ans))
input()
lis = list(map(int,input().split(' ')))
sol(lis)


Measured memory_bytes: 32132
#include <bits/stdc++.h>  // ver2.2.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0 * 10^18 (MAXの1/3くらい)
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  set<string> kind;
  string s,t;
  
  rep(i,0,n){
    cin >> s >> t;
    if(s=="insert") kind.insert(t);
    else {
      if(kind.count(t)) cyes;
      else cno;
    }
  }
  return 0;
}


Measured memory_bytes: 29772
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


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

	int n;
	cin >> n;

	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];

	for(int i = 0; i < n; i++)
		cin >> b[i];

	reverse(b.begin(), b.end());
	int lo = -1, hi = -1, c = -1;
	for(int i = 0; i < n; i++)
		if(a[i] == b[i]){
			hi = i;
			if(lo == -1)
				lo = i;
			c = a[i];
		}

	if(c != -1){
		vector<int> pos;
		for(int i = 0; i < n; i++)
			if(a[i] != c && b[i] != c)
				pos.push_back(i);

		if(pos.size() < hi - lo + 1){
			cout << "No" << endl;
			return 0;
		}

		for(int i = lo; i <= hi; i++){
			int p = pos.back();
			pos.pop_back();
			swap(b[i], b[p]);
		}
	}
	

	cout << "Yes" << endl;
	for(int i = 0; i < n; i++)
		cout << b[i] << " \n"[i + 1 == n];
	
	return 0;
}


Measured memory_bytes: 5900
//Practice more and more
//learn for better
#define bn begin()
#define en end()
#define mx 5000010
#define pb push_back
#define PI (2.0*acos(0.0))
#define ALL(a) a.begin(),a.end()
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rep(a,b) for(int a=0;a<b;++a)
#define fastio ios::sync_with_stdio(false)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int>  vi;
typedef vector<ll>   vll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
	int a,b,n,i,t,tmp,x;
	bool bb[110];
	memset(bb,true,sizeof(bb));
	vector<int> v;
	cin>>x>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		v.pb(a);
		bb[a]=false;
	}
	for(i=x+1;;i++)
	{
		if(bb[i]==false)
		;
		else
		{
			tmp=i;
			break;
		}
	}
		for(i=x-1;;i--)
	{
		if(bb[i]==false)
		;
		else
		{
			t=i;
			break;
		}
	}
//	cout<<tmp<<" "<<t<<endl;
	if(bb[x]==true)
	cout<<x<<endl;
	else
	{
		int c,d;
		c=abs(x-t);
		d=abs(x-tmp);
//			cout<<c<<" "<<d<<endl;
		if(c<d)
		cout<<t<<endl;
		else if(c>d)
		cout<<tmp<<endl;
		else
		cout<<t<<endl;
	}


	return 0;
}

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

const int MAX = 2e5 + 5;

ll a[MAX];
int main() {
  ll n;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(a, a + n);
  ll val = a[n >> 1];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += abs(a[i] - val);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    vector<int> S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << S.at(K - 1) << endl;
}

Measured memory_bytes: 256
# from collections import defaultdict
import heapq
N, M = map(int, input().split())

W = []
for _ in range(N):
    W.append(tuple(map(int, input().split())))
W = sorted(W, key=lambda x: (x[0], -x[1]))


a = []
heapq.heapify(a)  # リストaのheap化

ans = 0
c = 0
for day in range(1, M+1):
    day_c = 0
    while c != N and W[c][0] == day:
        if day_c <= M-day:
            x = W[c][1]
            heapq.heappush(a, -x)  # heap化されたリストaに要素xを追加
            day_c += 1
        c += 1
    if len(a) >= 1:
        ans += -heapq.heappop(a)  # heap化されたリストaから最小値を削除＆その最小値を出力

print(ans)


Measured memory_bytes: 85208
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

#define N 100010
#define Mod 1000000007
int n;
int a[N],b[N],p,q,maxa,maxb,c[N];

int main() {
    sf("%d",&n);
    rep(i,1,n) {
        sf("%d", a+i);
        if (gmax(maxa, a[i])) {
            p = i;
        }
    }
    rep(i,1,n) {
        sf("%d", b+i);
    }
    rrep(i,n,1) {
        if (gmax(maxb, b[i])) {
            q = i;
        }
    }

    if (p > q || a[p] != b[q]) {
        pf("0\n");
        return 0;
    }

    ll ans = 1;
    rep(i,1,n) {
        c[i] = min(a[i], b[i]);
    }
    rep(i,2,p) {
        if (c[i] == c[i-1]) ans = (ans * c[i]) % Mod;
    }
    rep(i,p+1,q-1) {
        if (c[i] == c[i-1] && c[i] == c[i+1]) ans = (ans * c[i]) % Mod;
    }
    rep(i,q,n-1) {
        if (c[i] == c[i+1]) ans = (ans * c[i]) % Mod;
    }
    pf("%d\n", (int)ans);

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
using namespace std;
const int N=200000+10;
int n,a[N],b[N];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++){
        if(a[i]<=b[n/2]) printf("%d\n", b[n/2+1]);
        else printf("%d\n", b[n/2]);
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define N 100001
using namespace std;
vector<int> G[N];
int col[N];

int D[N];
void bfs(int start,int d,int c){
  if(D[start]>=d)return;
  D[start] = d;
  queue<int> Q;
  Q.push(start);
  while(!Q.empty()){
    int pos = Q.front();Q.pop();
    if(col[pos]==-1)col[pos] = c;
    for(int i=0;i<G[pos].size();i++){
      int nx = G[pos][i];
      if(D[nx]>=D[pos]-1) continue;
      Q.push(nx);
      D[nx] = D[pos]-1;
    }
  }
}

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int q;
  cin>>q;
  
  int v[N],d[N],c[N];
  for(int i=0;i<q;i++)cin>>v[i]>>d[i]>>c[i];
  memset(col,-1,sizeof(col));
  memset(D,-1,sizeof(D));
  for(int i=q-1;i>=0;i--)bfs(v[i]-1,d[i],c[i]);
  for(int i=0;i<n;i++) cout<<max(0,col[i])<<endl;
  
  return 0;
}


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

/*
O(|E|log|V|)

P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/

struct edge {
    int to, cost;
};

void dijkstra(vector< vector< edge > > &G, vector< int > &d, int s) {
    int V = G.size();
    const int INF = 10e8;
    priority_queue< P, vector< P >, greater< P > > que;

    rep(i, V) d[i] = INF;
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    vector< vector< edge > > G(N);
    rep(i, N - 1) {
        G[i].push_back((edge){i + 1, 1});
        G[i + 1].push_back((edge){i, 1});
    }
    --X;
    --Y;
    G[X].push_back((edge){Y, 1});
    G[Y].push_back((edge){X, 1});

    vector< int > ans(N);
    rep(i, N) {
        vector< int > d(N);
        dijkstra(G, d, i);
        rep(j, N) {
            if (1 <= d[j] && d[j] <= N - 1) {
                ++ans[d[j] - 1];
            }
        }
    }

    rep(k, N - 1) { cout << ans[k] / 2 << endl; }
}

Measured memory_bytes: 384
import math

N, M = map(int, input().split())
p = 10**9 + 7
n_kai = math.factorial(N) % p
m_kai = math.factorial(M) % p
if abs(N - M) > 1:
    print(0)
elif abs(N - M) == 1:
    print(n_kai * m_kai % p)
else:
    print(2*n_kai*m_kai % p)


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


int main(){
  ll n; cin>>n;
  ll wa=0;
  ll m=n;
  while(n>=1){
    wa+=n%10;
    n/=10;
  }
  if(m%wa==0){cout<<"Yes"<<endl;}
  else cout<<"No"<<endl;
}
  


Measured memory_bytes: 256
R=str(input())
min=999
for i in range(len(R)-2):
    S=0
    S=int(R[i])*100
    S=S+int(R[i+1])*10
    S=S+int(R[i+2])
    if abs(S-753)< min:
        min=abs(S-753)
print(min)


Measured memory_bytes: 2940
#include <stdio.h>

int main() {
    int n, q;
    scanf("%d", &n);
    
    int S[n];
    for (int i=0; i<n; i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    
    int tmp, count=0;
    for (int i=0; i<q; i++) {
        scanf("%d", &tmp);
        for (int j=0; j<n; j++) {
            if(S[j] == tmp) { 
                count++;
                break;
            }
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 2696