akhauriyash/Code-Regression huggingface dataset:
using CompLib.Util;
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.NextInt();
        }
        Array.Sort(a, (x, y) => -x.CompareTo(y));
        if (n % 2 == 0)
        {
            long b = 0;
            for (int i = 0; i < n / 2; i++)
            {
                b += a[i];
                if (i < n / 2 - 1)
                {
                    b += a[i];
                }
            }

            for (int i = n / 2; i < n; i++)
            {
                b -= a[i];
                if (i > n / 2)
                {
                    b -= a[i];
                }
            }

            Console.WriteLine(b);
        }
        else
        {
            long b = 0;
            for (int i = 0; i < n / 2; i++)
            {
                b += a[i];
                b += a[i];
            }

            for (int i = n / 2; i < n; i++)
            {
                b -= a[i];
                if (i > n / 2 + 1)
                {
                    b -= a[i];
                }
            }

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

            for (int i = n / 2 + 1; i < n; i++)
            {
                c -= a[i];
                c -= a[i];
            }

            Console.WriteLine(Math.Max(b, c));
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;
    class Scanner
    {
        private int _index;
        private string[] _line;
        const char separator = ' ';

        public Scanner()
        {
            _index = 0;
            _line = new string[0];
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(separator);
                _index = 0;
            }
            return _line[_index++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(separator);
            _index = _line.Length;
            return _line;
        }
        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
    }
}

Measured memory_bytes: 15568
#B
nm = [int(x) for x in input().split()]
line = [int(x) for x in input().split()]

m = nm[1]
yeet = sum(line)
line.sort(reverse = True)

if line[m-1] >= ((1/(4*m))*yeet):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000003
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
long long fac[2200000],finv[2200000],inv[2200000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<2200000;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
long long facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}

long long powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}
 
int main(void){
  COMinit();
  int Q;
  cin >> Q;
  rep(i,Q){
    lint x,d,n;
    cin >> x >> d >> n;
    if(d==1) cout << facdiv(x+n-1,x-1) << endl;
    else if(d==0) cout << powmod(x,n) << endl;
    else{
      x=(x*powmod(d,MOD-2))%MOD;
      lint a=powmod(d,n)%MOD;
      if(n>1000003) cout << "0" << endl;
      else cout <<(facdiv(x+n-1,x-1)*a)%MOD << endl;
    }
  }
}

Measured memory_bytes: 52860
#include <iostream>
#include <cstdint>

using namespace std;

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

	if(a <= c && b >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

int[string] h;

void f (int dx) {
  int n = readln.strip.to! (int);
  foreach (i; 0 .. n) {
    string s = readln.strip();
    if (s in h) {
      h[s] = h[s] + dx;
    } else {
      h[s] = dx;
    }
  }
}

void main() {
  f (1);
  f (-1);
  int r = 0;
  foreach (k, v; h) {
    r = max (r, v);
  }
  writeln (r);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string a,b;
    cin >> a >> b;
    string s,l;
    for(int i = 0; i < stoi(b); i++) {
        s += a;
    }
    for(int i = 0; i < stoi(a); i++) {
        l += b;
    }
    if(s >= l) {
        cout << l;
    }else {
        cout << s;
    }
}

Measured memory_bytes: 256
#52 ABC132E
class Dijkstra():
    class Edge():
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        self.G = [[] for i in range(V)]  # 隣接リストG[u][i] := 頂点uのi個目の隣接辺
        self._E = 0  # 辺の数
        self._V = V  # 頂点の数
    @property
    def E(self):
        return self._E
    @property
    def V(self):
        return self._V
    def add(self, _from, _to, _cost):
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1
    def shortest_path(self, s):
        import heapq
        que = []  # プライオリティキュー（ヒープ木）
        d = [float("inf")] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))  # 始点の(最短距離, 頂点番号)をヒープに追加する
        while len(que) != 0:
            cost, v = heapq.heappop(que)
            # キューに格納されている最短経路の候補がdの距離よりも大きければ、他の経路で最短経路が存在するので、処理をスキップ
            if d[v] < cost: continue
            for i in range(len(self.G[v])):
                # 頂点vに隣接する各頂点に関して、頂点vを経由した場合の距離を計算し、今までの距離(d)よりも小さければ更新する
                e = self.G[v][i]  # vのi個目の隣接辺e
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost  # dの更新
                    heapq.heappush(que, (d[e.to], e.to))  # キューに新たな最短経路の候補(最短距離, 頂点番号)の情報をpush
        return d

n,m=map(int,input().split())
uv=[list(map(int,input().split())) for _ in range(m)]
s,t=map(int,input().split())

djk=Dijkstra(3*n+1)
for u,v in uv:
	djk.add(u,v+n,1)
	djk.add(u+n,v+n*2,1)
	djk.add(u+n*2,v,1)
d = djk.shortest_path(s)
print(d[t]//3 if d[t]!=float("inf") else -1)

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll A;
  string B;
  cin >> A >> B;
  B.erase(1, 1);
  ll C = stoll(B);
  cout << A * C / 100 << endl;

  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int a[100050];
    map<int, int> mp;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        mp[a[i] - 1]++;
        mp[a[i]]++;
        mp[a[i] + 1]++;
    }
    int ans = 0;
    for(int val = 1; val <= 1e5; val++){
        ans = max(ans, mp[val]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    bool flag = true;
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i++){
        if(a[i]%2 == 0 && a[i]%3 != 0 && a[i]%5 != 0){
            flag = false;
            break;
        }
    }
    if(flag == true){
        cout << "APPROVED";
    }else{
        cout << "DENIED";
    }
    return 0;
}

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

int main()
{
    int n,tmp;
    std::cin >> n;
    std::priority_queue<double, std::vector<double>, std::greater<double>> v;
    for (int i = 0; i < n; i++) { std::cin >> tmp; v.push(tmp); }
    for (;v.size() >= 2;) {
        double m1 = v.top();
        v.pop();
        m1 += v.top();
        v.pop();
        v.push(m1/2);
    }
    
    std::cout << v.top() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF MOD
typedef long long ll;
typedef pair<int,int> P;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
//#define int ll


signed main(){
    int N,a=0,b=0;
    string S[10010],P[10010],Q[10010],T;
    cin >> N;
    REP(i,N){
        cin >> S[i];
        P[i]=S[i];
        Q[i]=S[i];
        REP(j,S[i].size()){
            if(S[i][j]=='?'){
                P[i][j]='a';
                Q[i][j]='z';
            }
        }
    }
    cin >> T;
    REP(i,N){
        if(T>Q[i]){
            a++;
        }
        if(P[i]<=T && T<=Q[i]){
            b++;
        }
    }
    //cout << a <<  " " << b << endl;
    REP(i,b+1){
        if(i!=0)cout << " ";
        cout << a+i+1;
    }cout << endl;
	return 0;
}


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

int main() {
  int num;
  int tmp,tmp2;
  int cnt = 0;
  
  cin >> num;
  
  map<int,int> m;
  for(int i = 0 ;i < num; i++){
    cin >> tmp;
    tmp--;
    
    m[i] = tmp;
  }
  
  int me,you;
  for(auto itr : m){
    me = itr.first;
    you = itr.second;
    
    auto sh = m.find(you);
    if(sh->second == me){
      cnt++;
    }
  }
  
  cout << cnt / 2;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    if (n == m) {
      System.out.println("Yes");
    }
    if (n != m) {
      System.out.println("No");
    }


  }
}


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

int A,B,C;

int main()
{
    scanf("%d%d%d",&A,&B,&C);
    if(A == B)printf("%d\n",C);
    else if(B == C)printf("%d\n",A);
    else printf("%d\n",B);
    return 0;
}


Measured memory_bytes: 256
m,d = map(int, input().split())
c = 0
for i in range(1,m+1):
  for j in range(22,d+1):
    a = int(str(j)[0])
    b = int(str(j)[1])
    if a*b == i and a > 1 and b > 1:
      #print(str(i)+"/"+str(a)+str(b))
      c += 1
print(c)

Measured memory_bytes: 2940
S=input()
i=0
ans="YES"
while i<len(S) or ans=="Yes":
    if S[i:i+7]=="dreamer" and S[i+5:i+10]!="erase":
        i+=7
    elif S[i:i+6]=="eraser":
        i+=6
    elif S[i:i+5] == "dream" or S[i:i+5] == "erase":
        i+=5
    else:
        ans="NO"
        break
if i<len(S)-1:
    ans="NO"
print(ans)

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

int main() {
    int n, ans = 0, last = 0;
    vector<int> a, b;
    cin >> n;
    a.resize(n), b.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    for (int i : b) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] >= i) {
                cnt++;
                while (j < n && a[j] >= i) {
                    j++;
                }
            }
        }
        ans += cnt * (i - last);
        last = i;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define CK(n, a, b) (a <= n && n < b)
#define MP(a, b) make_pair(a, b)
typedef long long ll;
const ll mod =1e9+7;
const int inf =1e9;
using namespace std;

ll h, w;
int main() {
    cin>>h>>w;

    if(h==1 || w==1){
        cout<<1<<endl;
        return 0;
    }

    if(h%2==0){
        cout<<h*w/2<<endl;
    }
    else{
        if(w%2==0){
            cout<<w*(h/2)+w/2<<endl;
        }
        else{
            cout<<w*(h/2)+(w/2+1)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
  
#define rep(i, n) for (int i = 0; i < int(n); ++i)
typedef long long i64;

const int N = 2438;
int dpma[N][N];
int dpmi[N][N];
const int inf = 1e8;
vector<int> solve(const vector<int> &a) {
  int n = a.size();
  vector<int> ret(n + 1);
  rep(i, N) rep(j, N) { dpma[i][j] = - inf; dpmi[i][j] = inf; }
  dpma[n][0] = 0;
  dpmi[n][0] = 0;

  for (int i = n - 1; i >= 0; --i) {
    rep(j, n - i + 1) {
      dpma[i][j] = max(dpma[i][j], dpma[i + 1][j] + a[i]);
      dpmi[i][j] = min(dpmi[i][j], dpmi[i + 1][j] + a[i]);
      if (j >= 1) {
	dpma[i][j] = max(dpma[i][j], -dpmi[i + 1][j - 1] + a[i]);
	dpmi[i][j] = min(dpmi[i][j], -dpma[i + 1][j - 1] + a[i]);
      }
    }
  }

  rep(i, n + 1) { ret[i] = max(abs(dpmi[0][i]), abs(dpma[0][i])); }
  return ret;
}

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  vector<int> rl, ud;
  rep(i, s.length()) {
    if (s[i] == 'R' || s[i] == 'L') {
      rl.push_back(s[i] == 'R' ? 1 : -1);
    } else {
      ud.push_back(s[i] == 'U' ? 1 : -1);
    }
  }
  vector<int> rl_res = solve(rl);
  vector<int> ud_res = solve(ud);
  int ma = 0;
  rep(i, rl_res.size()) {
    rep(j, ud_res.size()) {
      if (i + j <= k) { ma = max(ma, rl_res[i] + ud_res[j]); }
    }
  }
  cout << ma << endl;
}

Measured memory_bytes: 49604
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long answer = N * (N - 1) / 2;
        System.out.println(answer);
    }
}


Measured memory_bytes: 21972
N, M = map(int, input().split())
X = [int(x) for x in input().split()]

if N >= M :
    print(0)
    exit()

X.sort()
Y = [X[i+1]-X[i] for i in range(M-1)]
Y.sort()

if N == 1 :
    print(sum(Y))
else :
    print(sum(Y[:1-N]))



Measured memory_bytes: 13840
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	string s;
	cin>>s;
	if( s == "MON"){
		cout<<6<<endl;
	}else if( s== "TUE"){
		cout<<5<<endl;
	}else if( s== "WED"){
		cout<<4<<endl;
	}else if( s== "THU"){
		cout<<3<<endl;
	}else if( s== "FRI"){
		cout<<2<<endl;
	}else if( s== "SAT"){
		cout<<1<<endl;
	}else if( s== "SUN"){
		cout<<7<<endl;
	}
	return 0;
}

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();

        long sum = 0;
        for(int i = 1; i<=a; i++){
            if(i % 3 != 0 && i % 5 != 0){
                sum += i;
            }
        }
        System.out.println(sum);
    }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define ln '\n'
typedef long long ll;

ll n, v, a[1000], b[1000], c[1000], d[1000], ps[1000000], r;

int main() {
	cin >> n >> v;
	rep(i,n) scanf("%lld",&a[i]);
	rep(i,n) scanf("%lld",&b[i]);
	rep(i,n) scanf("%lld",&c[i]);
	rep(i,n) scanf("%lld",&d[i]);
	rep(i,n) rep(j,n) ps[i*n+j] = a[i] + b[j];
	sort(ps, ps+n*n);
	rep(i,n) rep(j,n) {
		ll t = c[i] + d[j];
		if (t<v) r += upper_bound(ps, ps+n*n, v-t) - lower_bound(ps, ps+n*n, v-t);
	}
	printf("%lld\n",r);
}

Measured memory_bytes: 11108
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=100005;
struct edge{
	int to,next;
}e[N*2];
int head[N],tot;
int deg[N],q[N],vis[N];
int n,ans,res,rt;
char s[N];
void add(int x,int y){
	e[++tot]=(edge){y,head[x]};
	head[x]=tot;
}
void topo(){
	int h=0,t=0;
	For(i,1,n)
		if (!s[i]&&deg[i]==1)
			q[++t]=i;
	while (h!=t){
		int x=q[++h]; vis[x]=1;
		for (int i=head[x];i;i=e[i].next)
			if ((--deg[e[i].to])==1&&!s[e[i].to])
				q[++t]=e[i].to;
	}
}
void dfs1(int x,int fa){
	s[x]^=deg[x]&1;
	if (s[x]) ans++;
	for (int i=head[x];i;i=e[i].next)
		if (!vis[e[i].to]&&e[i].to!=fa)
			ans+=2,dfs1(e[i].to,x);
}
int dfs2(int x,int fa){
	int mx=s[x];
	for (int i=head[x];i;i=e[i].next)
		if (!vis[e[i].to]&&e[i].to!=fa){
			int v=dfs2(e[i].to,x);
			res=max(res,mx+v);
			mx=max(mx,v+s[x]);
		}
	return mx;
}
int main(){
	scanf("%d",&n);
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
		++deg[x]; ++deg[y];
	}
	scanf("%s",s+1);
	For(i,1,n) s[i]=(s[i]=='W');
	if (n==1){
		printf("%d\n",s[1]);
		return 0;
	}
	topo();
	For(i,1,n) if (!vis[i]) rt=i;
	if (!rt) return puts("0"),0;
	dfs1(rt,0); dfs2(rt,0);
	printf("%d\n",ans-2*res);
}
/*
BBWB 7->5

*/

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=1;i<=ty-sy;i++)
    {
        cout<<"U";
    }
    for(int i=1;i<=tx-sx;i++)
    {
        cout<<"R";
    }
    for(int i=1;i<=ty-sy;i++)
    {
        cout<<"D";
    }
    for(int i=1;i<=tx-sx;i++)
    {
        cout<<"L";
    }
    cout<<"L";
    for(int i=0;i<=ty-sy;i++)
    {
        cout<<"U";
    }
    cout<<"R";
    for(int i=1;i<=tx-sx;i++)
    {
        cout<<"R";
    }
    cout<<"D";
    cout<<"R";
    for(int i=0;i<=ty-sy;i++)
    {
        cout<<"D";
    }
    cout<<"L";
    for(int i=1;i<=tx-sx;i++)
    {
        cout<<"L";
    }
    cout<<"U";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>

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

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/

const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve()
{
	ll a, b, c;
	cin >> a >> b >> c;
	c *= 2;
	ll x, y;
	cin >> x >> y;
	ll min = max(a * x + b * y, max(x, y) *c);
	for (ll i = 0; i <= max(x, y); i++)
	{
		ll mon = 0;
		if (x - i >= 0 && y - i >= 0)
		{
			mon = c * i + (x - i) * a + (y - i) * b;
		}
		else{
			if(x-i>=0){
				mon = c * i + (x - i) * a;
			}
			else{
				if(y-i>=0){
					mon = c * i + (y - i) * b;
				}
				else{
					mon = c * i;
				}
			}
		}
		if(min>mon){
			min = mon;
		}
	}

	cout << min << endl;
}

int main(){
	
	solve();
	
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;


pair<int,int> NA;
using Weight=int;
struct Edge{
  int src,dst;
  Weight weight;
  Edge():src(0),dst(0),weight(0){}
  Edge(int s,int d,Weight w):src(s),dst(d),weight(w){}
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;

pair<vector<Weight>,vector<int>> Dij(Graph&g,int s){
  using state = pair<Weight,int>;
  priority_queue<state,vector<state>,greater<state>> pq;
  vector<int> from(g.size());
  vector<Weight> dis(g.size(),INF);
  dis[s]=0;
  pq.push(state(0,s));
  while(!pq.empty()){
    Weight d=pq.top().first;
    int v=pq.top().second;
    pq.pop();
    if(dis[v]<d)continue;
    rep(i,g[v].size()){
      Edge &e=g[v][i];
      if(dis[e.dst]>dis[v]+e.weight){
        dis[e.dst]=dis[v]+e.weight;
        pq.push(state(dis[e.dst],e.dst));
        from[e.dst]=v;
      }
    }
  }
  return {dis,from};
}

vector<int> GetPath(int t,vector<int> from){
  vector<int> path;
  for(;t!=0;t=from[t])path.push_back(t);
  path.push_back(0);
  reverse(all(path));
  return path;
}

vector<int> vis(100005,0);
int ans=0;
void dfs(Graph& g,int par){
  vis[par]=1;
  ans++;
  rep(i,g[par].size()){
    if(vis[g[par][i].dst]==0&&g[par][i].dst!=NA.second){
      dfs(g,g[par][i].dst);
    }
  }
  return;
}

signed main(){
  int n;
  cin>>n;
  Graph g(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].emplace_back(a,b,1);
    g[b].emplace_back(b,a,1);
  }

  pair<vector<int>,vector<int>> path=Dij(g,0);
  vector<int> route=GetPath(n-1,path.second);

  pair<int,int> index={path.first[n-1]/2,path.first[n-1]/2+1};
  //cout<<"index"<<' '<<index.first<<' '<<index.second<<endl;
  NA={route[index.first],route[index.second]};

  dfs(g,0);
  //cout<<ans<<endl;
  cout<<(ans>n-ans?"Fennec":"Snuke")<<endl;

  return 0;
}


Measured memory_bytes: 14420
#include<bits/stdc++.h>
using namespace std;
int sum[500005];
int vis[500005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,i,j=0;
    cin>>n;
    if(n%2==0 || n%5==0)
    {
        cout<<-1<<endl;
    }
    else{
        long long p=7%n;
        j++;
        while(p!=0)
        {
            p=(p*10+7)%n;
            j++;
        }
        cout<<j<<endl;

    }

}


Measured memory_bytes: 3656
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

N = input()
ls = []
m = {}
for i in range(N):
    S = raw_input()
    ls.append(S)
    m[S] = 1

if len(m) != N:
    print "No"
    exit()

for i in range(N - 1):
    if ls[i][-1] != ls[i + 1][0]:
        print "No"
        exit()

print "Yes"

Measured memory_bytes: 2812
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a[] = new int[4];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = a[0] - 1;
		a[3] = a[1] - 1;

		Arrays.sort(a);

		System.out.println(a[3] + a[2]);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305,mod=1e9+7;
int n,tot,a[2*N],mark[2*N],tmp[2*N],f[2*N][N][N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i*2-1]!=-1&&a[i*2]!=-1){
			mark[a[i*2-1]]=mark[a[i*2]]=-1;
			continue;
		}
		if(a[i*2]!=-1){
			mark[a[i*2]]=1;
			continue;
		}
		if(a[i*2-1]!=-1){
			mark[a[i*2-1]]=1;
			continue;
		}
		cnt++;
		mark[a[i*2-1]]=mark[a[i*2]]=2;
	}
	for(int i=1;i<=2*n;i++)if(~mark[i])tmp[++tot]=mark[i];
	f[tot+1][0][0]=1;
	for(int i=tot+1;i>1;i--)
		for(int j=0;j<=n;j++)
			for(int k=0;k<=n;k++)
				if(tmp[i-1]==1){
					f[i-1][j][k+1]=(f[i-1][j][k+1]+f[i][j][k])%mod;
					if(j)f[i-1][j-1][k]=(f[i-1][j-1][k]+f[i][j][k])%mod;
				}
				else{
					f[i-1][j+1][k]=(f[i-1][j+1][k]+f[i][j][k])%mod;
					if(j)f[i-1][j-1][k]=(f[i-1][j-1][k]+f[i][j][k])%mod;
					if(k)f[i-1][j][k-1]=(f[i-1][j][k-1]+(ll)f[i][j][k]*k)%mod;
				}
	int ans=f[1][0][0];
	for(int i=2;i<=cnt;i++)ans=(ll)ans*i%mod;
	cout<<ans<<"\n";
}
/*
4
1 -1 -1 -1 -1 3 6 -1
*/

Measured memory_bytes: 219008
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
ll modpow(ll a, ll p) {
    if(p == 0)
        return 1;
    if(p % 2 == 0) {
        ll halfp = p / 2;
        ll half = modpow(a, halfp);
        return half * half % MOD;
    } else {
        return a * modpow(a, p - 1) % MOD;
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    //したから
    vector<ll> x(n);
    REP(i, n) { cin >> x[i]; }
    //左から
    vector<ll> y(m);
    REP(i, m) { cin >> y[i]; }
    ll x_sum = 0;
    ll y_sum = 0;
    /*
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            x_sum += (x[j] - x[i]) % MOD;
            x_sum %= MOD;
        }
    }
    */
    for(int i = 0; i < n; i++) {
        x_sum += (i * x[i] - (n - i - 1) * x[i]) % MOD;
        x_sum %= MOD;
    }
    /*
    for(int k = 0; k < m; k++) {
        for(int l = k + 1; l < m; l++) {
            y_sum += (y[l] - y[k]) % MOD;
            y_sum %= MOD;
        }
    }
    */
    for(int j = 0; j < m; j++) {
        y_sum += (j * y[j] - (m - j - 1) * y[j]) % MOD;
        y_sum %= MOD;
    }

    ll area = x_sum * y_sum % MOD;
    cout << area % MOD << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
  char a[3];
  cin>>a;
  int c=0;
  for(int i=0;i<3;i++)
  {
    if(a[i]=='7')
      c++;
  }
  if(c>0)
    cout<<"Yes";
  else
    cout<<"No";
}

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

int main(){
    int n;
    cin>>n;
    if(n>81){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
  }
  sort(all(A));
  sort(all(B));

  if (n & 1) {
    int minn = A[n / 2];
    int maxx = B[n / 2];

    cout << maxx - minn + 1 << "\n";
  } else {
    double minn = (double)(A[n / 2] + A[n / 2 - 1]) / 2;
    double maxx = (double)(B[n / 2] + B[n / 2 - 1]) / 2;
    cout << (int)(2 * (maxx - minn) + 1) << "\n";
  }
  return 0;
}

Measured memory_bytes: 4696
n, k = map(int, input().split())
h = list(map(int, input().split()))
cost = [0] * n
for i in range(1, n):
    ans = 1000000000
    for j in range(1, k + 1):
        if i - j >= 0: ans = min(ans, cost[i - j] + abs(h[i] - h[i - j]))
    cost[i] = ans
print(cost[n - 1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.000000001
#define ld long double
#define inf 5e18
#define N 2000001
#define K 17


int fact[N],ifact[N];

ll fastexpom(ll a,ll b,ll m)
{
    ll res=1;
    a = a % m;
    while(b>0)
    {
        if(b % 2 == 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b/=2;
    }
    return res;
}
ll modinv(ll a, ll m=1000000007)
{
  return fastexpom(a,m-2,m);
}
void preprocess()
{
    fact[0] = 1;
    ifact[0] = 1;
    for(int i = 1;i < N;i++)
    {
        fact[i] = (fact[i-1] * i)%mod;
        ifact[i] = modinv(fact[i],mod);
    }
}
int nCr(int n,int r)
{
    if(n == 0 and r == 0)
        return 1;
    if(r > n or r < 0 or n == 0)
        return 0;
    int ans = (fact[n] * ifact[n-r])%mod;
    ans = (ans * ifact[r])%mod;
    return ans;
}


int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int k;
    string s;
    cin >> k >> s;
    int n = s.length();
    preprocess();
    int ans = 0;
    for(int i = n;i <= n + k;i++)
    {
        int  lans = fastexpom(26, n + k - i, mod);
        lans = (lans * ((nCr(i - 1, n - 1) * fastexpom(25, i - n, mod)) % mod)) %mod;
        // assert(lans >= 0);
        ans = (ans + lans)  % mod;
    }
    cout << ans;
    return 0;
    
}   

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

const int M=1e9+7;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];
    ll totalHeight=0;
    for(int i=1;i<n;++i)
    {
        if(a[i]<a[i-1])
            {
                totalHeight+=(a[i-1]-a[i]);
                a[i]+=(a[i-1]-a[i]);
            }
    }
    cout<<totalHeight<<endl;
    return 0;
}


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

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll a; cin >> a;
    cout << 3*a*a << endl;
}


Measured memory_bytes: 256
use strict;
use warnings;
use List::Util qw(sum);

chomp(my $nm = <>);
my ($n, $m) = split(/ /, $nm);

chomp(my $input_a = <>);
my @a = split(/ /, $input_a);
@a = sort {$b <=> $a} @a;

# 総投票数
my $sum = sum(@a);

if ($a[$m-1] >= $sum/(4*$m)) {
  print "Yes\n";
} else {
  print "No\n";
}



Measured memory_bytes: 768
import numpy as np


H, W, K = map(int,input().split())
L = np.zeros([6,6],dtype=int)
count = 0

# print(L)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j-1] == "#":
            L[i,j] = 1

# print(L)

for i in range(2**H):
    for j in range(2**W):
        tmp = L.copy()
        for ib in range(H):
            if (i >> ib) & 1:
                tmp[ib,:] = 0
            for jb in range(W):
                if (j >> jb) & 1:
                    tmp[:,jb] = 0
        if np.sum(tmp) == K:
            count += 1

print(count)

Measured memory_bytes: 27248
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, C, K;
	cin >> N >> C >> K;
	int A[N];
	rep(i,N) cin >> A[i];
	sort(A, A+N);
	int num = A[0], cnt = 0, ans = 0;
	rep(i,N){
		if(cnt == 0){
			num = A[0];
			cnt++;
			++ans;
		}
		else if(cnt < C){
			if(num+K >= A[i]){
				cnt++;
			}
			else{
				++ans;
				num = A[i];
				cnt = 1;
			}
		}
		else{
			++ans;
			cnt = 1;
			num = A[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4400
#include<stdio.h>
#include<string.h>
int main()
{
  char w[100];
  char moji;
  int con[100]={0},r=0,flag=0;
  
  scanf("%s",w);
  
  for(int i=0;i<strlen(w)-1;i++){
    for(int j=i+1;j<strlen(w);j++){
      if(w[i]>w[j]){
        moji=w[i];
        w[i]=w[j];
        w[j]=moji;
      }
    }
  }
  
  for(int i=0;i<strlen(w);i++){
    if(w[i]==w[i+1]) con[r]++;
    else {
      con[r]++;
      r++;
    }
  }
  for(int i=0;i<100;i++){
    if(con[i]%2!=0){
      flag=1;
      break;
    }
  }
  if(flag==0) printf("Yes");
  else printf("No");
    
  return 0;
}

Measured memory_bytes: 128
n=int(input())
s=list(map(ord,list(input())))
dp=[n*[0]for _ in range(n)]
for i in range(n):
  if s[i]==s[0]:
    dp[i][0]=dp[0][i]=1
for i in range(1,n):
  for j in range(1,n):
    if s[i]==s[j]:
      dp[i][j]=dp[i-1][j-1]+1
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if i<j-dp[i][j]+1:ans=max(ans,dp[i][j])
print(ans)

Measured memory_bytes: 231560
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  ll N; cin >> N;
  ll ans = INF;
  for(ll i=1; i <= sqrt(N)+10; ++i) {
    if(N%i == 0){
      int A = to_string(i).size(), B = to_string(N/i).size();
      if(ans > max(A,B)) ans = max(A,B);
    }
  }
  cout << ans << endl;
}


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

int main(){
    int N,L;
    cin >> N >> L;
    int A[N];

    int sum=0;
    for(int i=0;i<N;i++) {
        A[i] = L+i;
        sum += A[i];
    }
    sort(A,A+N);

    if(A[0]>0) sum -= A[0];
    if(A[N-1]<0) sum -= A[N-1];
    cout << sum <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

static vector<int> P={2};
template<class T>
T next_prime(T x){
    int size=P.size();
    
    if(x<P[size-1]){
        int begin=0,end=size;
        while(end-begin>1){
            int c=(begin+end)/2;
            if(x<P[c]){
                end=c;
            }else{
                begin=c;
            }
        }
        return P[begin];
    }

    T res=P[size-1];
    while(true){
        res++;
        bool prime=true;
        for(int i=0;i<size;i++){
            if(P[i]<=sqrt((double)res)){
                if(res%P[i]==0){
                    prime=false;
                    break;
                }
            }else{
                break;
            }
        }

        if(prime){
            P.push_back(res);
            size++;
            if(res>x){
                break;
            }
        }
    }

    return res;
}

template<class T>
bool prime(T x){
    if(x==next_prime(x-1)) return true;
    return false;
}

int N;
vector<int> a;

int main(){
    cin>>N;

    int prev=1;
    while(N!=0){
        int p=next_prime(prev);
        if(p%10==1){
            a.push_back(p);
            N--;
        }
        prev=p;
    }

    repr(e,a) cout<<e<<' ';
    cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int a, b;
	scanf("%d %d", &a,&b);

	if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
		printf("%d", a * b);
	}
	else {
		printf("-1");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

A,B=input().split()
Aint = int(A)
Bint = int(B)
V=[A*Bint,B*Aint]
V.sort()
print(V[0])


Measured memory_bytes: 3188
import sys
n, k = map(int, sys.stdin.readline().split())
r, s, p = map(int, sys.stdin.readline().split())
t = sys.stdin.readline()
ans = 0
for i in range(k, n):
  if t[i] == t[i-k]:
#    t[i] = "a"
    t = t[:i] + "a" + t[i+1:]
ans = t.count("r")*p + t.count("s")*r + t.count("p")*s

print(ans)


Measured memory_bytes: 3444
n = int(input())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a+b,a,b])
l1 = sorted(l)[::-1]
bit = 0
ans = 0
for i,j,k in l1:
  if bit==0:
    ans += j
    bit = 1
  else:
    ans -= k
    bit = 0
print(ans)

Measured memory_bytes: 30152
import math
n = int(input())
def prime_factorization(n):
    arr = []
    temp = n
    for i in range(2, int(math.sqrt(temp)) + 1):
        if n%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            if cnt != 0:
                arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if n == 1:
    print(0)
elif len(prime_factorization(n)) == 1 and prime_factorization(n)[0][1] == 1:
    print(1)
else:
    ans = 0
    prime_list = prime_factorization(n)
    # print(prime_list)
    for i in prime_list:
        a = i[1]
        sub = 1
        j = 0
        while True:
            if a < sub:
                break
            a -= sub
            sub += 1
            j += 1
            
        #     print(a, sub, j)
        # print(j, i[1])
        ans += j
        
    print(ans)

Measured memory_bytes: 9260
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
		
	string first_point, second_point;
	unsigned int i;
	
	first_point = s.find_first_of("A", 0);
	second_point = s.find_last_of("Z", 0);
	
	string result;
	result = s.substr(s.find_first_of("A", 0),s.find_last_of("Z") - s.find_first_of("A", 0) + 1);
	
	cout << result.length();
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define per(i,b,a) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<#x" = "<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nex)
typedef pair<int,int> pii;
typedef long long ll;
const int inf=~0u>>1,MOD=1e9+7;/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int rd() {
	int x=0,c=0,f=1;
	for(; c<'0'||c>'9'; c=getchar())f=c!='-';
	for(; c>='0'&&c<='9'; c=getchar())x=x*10+c-'0';
	return f?x:-x;
}
const int N=1e5+11;
struct Edge{
	int v;Edge *nex;
} pl[N<<1],*cur=pl,*G[N];
void ins(int u,int v){
	cur->v=v,cur->nex=G[u],G[u]=cur++;
}
int n;
int dfs(int x,int fa=0){
	int k=0;
	Es(x,i)if(i->v!=fa){
		k^=dfs(i->v,x)+1;
	}
	return k;
}
int main(){
	n=rd();
	rep(i,2,n){
		int u=rd(),v=rd();
		ins(u,v),ins(v,u);
	}
	puts(dfs(1)?"Alice":"Bob");
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int INF = (int)1e9 + 7;
#define REP(i, n) for (int i = 0, i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x <<
//cin,coutより遅いので注意
template <class T = int>
void in() //in<string>();とか書く intのときはそのままin();
{
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T &x) { cout << x << "\n"; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if (x / 100 == x % 10)
    {
        print("Yes");
    }
    else
    {
        print("No");
    }
}

Measured memory_bytes: 256
(defvar *n* (read))
(defvar *m* (read))
(defvar *x* (read))
(defvar *y* (read))

(defun set-lst (n)
  (let ((lst (list nil)))
    (dotimes (x n)
      (let ((tmp (read)))
        (push tmp lst)))
    (cdr (reverse lst))))

(defvar *lst-x* (set-lst *n*))
(defvar *lst-y* (set-lst *m*))

(defun calc-x (lst z)
  (let ((count 0)
        (size (length lst)))
    (dolist (x lst)
      (when (< x z)
        (incf count)))
    (if (= count size)
        t
        nil)))    

(defun calc-y (lst z)
  (let ((count 0)
        (size (length lst)))
    (dolist (y lst)
      (when (>= y z)
        (incf count)))
    (if (= count size)
        t
        nil)))

(defun calc (z)
  (let ((x (calc-x *lst-x* z))
        (y (calc-y *lst-y* z)))
  (cond ((and x y (< *x* z) (<= z *y*))
         t)
        ((> z *y*)
         nil)
        (t (calc (1+ z))))))

(defun main ()
  (if (calc (1+ *x*))
      (format t "No War~%")
      (format t "War~%")))


(main)

Measured memory_bytes: 15200
n = int(input())
a = { (i + 1):int(input()) for i in range(n) }
s = 1
ans = 0
seen = set()
while True:
    if s == 2:
        break
    seen.add(s)
    s = a[s]
    ans += 1
    if s == 1 or s in seen:
        ans = -1
        break
print(ans)


Measured memory_bytes: 22240
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define mp make_pair
#define pb push_back
#define f first
#define s second
const ll mod=998244353;
const ll N=2e5+5;
unordered_map<ll,vector<ll>> adj;
vector<ll> vis(300005,0);
vector<ll> p(100005,0);
ll c[100005];
ll cnt;
ll n;
void dfs(ll node)
{
  if(vis[node])
    return;
  vis[node]=1;
  cnt++;
  for(auto i:adj[node])
    {
      dfs(i);
    }
}
struct range{
  ll l;
  ll r;
  ll index;
};
bool cmp(range& p1,range& p2)
{
     return p1.l<p2.l;
}
int main()
{
   ll n,k;
   cin>>n>>k;
   ll a,b;
   vector<pair<ll,ll>> v;
   ll dp[n+1];
   while(k--)
    {
     cin>>a>>b;
       v.pb(mp(a,b));
    }
    memset(dp,0,sizeof(dp));
    ll pre[n+1];
    pre[0]=0;
    pre[1]=1;
    dp[1]=1;
    //cout<<v[0]<<endl;
    ll j,i;
     for (i = 2; i <=n; i++) {
        for (j = 0; j <v.size(); j++) {
              ll r=max(0LL,i-v[j].f);
              ll l=max(0LL,i-v[j].s-1);
                 dp[i] = (dp[i]+pre[r]-pre[l])%mod;
            
          }
          pre[i]=pre[i-1]+dp[i];
      }
   cout<<dp[n];
}

Measured memory_bytes: 9568
package main 

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scan(&n)
  
  var odd, even int
  
  s := make([]int ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&s[i])
  }
  
  for i := 0; i < n; i++ {
    if s[i] % 2 == 0 {
      even++
    } else if s[i] % 2 == 1 {
      odd++
    }
  }
  
  if odd % 2 == 0 {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s.back() == 's') s += "es";
    else s += 's';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
double dp[310][310][310];
 
signed main() {
	int n;
	cin >> n;
	int a=0;
	int b=0;
	int c=0;
	int arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
		if(arr[i]==1){
			a++;
		}
		else if(arr[i]==2){
			b++;
		}
		else if(arr[i]==3){
			c++;
		}
	}
	dp[0][0][0]=0.0L;
	dp[1][0][0]=(double)n;
	for(int i=2;i<=n;i++){
		dp[i][0][0]=((double)n+dp[i-1][0][0]*(double)i)/(double)i;
	}
	for(int j=1;j<=n;j++){
		for(int i=0;i<=n;i++){
			if(i!=0){
				dp[i][j][0]=(((double)j*dp[i+1][j-1][0]+(double)i*dp[i-1][j][0]+(double)n)/(double)(i+j));
			}
			else{
				dp[i][j][0]=(((double)j*dp[i+1][j-1][0]+(double)n)/(double)(j));
			}
		}
	}
	for(int k=1;k<=n;k++){
		for(int j=0;j<=n;j++){
			for(int i=0;i<=n;i++){
				if(i+j+k>n){
					dp[i][j][k]=0;
				}
				else if(i!=0 && j!=0){
					dp[i][j][k]=(((double)k*dp[i][j+1][k-1]+(double)j*dp[i+1][j-1][k]+ (double)n + i*(dp[i-1][j][k]))/(double)(i+j+k));
				}
				else if(i==0 && j!=0){
					dp[i][j][k]=(((double)k*dp[i][j+1][k-1]+(double)j*dp[i+1][j-1][k]+ (double)n )/(double)(j+k));
				}
				else if(i!=0 && j==0){
					dp[i][j][k]=(((double)k*dp[i][j+1][k-1]+ (double)n + i*(dp[i-1][j][k]))/(double)(i+k));
				}
				else{
					dp[i][j][k]=(((double)k*dp[i][j+1][k-1] + (double)n)/(double)(k));
				}
			}
		}
	}
	cout.precision(17);
	cout << fixed << dp[a][b][c];
	// your code goes here
	return 0;
}

Measured memory_bytes: 452864