akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin>>n;
	int m=0,ans=0;
	for(int i=0;i!=n;++i){
		int k;
		cin>>k;
		ans+=k;
		if(k>m)
			m=k;
	}
	ans-=m/2;
	cout<<ans;
}

Measured memory_bytes: 256
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);

    if ($data[2] < 0 || $data[3] < 0) {
        echo "No" . PHP_EOL;
    } else {
        if ($data[2] + $data[4] <= $data[0] && $data[3] + $data[4] <= $data[1]) {
            echo "Yes" . PHP_EOL;
        } else {
            echo "No" . PHP_EOL;
        }
    }
}

Measured memory_bytes: 15392
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <fstream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

void solve(istream &input = cin, ostream &output = cout) {
  ll a, b, c;
  input >> a >> b >> c;
  if (a + b == c or a + c == b or b + c == a) {
    output << "Yes" << endl;
  } else {
    output << "No" << endl;
  }
}

int main() {
  solve();

  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    bool ok = false;
    rep(i,100)rep(j,100){
        if (i*4 + j*7 == n) {
            ok = true;
        }
    }
    cout << ((ok) ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {

  char b;
  cin >> b;
  
  if(b == 'A') cout << 'T' << endl;
  else if(b == 'T') cout << 'A' << endl;
  else if(b == 'C') cout << 'G' << endl;
  else cout << 'C' << endl;
  
}

Measured memory_bytes: 3632
let () =
  Scanf.scanf "%d %d %d" @@ fun n m q ->
  let lr = Array.init m (fun _ -> Scanf.scanf " %d %d" (fun x y -> x-1, y-1)) in
  let pq = Array.init q (fun _ -> Scanf.scanf " %d %d" (fun x y -> x-1, y-1)) in

  let co = Array.init n (fun _ -> Array.make n 0) in
  lr |> Array.iter (fun (l, r) -> co.(l).(r) <- co.(l).(r) + 1);

  for w = 1 to n-1 do
    for j = 0 to n-1-w do
      co.(j).(j+w) <- co.(j).(j+w) + co.(j+1).(j+w) + co.(j).(j+w-1);
      if w > 1 then co.(j).(j+w) <- co.(j).(j+w) - co.(j+1).(j+w-1);
    done
  done;

  pq |> Array.iter (fun (p, q) -> Printf.printf "%d\n" co.(p).(q))

Measured memory_bytes: 15872
#include<stdio.h>
int main(){
  long long a,b=1,c=1,n,i;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    c*=2-a%2;
    b*=3;
  }
  printf("%lld\n",b-c);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 2000000000
#define pb push_back
int N, M, P, a, b;
int t[10];
struct edge
{
	int to;
	double cost;
	edge(int to, double cost):to(to), cost(cost){}
};
vector<edge> g[40];
double dp[40][1<<8];
double rec(int v, int bit)
{
	if(dp[v][bit]!=-1)return dp[v][bit];
	double res = INF;
	for(int i=0; i<g[v].size(); i++)
	{
		int u = g[v][i].to;
		double cost = g[v][i].cost;
		for(int j=0; j<N; j++)
		{
			if(!((bit>>j)&1))
			{
				res=min(res, rec(u, bit|(1<<j))+cost/t[j]);
			}
		}
	}
	return dp[v][bit]=res;
}
int main()
{
	while(1)
	{
		for(int i=0; i<40; i++)g[i].clear();
		scanf("%d %d %d %d %d", &N, &M, &P, &a, &b);
		if(N==0&&M==0&&P==0&&a==0&&b==0)break;
		a--; b--;
		for(int i=0; i<N; i++)scanf("%d", &t[i]);
		for(int i=0; i<P; i++)
		{
			int x, y;
			double z;
			scanf("%d %d %lf", &x, &y, &z);
			x--; y--;
			g[x].pb(edge(y, z));
			g[y].pb(edge(x, z));
		}
		for(int i=0; i<M; i++)for(int j=0; j<(1<<N); j++)dp[i][j]=-1;
		dp[a][(1<<N)-1]=0;
		double ans = INF;
		for(int i=0; i<(1<<N); i++)ans = min(ans, rec(b, i));
		if(ans == INF)printf("Impossible\n");
		else printf("%f\n", ans);
	}
	return 0;
}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

bool IsPrime(int);

int fact(int x)          //defining the function
{
	int ans = 1;
  REPS(i, 2, x+1) {
    ans *= i;
  }
	return ans;
}

/***** MAIN *****/
signed main() {
  int n;
  int ans = 0;
  int tb, tf;
  string s;
  cin >> n;
  cin >> s;
  set<int> intSetF;
  REP(i, n) {
    tb = intSetF.size();
    intSetF.insert(s[i]);
    tf = intSetF.size();
    if(tb == tf) continue;
    set<int> intSetS;
    REPS(j, i+1, n) {
      tb = intSetS.size();
      intSetS.insert(s[j]);
      tf = intSetS.size();
      if(tb == tf) continue;
      set<int> intSetT;
      REPS(k, j+1, n) {
        intSetT.insert(s[k]);
      }
      ans += intSetT.size();
      // cout << ans << endl;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

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

int main(void) {
	int n, t, a;
	int ans, min_a, dist;

	cin >> n >> t;
	cin >> a;

	min_a = a;
	dist = -1;
	ans = 0;
	for (int i = 2; i <= n; ++i) {
		cin >> a;
		if (a - min_a > dist) {
			dist = a - min_a;
			ans = 1;
		}
		else if (a - min_a == dist) {
			++ans;
		}

		if (a < min_a)
			min_a = a;
	}

	cout << ans << '\n';
	return 0;
}


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

ll n,a,b,h[100005];

bool prov(long long t)
{
    ll ost=0;
    for(ll i=0;i<n;i++)
    {
        ll tr=h[i]-b*t;
        if(tr>0)
        {
            ll y=tr/(a-b)+((tr%(a-b))!=0);
            ost+=y;
        }
    }
    return ost<=t;
}

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

    cin>>n>>a>>b;
    for(ll i=0;i<n;i++)
        cin>>h[i];
    sort(h,h+n);

    ll levo=1,desno=1e10;
    while(levo<=desno)
    {
        ll tren=(levo+desno)/2;
        if(prov(tren))
            desno=tren-1;
        else
            levo=tren+1;
        //cout<<ind<<endl;
    }

    cout<<levo<<endl;

    return 0;
}


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

int main(){
  long long a,b;
  cin >> a >> b;
  if (a*b<=0){
    cout << "Zero" << endl;
  }
  else if(a>0){
    cout << "Positive" << endl;
  }
  else if(abs(b-a)%2==0){
    cout << "Negative" << endl;
  }
  else {
    cout << "Positive" << endl;
  }
}
      


Measured memory_bytes: 256
#include <stdio.h>
#define N 200000
typedef struct process{
	char name[11];
	int time;
}process;

process P[N];
int head = 0;
int bottom = 0;

void push(process x){
	P[head%N]= x;
	head++;
}
process pop(void){
	int d;
	d = bottom%N;
	bottom++;
	return P[d];
}

int main(int argc, char argv[]){
	int n;
	int q;
	int t=0;
	scanf("%d %d",&n,&q);
	process ins;

	int i;
	for(i=0;i<n;i++){
		scanf("%s %d",ins.name,&ins.time);
		push(ins);
	}

	while(head!=bottom){
		ins = pop();
		if(ins.time-q>0){
			ins.time -= q;
			push(ins);
			t += q;
		}else{
			t += ins.time;
			printf("%s %d\n",ins.name,t);
		}
	}

	return 0;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;
const ll INF = 1e17;

int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll a, b;
    cin >> a >> b;
    cout << 6 - a - b << endl;
	    
    return (0) ;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
using namespace std;

int jousu(int, int);
int jousu(int x, int y) {
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}
	return z;
}
int kurai(int x, int y) {
	int z = (x%jousu(10,y)) / jousu(10, y-1);
	return z;
}
int keta(int x) {
	int z = x;
	int w = 0;
	while (z != 0) {
		z /= 10;
		w++;
	}
	return w;
}


int main() {
	int n, b=0;
	string a;
	cin >> n;
	vector<string>vec3;
	map<string, int>map1;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (!map1.count(a)) {
			map1[a] = 1;
		}
		else {
			map1[a]++;
		}
	}
	for (auto p:map1) {
		if (b < p.second) {
			b = p.second;
		}
	}
	for (auto p:map1) {
		if (p.second == b) {
			vec3.push_back(p.first);
		}
	}
	sort(vec3.begin(), vec3.end());
	for (int i = 0; i < vec3.size(); i++) {
		cout << vec3[i] << endl;
	}
}

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

int main(){
    string s;
    int a,b;
    cin>>a>>b>>s;
    bool flag=true;
    for(int i=0;i<a;i++){
        int num=s[i]-'0';
        if(num<0||num>9)flag=false;
    }
    if(s[a]!='-')flag=false;
    for(int i=a+1;i<a+b+1;i++){
        int num=s[i]-'0';
        if(num<0||num>9)flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3588
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (llong (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include <iostream>
#include <vector>
using namespace std;
using llong = long long;

llong n, q;
vector<vector<int>> g;
vector<llong> cnt;
vector<llong> ans;

void dfs(int u, int par, llong c) {
    c += cnt[u];
    ans[u] = c;

    for (auto vs:g[u]) {
        if (vs == par) continue;
        dfs(vs, u, c);
    }
}

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

    g.resize(n + 1);
    cnt.resize(n + 1);
    ans.resize(n + 1);
    repeat(i, n - 1) {
        llong a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    repeat(i, q) {
        llong p, x;
        cin >> p >> x;
        cnt[p] += x;
    }

    dfs(1, 0, 0);

    repeat(i, 1, n + 1) {
        cout << ans[i] << ' ';
    }

    return 0;
};


Measured memory_bytes: 26632
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector< vector <int> >vee;
typedef vector<pair<int,int> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const ll N=1e5+5;
bool f;
ll n,arr[N],dp[N];
ll solve(ll i=0)
{
  if(i==n-1)return 0;
  ll &ret=dp[i];
  if(~ret)return ret;
   return ret=min(solve(i+1)+abs(arr[i]-arr[i+1]) ,i+2<n? solve(i+2)+abs(arr[i]-arr[i+2]):12345 );
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
   cin>>n;
   memset(dp,-1,sizeof dp);
   rep(i,n)
    cin>>arr[i];
   cout<<solve();

go;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 3030
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],sg[MAX];
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1;
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;}
void dfs(int u,int ff)
{
	sg[u]=0;
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff&&a[e[i].v]<a[u]){dfs(e[i].v,u);if(!sg[e[i].v])sg[u]=1;}
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	for(int i=1,u,v;i<n;++i)u=read(),v=read(),Add(u,v),Add(v,u);
	for(int u=1;u<=n;++u){dfs(u,0);if(sg[u])printf("%d ",u);}
	puts("");return 0;		
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int n,k,ans=0;

int get_sum(int l,int r)
{
	return (((l+r)*(r-l+1))/2ll)%mod;
} 
 
signed main()
{
	cin>>n>>k;
	for (int i=k;i<=n+1;i++)
    ans=(ans+((get_sum(n-i+1,n)-get_sum(0,i-1)+1)%mod+mod)%mod)%mod;
	cout<<ans%mod<<endl;
	
	return 0;
}

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

int main() {
  int n;
  std::cin >> n;
  int k;
  std::cin >> k;

  int len = 0;

  for (int i = 0; i < n; i++) {
    int j;
    std::cin >> j;
    len += std::min(j, k - j) * 2;
  }

  std::cout << len << std::endl;
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int t, d, l;
    cin >> t >> d >> l;
    if (t + d + l == 0) return 0;
    
    vector<int> x(t);
    for (int i = 0; i < t; i++) cin >> x.at(i);
    
    vector<int> imos(210000);
    for (int i = 0; i < t; i++) {
      if (x[i] >= l) {
        imos[i + 1]++;
        imos[i + 1 + d]--;
      }
    }
    
    for (int i = 1; i < 209999; i++) imos[i] += imos[i - 1];
    
    int ans = 0;
    for (int i = 1; i <= t - 1; i++) {
      if (imos[i] > 0) ans++;
    }
    
    cout << ans << '\n';
  }
}


Measured memory_bytes: 4376
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    if (A[0] > X) cout << A[0] - X << endl;
    else cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    if (A[i] + A[i - 1] > X) {
      ans += A[i] + A[i - 1] - X;
      A[i] -= A[i] + A[i - 1] - X;
      A[i] = max(0, A[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
"use strict";
function Main(input) {
    const div = (a, b) => Math.floor(a / b);
    let cin = new Inputer(input);
    let D = cin.getInt(), G = cin.getInt();
    let p = new Array(D), c = new Array(D);
    for (let n = 0; n < D; n++) {
        p[n] = cin.getInt();
        c[n] = cin.getInt();
    }
    let ans = 1e9;
    for (let mask = 0; mask < (1 << D); ++mask) {
        let s = 0, num = 0, rest_max = -1;
        for (let i = 0; i < D; ++i) {
            if (mask >> i & 1) {
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            } else rest_max = i;
        }
        if (s < G) {
            let s1 = 100 * (rest_max + 1);
            let need = div(G - s + s1 - 1, s1);
            if (need >= p[rest_max]) continue;
            num += need;
        }
        ans = Math.min(ans, num);
    }
    console.log(ans);
}
class Inputer{constructor(t){this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <numeric>
#include <map>
#include <utility>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    ll n,k,cnt=0;
    cin>>n>>k;
    rep(b,k+1,n+1)cnt+=(n/b)*(b-k)+(k?max((ll)0,n%b-k+1):n%b);
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec<pair<int, int>> p(N);
  //  vec<int> pRev(N);
  REP(i, N) {
    int q;
    cin >> q;
    p[i] = mp(q, i + 1);
  }
  sort(ALL(p));
  reverse(ALL(p));
  //    pRev[p[i]] = i;

  // p_k = q の場合、
  // q よりも大きい　q qよりも大きい。
  multiset<int> indexS;
  indexS.insert(0);
  indexS.insert(0);

  multiset<int> indexT;
  indexT.insert(N + 1);
  indexT.insert(N + 1);
  int cnt = 0;
  FORA(e, p) {
    int val = e.fst;
    int index = e.snd;

    auto itrS = indexS.upper_bound(-index);
    int s1 = -*itrS++;
    int s0 = -*itrS;

    auto itrT = indexT.upper_bound(index);
    int t1 = *itrT++;
    int t0 = *itrT;

    int tmpcnt = 0;
    tmpcnt += (s1 - s0) * (t1 - index);
    tmpcnt += (t0 - t1) * (index - s1);
    cnt += tmpcnt * (val);
    indexS.insert(-index);
    indexT.insert(index);
  }
  print(cnt);
}

Measured memory_bytes: 11264
# Union-Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n + 1)]

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return 0
        elif x < y:
            self.parents[y] = x
        else:
            self.parents[x] = y
        return 1

from collections import Counter
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.unite(a, b)
    
roots = []
for num in uf.parents:
    roots.append(uf.find(num))
roots.pop(0)

mn = Counter(roots)
print(len(mn)-1)

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

int main()
{
    string a, b, c;
    int x = 0, y = 0, z = 0;
    char next = 'a';
    cin >> a >> b >> c;
    while (true)
    {
        if (next == 'a')
        {
            next = a[x];
            x++;
            if (x == a.size() + 1)
            {
                cout << "A" << endl;
                break;
            }
        }
        else if (next == 'b')
        {
            next = b[y];
            y++;
            if (y == b.size() + 1)
            {
                cout << "B" << endl;
                break;
            }
        }
        else if (next == 'c')
        {
            next = c[z];
            z++;
            if (z == c.size() + 1)
            {
                cout << "C" << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    vector<int> a(n);

    for(int t=0;t<n;t++)
    {
        cin>>a[t];
        sum+=a[t];
    }
    sort(a.begin(),a.end());
    n+=(k-sum)/a[0];
    cout<<n<<'\n';
    
    return 0;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))

mn=min(al)+min(bl)

for i in range(m):
    price=0
    x,y,c=map(int,input().split())
    price=al[x-1]+bl[y-1]-c
    if mn>price:
        mn=price
print(mn)

Measured memory_bytes: 18736
#include<stdio.h>
void selection_sort(int a[], int n){
    for(int i = 0; i<n; i++){
        int mini = i;
        for(int j=i; j<n;j++){
            if(a[j] < a[mini]) mini = j;
        }
        //swap
        int temp = a[i];
        a[i] = a[mini];
        a[mini] = temp;
    }
}
int solve(int p, int t, int a[], int n){
	if(t==0) return 1;
	if(t<0) return 0;
	if(p>=n) return 0;
	//choose
	int l= solve(p+1,t-a[p],a,n);
	int r =  solve(p+1,t,a,n);
	
	return l+r;
}
int check(int b,int a[],int n){
	
	if(solve(0,b,a,n)) return 1;
	else return 0;
}


int main(){
	int n,m;
	scanf("%d",&n);
	int a[n+1];
	for(int i= 0; i<n; i++) scanf("%d",&a[i]);
	selection_sort(a,n);
	scanf("%d",&m);
	int b;
	for(int i= 0; i<m; i++){
		scanf("%d",&b);
		if(check(b,a,n))
			printf("yes\n");
		else printf("no\n");
	}
	
	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner in= new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n+1];
		int sent=1;char childs=0;
		
		A[1]=Integer.parseInt(in.next());
		for(int i=1;i<n;i++) {
			int key=Integer.parseInt(in.next());
			
			if(childs==0)A[sent*2]=key;
			else A[sent*2+1]=key;
			childs++;
			
			if(childs==2) {
				sent++;
				childs=0;
			}
		}
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=1;i<=n;i++) {
			out.printf("node %d: key = %d, ",i,A[i]);
			if(i!=1)out.printf("parent key = %d, ", A[i/2]);
			if(i*2<=n)out.printf("left key = %d, ", A[i*2]);
			if(i*2+1<=n)out.printf("right key = %d, ", A[i*2+1]);
			out.println();
		}
		out.flush();
	}

}



Measured memory_bytes: 30516
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N,K = list(map(int, input().split()))
        R,S,P = list(map(int, input().split()))
        T = input()
        
    else:
        A = 6
        for i in range(0,A,4):
            print(i)
    rsp = {}
    rsp["s"] = R
    rsp["p"] = S
    rsp["r"] = P
    rsp["n"] = 0
    
    NN = N if N % K == 0 else (N // K + 1) * K
    score = 0
    T = np.asarray(list(T + "n"*(NN-N))).reshape((NN//K,K))
    for k in range(K):
        tmp = ""
        t = T[:,k]
        #print(t)
        for tt in t:
            if tmp == tt:
                tmp = ""
                #print(k,tt)
            else:
                tmp = tt
                score += rsp[tt]
    print(score)
    



if __name__ =='__main__':
    main()

Measured memory_bytes: 14628
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(3*n);

  for (int i = 0; i < 3*n; i++){
    cin >> a[i];
  }

  //前半の大きいものを格納
  priority_queue<ll, vector<ll>, greater<ll>> Q1;
  vector<ll> m1(n + 1, 0);
  for (int i = 0; i < n; i++){
    Q1.push(a[i]);
    m1[0] += a[i];
  }

  // 後半の小さいものを格納
  priority_queue<ll> Q2;
  vector<ll> m2(n + 1, 0);
  for (int i = 0; i < n; i++){
    Q2.push(a[i + 2*n]);
    m2[n] += a[i + 2*n];
  }



  for (int i = 1; i <= n; i++){
    Q1.push(a[i + n - 1]);
    m1[i] = m1[i - 1] + a[i + n - 1] - Q1.top();
    Q1.pop();
  }

  for (int i = 1; i <= n; i++){
    Q2.push(a[2*n - i]);
    m2[n-i] = m2[n - i + 1] + a[2*n - i] - Q2.top();
    Q2.pop();
  }
 
  ll res = -INF;
  for (int i = 0; i <= n; i++){
    res = max(res, m1[i] - m2[i]);
  }
  cout << res << endl;



  return 0;
}


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

int main() {
	long long A[100][100], B[100][100], C[100][100];
	int n, m, l;
	cin >> n >> m >> l;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];



	for (int i = 0; i < m; i++)
		for (int j = 0; j < l; j++)
			cin >> B[i][j];



	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			C[i][j] = 0;
			for (int k = 0; k < m; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			if (j) cout << " ";
			cout << C[i][j];
		}
		cout << endl;
	}


	return 0;
}

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

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    
    double hourX, hourY, minuteX, minuteY;
    double hourRad, minuteRad;

    hourRad = 2 * M_PI / 12 * (h + m / 60);
    minuteRad = 2 * M_PI / 60 * m;

    hourX = a * cos(M_PI / 2 - hourRad);
    hourY = a * sin(M_PI / 2 - hourRad);
    minuteX = b * cos(M_PI / 2 - minuteRad);
    minuteY = b * sin(M_PI / 2 - minuteRad);

    double ans;
    ans = pow(hourX - minuteX, 2) + pow(hourY - minuteY, 2);
    ans = pow(ans, 0.5);

    cout << fixed<< setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,ans;
    double t,num=1e9,a;
    cin>>n>>t>>a;
    double h;
    for(int i=1;i<=n;i++){
        cin>>h;
        if(abs(t-h*0.006-a)<num){
            ans=i;
            num=abs(t-h*0.006-a);
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool dfs(ll x, ll y, ll cnt) {
    if (x == 0 and y == 1) return cnt % 2;
    if (x == 1 and y == 0) return cnt % 2;
    if (x == 1 and y == 1) return cnt % 2;
    bool ret;
    if (cnt % 2 == 0) {
        ret = false;
        rep(i, x / 2 + 1) if (i) { ret |= dfs(x - 2 * i, y + i, cnt + 1); }
        rep(i, y / 2 + 1) if (i) { ret |= dfs(x + i, y - 2 * i, cnt + 1); }
    } else {
        ret = true;
        rep(i, x / 2 + 1) if (i) { ret &= dfs(x - 2 * i, y + i, cnt + 1); }
        rep(i, y / 2 + 1) if (i) { ret &= dfs(x + i, y - 2 * i, cnt + 1); }
    }
    return ret;
}
int main() {
    ll x, y;
    cin >> x >> y;
    string ans;
    if (abs(x - y) < 2)
        ans = "Brown";
    else
        ans = "Alice";
    cout << ans << endl;
    return 0;
    rep(x, 20) {
        rep(y, 20) { cout << dfs(x, y, 1) << " "; }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static long[][] aa;
    static long maxx(int ind1,int ind2,int[] arr,int flag){
        if(ind1>=arr.length || ind2<0 || ind1>ind2){
            return 0;
        }
        if(ind1==ind2){
            return arr[ind1];
        }
        if(aa[ind1][ind2]!=-1){
            return aa[ind1][ind2];
        }
        //if(flag==0){
            return aa[ind1][ind2]=Math.max( -maxx(ind1+1,ind2,arr,1)+(long)arr[ind1],-maxx(ind1,ind2-1,arr,1)+(long)arr[ind2]  );
      //  }
//        else{
//            return aa[ind1][ind2][flag]=Math.min(maxx(ind1+1,ind2,arr,0),maxx(ind1,ind2-1,arr,0));
//        }


    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        int[] a=new int[n];
        long sum=0;
        for(int j=0;j<n;j++){
            a[j]= scanner.nextInt();
            sum=(long)((long)sum+(long)a[j]);
        }
        aa=new long[n][n];
        for(int j=0;j<n;j++){
            for(int i=0;i<n;i++){
               // for(int k=0;k<2;k++){
                    aa[j][i]=-1;
                //}
            }
        }
        //System.out.println(-(long)sum+(long)2*(long)maxx(0,n-1,a,0));
       System.out.println(maxx(0,n-1,a,0));
    }

}


Measured memory_bytes: 129132
use proconio::input;

fn main() {
    input! {
        h: usize,
        w: usize,
        mut cc: [[usize; 10]; 10],
        aa: [[isize; w]; h],
    }

    for k in 0..=9 {
        for i in 0..=9 {
            for j in 0..=9 {
                cc[i][j] = std::cmp::min(cc[i][j], cc[i][k] + cc[k][j]);
            }
        }
    }

    let mut ans = 0;

    for aa in aa {
        for a in aa {
            if a != -1 {
                ans += cc[a as usize][1];
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2412
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N, K = MI()
    A = LI()
    print((N+K-3)//(K-1))
    # a = min(A)
    # count = []

    # tmp = 0
    # for i in range(len(A)):
    #     if A[i] != a:
    #         tmp += 1
    #     else:
    #         count.append(tmp)
    #         tmp = 0

    # if tmp != 0:
    #     count.append(tmp)

    # print(count)

    # ans = 0
    # for c in count:
    #     # print(c, (K-1), math.ceil(float(c) / (K-1)))
    #     ans += math.ceil(float(c) / (K-1))
    # print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 78440
def haveCakes(cakes1, cakes2)
  if cakesNormalize(cakes1, cakes2) then
    if cakesHerf(cakes1, cakes2) then
      puts POSSIBLE
    else
      puts ERROR
    end
  else
    puts ERROR
  end
end

def cakesHerf(cakes1, cakes2)
  if cakes1 <= CAKEHARF && cakes2 <= CAKEHARF then
    return true
  else
    return false
  end
end

def cakesNormalize(cakes1, cakes2)
  if cakes1 < 0 && cakes1 > CAKEMAX && cakes2 < 0 && cakes2 > CAKEMAX 
    return false
  end
  if cakes1+cakes2 <= CAKEMAX then
    return true
  else return false
  end
end

input = gets
arr = input.split(" ")

CAKEMAX = 16
CAKEHARF = 8

POSSIBLE = "Yay!"
ERROR = ":("

cakes1 = arr[0].to_i
cakes2 = arr[1].to_i

haveCakes(cakes1, cakes2)


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

vector<pair<int,PII>> G[200010];
const int BASE = 100000;
const int INF = 2e9;

void Dijkstra(vector<PII>& d, int s){
  using Type = pair<PII,int>;
  priority_queue<Type, vector<Type>, greater<Type> > pq;
  fill(d.begin(), d.end(), MP(INF,INF));
  d[s] = MP(0,0);
  pq.push(Type(MP(0,0),s));

  while(!pq.empty()){
	Type pii = pq.top(); pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(unsigned int i=0;i<G[v].size();++i){
	  const PII& cost = G[v][i].SS;
	  int to = G[v][i].FF;
	  PII nxt(pii.FF.FF + cost.FF, pii.FF.SS + cost.SS);
	  if(d[to] > nxt){
		d[to] = nxt;
		pq.push(MP(d[to], to));
	  }
	}
  }
}

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

  int gid = 0;
  unordered_map<string,int> id;

  int N, T; cin >> N >> T;
  string A, B; cin >> A >> B;
  id[A] = gid++;
  id[B] = gid++;
  int tot = 0;
  REP(i,N){
	int m; cin >> m;
	VI xs(m), ts(m-1);
	REP(i,m){
	  string s; cin >> s;
	  if(!id.count(s)) id[s] = gid++;
	  xs[i] = id[s];
	}
	REP(i,m-1) cin >> ts[i];
	
	REP(i,m-1){
	  G[tot+i].PB(MP(tot+i+1, MP(ts[i], 0)));
	  G[tot+i+1].PB(MP(tot+i, MP(ts[i], 0)));
	}
	REP(i,m){
	  G[tot+i].PB(MP(xs[i]+BASE, MP(T, 1)));
	  G[xs[i]+BASE].PB(MP(tot+i, MP(0, 0)));
	}
	tot += m;
  }
  
  vector<PII> d(200010);
  Dijkstra(d, id[A]+BASE);
  PII ans = d[id[B]+BASE];
  if(ans.FF == INF)
	cout << -1 << endl;
  else
	cout << ans.FF-T << " " << ans.SS-1 << endl;

  return 0;
}

Measured memory_bytes: 26148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5,mod=1e9+7;
vector<ll>g[N];
ll a[N],n,sz[N],tmp=1; //a[i]表示以结点i为开始点对排列的影响。 
ll ksm(ll a,ll n){ //ksm(快速幂） 
	ll ans=1;
	while(n){
		if(n&1) ans=ans*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans;
}
void dfs(int u,int fa){
	sz[u]=1;
	for(auto v:g[u]){
		if(v!=fa){
			dfs(v,u);
			sz[u]+=sz[v];
		}
	}
	tmp=tmp*sz[u]%mod;//sz[ i ]的连乘 
}
void fun(int u,int fa){ //状态转移方程. 
	 for(auto v:g[u]){
	 	 if(v!=fa){
	 	 	 a[v]=a[u]*ksm(sz[v],mod-2)%mod*(n-sz[v])%mod;
			 fun(v,u);	
		  }
	 }
}
int main(){
	cin>>n; 
	ll jc=1;//jc ( 阶乘 ) 
	for(ll i=2,u,v;i<=n;i++){
		 cin>>u>>v;
		 g[u].push_back(v),g[v].push_back(u);
		 jc=jc*i%mod; 
	}
	dfs(1,0);
	a[1]=tmp;
	fun(1,0); 
		for(int i=1;i<=n;i++)
			printf("%lld\n",jc*ksm(a[i],mod-2)%mod);
	return 0;
} 

Measured memory_bytes: 17776
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e5+5;
int n,m,v,p,a[MAXN];
bool check(int pos)
{
	int dev=n-v,k=n-p;
	ll desum=0;
	for(int i=n;i>=1&&k;i--)
	{
		if (i==pos)
			continue;
		if (a[i]-a[pos]>m)
			return false;
		desum+=1LL*max(0,a[i]-a[pos]);
		--k;
	}
	return desum<=1LL*m*dev;
}
int main()
{
	cin>>n>>m>>v>>p;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r+1)/2;
		if (check(mid))
			l=mid;
		else
			r=mid-1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		long K=stdIn.nextLong();
		int A[]=new int[N];
		int key[]=new int[N*5];
		boolean visit[]=new boolean[N];
		int s=0,f=0,si=0,fi=0;
		for(int i=0;i<N;i++){
			A[i]=stdIn.nextInt()-1;
		}
		for(int i=0;;i++){
			if(i==K){
				System.out.println(key[i]+1);
				System.exit(0);
			}
			key[i+1]=A[key[i]];
			visit[key[i]]=true;
			if(visit[key[i+1]]){
				s=key[i+1];f=key[i];
				break;
			}
		}
		for(int i=0;i<N*5;i++){
			if(key[i]==s)
				si=i;
			if(key[i]==f){
				fi=i;
				break;
			}
		}
		int ans=fi-si+1;
		System.out.println(key[si+(int)((K-si)%ans)]+1);
	}
}


Measured memory_bytes: 65040
/*input
9 9
*/
/**
    Author: Kristopher Paul
    Date Created: 27-10-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int a,b;
    cin >> a >> b;
    int x = floor(log10(a));
    int y = floor(log10(b));
    if(x == y && x == 0){
        cout << a*b << endl;
    }else{
        cout << "-1" << endl;
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int a,b,c;
    cin >> a >> b >>c;
    int k;
    cin >> k;
    int cnt = 0;
    while(b<=a) b*=2,cnt++;
    while(c<=b) c*=2,cnt++;
    if(cnt<=k) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int dp[3003][3003];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s1,s2;
    cin >> s1 >> s2;
    int n = s1.length();
    int m  =s2.length();

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
   // cout<<dp[n][m]<<"\n";
    int i = n;
    int j = m;
    string ans="";
    while(i && j)
    {  
        if(s1[i-1] == s2[j-1])
        {
            ans=s1[i-1]+ans;
            i--;
            j--;
            continue;
        }
         if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        j--;

    }
    //reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";

}

Measured memory_bytes: 35456
MOD = 10**9 + 7
N, M = map(int, input().split())
stairs = [0]*(N+1)
for _ in range(M):
    stairs[int(input())] = 1
if N == 1:
    print(1)
    exit()
ans = [0]*(N+1)
ans[1] = 1 if stairs[1] == 0 else 0
ans[2] = 1 + ans[1] if stairs[2] == 0 else 0
for i in range(3,N+1):
    if stairs[i] == 1:
        ans[i] = 0
        continue
    ans[i] = (ans[i-1] + ans[i-2]) % MOD
print(ans[N])

Measured memory_bytes: 7668
/*
بسم الله الرحمن الرحيم
اللہ کے نام سے شروع جو بڑا مہربان اور نہایت رحم والا ہے
Allah in the name of The Most Affectionate, the Merciful
अल्लाह के नाम से जो दयालु और कृपाशील है

                            |		MD BAHAUDDIN aka Mujahid	|
                            |			NIT JAMSHEDPUR			|	
                            |		linkedin.com/in/bahau/		|
*/

//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<stack>
#include<queue>
#include<cstring>
#include<ctime>

using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define ll long long
#define ull unsigned ll
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(t,val) memset(t,val,sizeof(t));
#define f first
#define s second
#define FOR(i,k,n) for(int i=k; i<n; i++)
#define ROF(i,k,n) for(int i=k; i>=n; i--)
#define endl '\n'
#define mod 1000000007



int main()
{
    fastio;

    #ifndef ONLINE_JUDGE
    // input from input.txt
    freopen("input.txt", "r", stdin);
    // output to output.cpp
    freopen("output.cpp", "w", stdout);
    #endif

    int t=1; //cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll maxi=INT_MIN;
        maxi=max(c*b,b*d);
        maxi = max(maxi,a*d);
        maxi = max(maxi,a*c);

        cout<<maxi;
    }
    return 0;
} 







Measured memory_bytes: 3656
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  if a<=m:
  	lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)
  

Measured memory_bytes: 18468
"""
map(int,input().split())

X = input().split()
x = []
for i in range(0,len(X)):
    x.append(X[i])

"""
N,M,X,Y = map(int,input().split())

x = input().split()
xls = []

for n in range(0,N):
    xls.append(int(x[n]))

y = input().split()
yls = []

for n in range(0,M):
    yls.append(int(y[n]))

xls.sort()
yls.sort()

if xls[len(xls)-1] >= yls[0]:
    print("War")
elif yls[0] <= X:
    print("War")
elif xls[len(xls)-1] >= Y:
    print("War")
else:
    print("No War")


Measured memory_bytes: 3064
/**
 *   created: 04 July 2019  20:06:43
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n,d;
		cin>>n>>d;
		vector< vi> v(n,vi(d));
		rep(i,0,n){
			rep(j,0,d)
				cin>>v[i][j];
		}
		int cnt=0;
		rep(i,0,n){
			rep(j,i+1,n){
				int sum = 0;
				rep(k,0,d){
					sum += (v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
				}
				int temp = sqrt(sum);
				if(temp*temp==sum)
					cnt++;
			}
		}
		cout<<cnt;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int a, b, n;
    while (std::cin >> a >> b >> n) {
        int sum = 0;
        while (n--) {
            a *= 10;
            sum += (a / b) % 10;
            a %= b;
        }

        std::cout << sum << std::endl;
    }

    return 0;
}

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

typedef long long ll;
using namespace std;

const ll MAX = 9223372036854775807;

ll beki(ll a, ll b) {
  if(b == 0) return 1;
  ll ret = beki(a, b / 2);
  ret = ret * ret;
  if(b & 1) ret = ret * a;
  return ret;
}

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
  ll K;
  cin >> K;

  vector<ll> a;
  for (int i = 1; i <= 9; ++i) a.push_back(i);
  while(1) {
    if (K <= a.size()) {
      cout << a[K-1] << endl;
      return 0;
    }
    K -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; ++i) {
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        ll nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned int u;
u n,p,j[65000];
u solve(){
    u ans=p*n;
    for(u i=0;n>1;i++){
        ans=max(ans,(p+=j[i])*--n);
    }
    return ans;
}
int main(void){
    while(1){
        
        cin>>n;
        if(n==0)break;
        p=0;
        for(u i=0;i<n;i++){
            u pn;
            cin>>pn;
            p+=pn;
        }
        for(u i=0;i<n-1;i++){
            cin>>*(j+i);
        }
        sort(j,j+n-1,greater<u>());
        cout<<solve()<<endl;
    }
}

Measured memory_bytes: 3352