akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
from functools import reduce
from fractions import gcd
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    lcd = reduce(lambda i,j: i*j//gcd(i,j), A, 1)
    m = lcd - 1
    A = [ m % i for i in A ]
    print(sum(A))

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 5380
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string res,res0;
    cin>>n;
    cout<<0<<endl;
    cin>>res0;
    if(res0=="Vacant") return 0;
    cout<<n-1<<endl;
    cin>>res;
    if(res=="Vacant") return 0;
    int l=0,r=n;
    while(r-l>1){
        int m=(l+r)/2;
        cout<<m<<endl;
        cin>>res;
        if(res=="Vacant") return 0;
        if((m%2==0 && res0==res) || (m%2==1 && res0 != res)) l=m;
        else r=m;
    }
}

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

const int MOD = (int)1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> C(N-1);
  vector<int> S(N-1);
  vector<int> F(N-1);
  for(int i=0;i<N-1;i++)  cin >> C.at(i) >> S.at(i) >> F.at(i);
  
  for(int i=0;i<N;i++){
    long long ans=0;
    for(int j=i;j<N-1;j++){
      if(j==i)	ans=S.at(j);
      else if(ans<=S.at(j)) ans=S.at(j);
      else  ans=S.at(j)+(ans-S.at(j)+F.at(j)-1)/F.at(j)*F.at(j);
      ans+=C.at(j);
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s=[]
for i in range(n):
  s.append(0)
for i in range(k):
  d=int(input())
  a=list(map(int,input().split()))
  for j in range(d):
    s[a[j]-1]+=1
ans=0
for i in range(n):
  if s[i]==0:
    ans+=1
print(ans)

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

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n > k)
    {
        cout << k * x + (n - k) * y;
    }
    else
    {
        cout << n * x << "\n";
    }
    return 0;
}


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

typedef long long ll;

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

    int a,b,c;
    cin >> a >> b >> c;
    if(a<b && b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,t,a[51],dp[51][51][2501];

ll solve(ll i, ll c, ll sum, ll m)
{
    if(i>n)
    {
//        if(c==0)
//            return 0;
        //cout<<sum<<" "<<c<<" "<<m<<endl;
        if(sum==m*c && c!=0)
            return 1;
        else return 0;
    }

    if(dp[i][c][sum]!=-1)return dp[i][c][sum];

    ll r1=0,r2=0;

    r1=solve(i+1,c+1,sum+a[i],m);

    r2=solve(i+1,c,sum,m);
    //cout<<" r1= "<<r1<<" r2= "<<r2<<endl;
    return dp[i][c][sum]=r1+r2;
}

int main()
{
    ll i,j,k,l,ans=0;

    scanf("%lld %lld",&n,&t);

    for(i=1; i<=n; i++)
        scanf("%lld",&a[i]);


    for(i=0; i<51; i++)
    {
        for(l=0; l<51; l++)
        {
            for(j=0; j<2501; j++)
                dp[i][l][j]=-1;
        }
    }
    ans+=solve(1,0,0,t);

    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 51072
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <stack>
#include <unordered_set>
using namespace std;

int main(){
    int n;
    cin >> n;
    long long res = 0;
    for(long long i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            res += i;
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

void dfs(int pos, int acc, int lim, const vector<pair<int,int> > &cards, vector<int> &patterns) {
    const int N = cards.size();
    if(acc > lim) return;
    if(pos == N) {
        patterns[acc]++;
        return;
    }
    for(int i = 0; i <= cards[pos].second; ++i) {
        dfs(pos+1, acc+cards[pos].first*i, lim, cards, patterns);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        vector<pair<int,int> > cards(N);
        for(int i = 0; i < N; ++i) {
            cin >> cards[i].first >> cards[i].second;
        }
        vector<int> patterns(1001, 0);
        dfs(0, 0, 1000, cards, patterns);

        int G;
        cin >> G;
        while(G--) {
            int NG;
            cin >> NG;
            cout << patterns[NG] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1200
n=int(input())
w=list(input()for i in range(n))
judge=True
worddic={}
worddic[w[0]]=0
for i in range(1,n):
    if w[i-1][-1]!=w[i][0]:
        judge=False
    if not w[i] in worddic:#重複を数える
        worddic[w[i]]=0
    else:
        judge=False
print("Yes") if judge else print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h> 
#define int long long
using namespace std;
void print (vector<int>&v){
	int k=0;
	for (int i:v) cout<<(i==INT_MAX?0:i)<<" ";
	cout<<endl;
}
void printv (vector<vector<int>>&v){
	for (vector<int> i:v) print(i);
	cout<<endl;
}
int solve(vector<int>& weights, vector<int>& value,int N, int W){
	int sum=0;
	for (int v:value) sum+=v;
	vector<vector<int>>dp(N+1,vector<int>(sum+1,W+1)) ;
	for (int i=0;i<=N;i++){
		dp[i][0]=0;
	}
	int ans=0;
	for (int i=1;i<=N;i++){
		for (int j=1;j<=sum;j++){
			if (value[i-1]>j) dp[i][j]=dp[i-1][j];
			else dp[i][j]=min(dp[i-1][j],weights[i-1]+dp[i-1][j-value[i-1]]);
			if (dp[i][j]<=W) ans=max(ans,j);
		}
	}
	// printv (dp);
	return ans;
}
signed main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	int N,W;
    cin>>N>>W;
    vector<int> weights(N);
    vector<int> value(N);
    for (int i=0;i<N;i++){
    	cin>>weights[i]>>value[i];
    }
	cout<< solve(weights,value,N,W)<<endl;
    return 0; 
}


Measured memory_bytes: 83088
n = int(input())
a = list(map(int,input().split()))

def check(m):
    tar = 1
    for i in range(n):
        if a[i] == tar:
            tar += 1
    if tar >= m+1:
        return 1
    else:
        return 0

if check(1) == 0:
    print(-1)
else:
    l = 1
    h = n
    mid = 1
    ans = None

    while l < h:
        mid = (l+h)//2
        guess = check(mid)
        #print(guess)
        if guess:
            l = mid + 1
        else:
            h = mid -1

    saku = sorted([l,h,mid], reverse=True)

    if check(saku[0]):
        print(n-saku[0])
    elif check(saku[1]):
        print(n - saku[1])
    else:
        print(n-saku[2])

Measured memory_bytes: 76364
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e3 + 5;
int main() {
    abdelrahman010
    ll sum = 0;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++) {
        if(i % 3 == 0 || i % 5 == 0)
            continue;
        sum += i;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),count=0;
        for(int i =0;i<n;i++){
            if(sc.nextInt()==count+1){
                count++;
            }
        }
        System.out.println(count==0?-1:n-count);
    }
}

Measured memory_bytes: 64868
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

vector<vector<ll>> bunkai(ll a){
  if(a<=0) return {};
  if(a==1) return {{1,1}};
  vector<ll> f;
  ll b=a;
  for(ll i=2;i*i<=a;i++){
    if(b%i==0){
      f.push_back(i);
      b=b/i;
      i--;
    }
  if(b==1)break;
  }
  if(b!=1)f.push_back(b);

  vector<vector<ll>> u;
  ll p=f[0];
  ll c=1;
  for(ll i=1;i<f.size();i++){
    if(f[i]==p)c++;
    else{
      u.push_back({p,c});
      p=f[i];
      c=1;
    }
  }
  u.push_back({p,c});

  return u;
}

vector<ll> yakusu(ll a){
  if(a==1)return {1};
  vec v;
  for(ll i=1;i*i<=a;i++){
    if(a%i==0){
      v.push_back(i);
      v.push_back(a/i);
    }
  }
  sort(v.begin(),v.end());
  return v;
}

int main(){

  ll n,m;
  cin >> n>>m;

  vec v=yakusu(m);
  ll ans=1;
  for(ll i=0;i<v.size();i++){
    if(v[i]<=m/n)ans=max(ans,v[i]);
  }
  cout << ans << endl;




}

Measured memory_bytes: 3644
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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 main() {
  ll N,D; // 変数の宣言
  cin >> N>>D; // 標準入力
  ll X[N],Y[N];
  double d;
  rep(i,N)
    cin >> X[i] >> Y[i];
  ll ans =0;
  rep(i,N){
    d=sqrt(X[i]*X[i] + Y[i]*Y[i]);
    if(D>=d){
      ans++;
    }
  }
  cout << setprecision(12) << ans << endl; // 標準出力
}


Measured memory_bytes: 6768
import sys
sys.setrecursionlimit(10**6)

# 入力
N,K =map(int,input().split())
InpList = list(map(int,input().split()))

result=0
i=0

# 必殺技の使用回数が1以上の場合、体力の多い敵から使っていく
InpList=sorted(InpList)[::-1]

if K>N:
    result=0
else:
    if K>0:
        for i in range(K):
            InpList[i]=0
    result=sum(InpList)

print(result)

    

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

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int dp[n];
    dp[0]=0; dp[1]=abs(h[0]-h[1]);
    for(int i=2; i<n; i++){
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout << dp[n-1] << endl;
return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

const ll inf = -1e16;

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    ll dp[3];
    rep(i,N) cin >> v[i];

    dp[0] = v[0];
    dp[1] = max(v[0],v[1]);
    if(N>2){
        dp[0] += v[2];
        dp[2] = max(dp[1],(ll)v[2]);
    }
    for(int i=3; i<N; ++i){
        ll tmp1,tmp2;
        tmp1 = dp[0];
        tmp2 = dp[1];
        if((i+1)%2){ // odd
            dp[0] += v[i];
            dp[1] = tmp1> tmp2? tmp1:tmp2 ;
            dp[2] += v[i];
            dp[2] = dp[1]>dp[2]? dp[1]:dp[2];
        }
        else{
            dp[1] += v[i];
            dp[2] = tmp2> dp[2]? tmp2:dp[2] ;
        }
    }

    if(N%2){
        cout << dp[2] << endl;
    }else{
        cout << dp[1] << endl;
    }

    return 0;
}


Measured memory_bytes: 4032
//#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>


//using namespace std;

int main()
{

//    freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);


    char str[1100];
    char str2[1000];
    int i, j, w;

    while(gets(str))
    {
        scanf("%d", &w);
        int len ;
        len = strlen(str);

        for( i=0, j=0; i<=len-1; i = i+w, j++ )
        {
            str2[j] = str[i];
        }

        for( i=0; i<j; i++ )
        {
            printf("%c", str2[i]);
        }
        printf("\n");

    }

    return 0;

}


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

bool isPerfectSquare(int n)
{
    for (int i = 1; i * i <= n; i++) {

        if ((n % i == 0) && (n / i == i)) {
            return true;
        }
    }
    return false;
}

main()
{
    int a, b, temp, newNum;

    cin >> a >> b;

    temp = b;

    while (temp%10 > 0)
    {
        a = a * 10;
        temp = temp /10;
    }

    newNum = a + b;

    if (isPerfectSquare(newNum))
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3612
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s = s.trim().to_string();
    s = s.clone() + &s;

    let mut t = String::new();
    io::stdin().read_line(&mut t).unwrap();
    let t = t.trim();

    let ans = match &s.find(t) {
        &Some(_) => "Yes",
        _ => "No"
    };

    println!("{}", ans);
}


Measured memory_bytes: 5032
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<bool> tate(N,false);
    vector<bool> yoko(M,false);
    vector<vector<char>> word(N, vector<char>(M));
    rep(i, N) {
        rep(j, M) {
            cin >> word[i][j];
            if (word[i][j] == '#') {
                tate[i] = true;
                yoko[j] = true;
            }
        }
    }
    rep(i, N) {
        rep(j, M) {
            if (tate[i] == true && yoko[j] == true)cout << word[i][j];
            
        }
        if(tate[i] == true)
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7, two = (mod+1)/2;
int n, x[N], d[N];
ll sum[N];
ll fac[N], inv[N];
ll powmod(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b&1) ans = ans*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return ans;
}
void init()
{
	fac[0] = 1;
	for(int i=1;i<=n;i++) fac[i] = fac[i-1]*i%mod;
	inv[n] = powmod(fac[n],mod-2);
	for(int i=n-1;i>=0;i--) inv[i] = inv[i+1]*(i+1)%mod;
}
ll comp(ll a,ll b)
{
	if(a<b||b<0) return 0;
	return fac[a]*inv[b]%mod*inv[a-b]%mod;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++) cin >> x[i];
 	for(int i=1; i<n; i++) d[i] = x[i+1] - x[i];
 	for(int i=1; i<n; i++) sum[i] = (sum[i-1]+d[i])%mod;
 	init();
 	ll res = 0;
 	for(int i=1; i<n-1; i++)
 	{
// 		for(int j=1; j+i<n; j++)
// 		{
// 			ll cur = d[j+i]*comp(n-1, i+1)%mod*fac[n-i-2]%mod*fac[i]%mod;
// 			//debug(cur);
//			res = (res+cur)%mod;	
// 		}
		ll cur = comp(n-1, i+1)%mod*fac[n-i-2]%mod*fac[i]%mod;
		cur = cur*(sum[n-1] - sum[i])%mod;
		res = (res+cur)%mod;
 	}
 	res = (res+fac[n-1]*sum[n-1]%mod)%mod;
 	res = (res+mod)%mod;
 	cout << res;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n;
vector<string> ss;
ll cnta,cntb;
bool aru=false;

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

  cin>>n;
  ss.resize(n);
  ll res=0;
  rep(i,n){
    cin>>ss[i];
    rep(j,ss[i].size()-1){
      if(ss[i].substr(j,2)=="AB")res++;
    }
    if(ss[i][ss[i].size()-1]=='A')cnta++;
    if(ss[i][0]=='B')cntb++;
    if((ss[i][ss[i].size()-1]=='A'&&ss[i][0]!='B')||(ss[i][ss[i].size()-1]!='A'&&ss[i][0]=='B'))aru=true;
  }

  if(aru)cout<<min(cnta,cntb)+res<<endl;
  else cout<<max(0LL,min(cnta,cntb)-1)+res<<endl;

  return 0;
}


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

class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[,] card = new string[4,14]; 
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 14; k++)
            {
                card[j,k] = "?";
            }
        }
        for(int i = 0; i < n;i++)
        {
            string[] s = Console.ReadLine().Split();
            
            card[0,0] = "S";
            card[1,0] = "H";
            card[2,0] = "C";
            card[3,0] = "D";
            if(s[0] == "S")
            {
                card[0,int.Parse(s[1])] = "X";
            }else if(s[0] == "H")
            {
                card[1,int.Parse(s[1])] = "X";
            }else if(s[0] == "C")
            {
                card[2,int.Parse(s[1])] = "X";
            }else if(s[0] == "D")
            {
                card[3,int.Parse(s[1])] = "X";
            }
        }
        for(int i = 0; i < 4;i++)
        {
            for(int j = 1; j < 14;j++)
            {
                if(card[i,j] == "?")
                {
                    Console.WriteLine(card[i,0] + " " + j);
                }
            }
        }
    }
}


Measured memory_bytes: 15892
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])


def main():
    n=inp()
    a=inpl()
    a.sort()
    dic = defaultdict(int)
    dic[0] += 1
    for i in range(n):
        dic[a[i]] += 1
    for e in dic:
        if dic[e] > 2:
            print(0)
            return
        if e == 0 or e == 12:
            if dic[e]>1:
                print(0)
                return
    x = [0 for _ in range(24)]
    cnt = 0
    for i in range(13):
        if dic[i]==0:
            continue
        elif dic[i] == 1:
            if cnt % 2 == 0:
                x[i] += 1
            else:
                x[24-i] += 1
        else:
            x[i] += 1
            x[24-i] += 1
        cnt += 1
    ans = 24
    for i in range(24):
        for j in range(24):
            if i==j or x[i]==0 or x[j]==0:
                continue
            ans = min(ans,abs(i-j),24-abs(i-j))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define int long long
#define lowbit(x) (x &(-x))
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EXP = 1e-8;
const ll   MOD = 1e9 + 7;
const int  N = 2e5 + 5;
int q, t, f;
char x;
string s;
signed main()
{
    IOS;
    cin >> s >> q;
    int vis = 1;
    while(q --){
        cin >> t;
        if(t == 1){
            vis = -vis;
            continue;
        }
        cin >> f >> x;
        if(f == 1){
            if(vis == 1) s.insert(s.begin(), x);
            else s.insert(s.end(), x);
        }
        else{
            if(vis == 1) s.insert(s.end(), x);
            else s.insert(s.begin(), x);
        }
    }
    if(vis == -1) reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 912
S=input()
N=len(S)
s=[i for i in S]
if s!=list(reversed(s)):
    print("No")
else:
    a=[i for i in s[int((N-1)/2)]]
    if a!=list(reversed(a)):
        print("No")
    else:
        a=[i for i in s[int((N+3)/2-1):N]]
        if a!=list(reversed(a)):
            print("No")
        else:
            print("Yes")

Measured memory_bytes: 3064
import math


def combination(n, m):

    if m > n or m < 0:
        return 0
    if m == 0 or n == 0:
        return 1

    return math.factorial(n) // (math.factorial(m)*math.factorial(n-m))


N, K = map(int, input().split())

divisor = 10**9 + 7

for i in range(1, K+1):
    divined = combination(N-K+1, i) * combination(K-1, i-1)
    print(divined % divisor)


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const size_t MAX_N = (size_t)1e5 + 5;

ll inv[MAX_N << 1], finv[MAX_N << 1], fperm[MAX_N << 1];

void process() {
    for (int i = 0; i < 2; i++) inv[i] = finv[i] = fperm[i] = 1;
    for (int i = 2; i < (MAX_N << 1); i++) {
        inv[i] = (-(MOD / i) * inv[MOD % i] + MOD) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;
        fperm[i] = (fperm[i - 1] * i) % MOD;
    }
}

auto C = [](int m, int n) -> ll {
    return fperm[m] * (finv[n] * finv[m - n] % MOD) % MOD;
};

int main() {
    process();
    ll res = 0;
    int h, w, a, b;
    cin >> a >> b >> h >> w;
    for (int j = w; j < b; j++)
        (res += C(j - 1 + a - h, j) * C(b - j + h - 2, h - 1)) %= MOD;
    cout << (res + MOD) % MOD;
}

Measured memory_bytes: 4992
N, M=map(int, input().split())
lst=[input().split() for _ in range(M)]
AC=[False for _ in range(N)]
WA=[0 for _ in range(N)]
for p, S in lst:
  p=int(p)-1
  if S=="AC":
    AC[p]=True
  if S=="WA" and not AC[p]:
    WA[p]+=1
for i in range(N):
  if not AC[i]:
    WA[i]=0
print(sum(AC), sum(WA))

Measured memory_bytes: 33896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)

ll dp[1002][(1<<13)+4];

vi a,b;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        a.pb(x);
        z = 0;
        for(int j=0;j<y;j++){
            cin>>x;
            x--;
            z+=(1<<x);
        }
        b.pb(z);
    }
    for(int i=0;i<(1<<n);i++){
        dp[m][i] = LLMAX;
    }
    dp[m][(1<<n)-1] = 0;
    
    for(int i=m-1;i>=0;i--){
        for(int j=0;j<(1<<n);j++){
            dp[i][j] = min(dp[i+1][j], dp[i+1][j|b[i]]+a[i]);
        }
    }
    if(dp[0][0]>=LLMAX){
        dp[0][0] = -1;
    }
    cout<<dp[0][0];
    
    

    return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long a, b; cin >> a >> b;

    if(a % 2 != b % 2){
        cout << "IMPOSSIBLE\n";
        return 0;
    }

    cout << (a + b >> 1) << "\n";

    return 0;

}


Measured memory_bytes: 256
import itertools
h,w,k2=map(int,input().split())
temp=[]
htemp=[i for i in range(h+w)]

for i in range(h):
    temp.append(list(input()))

retsum=0
import copy
def check(temp3,htemplist2):
    temp2=copy.deepcopy(temp3)
    for k in range(len(htemplist2)):
        if htemplist2[k]<h:
            for l in range(w):
                temp2[htemplist2[k]][l]="."
        if htemplist2[k]>=h:
            for l in range(h):
                temp2[l][htemplist2[k]-h]="."
    tempsum=0
    for x in range(h):
        for y in range(w):
            if temp2[x][y]=="#":
                tempsum+=1
    if tempsum==k2:
        return 1
    else:
        return 0

tempsum2=0
for x in range(h):
    for y in range(w):
        if temp[x][y]=="#":
            tempsum2+=1
if tempsum2==k2:
    retsum+=1

for i in range(1,h+w):
    htemplist=list(itertools.combinations(htemp,i))
    for j in range(len(htemplist)):
        retsum+=check(temp,htemplist[j])



print(retsum)



Measured memory_bytes: 77808
// Karm Kar, Phal Ki Chinta na Kar:)
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
int main()
{
    ll n,i;
    cin>>n;
    ll A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    ll ans=0,j;
    for(i=0;i<n;i++)
    {

        for(j=i+1;j<n;j++)
        {

            ans+=A[i]*A[j];
        }
    }
    cout<<ans;

}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int k;
    unsigned long long x = 0;
    cin >> k;
    rep(i, k) {
        int b;
        cin >> b;
        x += 1ULL<<b;
    }

    for(unsigned long long i = x; i < (1ULL<<n); i = (i+1)|x) {
        cout << i << ':';
        rep(j, n) if(i>>j&1) {
            cout << ' ' << j;
        }
        cout << '\n';
    }
}


Measured memory_bytes: 3220
"use strict";

function main(input){
  const args = input.trim().split('\n');
  const n = parseInt(args[0],10);
  const happiness = args.slice(1).map(_=>_.split(' ').map(_=>parseInt(_,10)));
  const dp = Array(n).fill(0).map(_=>Array(3).fill(0));
  dp[0][0] = happiness[0][0];
  dp[0][1] = happiness[0][1];
  dp[0][2] = happiness[0][2];
  
  for(let i=1; i<n; i++){
    dp[i][0] = Math.max(happiness[i][0] + dp[i-1][1], happiness[i][0] + dp[i-1][2]);
    dp[i][1] = Math.max(happiness[i][1] + dp[i-1][0], happiness[i][1] + dp[i-1][2]);
    dp[i][2] = Math.max(happiness[i][2] + dp[i-1][0], happiness[i][2] + dp[i-1][1]);
  }
  
  console.log(Math.max(dp[n-1][0],dp[n-1][1],dp[n-1][2]));
}

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

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

vector<int> depth;
vector<pair<int, int>> G;

int depthG(int n) {
  if (depth[n] != -1) return depth[n];

  auto it = lower_bound(G.begin(), G.end(), make_pair(n, 0));
  int ans = 0;
  while (it != G.end() and *it < make_pair(n + 1, 0)) {
    ans = max(ans, depthG(it->second) + 1);
    it++;
  }
  return depth[n] = ans;
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> dp(N, 0);

  for (int i = 0; i < M; i++)
  {
    int x, y; cin >> x >> y;
    x--; y--;
    G.emplace_back(x, y);
  }
  sort(G.begin(), G.end());
  vector<int> _depth(N, -1);
  depth = _depth;

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans = max(ans, depthG(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4212
#include<stdio.h>
int main (void)

{
int A,B,C,D,E,F;

scanf("%d%d%d",&A,&B,&C);

if(A>B)
{
D=A;
A=B;
B=D;

}

if(B>C)
{
E=B;
B=C;
C=E;
}
if(A>B)
{
F=A;
A=B;
B=F;
}
printf("%d %d %d\n",A,B,C);
return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static String req(String s, int k) {
		StringBuilder res = new StringBuilder();
		res.append(s.charAt(0));
		int n = s.length();
		for (int i=0; i<n; i++) {
			if (i != n-1 && (s.charAt(i) == 'a' || s.charAt(i) == 'i' || s.charAt(i) == 'u' || s.charAt(i) == 'e' || s.charAt(i) == 'o'))
				res.append(s.charAt(i+1));
		}
		return res.substring(0, Math.min(k, res.length()));
	}

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		String[] s = new String[n];
		for (int i=0; i<n; i++) {
			s[i] = in.next();
		}

		for (int k=1; k<=50; k++) {
			HashSet<String> set = new HashSet<>();
			for (int i=0; i<n; i++) {
				set.add(req(s[i], k));
			}
			if (set.size() == n) {
				out.println(k);
				return true;
			}
		}

		out.println("-1");

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 47468
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int k; cin>>k;
    string s; cin>>s;
    s[k-1]=s[k-1]-'A'+'a';
    cout<<s<<endl;
    return 0;
}


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

int main(){
    int N,L;
    cin >> N >> L;
    vector<string> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }

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

    string str = vec.at(0);

    for(int j=1;j<N;j++){
        str += vec.at(j);
    }

    cout << str << endl;
}

Measured memory_bytes: 3588
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;


public class Main {
    static int D;
    static long[] c;
    static long[][] s;

    private static class Solution implements Comparable<Solution>{
        int[] contests;
        long score;
        private int last(int d, int i){
            for(int p=d; p>=0; p--){
                if(contests[p]==i) return p;                
            }
            return -1;
        }

        private long calculateScore(){
            long sc = 0;
            for(int d=0; d<D; d++){
                sc += s[d][contests[d]];
                for(int i=0; i<26; i++){
                    sc -= c[i] * (d - last(d,i));
                }
            }
            return sc;
        }

        private long calculateScoreWithOutput(){
            long sc = 0;
            for(int d=0; d<D; d++){
                sc += s[d][contests[d]];
                for(int i=0; i<26; i++){
                    sc -= c[i] * (d - last(d,i));
                }
                System.out.println(sc);
            }
            return sc;
        }

        public Solution(int[] t){
            contests = new int[D];
            for(int d=0; d<D; d++) contests[d] = t[d];
            score = calculateScore();            
        }
        public int compareTo(Solution another){
            return Long.compare(this.score, another.score);
        }
        public long getScore(){
            return score;
        }
        public int[] getSchedule(){
            return contests;
        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        D = sc.nextInt();
        c = new long[26];
        s = new long[D][26];

        for(int a=0;a<26; a++) c[a] = sc.nextLong();
        for(int d=0; d<D; d++) for(int a=0; a<26; a++) s[d][a] = sc.nextLong();

        int[] t = new int[D];
        for(int d=0; d<D; d++) t[d] = sc.nextInt()-1;

        Solution sample = new Solution(t);
        
        sample.calculateScoreWithOutput();
    }
}


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

int main() {
    char x,y;
    cin >> x >> y;

    if(x > y) cout << '>' << endl;
    else if(x < y) cout << '<' << endl;
    else cout << '=' << endl;
 }

Measured memory_bytes: 256
def main():
    N, M = (int(i) for i in input().split())
    s = [[int(i) for i in input()[2:].split()] for j in range(M)]
    p = [int(i) for i in input().split()]
    ans = 0
    for bit in range(1<<N):
        switches = [0] * N
        for i in range(N):
            if bit & (1<<i):
                switches[i] = 1
        for ss,pp in zip(s,p):
            tmp = 0
            for i in ss:
                if switches[i-1]:
                    tmp += 1
            if tmp%2 != pp:
                break
        else:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 43120
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>

std::vector<int64_t> dp;
int main(void){
	int64_t n;
	std::vector<int64_t> g(2), s(2), b(2);
	std::cin >> n;
	for(int i=0;i<2;i++){
		std::cin >> g[i] >> s[i] >> b[i];
	}
	dp.resize(5002);
	int64_t gain[3];
	gain[0] = g[1] - g[0];
	gain[1] = s[1] - s[0];
	gain[2] = b[1] - b[0];

	for(int i=0;i<=dp.size();i++)dp[i] = n;
	for(int i=0;i<=n;i++){
		dp[(i + g[0]) % 5001] = std::max(dp[(i + g[0]) % 5001], dp[i % 5001] + gain[0]);
		dp[(i + s[0]) % 5001] = std::max(dp[(i + s[0]) % 5001], dp[i % 5001] + gain[1]);
		dp[(i + b[0]) % 5001] = std::max(dp[(i + b[0]) % 5001], dp[i % 5001] + gain[2]);
		if(i != n)dp[i % 5001] = n;
	}
	n = dp[n % 5001];
	for(int i=0;i<3;i++)gain[i] *= -1;
	for(int i=0;i<=dp.size();i++)dp[i] = n;
	for(int i=0;i<=n;i++){
		dp[(i + g[1]) % 5001] = std::max(dp[(i + g[1]) % 5001], dp[i % 5001] + gain[0]);
		dp[(i + s[1]) % 5001] = std::max(dp[(i + s[1]) % 5001], dp[i % 5001] + gain[1]);
		dp[(i + b[1]) % 5001] = std::max(dp[(i + b[1]) % 5001], dp[i % 5001] + gain[2]);
		if(i != n)dp[i % 5001] = n;
	}
	std::cout << dp[n % 5001] << std::endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n;
    cin>>h>>n;
    vint a(n+1);
    vint b(n+1);
    vector<vector<ll> > dp(n+1,vector<ll>(h+1));
    REP(i,1,n+1){
        cin>>a[i]>>b[i];
    }
    rep(i,n+1){
        rep(j,h+1){
            dp[i][j]=999999999ll;
        }
    }
    dp[0][0]=0;
    REP(i,1,n+1){
        REP(j,0,h+1){
            if(j>a[i]){
                dp[i][j]=min(dp[i-1][j],dp[i][j-a[i]]+b[i]);
            }
            else{
                dp[i][j]=min(dp[i-1][j],dp[i][0]+b[i]);
            }
        }
    }
    cout<<dp[n][h]<<'\n';
    return(0);
}

Measured memory_bytes: 78592
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n, x[100], y[100];
  double sum=0, ma=0;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  for(int i = 0; i < n; i++){
    cin >> y[i];
  }

  for(int i = 1; i <= 3; i++){
    for(int j = 0; j < n; j++){
      sum += pow(abs(x[j]-y[j]), i);
      ma = max(ma, (double)abs(x[j]-y[j]));
    }
    printf("%.8f\n", pow(sum, (double)1/i));
    sum = 0;
  }
  printf("%.8lf\n", ma);
  
  return 0;
}



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

sdic={}
snum=""
for i in s:
    if i not in sdic:
        sdic[i]=len(sdic)
        snum+=str(sdic[i])
    else:
        snum+=str(sdic[i])

tdic={}
tnum=""
for i in t:
    if i not in tdic:
        tdic[i]=len(tdic)
        tnum+=str(tdic[i])
    else:
        tnum+=str(tdic[i])

#print(snum, sdic)
#print(tnum, tdic)

if snum==tnum:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 4144
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int& i : a) cin >> i;

	double ave = 0;
	for (int i : a) ave += 1.0*i / n;

	double m = 114514810;
	int ans = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		double d = abs(a[i] - ave);
		if (m >= d) {
			m = d;
			ans = i;
		}
	}
	cout << ans << endl;
	int _; cin >> _;
}

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

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

Measured memory_bytes: 4836
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
num=[1]
M=10**9+7
for i in range(n):
    x=(num[i]*(i+1))%M
    num.append(x)
def inverse(number,mod):
    m=mod-2
    mod2=""
    while m!=0:
        if m%2==0:
            mod2="0"+mod2
        else:
            mod2="1"+mod2
        m=m//2
    two=[]
    for i in range(len(mod2)):
        if mod2[len(mod2)-1-i]=="1":
            two.append(i)
    ret=1
    for i in two:
        v=i
        retsub=number
        while v>0:
            retsub=retsub**2
            retsub=retsub%mod
            v-=1
        ret*=retsub
    ret=ret%mod
    return ret
def comb(p,q):
    ret1=num[p]
    ret2=inverse(num[p-q],M)
    ret3=inverse(num[q],M)
    ret=(ret1*ret2*ret3)%M
    return ret
#min
minsum=0
for i in range(n):
    if n-(i+1)>=k-1:
        minsum+=(a[i] * comb(n-i-1,k-1))%M
        minsum%=M
b=sorted(a,reverse=True)
#max
maxsum=0
for i in range(n):
    if n-(i+1)>=k-1:
        maxsum+=(b[i] * comb(n-i-1,k-1))%M
        maxsum%=M
print((maxsum-minsum)%M)


Measured memory_bytes: 65960
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,R = LI()
    print(R if N>=10 else R+100*(10-N))


main()



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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var h = long.Parse(Console.ReadLine());

        var k = 0L;
        var n = 1L;
        while (h > 0)
        {
            h = h ^ (h & 1);
            k += n;
            n *= 2;
            h /= 2;
        }
        
        Console.WriteLine(k);
    }
}


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

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int main() {
	ll n, a, b;
	 cin >> n;
	 vector <pair<ll, ll>> vec;
	 for(ll i = 0; i < n; i++)
	 {
	 	cin >> a >> b;;
	 	vec.push_back(make_pair(a, b));
	 }
	  sort(vec.begin(), vec.end(), sortbysec);
	  bool flag = true;ll sum = 0;
	  for(ll i = 0; i < n; i++)
	  {
	  	sum += (vec[i].first);
	  	if(sum > vec[i].second)
	  	flag = false;
	  }
	  
	  if(flag == true) cout << "Yes";
	  else cout << "No";
	// your code goes here
	return 0;
}

Measured memory_bytes: 6256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
const int N = 1e5 + 5;
int value[N], weight[N];
long long dp[105][N];
int main() {
	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		cin >> weight[i] >> value[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			if (weight[i - 1] > j) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
			}
		}
	}

	cout << dp[n][w];
	
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }

ll N, X;
vector<ll> city;

signed main()
{
    cin >> N >> X;
    city.assign(N, 0);
    REP(i, N) { cin >> city[i]; }
    SORT(city);

    ll ans = abs(city[0] - X);
    REP(i, N) {
        ans = gcd(ans, abs(city[i] - X));
    }
    printf("%lld\n", ans);

    return 0;
}


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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  vector<int> perfect(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    perfect[i] = (i+1)*100*p[i] + c[i];
  }
  int res = 100000;
  for (int bit = 0; bit < (1<<D); bit++) {
    int tmp_score = 0;
    int tmp_problems = 0;
    for (int i = 0; i < D; i++) {
      if (bit & (1<<i)) {
        tmp_score += perfect[i];
        tmp_problems += p[i];
      }
    }
    if (tmp_score >= G) res = min(res, tmp_problems);
    else {
      for (int i = D-1; i >= 0; i--) {
        if (!(bit & (1<<i))) {
          for (int j = 0; j < p[i]; j++) {
            if (tmp_score >= G) break;
            tmp_score += (i+1)*100;
            tmp_problems++;
          }
        }
      }
      res = min(res, tmp_problems);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,dp[500005],nxt[500005];
char s[500005];
int main()
{
	scanf("%d",&n);
	scanf("%s",&s);
	for(int i=1;i<=n;i++)dp[i]=500005;
	int s1=0;
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='1')s1++;
		if(s[i]=='0')nxt[i]=i;else if(i<n-1)nxt[i]=nxt[i+1];else nxt[i]=n;
	}
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='0')dp[i+1]=min(dp[i],dp[i+1]);
		else
		{
			dp[i+1]=min(dp[i]+1,dp[i+1]);
			if(nxt[i]==i+1)
				for(int j=i+2;j<n&&s[j]=='1';j++)dp[j+1]=min(dp[j+1],dp[i]+1);
			else
				if(nxt[i]<n&&s[nxt[i]+1]=='1')dp[nxt[i]+2]=min(dp[nxt[i]+2],dp[i]+1);
		}
	}
	printf("%d\n",s1-dp[n]);
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,i,d;
long long int a,c;
cin>>N;
    a=1;
    d=1e9;
    for(i=1;i<=N;i++){
        a=a*i;
        a=a%(d+7);
    }
c=a;
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
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; }

char alp[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
vector<string> answers;

void loop(string text, int num, int pos, int max, int max_use)
{
  text += alp[num];
  if (pos == max) {
    answers.push_back(text);
    return;
  } else {
    for (int i = 0; i < pos + 1; ++i) {
      if (i - max_use > 1) continue;
      loop(text, i, pos + 1, max, max_use < i ? i : max_use);
    }
  }
}

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

  loop("", 0, 1, n, 0);
  for (auto val : answers) {
    cout << val << endl;
  }

  return 0;
}


Measured memory_bytes: 7796
#include <stdio.h>
  int main(void)
  {
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int r = 0;
    for (int i =1; i <= n; i++)
    {
      int c = 0, t = i;
      for (int j = 0; j < 5; j++)c += t%10, t/=10;
      if (a <= c && c <= b)r += i;
    }
    printf("%d\n",r);
    return 0;
  }


Measured memory_bytes: 128
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	while(cin>>s,s!="#"){
		bool alphabet[26];
		loop(i,0,(int)('h'-'a'))alphabet[i]=0;
		loop(i,(int)('h'-'a'),(int)('q'-'a'))alphabet[i]=1;
		loop(i,(int)('q'-'a'),26){
			if(i==(int)('u'-'a')||i==(int)('y'-'a'))alphabet[i]=1;
			else alphabet[i]=0;
		}
		int cnt=0;
		rep(i,s.size()-1){
			if(alphabet[(int)(s[i]-'a')]!=alphabet[(int)(s[i+1]-'a')])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}


Measured memory_bytes: 3140