akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,m; cin >> n >> m;
  vector<int> ans(n,9);
  vector<bool> flag(n,false);
  
  rep(i,m){
    int s; cin >> s;
    int c; cin >> c;
    s--;
    if(flag[s] && ans[s] != c){
      cout << "-1" << endl;
      return 0;
    }
    flag[s]=true;
    if(ans[s]>c) ans[s] = c;
  }

  if(n!=1){
    if(flag[0] && ans[0]==0){
      cout << "-1" << endl;
      return 0;
    }
    if(!flag[0]) ans[0]=1;
    for(int i=1;i<=n;i++){
      if(!flag[i]) ans[i] = 0;
    }
  }
  else{
    if(!flag[0]) ans[0]=0;
  }

  double ret=0;
  for(int i=0;i<n;i++){
    ret+=ans[i]*pow(10,n-i-1);
  }
  cout << (int)ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if (L[i] != L[j] != L[k]) and (L[i] + L[j] > L[k]):
                ans += 1
print(ans)    

Measured memory_bytes: 67932
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

from collections import Counter

c = Counter(a)

ma1 = 0
ma2 = 0

for k,v in c.items():
    if v < 2:
        continue

    if k > ma1:
        if v >= 4:
            ma2 = k
            ma1 = k
            continue
        else:
            ma2 = ma1
            ma1 = k
    elif k > ma2:
        ma2 = k

print(ma1*ma2)


Measured memory_bytes: 18116
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 5;
 
int n;
vector<int> g[N];
int A, newA, lim;
 
int dfs(int u,int p) {
	multiset<int> ms;
	for (int v : g[u]) if (v != p) {
		ms.insert(dfs(v, u) + 1);
	}
	
	vector<int> rem;
	while (!ms.empty()) {
		multiset<int>::iterator it = ms.end();
		int x = *(--it);
		ms.erase(it);
		it = ms.upper_bound(lim - x);
		if (it == ms.begin()) rem.push_back(x);
		else ms.erase(--it), newA++; 
	}
	
	reverse(rem.begin(), rem.end());
	while (!rem.empty() && rem.back() == lim) newA++, rem.pop_back();
	if (rem.empty()) return 0;
	else { newA += rem.size() - 1; return rem[0]; }
}
 
bool check() {
	newA = 0;
	newA += dfs(1, 1) > 0;
	return newA == A;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n - 1; ++i) {
		int u, v; cin >> u >> v;
		g[u].push_back(v), g[v].push_back(u);
	}
	for (int i = 1; i <= n; ++i) {
		A += g[i].size() & 1;
	}
	A /= 2;
	int l = 1, r = n;
	while (l < r) {
		lim = l + r >> 1;
		if (check()) r = lim;
		else l = lim + 1;
	}
	cout << A << ' ' << l << '\n';
}

Measured memory_bytes: 20352
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int price =(int)(N/1.08);
        if((int)(price*1.08) != N){
          if((int)((price+1)*1.08) != N){
            if((int)((price-1)*1.08) != N){
              System.out.println(":(");
            }else{
              System.out.println(price-1);
            }
          }else{
            System.out.println(price+1);
          }
        }else{
          System.out.println(price);
        }
	}
}

Measured memory_bytes: 35756
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




struct P{
    ll a;
    char c;
    
    bool operator < (const P &p){
        return a<p.a;
    }
    
    bool operator > (const P &p){
        return a>p.a;
    }
};

void select_sort(vector<P> &A){
    for(int i=0;i<A.size();i++){
        ll mi=i;
        for(int t=i;t<A.size();t++){
            if(A[t]<A[mi]){
                mi=t;
            }
        }
        swap(A[i],A[mi]);
    }
}


void merge_sort(vector<P> &A){
    bool j=true;
    while(j){
        j=false;
        for(int i=0;i+1<A.size();i++){
            if(A[i]>A[i+1]){swap(A[i],A[i+1]); j=true;}
        }
    }
}


int main(){
    ll n;
    cin>>n;
    vector<P> A(n);
    vector<P> B(n);
    for(int i=0;i<n;i++){
        char c;
        ll a;
        cin>>c>>a;
        A[i]={a,c};
        B[i]={a,c};
    }
    merge_sort(A);
    select_sort(B);
    for(int i=0;i<A.size();i++){
        cout<<A[i].c<<A[i].a;
        if(i+1!=A.size()){cout<<" ";}
    }
    cout<<endl<<"Stable"<<endl;
    bool s=true;
    for(int i=0;i<B.size();i++){
        cout<<B[i].c<<B[i].a;
        if(i+1!=B.size()){cout<<" ";}
        if(B[i].c!=A[i].c){s=false;}
    }
    cout<<endl<<(s?"Stable":"Not stable")<<endl;
    
    
    
    
    return 0;
}




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

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n;
ll f[N], a[N], k;

bool ok(ll s) {
	ll usedSet = 0;
	for (int i = 1; i <= n; ++i) {
		ll maxAi = s / f[i];
		if (a[i] > maxAi) usedSet += a[i] - maxAi;
	}
	return usedSet <= k;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) cin >> f[i];
	sort(a + 1, a + n + 1); sort(f + 1, f + n + 1, greater<ll>());
	ll l = 0, r = 1e12, ans=1e12;
	while (l <= r) {
		ll m = (l + r) / 2;
		if (ok(m)) {
			ans = m;
			r = m - 1;
		}
		else l = m + 1;
	}
	cout << ans << endl;
}

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

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    double a,b;cin >> a >> b;
    printf("%0.5f\n",a/b);
    return 0;
}

Measured memory_bytes: 3788
N = int(input())
H = list(map(int, input().split()))

# 各足場までのコストの最小値のリスト
dp = [0] * N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]), dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])

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

namespace AtCoderBC043 {
  class AtCoderBC043 {
    static void Main(string[] args) {
      new AtCoderBC043().solveB();
    }
    private void solveB() {
      string s = Console.ReadLine();
      string res = "";
      for (int i=0;i<s.Length;i++){
        if (s[i] != 'B')
          res += s[i];
        else if (res.Length == 0)
          continue;
        else
          res = res.Remove(res.Length - 1);            
      }
      Console.WriteLine(res);
    }//end M.
  }
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

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

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int T;
ll a,b,c,d;
ll gcd(ll x,ll y){
    ll t;
    while(y){
        t=x%y;
        x=y;
        y=t;
    }
    return x;
}
int main()
{
	scanf("%d",&T);
	while(T--){
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(a<b||d<b){
			puts("No");
        }
        else if(c>=b){
            puts("Yes");
        }
        else if(b-gcd(b,d)+a%gcd(b,d)>c){
            puts("No");
        }
        else{
            puts("Yes");
        }
	}
}


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

#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
int N,K;
ll res;
vector<int> g[101010],ct;
void dfs(int idx,int p,int d){
  if(~p){
    res*=(ct[p]--)-min(d,2);
    res%=MOD;
  }
  for(auto e:g[idx])
    if(e-p)dfs(e,idx,d+1);
}
void solve(){
  int N,K;
  cin>>N>>K;
  rep(i,N-1){
    int a,b;
    cin>>a>>b;--a;--b;
    g[a].push_back(b);g[b].push_back(a);
  }
  ct.assign(N,K);res=K;dfs(0,-1,0);
  cout<<res<<endl;
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

template<class T> inline bool chmax(T &a, T b) {
    if(a<b) {
        a=b; return 1;
    } 
    return 0;
}

template<class T> inline bool chmin(T &a, T b) {
    if(a>b) {
        a=b; return 1;
    } 
    return 0;
}

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double ans;
    fix(10);
    ans=a*a+b*b-2*a*b*cos(M_PI*(6*m-(60*h+m)/2)/180);
    ans=sqrt(ans);
    
    cout<<ans<<endl;
}

Measured memory_bytes: 4228
#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>

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

using namespace std;

typedef unsigned long long ull;

#define TH(x) (((x)/180.0)*pi)

int main(){
  double a,b,c,d;
  const double r  = 6378.1;
  const double pi = M_PI;
  while(cin>>a>>b>>c>>d, (a!=-1 || b!=-1 || c!=-1 || d!=-1)){
    double x1,y1,z1,x2,y2,z2,ip,ang;
    a = TH(a); b = TH(b); c = TH(c); d = TH(d);

    x1 = cos(b) * cos(a);
    y1 = sin(b) * cos(a);
    z1 = sin(a);

    x2 = cos(d) * cos(c);
    y2 = sin(d) * cos(c);
    z2 = sin(c);

    ip  = x1*x2 + y1*y2 + z1*z2;
    ang = acos(ip);

    cout << (int)(floor(r*ang+0.5)) << endl;
  }
  return 0;
}

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

int main()
{
	int arr[10];
	int k;
	bool benar=false;
	memset(arr,0,sizeof(arr));
	for(int i=1;i<=5;i++)
	{
		cin >> arr[i];
	}
	cin >> k;
	for(int i=1;i<=5;i++)
	{
		for(int j=i;j<=5;j++)
		{
			if(abs(arr[i]-arr[j])<=k)
			{
				benar=true;
			}
			else
			{
				benar=false;
				cout << ":("<< endl;
				return 0;
			}
		}
	}
	if(benar==true)
	{
		cout << "Yay!"<< endl;
	}
}

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

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}
int main(void)
{
  ll n, k, ans;
  cin >> n >> k;
  vector<ll> D(k);
  RAP(i, k){
    cin >> D[i];
  }
  bool flag = false;
  ans = n;
  string s = to_string(n);
  while(!flag){
    RAP(i,k){
      if(s.find(to_string(D[i]))!=string::npos){
        ans++;
        s = to_string(ans);
        break;
      }else if(i==k-1){
        flag = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << end
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int x,a,b; cin>>x>>a>>b;
    x-=a;
    cout << x-(x/b)*b << endl;
}


Measured memory_bytes: 256
//49
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    char m[101];
    cin>>m;
    int a[100][2];
    for(int i=0;i<n;i++){
      cin>>a[i][0]>>a[i][1];
    }
    for(int i=n-1;i>=0;i--){
      for(int j=0;j<2;j++){
	m[a[i][j]-1]=((m[a[i][j]-1]-'a')+(a[i][1]-a[i][0]))%26+'a';
      }
      swap(m[a[i][0]-1],m[a[i][1]-1]);
    }
    cout<<m<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 1160
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<int> es[114514];
signed main(){
    string s;cin>>s;
    int key=0;
    rep(i,0,s.size()){
        if(s[i]=='g')key++;
    }
    int jud=(s.size()+1)/2;
    cout<<key-jud<<endl;
    return 0;
}


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

int main(){
  int N,A,count[N];
  int count_min=9999;
  cin >> N;

  for(int i=0;i<N;i++){
    count[i]=0;
    cin >> A;
    while(A%2==0){
      A=A/2;
      count[i]++;
    }
    if(count[i]<count_min){
      count_min=count[i];
    }
  }
  cout << count_min << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)

	digit := 1
	ans := 0
	for n := N; n >= 10 ; n /= 10 {
		if digit % 2 == 1 {
			ans += int(math.Pow(10, float64(digit)) - math.Pow(10, float64(digit - 1)))
		}
		digit++
	}

	if digit % 2 == 1 {
		ans += N - int(math.Pow(10, float64(digit - 1))) + 1
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n,s,sum,m=101;
int main(){
    cin>>n;
    while(n--){cin>>s;sum+=s;if(s%10)m=min(m,s);}
    cout<<(sum%10?sum:m!=101?sum-m:0)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

//        int[] a = new int[N];
        SortedSet<Integer> a = new TreeSet<>();
        for (int i = 0; i < N; i++) {
//            a[i] = sc.nextInt();
            a.add(sc.nextInt());
        }







        System.out.println(a.size());
    }
}


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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	// your code goes here
	int N=read();
	vector<int> A;
	REP(i,N) A.push_back(read());
	sort(A.begin(),A.end());
	for(int i=1;i<N;i+=2){
		REP(j,2){
			if(A.back()!=N-i){
				cout << 0;
				return 0;
			}
			A.pop_back();
		}
	}
	if(N%2!=0&&A.back()!=0){
		cout << 0;
		return 0;
	}
	int ans=1;
	REP(i,N/2) ans=(ans*2)%(1000000000+7);
	cout << ans;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++ i)
#define LL long long

int main()
{
  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  
  int dist = abs(b - a);
  int speed_diff = w - v;
  
  if (speed_diff >= 0)
  {
    cout << "NO";
    return 0;
  }
  else if ((double)dist / (double)abs(speed_diff) > (double)t)
  {
    cout << "NO";
    return 0;
  }
  else
  {
    cout << "YES";
    return 0;
  }
  
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n;
    cin>>n;
    ll num = 0, sum = 0;
    for(int i=0;i<n;i++)
    {
        ll d,c;
        cin>>d>>c;
        num += c;
        sum += d*c;
    }
    ll ans = (num-1 + (sum-1)/9);
    cout<<ans,nl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
const ull BASE = 1e9 + 7;

int d, n, m;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> d;
        if (d == 0) break;
        cin >> n >> m;
        vector<int> pos(n);
        rep(i, n - 1) cin >> pos[i + 1];
        pos.pb(d);
        sort(all(pos));
        pos.erase(unique(all(pos)), pos.end());
        ll ans = 0;
        rep(j, m) {
            int k;
            cin >> k;
            if (k == 0) continue;
            int pos1 = *lower_bound(pos.begin(), pos.end(), k);
            int pos2 = *(--lower_bound(pos.begin(), pos.end(), k));
            ans += min(abs(pos1 - k), abs(pos2 - k));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3904
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <stack>
#include <queue>
#include <numeric>
#include <cstring>

#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main(){
    int i;
    string in;
    vector<int> count;
   
    cin >> in;
    count.resize(4);
    
    rep(i, in.length()){
        if(in[i] == 'K') count[0]++;
        if(in[i] == 'U') count[1]++;
        if(in[i] == 'P') count[2]++;
        if(in[i] == 'C') count[3]++;
    }
    sort(count.begin(), count.end());

    cout << count[0] << endl;
}

Measured memory_bytes: 0
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -----------------------------------------------------------------------


// -----------------------------------------------------------------------


void solve(){
	int x;
	cin>>x;
	int arr[1005];
	for(int i=0;i<1005;++i)
	arr[i]=0;
	arr[1]=1;
	for(int i=2;i*i<=1000;++i){
		int res=i;
		for(int j=2;res<=1000;++j){
			res*=i;
			if(res>1000)
			break;
			arr[res]=1;
		}
	}
	for(int i=x;i>=1;--i)
	if(arr[i]){
		cout<<i;
		return ;
	}
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main(){
	int N;
	int K;
	string S;
	cin >> N;
	cin >> K;
	cin >> S;
	int c = S[K-1];
	S[K-1]=tolower(c);
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int y, m, d;
    scanf("%lld/%lld/%lld", &y, &m, &d);
    if (y < 2019 || (y == 2019 && m < 4) || (y == 2019 && m == 4 && d <= 30)) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
// ABC 110 C

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int gcd(int u, int v)
{
  return (v != 0) ? gcd(v, u % v) : u;
}

void dump(vector<int> a)
{
  for (auto v : a) {
    cerr << v << " ";
  }
  cerr << endl;
}

int main(int argc, char** argv) {
  int n, k;
  cin >> n >> k;

  vector<ll> pos;
  pos.reserve(n);
  vector<ll> neg;
  neg.reserve(n);

  rep(i, n) {
    int a;
    cin >> a;
    if (a == 0) {
      k--;
    } else if (a > 0) {
      pos.push_back(a);
    } else {
      neg.push_back(-a);
    }
  }

  if (k == 0) {
    cout << 0 << endl;
    return 0;
  }

  reverse(neg.begin(), neg.end());

  ll ans = INFL;

  // 右だけに行く
  if (pos.size() >= k) {
    ll tmp = pos[k-1];
    chmin(ans, tmp);
  }
  // 左だけに行く
  if (neg.size() >= k) {
    ll tmp = neg[k-1];
    chmin(ans, tmp);
  }

  // 右に行って折り返して左
  // 折り返す -> 距離が 2 倍
  int maxRight = min(int(pos.size()), k - 1);
  for (int i = 1; i <= maxRight; i++) {  // i: 右のろうそくを何本取るか
    if (neg.size() < k - i) {
      continue;
    }
    ll tmp = pos[i-1] * 2L;
    tmp += neg[k-i-1];
    chmin(ans, tmp);
  }

  // 左に行って折り返して右
  int maxLeft = min(int(neg.size()), k - 1);
  for (int i = 1; i <= maxLeft; i++) {  // i: 左のろうそくを何本取るか
    if (pos.size() < k - i) {
      continue;
    }
    ll tmp = neg[i-1] * 2L;
    tmp += pos[k-i-1];
    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    string s; cin >> s;
    for(auto c : s){
        char cc;
        if(c=='A') cc='T';
        if(c=='T') cc='A';
        if(c=='C') cc='G';
        if(c=='G') cc='C';
        cout << cc;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
l=[]
m=1000000
index=1001
for i in range(n):
  candidate=abs((t-h[i]*0.006)-a)
  if m > candidate:
  	index=i
  	m=candidate
  else:
    pass
print(index+1)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    sort(A, A+N, greater<int>());
    int sum = 0;
    for (int i=1; i<N; i++) sum += A[i];
    if (A[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

const int N=2e+5+5;
vector<int> adj[N];
long long int n;
long long int ans=0;

int main()
{
	cin>>n;
	for(long long int i=1;i<n;i++)
	{
		long long int u,v;
		cin>>u>>v;
		if(u>v)
			swap(u,v);
		ans=ans+(i*(i+1))/2-u*(n-v+1);
	}
	ans=ans+(n*(n+1))/2;
	cout<<ans;
	
}



Measured memory_bytes: 8244
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long[] arr = new long[110000];
        long sum = 0;
        for(int i =0;i<n;i++){
            long a = s.nextLong();
            arr[(int)a-1]++;
            sum+=a;
        }
//        System.out.println(Arrays.toString(arr));
        int q = s.nextInt();
        for(int i = 0;i<q;i++){
            long t = s.nextLong();
            long k =s.nextLong();
            long v1 = arr[(int)t-1];
//            int v2 = arr[k];
            arr[(int)t-1] = 0;
            arr[(int)k-1] += v1;
//            System.out.println(Arrays.toString(arr));
            sum += v1 * (k-t);
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 60800
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int dp[3010][3010] = {0};

int main(){
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) for (int j = 0; j < t.size(); j++){
		if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
		chmax(dp[i+1][j+1], dp[i+1][j]);
		chmax(dp[i+1][j+1], dp[i][j+1]);
	}
	string ans = "";
	int i = s.size(), j = t.size();
	while(i > 0 && j > 0){
		if(dp[i][j] == dp[i-1][j]) i--;
		else if(dp[i][j] == dp[i][j-1]) j--;
		else{
			i--; j--;
			ans = s[i] + ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35584
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

int run1(int H, int W, boost::multi_array<int, 2>const& data)
{
	const int shift = 12720;
	boost::multi_array<bool, 3> dp(boost::extents[H][W][2 * shift + 1]);
	dp[0][0][shift + data[0][0]] = true;
	dp[0][0][shift - data[0][0]] = true;
	for (auto i : boost::irange(0, H))
	{
		for (auto j : boost::irange(0, W))
		{
			for (auto v : boost::irange(0, 2 * shift + 1))
			{
				if (!dp[i][j][v])
				{
					continue;
				}
				if (i + 1 != H)
				{
					dp[i + 1][j][v + data[i + 1][j]] = true;
					dp[i + 1][j][v - data[i + 1][j]] = true;
				}
				if (j + 1 != W)
				{
					dp[i][j + 1][v + data[i][j + 1]] = true;
					dp[i][j + 1][v - data[i][j + 1]] = true;
				}
			}
		}
	}
	for (auto v : boost::irange(0, shift + 1))
	{
		if (dp[H - 1][W - 1][shift + v] || dp[H - 1][W - 1][shift - v])
		{
			return v;
		}
	}
	return shift + 1;
}

void Main()
{
	int H, W;
	std::cin >> H >> W;
	boost::multi_array<int, 2> data(boost::extents[H][W]);
	for (auto i : boost::irange(0, H))
	{
		for (auto j : boost::irange(0, W))
		{
			std::cin >> data[i][j];
		}
	}
	for (auto i : boost::irange(0, H))
	{
		for (auto j : boost::irange(0, W))
		{
			int b;
			std::cin >> b;
			data[i][j] -= b;
		}
	}
	
	std::cout << run1(H, W, data) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 159360
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int
main(int argc, char *argv[])
{
  int n;
  int a[100], b[100], c[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  for (int i = 0; i < n - 1; i++) scanf("%d", &c[i]);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[a[i] - 1];
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i] + 1 == a[i + 1]) ans += c[a[i] - 1];
  }

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

  return 0;
}

  
  
  


Measured memory_bytes: 128
#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(){
    string s;
    cin>>s;
    deque<char> st;
    rep(i, s.size()) st.push_back(s[i]);
    int Q;
    cin>>Q;
    int t, f;
    char c;
    int start=0;
    rep(i, Q){
        cin>>t;
        if(t==1){
            if(start==0) start=-1;
            else start=0;
        }
        if(t==2){
            cin>>f>>c;
            if(f==1){
                if(start==0) st.push_front(c);
                else st.push_back(c);
            }
            if(f==2){
                if(start==0) st.push_back(c);
                else st.push_front(c);
            }
        }
    }

    if(start==0){ 
        rep(i, st.size()){
            cout<<st[i];
        }
    }else{
        rep(i, st.size()){
            cout<<st[st.size()-i-1];
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 20050;
int p[MAXN];
int a[MAXN], b[MAXN];

int main() {
	int N;
	scanf("%d", &N);
	for(int i=0;i<N;i++)
		scanf("%d", &p[i]);
	a[1]=MAXN;
	for(int i=2;i<=N;i++) a[i]=a[i-1]+MAXN;
	b[N]=MAXN;
	for(int i=N-1;i>=1;i--) b[i]=b[i+1]+MAXN;
	for(int i=0;i<N;i++)
		a[p[i]]+=i;
	for(int i=1;i<=N;i++)
		printf("%d%c", a[i], " \n"[i==N]);
	for(int i=1;i<=N;i++)
		printf("%d%c", b[i], " \n"[i==N]);
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
 
using namespace std;

int main()
{
	float x=6.28318530717958623200;
	float k;
	scanf("%f",&k);
	printf("%.2f",k*x);
	return 0; 

 } 

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll a,b; cin>>a>>b; cout<<a/__gcd(a,b)*b<<"\n";
	return 0;
}

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

#define    ll     long long int

const int N = 200005;
pair<int, int> ara[N];
int order[N];
int araa[N];

int compare(pair<int, int> a, pair<int, int> b)
{
    return a.second < b.second;
}

int main( )
{
    int n, i, j, k, l;
    cin >> n;
    l = n / 2;
    for (i = 0; i < n; i++) {
        cin >> ara[i].first;
        ara[i].second = i;
    }
    sort(ara, ara + n);
    for (i = 0; i < n; i++) {
        order[ara[i].second] = i;
        araa[i] = ara[i].first;
    }
    sort(ara, ara + n, compare);
    for (i = 0; i < n; i++) {
        j = order[ara[i].second];
        if (j >= l) {
            cout << araa[l - 1];
        }
        else {
            cout << araa[l];
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>

int main()
{
    int decimalNumber = 0;
    std::cin >> decimalNumber;

    int baseCount = 0;
    std::cin >> baseCount;


    const auto digitCount = static_cast<int>(std::log10(decimalNumber) / std::log10(baseCount));
    std::cout << digitCount + 1;

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double PI=acos(-1);

signed main(){
    int A,B;
    cin>>A>>B;

    printf("%.20f\n",4.0/3.0*PI*B*B*B);
    return 0;
}



Measured memory_bytes: 3212
package main

import (
	"fmt"
)

const mod = 1000000007

func main() {
	var H, W, K int
	fmt.Scanf("%d%d%d", &H, &W, &K)
	dp := make([][]int, H+1)
	for i := 0; i <= H; i++ {
		dp[i] = make([]int, W+1)
	}
	cp := make([]int, W+1)
	cp[0] = 1
	cp[1] = 1
	for i := 2; i <= W; i++ {
		cp[i] = cp[i-1] + cp[i-2]
	}
	dp[0][1] = 1
	for i := 0; i < H; i++ {
		for j := 1; j <= W; j++ {
			if j >= 2 {
				dp[i+1][j-1] += dp[i][j] * cp[j-2] % mod * cp[W-j] % mod
				dp[i+1][j-1] %= mod
			}
			dp[i+1][j] += dp[i][j] * cp[j-1] % mod * cp[W-j] % mod
			dp[i+1][j] %= mod
			if j <= W-1 {
				dp[i+1][j+1] += dp[i][j] * cp[j-1] % mod * cp[W-j-1] % mod
			}
		}
	}
	fmt.Printf("%d\n", dp[H][K])
	return
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N;
    int A[214514],B[214514]={};
    map<int,int> M;
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    B[0]=0;
    REP(i,N){
        B[i+1]=B[i]+A[i];
    }
    
    REP(i,N+1){
        //cout << B[i] << " ";
        M[B[i]]++;
    }
    int Ans=0;
    REP(i,N+1){
        int R=M[B[i]];
        M[B[i]]=0;
        Ans+=R*(R-1)/2;
    }
    cout << Ans << endl;
    
    return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
 #define rep(i,n) for(int i=0;i<n;i++)
 using namespace std;
  int main(){
      string s;
      cin >> s;
      string ans;
      rep(i,s.size()){
          if(s[i]!='B'){
              ans.push_back(s[i]);
          }
          else{
              if(ans.size()==0)continue;
              else ans.pop_back();
          }
      }
      cout << ans << endl;
  }

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str;
	str[3]='8';
	cout<<str;





	cout<<endl;
} 


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    string s;
    cin>>s;
    
    int l=s.length();
    int j=0;
    
    for(char i='a';i<='z';i++){
        
        for(int k=0;k<l;k++){
            if(i==s[k]){
                j=1;
            }
        }
        
            if(j==0){
                cout<<i<<endl;
                return 0;
            }
            if(i=='z'){
                cout<<"None"<<endl;
                return 0;
            }
        
        j=0;
            
            
        }
        
        
        
    
   
    return 0;
}








Measured memory_bytes: 512
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll a,b;
int32_t main(){
CODE_START;
cin>>a;
cin>>b;
if(a<b){
    rc(0);
}else rc(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,A,B;
    cin >> N >> A >> B;
    vector<int>X(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i];
    }
    int ans = 0;
    for(int i = 1; i < N; i++) {
        ans += min(B,(X[i]-X[i-1])*A);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl


int main(){
  ll n,c;cin>>n>>c;
  ll ans=0,total;
  // 1-indexed
  vector<ll> x(n+1),v(n+1);
  rep(i,n){
    cin>>x[i+1]>>v[i+1];
  }
  vector<ll> sum(n+1);
  // 1-indexed
  FOR(i,1,n+1){
    sum[i]=sum[i-1]+v[i];
  }
  vector<ll> max_right(n+1);
  vector<ll> max_left(n+1);
  FOR(i,1,n+1){
    // 1-indexedでx_iまでの最大
    max_right[i]=max(max_right[i-1],sum[i]-x[i]);
    // 1-indexedでi個を使う時の最大
    max_left[i]=max(max_left[i-1],sum[n]-sum[n-i]-(c-x[n-i+1]));
  }

  for(int l=1;l<n+1;l++){
    total=sum[n]-sum[n-l]-2*(c-x[n-l+1])+max_right[n-l];
    ans=max(ans,total);
  }

  for(int r=1;r<n+1;r++){
    total=max_left[n-r]+sum[r]-2*x[r];
    ans=max(ans,total);
  }

  FOR(i,1,n+1){
    ans=max(ans,sum[n]-sum[n-i]-(c-x[n-i+1]));
    ans=max(ans,sum[i]-x[i]);
  }

  cout<<ans<<endl;
      
  return 0;
}

Measured memory_bytes: 4224
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n = int(input())
ns = defaultdict(set)
uv2e = {}
for i in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1,u-1] = i
    
m = int(input())
uvs = [None]*m
for i in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    uvs[i] = (u,v)
    
from queue import deque    
def bfs(start):
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    return seen

paths = [None]*m
for i,(u,v) in enumerate(uvs):
    seen = bfs(u)
    ss = set()
    z = v
    while z!=u:
        z1 = seen[z]
        ss.add(uv2e[z,z1])
        z = z1
    paths[i] = ss
    
ans = 0
def dfs(l, s):
    if len(l)==m:
        global ans
        val = pow(2, n-1-len(s)) * pow(-1, sum(l))
        ans += val
#         print(val, sum(l), ans)
        return
    dfs(l + [0], s)
    
    i = len(l)
    p = paths[i]
    dfs(l + [1], s|p)
    
dfs([], set())
# ans = pow(2,n-1) - ans
print(ans)

Measured memory_bytes: 75828
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long n;
    cin >> n;
    long sum=0, a[n];
    for (auto &ai:a) {
        cin >> ai;
        sum += ai;
    }
    long b = max(sum - n*(n-1), 0l), c = sum, k;
    for (k=b; k<=c; k++) {
        long step = 0;
        for (auto ai:a) {
            if ((ai + k) % (n + 1) == n) {
                step = -1;
                break;
            }
            if (ai + k >= n) 
                step += (ai + k - n) / (n + 1) + 1;
        }
        // cerr << k << ' ' << step << '\n';

        if (step == k) break;
    }
    cout << k << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
int a[200005];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=read();
	ll sum=0;
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1),sum=a[n];
	for(int i=n-1,t=n-2;i>=1;i--){
		if(t==0)break;
		if(t>=2)sum+=a[i]*2,t-=2;
		else {sum+=a[i];break;}
	}cout<<sum;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    rep(h, H) {
        rep(w, W) {
            if(S[h][w] == '#') {
                cout << '#';
            } else {
                ll ans = 0;
                if(w > 0 && S[h][w - 1] == '#') ans++;
                if(w < W - 1 && S[h][w + 1] == '#') ans++;
                if(h > 0 && S[h - 1][w] == '#') ans++;
                if(h < H - 1 && S[h + 1][w] == '#') ans++;
                if(h < H - 1 && w < W - 1 && S[h + 1][w + 1] == '#') ans++;
                if(h > 0 && w > 0 && S[h - 1][w - 1] == '#') ans++;
                if(h > 0 && w < W - 1 && S[h - 1][w + 1] == '#') ans++;
                if(h < H - 1 && w > 0 && S[h + 1][w - 1] == '#') ans++;
                cout << ans;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3612