akhauriyash/Code-Regression huggingface dataset:
INF = 1.0e+6
WHITE = 0
BLACK = 1

def dijkstras(M):
    n = len(M)
    d = [INF] * n
    color = [WHITE] * n

    d[0] = 0

    while True:
        minv = INF
        u = -1
        for i in range(n):
            if d[i] < minv and color[i] != BLACK:
                u = i
                minv = d[i]

        if u == -1:
            break

        color[u] = BLACK

        for v in range(n):
            if color[v] != BLACK and M[u][v] != INF:
                if d[v] > d[u] + M[u][v]:
                    d[v] = d[u] + M[u][v]

    for i in range(n):
        print("{} {}".format(i, -1 if d[i] == INF else d[i]))


if __name__ == "__main__":
    n = int(input())
    M = [[INF] * n for i in range(n)]

    for i in range(n):
        arr = list(map(int, input().split()))
        for j in range(arr[1]):
            M[arr[0]][arr[2+j*2]] = arr[3+j*2]

    dijkstras(M)



Measured memory_bytes: 5824
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

ave = sum(A)/N

d = [abs(a - ave) for a in A]
mi = min(d)

for i in range(N):
    if d[i] == mi:
        print(i)
        sys.exit(0)

sys.exit(0)


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

int main( void )
{
    int x, y;
    cin >> x >> y;
    int gr[ 13 ] = { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
    if ( gr[ x ] == gr[ y ] )
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
   
class Cube{
public:
 int f[6];
 Cube(){}
 void roll_z(){ roll(1,2,4,3);}
 void roll_y(){ roll(0,2,5,3);}
 void roll_x(){ roll(0,1,5,4);}
 void roll(int i,int j,int k,int l){
   int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
 }
};
   
int getRight( Cube c1,int f1,int f2 ){
 for(int i=0;i<6;i++){
   for(int j=0;j<4;j++){
     if( c1.f[0]==f1 && c1.f[1]==f2 ) return c1.f[2];
     c1.roll_z();
   }
   if( i%2 == 0 )c1.roll_y();
   else c1.roll_x();
 }
 return -1;
}
   
int main(){
 Cube c;
 int f1,f2;
 for(int i=0;i<6;i++)cin>>c.f[i];
 int q; cin>>q;
 for(int i=0;i<q;i++){
   cin>>f1>>f2;
   cout<<getRight(c,f1,f2)<<endl;
 }
 return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const ll mod = 1e9 + 7;
typedef pair<ll,ll>P;

int main(){

  int n;cin>>n;
  string s;cin>>s;

  vector<int>e(n+1,0);
  rep(i,0,n)e[i+1]=e[i]+(s[i]=='E');

  int mi=1000000;
  rep(i,0,n)mi=min((i-e[i])+(e[n]-e[i+1]),mi);

  out(mi);

  return 0;
}


Measured memory_bytes: 1796
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<long> s(A + 2), t(B + 2);
  long INF = 1e18;
  s[0] = -1 * INF;
  for (int i = 1; i <= A; i++)
    cin >> s[i];
  s[A + 1] = INF;
  t[0] = -1 * INF;
  for (int i = 1; i <= B; i++)
    cin >> t[i];
  t[B + 1] = INF;
  vector<long> ans(Q);
  for (int i = 0; i < Q; i++)
  {
    long x;
    cin >> x;
    int b = lower_bound(s.begin(), s.end(), x) - s.begin();
    int d = lower_bound(t.begin(), t.end(), x) - t.begin();
    int a = b - 1;
    int c = d - 1;
    long ans1 = min(abs(x - s[a]), abs(x - t[d])) + abs(s[a] - t[d]);
    long ans2 = min(abs(x - s[b]), abs(x - t[c])) + abs(s[b] - t[c]);
    long ans3 = min(abs(x - s[a]), abs(x - t[c])) + abs(s[a] - t[c]);
    long ans4 = min(abs(x - s[b]), abs(x - t[d])) + abs(s[b] - t[d]);
    ans[i] = min(min(ans1, ans2), min(ans3, ans4));
  }
  for (int i = 0; i < Q; i++)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << endl;
	else if (b == c) cout << a << endl;
	else cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
/* Bubble Sort */
#include<stdio.h>
main(){
  int A[101];
  int n,i,j,temp,times=0;

  scanf("%d",&n); /* This n is length of array.*/
  if(n<1||n>100)return 0; /* Constraints: 1<= n <=100 */

  for(i=1;i<=n;i++){ 
    scanf("%d",&A[i]);
  }
  /* Bubble Sort */
  for(i=1;i<=n;i++){
    for(j=n;j>i;j--){
      if(A[j]<A[j-1]){
	temp=A[j];
	A[j]=A[j-1];
	A[j-1]=temp;
	times++;  /* This times is number of swap operations. */
      }
    }
  }
  
  for(i=1;i<n;i++){
    printf("%d ",A[i]); 
  }
  printf("%d\n",A[i]);
  printf("%d\n",times);
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  if (a % 2 == 0 ||b % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll N, M;
    cin >> N >> M;
    vl a(M);
    map<int, bool> broken;
    FOR(i, 0, M) {
        cin >> a[i];
        broken[a[i]] = true;
    }
    ll DP[N + 1] = {0};
    DP[0] = 1;
    DP[1] = (ll)!broken[1];
    FOR(i, 2, N + 1) {
        if (!broken[i]) {
            DP[i] = DP[i - 1] + DP[i - 2];
            DP[i] %= INF;
        }
    }
    cout << DP[N] << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

void pre(){

}

void solve(){
  ll a,b,c,k; cin>>a>>b>>c>>k;
  ll sum=0;
  ll temp;
  temp=min(a,k);
  sum+=temp;
  k=k-temp;
  temp=min(b,k);
  k=k-temp;
  temp=min(c,k);
  sum-=temp;
  cout<<sum<<"\n";
}

int main(){
  #ifndef ONLINE_JUDGE
    // freopen("in.txt","r",stdin);
  #endif
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int x;
    int y;
    int a;
    int b;
    int c;
    vector<LL> p;
    vector<LL> q;
    vector<LL> r;
    vector<LL> pqr;
    LL ans=0;
    LL tmp_p;
    LL tmp_q;
    LL tmp_r;
    cin >> x >> y >> a >> b >> c;
    for(int i=0; i<a; i++){
        cin >> tmp_p;
        p.push_back(tmp_p);
    }
    for(int i=0; i<b; i++){
        cin >> tmp_q;
        q.push_back(tmp_q);
    }
    for(int i=0; i<c; i++){
        cin >> tmp_r;
        r.push_back(tmp_r);
    }

    sort(p.begin(), p.end(), greater<LL>());
    sort(q.begin(), q.end(), greater<LL>());
    for(int i=0; i<x; i++){
        pqr.push_back(p[i]);
    }
    for(int i=0; i<y; i++){
        pqr.push_back(q[i]);
    }
    for(int i=0; i<c; i++){
        pqr.push_back(r[i]);
    }
    sort(pqr.begin(), pqr.end(), greater<LL>());

    for(int i=0; i<x+y; i++){
        ans+=pqr[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int n, k; cin >> n >> k;
    int q; cin >> q;
    vector<int> point(n, k - q);
    for (int i = 0; i < q; i++) {
        int a; cin >> a; a--;
        point[a]++;
    }
    for (int i = 0; i < n; i++) {
        cout << (point[i] > 0 ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

map <pii, ll> mp;
set <pii> s;
int main()
{
	boost;
	int n, d, a, i;
	cin >> n >> d >> a;
	pii arr[n];
	fo(i, 0, n)
	cin >> arr[i].f >> arr[i].s;
	sort(arr, arr + n);
	
	ll curr = 0;
	ll ans = 0;
	fo(i, 0, n) {
		pii p = arr[i];
		while(!s.empty()) {
			auto it = s.begin();
			if(it -> s >= p.f) break;
			
			curr -= mp[*it]; 
			mp[*it] = 0;
			s.erase(it);
		}
		if(curr >= p.s) continue;
		p.s -= curr;
		
		int cnt = (p.s % a ? p.s / a + 1 : p.s / a);
		ans += cnt;
		pii seg = {p.f, p.f + 2 * d};
		mp[seg] = 1ll * cnt * a;
		curr += mp[seg];
		s.insert(seg);
	}
	cout << ans;	
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define maxn 200010
using namespace std;
int n;
int main()
{
    cin>>n;n++;vector<int> vec(n+1),b(n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&vec[i]);
	}
	ll ans=0;
	for(int i=1;i<n;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>=(vec[i]+vec[i+1]))
		{
			ans+=(vec[i]+vec[i+1]);
			vec[i]=0,vec[i+1]=0;
		}
		else if(b[i]>=vec[i])
		{
			ans+=b[i];b[i]-=vec[i];
			vec[i]=0;vec[i+1]-=b[i];b[i]=0;
		}
		else
		{
			ans+=b[i];vec[i]-=b[i];
		}
		//cout<<ans<<endl;
	} 
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for (int loop = 0; loop < n; loop++) {
            String train = scan.next();
            HashSet<String> set = new HashSet<String>();
            int len = train.length();
            for (int i = 1; i < len; i++) {
                String front = train.substring(0,i);
                String rear = train.substring(i);
                String r_front = 
                    new StringBuffer(front).reverse().toString();
                String r_rear = 
                    new StringBuffer(rear).reverse().toString();
                set.add(front.concat(rear));
                set.add(front.concat(r_rear));
                set.add(r_front.concat(rear));
                set.add(r_front.concat(r_rear));
                set.add(rear.concat(front));
                set.add(rear.concat(r_front));
                set.add(r_rear.concat(front));
                set.add(r_rear.concat(r_front));
            }
            System.out.println(set.size());
        }
    }
}

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

signed main(){
  string S;
  cin>>S;
  string SS[20] = { "KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA" };
  string ans="NO";
  rep(i,20){
    if(S==SS[i]){
      ans="YES";
      break;
    }
  }
  cout<<ans<<endl;
}

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

int hh[1000*1500+1];
int ww[1000*1500+1];

int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<int> h(n);
    vector<int> w(m);
    memset(hh,0,sizeof(hh));
    memset(ww,0,sizeof(ww));
    int _max = 0;
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=0;i<m;i++) cin>>w[i];
    for(int i=0;i<n;i++){
      int sum = 0;
      for(int j=i;j<n;j++){
	sum += h[j];
	hh[sum]++;
	_max = max(_max,sum);
      }
    }

    for(int i=0;i<m;i++){
      int sum = 0;
      for(int j=i;j<m;j++){
	sum += w[j];
	ww[sum]++;
	_max = max(_max,sum);
      }
    }
    
    int sum = 0;
    for(int i=0;i<=_max;i++){
      if(ww[i]!=0 && hh[i]!=0){
	sum += (hh[i]*ww[i]);
      }
    }
    cout<<sum<<endl;

  }
  return 0;
}

Measured memory_bytes: 12932
// AOJ CGL_2_C Cross Point
// 2018.5.2 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;

#define INF			1e8
#define EPS			1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)
#define PPeQ(a,b)	(EQ(a.x,b.x)&&EQ(a.y,b.y))

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
PP vmul(PP p1, PP p2) { PP r;
	r.x = p1.x * p2.x - p1.y * p2.y, r.y = p1.x * p2.y + p1.y * p2.x; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return hypot(p1.x-p2.x, p1.y-p2.y); };
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }
PP dir(SEG s) { return vsub(s.e, s.s); }

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

PP crossPointSS(SEG s1, SEG s2)
{
	double n, d;
	n = cross(vsub(s2.s, s1.s), dir(s2));
	d = cross(dir(s1), dir(s2));
	return vadd(s1.s, vsmul(dir(s1), n/d));
}

int main()
{
	int q, x, y;
	PP p0, p1, p2, p3, ans;
	SEG s1, s2;

	q = in();
	while (q--) {
		x = in(), y = in(), p0 = vset(x, y);
		x = in(), y = in(), p1 = vset(x, y);
		x = in(), y = in(), p2 = vset(x, y);
		x = in(), y = in(), p3 = vset(x, y);
		s1.s = p0, s1.e = p1;
		s2.s = p2, s2.e = p3;
		ans = crossPointSS(s1, s2);
		printf("%.10lf %.10lf\n", ans.x, ans.y);
	}
	return 0;
}



Measured memory_bytes: 2124
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,sj,x,y;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>sj>>x>>y;
		sj-=x+y;
		if(sj<0||sj%2==1)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

int main()
{
    int l, r, d, x, y;

    cin >> l >> r >> d;

    x=l/d;
    y=r/d;

    if(l%d==0)
        cout << y-x+1 << endl;
    else
        cout << y-x << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int main(){
	ll ans=0;
	ll l,r,d;
	cin>>l>>r>>d;
	for(ll i=l;i<=r;i++){
		if(i%d==0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3588
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
p.reverse()
q.reverse()
p=p[:X]
q=q[:Y]
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
sum=0
for i in range(X+Y):
  sum+=a[i]
print(sum)

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,c;
	cin>>n>>c;
	vector<ll> x(n+2),v(n+2),sum1(n+2,0),sum2(n+2,0);
	vector<ll> sum3(n+2,0),sum4(n+2,0);
	FOR(i,1,n+1){
		cin>>x[i]>>v[i];
		sum1[i]=sum1[i-1]+v[i];
		sum3[i]=max(sum3[i-1],sum1[i]-2*x[i]);
	}
	x[0]=0,x[n+1]=c;
	for(int i=n;i>=1;i--){
		sum2[i]=sum2[i+1]+v[i];
		sum4[i]=max(sum4[i+1],sum2[i]-2*(c-x[i]));
	}
	ll ans=0;
	rep(i,n+2){//出る位置の全探索
		if(i!=n+1) chmax(ans,sum4[i+1]+sum1[i]-x[i]);
		if(i) chmax(ans,sum3[i-1]+sum2[i]-(c-x[i]));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<set>
using namespace std;
int res,start[100],endd[100],n,m;
int pass(int k,int in,set<int> a){
	int num;
	if(k==n){
//		cout<<"@#@"<<endl;
		res++;
		return 0;
	}
	for(int i=0;i<m*2;i++){
//		cout<<"k:"<<k<< "i:"<<i<<" start:"<<start[i]<<" end:"<<endd[i]<<endl;
		set<int> b=a;
		if(start[i]==in&&a.count(endd[i])==0){
			b.insert(in);
			pass(k+1,endd[i],b);
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	set<int> a;
	a.insert(1);
	for(int i=0;i<m;i++){
		cin>>start[i*2]>>endd[i*2];
		start[i*2+1]=endd[i*2];
		endd[i*2+1]=start[i*2];
	}
	pass(1,1,a);
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m,a,b,c,d;

	cin >> a >> b >> c >> d;

	x=0;
	while(1)
	{
		if(x%2==0)
		{
			c-=b;
			if(c<=0)
			{
				cout<<"Yes"<<endl;
				break;
			}
		}
		else
		{
			a-=d;
			if(a<=0)
			{
				cout<<"No"<<endl;
				break;
			}
		}
		x++;
	}
}

Measured memory_bytes: 3652
a, b = gets.split.map(&:to_i)
a1 = (a * 12.5).ceil.to_i
a2 = ((a + 1) * 12.5).to_i
b1 = b * 10
b2 = (b + 1) * 10
r = -1
(a1...a2).each do |i|
  if (b1...b2).include?(i)
    r = i
    break
  end
end
puts r

Measured memory_bytes: 3836
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M, K = LI()

    ans = 'No'
    for i, j in itertools.product(range(N + 1), range(M + 1)):
        if i * j + (N - i) * (M - j) == K:
            ans = 'Yes'
            break

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10084
#include <iostream>

#include <deque>

#include <stdio.h>

#include <cstdio>

#include <algorithm>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "
#define nw <<"\n"
#define ca "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define ull unsigned LL
#define check cout<<"* ";
#define show_vector for(int q=0;q<v.size();q++){cout<<v[q]<<" ";}
#define REP(i,n) for (int i=0;i<(n);++i)
#define N_MAX 26


const int inf=1<<30;
const long long int INF=1e10;
const int MOD=1e9+7;
const int maxn = 1e5+10;
int a[200005],b[1000005];

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
/*
int ck_prime(int n)
{
    int coun;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
           return 1; // n is prime
        }
    return 0;
}
*/
int main()
{
    int n,z,sum=0;
    cin>>n;
    vector<int>order;
    vector<int>extra;
    for(int i=1;i<=n;i++){
        cin>>z;
        order.pub(z);
    }
    order.pub(0);
    for(int i=1;i<=n;i++){
       cin>>z;
       sum+=z;
    }
    for(int i=1;i<n;i++){
        cin>>z;
        extra.pub(z);
    }

    for(int i=0;i<n;i++){
        int x=order[i];
        int y=x+1;

        if(order[i+1]==y){
            sum+=extra[x-1];
        }
    }
    cout<<sum nw;
}



Measured memory_bytes: 3576
import math

n = int(input())
x =list(map(float,input().split()))
y =list(map(float,input().split()))

D1=[]
D2=[]
D3=[]
for i in range(n):
    D1.append(abs(x[i]-y[i]))
    D2.append((x[i]-y[i])**2)
    D3.append((abs(x[i]-y[i]))**3)

print(sum(D1))
print(math.sqrt(sum(D2)))
print(math.pow(sum(D3),(1/3)))
print(max(D1))



Measured memory_bytes: 5716
//k_tourist
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 500005
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<ll, pl>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
 
bool isp[mx];
 
void sv(){
 
	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void bta_de_yarr(){
    
	sv();
    vl vec;
    ll i,j;
    rep(i, 2, mx)
    if(isp[i])
    vec.pb(i);

    ll a;
    cin>>a;
    auto ans= lb(all(vec), a);
    cout<<(*ans);
	
	cout<<endl;
}

int main(){
    fst
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> v(n), c(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> c[i];
	}
	int ans = 0;
	for (int i = 0; i < (1LL << n); ++i)
	{
		int k = 0, x = 0, y = 0;
		for (int j = i; j > 0; j >>= 1)
		{
			//cout << k << endl;
			if (j & 1)
			{
				x += v[k];
				y += c[k];
			}
			k++;
		}
		ans = max(x - y, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if ((b - a) == (c - b))
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 22996
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int N, K;
vector<vector<int> >to;
int res = 0;
int dfs(int b,int lev) {
	int ret = 0;
	for (int i = 0; i < to[b].size(); i++) {
		ret = max(ret, dfs(to[b][i],lev+1));
	}
	if (ret == K-1) {
		if (lev > 1) {
			res++;
		}
		return 0;
	}
	return ret + 1;
}
int main() {
	cin >> N >> K;
	to.resize(N);
	int a;
	cin >> a;
	if (a != 1) {
		res++;
	}
	for (int i = 1; i < N; i++) {
		cin >> a;
		a--;
		to[a].push_back(i);
	}

	dfs(0, 0);

	cout << res << endl;
		
	return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

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

  int i=0, acc=0;
  while(acc<n){ acc += i++;}
  i--;

  cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define All(a) (a).begin(),(a).end()
#define clr(a) memset((a),0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(b);--i)
#define FOR_edge(i,u)  for(int i=hd[u];i;i=e[i].nxt)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

inline char in() {
	static char buf[10001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;
	register bool neg=0;
	register char c;
	while(!isdigit(c=in())) if(c=='-') neg=1;
	while(s=(s<<3)+(s<<1)+c-48,isdigit(c=in()));
	s=(neg?-s:s);
}
template <class Tp> inline void write(register Tp x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
template <class Tp> inline void print(const Tp &x,const char &end) {write(x); putchar(end);}
template <class Tp> inline Tp pow(register Tp x,register Tp p,const Tp &mod) {
	register Tp res=1;
	for(;p;p>>=1,x=(x*x)%mod) if(p&1) res=(res*x)%mod;
	return res;
}
inline int comp(const double &x,const double &y) {
	const double d=x-y,eps=1e-8;
	return (d<=eps&&d>=-eps)?0:(d>eps?1:-1);
}
template <class Tp> inline Tp sqr(const Tp &x) {return x*x;}
template <class Tp> inline Tp gcd(const Tp &x,const Tp &y) {return(y==0?x:gcd(y,x%y));}
template <class Tp> inline Tp inv(const Tp &x,const Tp &MOD) {return POW(x,MOD-2,MOD);}
template <class Tp> inline Tp lowbit(const Tp &x) {return x&-x;}

string s,t;
int main() {
	cin>>s>>t;
	if(s==t) return puts("Yes"),0;
	int n=s.size();
	for(int i=1;i<=n;++i) {
		char c=s[0];
		s.erase(s.begin(),s.begin()+1);
		s.insert(s.end(),c);
		if(s==t) return puts("Yes"),0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
	int x, n;
	cin >> x >> n;
	vector<bool> vec(101,true);
	for(int i=0; i<n; i++){
		int p; cin >> p;
		vec[p] = false;
	}
	int dx = 0;
	int ans;
	while(1){
		if(x-dx < 0){
			ans = x-dx;
			break;
		}
		else if(vec[x-dx]){
			ans = x-dx;
			break;
		}
		else if(x+dx > 100){
			ans = x+dx;
			break;
		}
		else if(vec[x+dx]){
			ans = x+dx;
			break;
		}
		dx++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
using System;

class Tester
{
    static void Main()
    {
        int a, b = 0;

        for(int i=0;i<3000;i++)
        {
            string x = Console.ReadLine();
            string[] result;

            const char Space = ' ';
            char[] delimiters = new char[] { Space };
            result = x.Split(delimiters);

            a = int.Parse(result[0]);
            b = int.Parse(result[1]);

            if (a == 0 && b == 0)
            {
                Environment.Exit(0);
            }

            int small, large;
            if (a < b)
            {
                small = a;
                large = b;
            }
            else
            {
                small = b;
                large = a;
            }
            Console.WriteLine("{0} {1}", small, large);
        }
    }
}


Measured memory_bytes: 17904
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        int idx = 0;
        int ans = 0;
        while (idx != -1) {
            idx = s.indexOf("ABC", idx);
            if (idx != -1) {
                ans++;
                s = s.substring(idx + 3);
                idx = 0;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	int n;
	while(cin>>n){
		bool flg=false;
		rep(i,10){
			if(1&(n>>i)){
				if(flg) cout<<' ';
				cout<<pow(2,i);
				flg=true;
			}
		}
		cout<<endl;
	}
    return 0;
}

Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n, d;
  cin >> n >> d;
  
  int r;
  r = n / (2 * d + 1);
  
  if( n % (2 * d + 1) != 0)
    cout << r + 1 << endl;
  else
    cout << r << endl;
}

Measured memory_bytes: 256
#C-snack

def saidaikouyakusu(a,b):
    if a%b==0:
        return b
    else:
        return saidaikouyakusu(b,a%b)

a,b=[int(x) for x in input().split()]

if a<b:
    tmp=a
    a=b
    b=tmp

ans=int(a*b/saidaikouyakusu(a,b))

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	char a, b;
	cin >> a >> b;
	int s = a - 'A', t = b - 'A';
	vector<string> v(h);
	REP(i, h)cin >> v[i];
	vvi g(26);
	vector<pii> p(26, { -1,-1 });
	REP(i, h) {
		REP(j, w) {
			if (isalpha(v[i][j]) && v[i][j] != 'o') {
				p[v[i][j] - 'A'] = { i,j };
				
			}
		}
	}
	REP(i, 26) {
		if (p[i].first == -1)continue;
		REP(k, 4) {
			int ni = p[i].first + dx[k * 2] * 2, nj = p[i].second + dy[k * 2] * 2;
			if (ni < 0 || nj < 0 || ni >= h || nj >= w)continue;
			if (dx[k * 2] == 0) {
				if (v[ni][nj] == '-') {
					while (v[ni][nj] != 'o') {
						ni += dx[k * 2];
						nj += dy[k * 2];
					}
					ni += dx[k * 2];
					nj += dy[k * 2];
					int j = v[ni][nj] - 'A';
					g[i].push_back(j);
					g[j].push_back(i);
				}
			}
			else {
				if (v[ni][nj] == '|') {
					while (v[ni][nj] != 'o') {
						ni += dx[k * 2];
						nj += dy[k * 2];
					}
					ni += dx[k * 2];
					nj += dy[k * 2];
					int j = v[ni][nj] - 'A';
					g[i].push_back(j);
					g[j].push_back(i);
				}
			}
		}
	}
	vi d(26, INF);
	queue<int> q;
	d[s] = 0;
	q.push(s);
	while (!q.empty()) {
		int x = q.front(); q.pop();
		REP(i, g[x].size()) {
			if (d[g[x][i]] > d[x] + 1) {
				q.push(g[x][i]);
			}
			d[g[x][i]] = min(d[g[x][i]], d[x] + 1);
		}
	}
	cout << d[t] << endl;

}



Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)v.size()
#define endl "\n"
#define ff first
#define ss second
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll INF=1e29;
const ll MOD=1e9+7;
const ll nxm=2e7+5;
bool c(pair<ll,ll> a,pair<ll,ll> b){    return a.ss>b.ss;    }
bool sgn(ll a){ if(a>=0) return 1 ;return 0;}
void solve()
{
string s;
cin>>s;
cout<<s[0]<<s[1]<<s[2];

}
int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}


	return 0;
}


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

using namespace std;

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

int main() {

	int a,b,c;
	ll x,y;
	cin>>a>>b>>c>>x>>y;
	if(a+b<=c*2)cout<<a*x+b*y<<endl;
	else{
		ll ans=0;
		if(x<=y){
			ans+=c*2*x;
			ans+=min(b*(y-x),c*2*(y-x));
		}else{
			ans+=c*2*y;
			ans+=min(a*(x-y),c*2*(x-y));
		}
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,L;cin>>N>>L;
    ll ans=0;
    ll m=INF;
    REP(i,N){
        ll t=i+L;
        if(abs(m)>abs(t))m=t;
        ans+=t;
    }
    //cout<<m<<"\n";
    cout<<ans-m<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

int main() {

  int n;
  cin >> n;

  vector< vector<int> > a(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      int val;
      cin >> val;
      a[i][j] = val;
    }
  }

  int max = 0;
  for (int j = 0; j < n; j++) {
    int sum = 0;
    for (int k = 0; k <= j; k++) {
      sum += a[0][k];
    }
    for (int k = j; k < n; k++) {
      sum += a[1][k];
    }

    if (sum > max) {
      max = sum;
    }
  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
N,A,B=map(int,input().split())
ssum=0
for i in range(1,N+1):
	listi=[0,0,0,0,0]
	temp=i
	for j in range(5):
		listi[j]=temp%10
		temp=(temp-temp%10)/10
	sumi=sum(listi)
	if(sumi>=A and sumi<=B):
		ssum=ssum+i
print(ssum)

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

int a,b,c,x,y;
int main(){
  int total;
  cin >> a >>b>>c>>x>>y;
  if (c*2 >= a+b){
    cout << a*x + b*y;
    return 0;
  }
  
  else{
    total = min(x,y)*c*2;
    if (x>y){
      if (c*2 < a){
        total += (x-y)*2*c;
      }
      else{
        total += (x-y)*a;
      }
    }
    else if(y>x){
      if (c*2 < b){
        total += (y-x)*2*c;
      }
      else{
        total += (y-x)*b;
      }
    }
  }
    
  cout << total;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

bool isHarshad(const int& X) {
    int total = 0;
    int next = X;
    while (next != 0) {
        total += next % 10;
        next /= 10;
    }
    return (X % total == 0);
}

int main(){
    int N;
    cin >> N;
    if (isHarshad(N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >>a >> b >> u;
  if(s==u)cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
}

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

Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
 
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}




void solve()
{
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/gcd(a,b)<<endl;
}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
        ll t;
    //cin>>t;
    //while(t--)
        solve();
}



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

int main(){
    int n,x;
    cin>>n>>x;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i];
    a.push_back(x);
    sort(a.rbegin(),a.rend());
    int ans=0;
    rep(i,n){
        b[i]=a[i]-a[i+1];
        ans=__gcd(ans,b[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long

int A, D, N;

bool IsPrime(int n)
{
    if (n <= 1) return false;
    int s = sqrt(n) + 1e-8;
    for (int i = 2; i <= s; i++)
    {
        if (n % i == 0) return false;
    }
    return true;
}

int Solve()
{
    int cnt = 0;
    for (int i = 0;; i++)
    {
        if (IsPrime(A + D * i))
        {
            if (++cnt == N) return A + D * i;
        }
    }
}

signed main()
{
    while (cin >> A >> D >> N, A || D || N)
    {
        printf("%lld\n", Solve());
    }
    return 0;
}

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

int n,k;
int a[505];
int a2[505];
int sum[505];
int sum2[505];

bool check(int v){
	for(int i=0;i<n;i++){
		a2[i]=a[i]%v;
	}
	sort(a2,a2+n);
	int r=n-1;
	int rest=k;
	for(int i=0;i<n;i++){
		while(a2[i]>0 && i<r){
			int dif=v-a2[r];
			int mi=min(dif,a2[i]);
			a2[i]-=mi;
			a2[r]+=mi;
			if(a2[r]==v)r--;
			rest-=mi;
		}
	}
	return (rest>=0);
}

int main(void){
	scanf("%d%d",&n,&k);
	int sum3=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum3+=a[i];
	}
	sort(a,a+n);
	if(k>=sum3){
		printf("%d\n",sum3);
	}else{
		int ans=0;
		for(int i=1;i*i<=sum3;i++){
			if(sum3%i!=0)continue;
			if(check(sum3/i))ans=max(ans,(int)sum3/i);
			if(check(i))ans=max(ans,i);
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 256