akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

int N, M;
VI P;

vector<VI> swaps;

int main(int argc, const char* argv[]) {
	scanf("%d%d", &N, &M);
	P.resize(N);
	swaps.resize(N);
	foreach (p, P) {
		scanf("%d", &p);
		p--;
	}

	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		swaps[a].push_back(b);
		swaps[b].push_back(a);
	}

	vector<int> vis(N, -1);

	int ret = 0;
	VI q(N);
	for (int i = 0; i < N; i++) {
		if (vis[i] < 0) {
			int qs = 0, qf = 1;
			q[0] = i;
			vis[i] = i;
			while (qs < qf) {
				int c = q[qs++];
				foreach (s, swaps[c]) {
					if (vis[s] < 0) {
						vis[s] = i;
						q[qf++] = s;
					}
				}
			}
			for (int j = 0; j < qf; j++) {
				if (vis[P[q[j]]] == i)
					ret++;
			}
		}
	}

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


	return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll ans=max(a+b,max(a-b,a*b));
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> cost(m);
  bitset<12> initial("000000000000");
  vector<bitset<12>> key(m, initial);
  for(int i=0;i<m;i++) {
    int a, b;
    cin >> a >> b;
    for(int j=0;j<b;j++) {
      int c;
      cin >> c;
      c--;
      key[i].set(c);
    }
    cost[i] = a;
  }
  const int lim = pow(2, n);
  vector<vector<int>> dp(lim, vector<int>(m+1));
  for(int i=0;i<lim;i++) {
    for(int j=0;j<m+1;j++) {
      if(i == 0) dp[i][j] = 0;
      else if(j == 0) dp[i][j] = -1;
      else {
        bitset<12> bit(i);
        bitset<12> amp = (bit & key[j-1]);
        if(amp.none()) {
          dp[i][j] = dp[i][j-1];
          continue;
        }
        int idx = 0;
        for(int k=0;k<12;k++) {
          if(bit.test(k) && !key[j-1].test(k)) {
            idx += pow(2, k);
          }
        }
        if(dp[idx][j-1] == -1) {
          dp[i][j] = -1;
          continue;
        }
        int tmp = dp[i][j-1];
        if(tmp == -1) tmp = INT_MAX;
        dp[i][j] = min(cost[j-1] + dp[idx][j-1], tmp);
      }
    }
  }
  cout << dp[lim-1][m] << endl;
  return 0;
}


Measured memory_bytes: 16384
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}


int main(void)
{
	//変数の宣言
	int n,h;
	int a[100010];
	int b[100010];
	int amax=0;
	int maxnumber;
	int count=0;
	int i;
	int flag=0;
	
	//データの読み込み
	scanf("%d %d",&n,&h);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		if(amax<a[i]){
			amax=a[i];
			maxnumber=i;
		}
	}
	
	qsort(b, n, sizeof(int), compare_int);
	
	
	i=0;
	while(flag==0&&i<n){
		if(b[i]>amax&&h>0){
			h=h-b[i];
			count++;
			i++;
//			printf("%d回目の攻撃、残りHP=%d\n",count,h);
		}else{
			flag=1;
		}
	}
	
	if(h>0){
		count=count+(h+amax-1)/amax;
	}
//	printf("計算部分終了\n");
	
	//出力
	
		printf("%d\n",count);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 1276
X=int(input())
ans=0
if X<600:
    ans=8
elif X<800:
    ans=7
elif X<1000:
    ans=6
elif X<1200:
    ans=5
elif X<1400:
    ans=4
elif X<1600:
    ans=3
elif X<1800:
    ans=2
else:
    ans=1
print(ans)

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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b;
  for(int i = 0; i < m; i++){
    int b_temp;
    cin >> b_temp;
    b.push_back(b_temp);
  }
  int count = 0;
  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++){
      int a_temp;
      cin >> a_temp;
      sum += a_temp * b.at(j);
    }
    sum += c;
    if(sum > 0){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>

const int N = 26;

int main(int argc, char *argv[]) {
  long n;
  std::cin >> n;
  --n;
  std::string ans, t;
  for (char i = 'a'; i <= 'z'; ++i)
    t.push_back(i);
  while (n >= N) {
    ans.push_back(t.at(n % N));
    n /= N;
    --n;
  }
  ans.push_back(t.at(n));

  std::reverse(ans.begin(), ans.end());
  std::cout << ans << std::endl;
}


Measured memory_bytes: 3128
import java.util.*;

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();
            int d = sc.nextInt();
            if(a < b){
              System.out.println(a*c);
            } else {
              System.out.println(b*c + (a-b)* d);
            }
          }
}

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

class dice
{
public:
    int F[6];
    dice();
    void roll_a();
    void roll_b();
    bool check(const dice& d);
};

dice::dice()
{
    for(int i = 0; i < 6; i++) cin >> F[i];
}

void dice::roll_a()
{
    static int i, j;
    i = F[0]; F[0] = F[2]; F[2] = F[1]; F[1] = i;
    j = F[3]; F[3] = F[4]; F[4] = F[5]; F[5] = j;
}

void dice::roll_b()
{
    static int k;
    k = F[0]; F[0] = F[5]; F[5] = k;
    k = F[1]; F[1] = F[3]; F[3] = k;
    k = F[2]; F[2] = F[4]; F[4] = k;
}

bool dice::check(const dice& d)
{
    if((d.F[0] != F[0]) || (d.F[5] != F[5])) return false;
    if((d.F[1] == F[1]) && (d.F[2] == F[2]) && (d.F[3] == F[3]) && (d.F[4] == F[4])) return true;
	if((d.F[1] == F[3]) && (d.F[2] == F[1]) && (d.F[3] == F[4]) && (d.F[4] == F[2])) return true;
    if((d.F[1] == F[4]) && (d.F[2] == F[3]) && (d.F[3] == F[2]) && (d.F[4] == F[1])) return true;
    if((d.F[1] == F[2]) && (d.F[2] == F[4]) && (d.F[3] == F[1]) && (d.F[4] == F[3])) return true;

    return false;
}

int main()
{
    dice d1 = dice();
    dice d2 = dice();
    bool eq = false;

    eq = d1.check(d2);
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }

    if(!eq) d1.roll_b();

    eq = d1.check(d2);
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }

    if(eq){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
const ll mod = 1e9 + 7;

int main()
{
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll l1 = min(min(min(q * 4, h * 2), h + q * 2), s);
    ll l2 = min(l1 * 2, d);
    cout << n / 2 * l2 + n % 2 * l1 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, math; readline = sys.stdin.readline; from collections import deque;

S = readline().rstrip()
K = int(readline())

a = []

_c = None
_count = 0
for c in S:
    if c == _c:
        a[-1] += 1
    else:
        a.append(1)
    _c = c
total = 0

if len(a) >= 2:
    for x in a[1:-1]:
        total += x // 2 * K

    if S[0] == S[-1]:
        total += (a[0] + a[-1]) // 2 * (K - 1)
        total += a[0] // 2 + a[-1] // 2
    else:
        total += (a[0] // 2 + a[-1] // 2) * K
else:
    total = (a[0] * K) // 2

print(total)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    cout << n * n * n << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n, k, *x = map(int, open(0).read().split())
    d= []
    for i, j in zip(x, x[k - 1:]):
        y = j - i + min(abs(i), abs(j))
        d.append(y)
    print(min(d))


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  vector<unsigned long> a(n);
  unsigned long sum=1;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0;i<n;i++){
    if((1000000000000000000/sum)>=a.at(i)){
      sum*=a.at(i);
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  char a, b; cin >> a >> b;
  if (a == b) flag = true;

  // cout << num << endl;
  cout << (flag ? "H" : "D") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  int i,j,k,nx,ny,t,r,x[150],y[150],c;
  char m[13][14];
  while(scanf("%s",m[0])!=EOF){
    for(i=1;i<12;i++)scanf("%s",m[i]);
    for(i=c=0;i<12;i++){
      for(j=0;j<12;j++){
	if(m[i][j]=='1'){
	  c++;
	  m[i][j]=0;
	  y[0  ]=i;
	  x[t=0]=j;
	  for(r=1;r-t;t++){
	    for(k=0;k<4;k++){
	      nx=x[t]+X[k];
	      ny=y[t]+Y[k];
	      if(nx<0||11<nx||ny<0||11<ny)continue;
	      if(m[ny][nx]=='0')continue;
	      x[r  ]=nx;
	      y[r++]=ny;
	      m[ny][nx]='0';
	    }
	  }
	}
      }
    }
    printf("%d\n",c);
  }
  return 0;
}
    

  

Measured memory_bytes: 544
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

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

    cout << r*r <<endl;

    return 0;
}

Measured memory_bytes: 256
/**
    AUTHOR:JUNSH
    TIME:19/6/2
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    string c="";
    for(int i=0;s[i];++i){
        if(s[i]=='A')
            c+='(';
        else if(s[i]=='B'&&s[i+1]=='C'){
            i++;
            c+=')';
        }
        else c+='$';
    }
    int len=c.length();
    int tmp=0;
    ll ans=0;
    for(int i=len-1;i>=0;--i){
        if(c[i]=='$'){
            tmp=0;
            continue;
        }
        else if(c[i]==')')
            tmp++;
        else if(c[i]=='(')
            ans+=tmp;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 916
($n,$a,$b,$c)=glob<>;@l=<>;$y=1e9;for$p(0..4**$n){@s=0 x4;$k=30;$s[$p%4]+=$l[$_],$k-=$p%4&&10,$p/=4for 0..$n;$x=abs($s[1]-$a)+abs($s[2]-$b)+abs($s[3]-$c)-$k,$x<$y&&($y=$x),if$s[1]*$s[2]*$s[3]}print$y

Measured memory_bytes: 768
#include<cstdio>
#include<algorithm>
using namespace std;

bool solve(){
  int a,b,n;
  int map[16][16];
  scanf("%d %d",&a,&b);
  if(a==0&&b==0) return 0;
  fill(map[0],map[0]+256,0);
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int x,y;
    scanf("%d %d",&x,&y);
    map[--x][--y] = -1;
  }
  map[0][0] = 1;
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(map[i][j]<0){
        map[i][j] = 0;
      }else{
        if(i!=0) map[i][j]+=map[i-1][j];
        if(j!=0) map[i][j]+=map[i][j-1];
      }
    }
  }
  printf("%d\n",map[a-1][b-1]);
  return 1;
}

int main(){
  while(true) if(!solve()) return 0;
}

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

const int MOD = 1e9+7, MAX_N = 1e5+2;
int N, K;
int a[MAX_N];
ll fac[MAX_N],inv[MAX_N];

ll powmod(ll x, ll y)
{
	ll res=1;
	while(y){
		if(y&1)(res*=x)%=MOD;
		(x*=x)%=MOD;
		y>>=1;
	}
	return res;
}

ll nCk(ll n, ll k)
{
	if(k<0||k>n) return 0;
	return (((fac[n]*inv[k])%MOD)*inv[n-k])%MOD;
}

void solve()
{
	if(K==1){
		cout << 0 << '\n';
		return;
	}
	fac[0] = fac[1]= 1;
	for(int i=2;i<=N;++i) fac[i]=(1LL*i*fac[i-1])%MOD;
	inv[N]=powmod(fac[N],MOD-2);
	for(int i=N-1;i>=0;--i)inv[i]=(1LL*(i+1)*inv[i+1])%MOD;
	sort(a,a+N);
	ll ans = 0;
	for(int i=K-1;i<N;++i)  ans=(ans+a[i]*nCk(i,K-1))%MOD;
	for(int i=N-K;i>=0;--i) ans=(ans-a[i]*nCk(N-i-1,K-1)+MOD)%MOD;
	cout << ans << '\n';
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 5516
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n, i;
  cin >> n;
  int a[n], ans=0, ans2=0;
  for(i=0; i<n; i++){
    cin >> a[i];
    if(a[i]%4==0) {
      ans+=2;
      ans2+=2;
    }
    else if(a[i]%2==0) ans++;
  }
  if(ans>=n||n-1<=ans2) cout << "Yes";
  else cout << "No";
  return 0;
}


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

int main(void){
  int n,T;
  cin>>n>>T;
  string s;cin>>s;
  int bgn=0,nxt;
  double sum=0.0;
  while((nxt=s.find("n^", bgn)) != string::npos){
    sum+=(double)T*(double)pow(n, s[nxt+2]-'0');
    if(sum>1e9){sum=-1;break;}
    bgn=nxt+3;
  }
  if(sum==-1) cout<< "TLE" <<endl;
  else cout<< (int)sum <<endl;
  return 0;
}

Measured memory_bytes: 1240
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int m=Integer.parseInt(scan.next());
    int[][] A=new int[n][m];
    int[] b=new int[m];
    for(int i=0;i<A.length;i++){
      for(int j=0;j<A[i].length;j++){
        A[i][j]=Integer.parseInt(scan.next());
      }
    }
    for(int i=0;i<b.length;i++){
      b[i]=Integer.parseInt(scan.next());
    }
    int[] c=new int[n];
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
          c[i]+=A[i][j]*b[j];
      }
    }
    for(int i=0;i<n;i++){
      System.out.println(c[i]);
    }
  }
}


Measured memory_bytes: 39404
#include<bits/stdc++.h>
using namespace std;
int Abs(int x){return x<0?-x:x;}
int n,a[100005],b[100005],x[100005];//bi-> |[i+2]-[i]|   ai->|[i+1]-[i]|
long long tot;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>x[i];
	for(int i=0;i<=n;i++)
	a[i]=Abs(x[i]-x[i+1]),tot+=a[i];
	for(int i=0;i<=n-1;i++)
	b[i]=Abs(x[i]-x[i+2]);
	for(int i=1;i<=n;i++)
	cout<<tot-a[i-1]-a[i]+b[i-1]<<endl;
	return 0;
}

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

int main() {

  ll N;
  cin >> N;

  vector<pair<ll, ll>> xy(N);

  ll max1 = -1e10;
  ll max2 = -1e10;
  ll min1 = 1e10;
  ll min2 = 1e10;

  for(int i = 0; i < N; i++){
    cin >> xy[i].first >> xy[i].second;

    if(xy[i].first + xy[i].second > max1){
      max1 = xy[i].first + xy[i].second;
    }
    if(xy[i].first + xy[i].second < min1){
      min1 = xy[i].first + xy[i].second;
    }
        
    if(xy[i].first - xy[i].second > max2){
      max2 = xy[i].first - xy[i].second;
    }
    if(xy[i].first - xy[i].second < min2){
      min2 = xy[i].first - xy[i].second;
    }
  }
  if(max1 - min1 > max2 - min2){
    cout << max1 - min1 << endl;
  }else{
    cout << max2 - min2 << endl;
  }
}

Measured memory_bytes: 6408
#include <stdio.h>

int selectionSort(int A[], int N)
{
  int minj = 0, i, j, tmp, count = 0;

  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }

    if(minj != i){      //iとminjが異なり実際に交換が行われた回数
      tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      count++;
    }
  }
  return count;
}

int main(void)
{
  int i, a[100], n, count = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  count = selectionSort(a, n);

  for(i = 0; i < n - 1; i++){
    printf("%d", a[i]);
    printf(" ");
  }

  printf("%d\n%d\n", a[n-1], count);

  return 0;
}



Measured memory_bytes: 2096
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define            bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
vi a , dp , ans;

void dfs(int i = 0 , int p = -1)
{
     int len = lower_bound( all(dp) , a[i] ) - begin(dp);
     int now = dp[len];
     dp[len] = a[i];

     ans[i] = lower_bound( all(dp) , INF) - begin(dp);

     for( auto j : adj[i] )
     {
          if( j != p ) dfs( j , i );
     }

     dp[len] = now;

}

void go()
{
     cin >> n;
     a.resize(n);
     dp.assign(n,INF);
     ans.assign(n , 1);

     fo(i,0,n) cin >> a[i];

     fo(i,0,n-1)
     {
          int u , v;
          cin >> u >> v;
          --u, --v;

          adj[u].pb(v);
          adj[v].pb(u);
     }

     dfs();

     fo(i,0,n) cout << ans[i] << endl;
}

int32_t main()
{
     FAST;     
     int t=1; 
     // cin>>t;
     test(t) go();
}

 

Measured memory_bytes: 30328
#include <iostream>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
llint a[200005];
llint dp[200005][5];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < 5; j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 5; j++){
			if(j == 0){
				dp[i][j] = min(dp[i][j], dp[i-1][j] + a[i]);
			}
			if(j == 1){
				llint val;
				if(a[i] == 0) val = 2;
				else if(a[i] % 2) val = 1;
				else val = 0;
				dp[i][j] = min(dp[i][j], dp[i-1][j] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + val);
			}
			if(j == 3){
				llint val;
				if(a[i] == 0) val = 2;
				else if(a[i] % 2) val = 1;
				else val = 0;
				dp[i][j] = min(dp[i][j], dp[i-1][0] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][1] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][2] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][3] + val);
			}
			if(j == 2){
				llint val;
				if(a[i] == 0) val = 1;
				else if(a[i] % 2) val = 0;
				else val = 1;
				dp[i][j] = min(dp[i][j], dp[i-1][j] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + val);
				dp[i][j] = min(dp[i][j], dp[i-1][j-2] + val);
			}
			if(j == 4){
				dp[i][j] = min(dp[i][j], dp[i-1][j] + a[i]);
				dp[i][j] = min(dp[i][j], dp[i-1][1] + a[i]);
				dp[i][j] = min(dp[i][j], dp[i-1][2] + a[i]);
				dp[i][j] = min(dp[i][j], dp[i-1][3] + a[i]);
			}
		}
	}
	
	llint ans = inf;
	for(int i = 0;  i < 5; i++) ans = min(ans, dp[n][i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >    vecll;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n;
  cin >> n;
  vecint a(10,0);
  int tmp;
  REP(i,n){
    cin >> tmp;
    if(tmp <= 3199){
      a[tmp/400]++;
    }else{
      a[9] ++;
    }
  }
  int num = 0;
  REP(i,9){
    num += (a[i] > 0);
  }
  // REP(i,10){
  //   cout << a[i] << endl;
  // }
  cout << max(1,num) << " " << num + a[9]<<endl;
} 

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

int main(){
	string a;
	char temp;
	while(getline(cin,a)){
		for(int j=0;j<26;j++){
			for(int i=0;i<a.size();i++){
				if(isalpha(a[i])){
					if(a[i] == 122){
						a[i] -= 25;
					}else{
						a[i] += 1;
					}
				}
			}
			if(a.find("the")!=string::npos || a.find("that")!=string::npos || a.find("this")!=string::npos){
				cout << a << endl;
				break;
			}
		}
		a.clear();
	}
	return 0;
}

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


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll positive_sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] > 0){positive_sum += a[i];}
    }
    ll sub_positive_sum = 0;
    ll sub_negative_sum = 0;
    for(int i = 0; i < k; i++){
        if(a[i]>0){sub_positive_sum += a[i];}
        if(a[i]<0){sub_negative_sum += a[i];}
    }
    ll min_sub_positive_sum = sub_positive_sum, posi_idx = 0;
    ll max_sub_negative_sum = sub_negative_sum, nega_idx = 0;
    for(int i = k; i < n; i++){
        if(a[i]>0){sub_positive_sum += a[i];}
        if(a[i]<0){sub_negative_sum += a[i];}
        if(a[i-k]>0){sub_positive_sum -= a[i-k];}
        if(a[i-k]<0){sub_negative_sum -= a[i-k];}
        if(sub_positive_sum < min_sub_positive_sum){
            min_sub_positive_sum = sub_positive_sum;
            posi_idx = i-k+1;
        }
        if(sub_negative_sum > max_sub_negative_sum){
            max_sub_negative_sum = sub_negative_sum;
            nega_idx = i-k+1;
        }
    }
    ll ans = positive_sum - min(min_sub_positive_sum, -1*max_sub_negative_sum);
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int ans = 1, l = 0, r = 1, t = s[0] == '1' ? 0 : 1;
	while (r < n) {
		if (s[r - 1] == '1' && s[r] == '0') {
			t++;
			if (t > k) {
				while (1) {
					l++;
					if (s[l - 1] == '0' && s[l] == '1')break;
				}
				t--;
			}
		}
		if (ans < r - l + 1)ans = r - l + 1;
		r++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
s = input().split(" ")
s = [int(i) for i in s]
s = sorted(s)
Max = s[2]
Med = s[1]
Min = s[0]

count = Max - Med
left = (Max - Min - count) 
if left % 2 == 1 : 
    count += (left+1)/2 + 1
else : 
    count += left/2
print(int(count))

Measured memory_bytes: 3064
program bbb

implicit none
integer :: i, n, res
integer, allocatable, dimension(:)  :: a, b, c

read(*,*) n

allocate(a(n))
allocate(b(n))
allocate(c(n-1))

read(*,*) a
read(*,*) b
read(*,*) c

res = b(1)

do i = 2, n
res = res + b(i)
if ((a(i)-a(i-1))==1) then
res = res + c(a(i-1))
end if
end do

write(*,'(i0)') res

end program


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned llu;
typedef pair<ll, ll> P;//change when necessary
typedef long double ld;
#define mp make_pair
#define N ll(200005)//change it
#define M ll(1)
const ll OO = 1e18;
const ll md = 1e9 + 7;
ll X[] = { 0,0,1,-1 }, Y[] = { 1,-1,0,0 };
ll gcd(ll xx, ll yy)
{
	ll x = min(xx, yy), y = max(xx, yy);
	if (x == 0)
		return y;
	return gcd(x, y%x);
}
ll vivo(ll x, ll y)
{
	if (y == 0)
		return 1LL;
	if (y == 1)
		return x;
	ll t = vivo(x, y / 2), r = vivo(x, y % 2);
	t *= t;
	t *= r;
	return t;
}
ll vivo_mod(ll x, ll y, ll m)
{
	if (y == 0)
		return 1LL;
	if (y == 1)
		return x%m;
	ll t = vivo(x, y / 2), r = vivo(x, y % 2);
	t *= t; t %= m;
	t *= r; t %= m;
	return t;
}
ll mo(ll x, ll y)
{
	return max(x, y) - min(x, y);
}
void fast()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

P p[N];
ll n, ans[N];
int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &p[i].first);
		p[i].second = i;
	}
	sort(p, p + n);
	for (int i = 0; i < n; i++)
	{
		if (i < n / 2)
			ans[p[i].second] = p[n / 2].first;
		else
			ans[p[i].second] = p[n / 2 - 1].first;
	}
	for (int i = 0; i < n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 6912
r=".IVXLCDM",require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(function(i){i?(n=s=p=0,i.split('').map(function(c){n=Math.pow(10,~~((n=r.indexOf(c))/2))/(2-(n%2)),n>p?p*=-1:0,s+=p,p=n}),console.log(s+=p)):0})

Measured memory_bytes: 8704
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
int a,b,c,ans,N,M,T;
int main(){
	scanf("%d%d",&a,&b);
	if ((a+b)%2) printf("IMPOSSIBLE\n");
	else printf("%d\n",(a+b)/2);
	return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readInt
	val a = scala.collection.mutable.Queue.empty[Long]

	for(x<-1L to 9L) a.enqueue(x)

	for(t<-1 to N-1){
		val x = a.dequeue()
		val tp = 10L*x + (x % 10L)
		if(x%10L != 0L) a.enqueue(tp - 1L)
		a.enqueue(tp)
		if(x%10L != 9L) a.enqueue(tp + 1L)
	}

	println(a.dequeue())
}

Measured memory_bytes: 47956
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#include <map>
#define INF 2147483647
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int N;
vector <ll> v;
ull C[100][100];
void combi(int n) {
	for (int i = 0; i <= n; i++) {
		C[i][0] = 1;
		C[i][i] = 1;
	}
	for (int j = 1; j <= n; j++) {
		for (int k = 1; k < j; k++) {
			C[j][k] = (C[j - 1][k - 1] + C[j - 1][k]);
		}
	}
}

int main() {
	int A, B;
	cin >> N >> A >> B;
	combi(N+1);
	v = vector<ll>(N, 0);
	for (int i = 0; i < N; i++)cin >> v[i];
	sort(v.begin(), v.end(), greater<ll>());
	double ans = 0;
	for (int i = 0; i < A; i++)ans += v[i];
	ans /= A;

	int a = 0, b = 0;
	for (int i = 0; i < N; i++) {
		if (v[A-1] == v[i]) {
			a++;
			if (i < A) b++;
		}
	}
	ull ans2 = 0;
	if (v[0] != v[A - 1]) {
		ans2 += C[a][b];
	}
	else {
		for (int i = A; i <= B; i++) {
			ans2 += C[a][i];
		}
	}
	cout.precision(20);
	cout << fixed << ans << endl;
	cout << ans2 << endl;
	return 0;
}

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

int main() {
  ll x;
  cin >> x;
  int ans=0;
  ans += (x/500)*1000;
  x%=500;
  ans+=(x/5)*5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long n,now=0,good,targ=0,log2=0;
int a[205]={0};
void solution(long long good)
{
    int i=40, L=101,R=L-1;
    for(;!((1ll<<i)&good);i--);
    for(i--;i>=0;i--){
        a[++R]=++now;
        if((1ll<<i)&good) a[--L]=++now;
    }

    n=R-L+1;
    for(int i=1;i<=n;i++) a[i]=a[i+L-1];
    for(int i=n+1;i<=n*2;i++) a[i]=i-n;
    n<<=1;
}
int main()
{
    cin>>good;
    int tep=good+1;
    while(tep/2){
        log2++;
        tep/=2;
    }
    targ=log2;
    solution(good+1);
    cout<<n<<endl;
    for(int i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>
#include <limits>
#include <map>
using namespace std;

int main()
{
    int h, w;
    while (cin >> h >> w)
    {
        if (h == 0 && w == 0)
        {
            break;
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (i != 0 && i != h - 1)
                {
                    if (j == 0 || j == w - 1)
                    {
                        cout << "#";
                    }
                    else
                    {
                        cout << ".";
                    }
                }
                else
                {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>


int main( void )
{
	int N ;
	while( scanf( "%d" ,&N ) != EOF )
	{
		long cnt[ 4 + 1 ][ 50 + 1 ] = { 1 } ;

		int i ,j ,k ;
		for( i = 1 ; i <= 4 ; ++i )
		{
			for( j = 0 ; j <= N ; ++j )
			{
				if( cnt[ i - 1 ][ j ] > 0 )
				{
					for( k = 0 ; k <= 9 ; ++k )
					{
						if( j + k < 50 + 1 )
						{
							cnt[ i ][ j + k ] += cnt[ i - 1 ][ j ] ;
						}
					}
				}
			}
		}

		printf( "%ld\n" ,cnt[ 4 ][ N ] ) ;
	}

	return 0 ;
}


Measured memory_bytes: 2032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int y = Integer.parseInt(str[1]);

		for (int i = 0; i <= n; i++) {
			for (int j = 0; j + i <= n; j++) {
				int k = (n - i - j);

				if (k < 0)
					continue;
				long sum = 10000 * i + 5000 * j + 1000 * k;

				//System.out.println(i + " " + j + " " + k);

				if (sum == y) {
					System.out.println(i + " " + j + " " + k);
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}


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


int main() {
  int A,B;cin >> A >> B;
  if (A+B >= 10){
    cout << "error" << endl;
  }else{
    cout << A+B << endl;
  }

}       

Measured memory_bytes: 256
def resolve():
    R, C, K = map(int, input().split())
    G = [[0] * (C + 1) for _ in range(R + 1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        G[r][c] = v

    dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                here = dp[k][i][j]
                # 次の行に移動する場合
                if i + 1 <= R:
                    # 移動先のアイテムを取らない場合
                    dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                    # 移動先のアイテムを取る場合
                    dp[1][i + 1][j] = max(dp[1][i + 1][j], here + G[i + 1][j])
                # 次の列に移動する場合
                if j + 1 <= C:
                    # 移動先のアイテムを取らない場合
                    dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                    # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                    if k < 3:
                        dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + G[i][j + 1])
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][-1][-1])
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 428148
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

vector<int> edge[5001];

bool same(string a,string b,int len,int v){
	if(a.size()<len || b.size()<len+v)return false;
	a=a.substr(0,v);
	b=b.substr(len,v);
	return (a==b);
}

void KMP(string text,string pattern,int v){
	int textN=text.size();
	int patternN=pattern.size();
	vector<int> next(patternN+1,0);
	next[0]=1;
	for(int i=1;i<=patternN;i++){
		string s=pattern.substr(0,i);
		int len=1;
		while(i-len>0 && !same(s,pattern,len,i-len))len++;
		next[i]=len;
	}
	int cnt=0;
	int tp=0,pp=0;
	while(tp<textN){
		if(text[tp]==pattern[pp]){
			tp++;
			pp++;
		}else{
			pp-=next[pp];
			if(pp<0){
				tp++;
				pp++;
			}
		}
		if(pp==patternN){
			edge[tp-pattern.size()].push_back(v);
		}
	}
}

int n,m;
string e[13];
string text;
bool dp[5001][1<<12];

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(int i=0;i<n;i++){
			cin >> e[i];
		}
		text="";
		for(int i=0;i<m;i++){
			string str;
			cin >> str;
			text+=str;
		}
		int len=text.size();
		for(int i=0;i<len;i++){
			edge[i].clear();
		}
		for(int i=0;i<n;i++){
			KMP(text,e[i],i);
		}
		memset(dp,false,sizeof(dp));
		ll res=0;
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<=len;j++){
				if(i==0)dp[j][i]=true;
				if(!dp[j][i])continue;
				if(i==((1<<n)-1)){
					res+=dp[j][i]?1:0;
				}
				for(int l=0;l<edge[j].size();l++){
					int k=edge[j][l];
					if((!((i>>k) & 1))){
						dp[j+e[k].size()][i|(1<<k)]|=dp[j][i];
					}
				}
			}
		}
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 23896
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "NO" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

long long fact(long long x){
    long long k=1;
    for(int i=1;i<=x;i++){
        k=(k*i)%MOD;
    }
    return k;
}

long long inverse(long long b){
    long long r=1,e=MOD-2;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}

int Comb(int i,int j){
    if(i==0 || j==0)return 0;
    int num=fact(i+j);
    num*=inverse(fact(i));num%=MOD;
    num*=inverse(fact(j));num%=MOD;
    return num;
}

signed main(void){
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    //おなじみパスカル行列を区間で和を取ろうという問題
    //F[n][r]=nCr(n+r,r)と、
    //G[a][b]をΣ[i,0~a-1](Σ[j,0~b-1](F[i][j]))と表す
    //ここで、G[a][b]をO(N)くらいで計算できれば勝ち
    //ところで、G[a][b]=F[a+1][b+1]-1になる
    //なので、それぞれのGをO(N+logMOD)で計算できるのでAC
    int Ans=0;
    Ans+=Comb(r2+1,c2+1);
    Ans-=Comb(r1,c2+1);
    Ans-=Comb(r2+1,c1);
    Ans+=Comb(r1,c1);
    Ans+=MOD;Ans+=MOD;Ans%=MOD;
    
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main()
{
	char s[200005];
	int l, i = 0, ans = 0;
	
	scanf("%s", s);
	
	l = strlen(s);
	
	while (i <= l-3)
		if (s[i] == s[i+1]) {
			i += 3; ans += 2;
		} else {
			i++; ans++;
		}
	
	if (i == l-2)
		if (s[i] == s[i+1]) {
			i += 2; ans++;
		} else {
			i++; ans++;
		}
	
	if (i == l-1) {
		i++; ans++;
	}
	
	printf("%d", ans);
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
    int f=x*a+y*b;
    int s=c*2*max(x,y);
    int t;
    if(x<y)t=c*2*x+(y-x)*b;
    else t=c*2*y+(x-y)*a;
    cout<<min(f,min(s,t))<<endl;
    return 0;
}

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

namespace BuildStairs
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            string[] h = Console.ReadLine().Split(' ');

            int before = int.Parse(h.Last());


            string result = "Yes";
            foreach (string v in h.Reverse())
            {
                int value = int.Parse(v);

                if (value > before)
                {
                    if (value - before != 1)
                    {
                        result = "No";
                    }
                    else
                    {
                        value--;
                    }
                    
                }


                before = value;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 25436
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    char c[3][3];
    while (scanf("%s",c[0])!=EOF)
    {
        scanf("%s",c[1]);
        scanf("%s",c[2]);
        printf("%c%c%c\n",c[0][0],c[1][1],c[2][2]);
    }
    return 0;
}

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n),b(n),c(n-1);
  rep(n) cin >> a[i];
  rep(n) cin >> b[i];
  rep(n-1) cin >> c[i];
  ll tmp = 0, prev = -2, cur;
  for (ll i = 0; i < n; i++)
  {
    cur = a[i]-1;
    tmp += b[cur];
    if(cur == prev+1) tmp += c[prev];
    prev = cur;
  }
  cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

vector<int> vi;

int main()
{
    int N;

    if (scanf("%d", &N) < 1) return 0;

    vi.resize(N);

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &vi[i]) < 1) return 0;
    }

    sort(vi.begin(), vi.end());
    reverse(vi.begin(), vi.end());

    int first = 0;
    int second = 0;

    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0) first += vi[i];
        else second += vi[i];
    }

    printf("%d\n", first - second);

    return 0;
}


Measured memory_bytes: 256
N = gets.to_i # レンガの個数
a = gets.split.map(&:to_i) # レンガに書かれてる数字

e=N
i=1

ans=0
s=a.index(i)
while s!=nil
  ans += s
  a = a.slice(s+1,e)
  e = a.length
  i = i+1
  s=a.index(i)
end

if i>1
  puts ans+e
else
  puts -1
end

Measured memory_bytes: 19204
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;
ll ans = 0;
int m,q;
long unsigned int n;
vi a,b,c,d;
void solve(vi v){
	if( v.size() == n){
		 ll temp = 0;
	 	for(int i = 0; i <q; i++){
			if( - v[a[i]] + v[b[i]]  == c[i]){
				temp+= d[i];
			}	
		}	 
		ans = max(ans,temp);
		return;
	} 
	else{
		// 0
		int st = 1;	
		if(v.size())
		 st = v.back();
		for(int i= st ; i <= m; i++){
			v.push_back(i);
			solve(v);
			v.pop_back();
		}	
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	rep(i,0,q-1){
		cin>>a[i]>>b[i]>>c[i]>>d[i];	
		a[i]--,b[i]--;
	}
	ans = 0;
	vector<int> v;
	solve(v);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3664
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;

char change(int x) {
	if (x == 1) return '1';
	else return '0';
}

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, s.length()) {
		if (s[i] == change(i%2)) {
			cnt++;
		}
	}
	int tmp2 = s.length() - cnt;
	show(min(cnt, tmp2));

	return 0;

}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

vi solve(int N, vi& x, vi& y, vi& h) {

    for (int cx=0; cx<=100; ++cx){
        for (int cy=0; cy<=100; ++cy){
            //
            int _h = 0, _cap = INT_MAX;
            rep(i, N){
                int mh = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                if (h[i] == 0) {
                    _cap = min(_cap, mh);
                } else {
                    if (_h == 0) {
                        _h = mh;
                    } else if (mh == _h) {
                        ; // continue;
                    } else {
                        goto wrong;
                    }
                }
            }
            // if (_h == 0 && _h != INT_MAX) {
            //     _h = _cap;
            // }
            if (_h != 0 && _h <= _cap) {
                return vi{cx, cy, _h};
            }
        wrong:
            ;
        }
    }
    return vi{-1,-1,-1};
}

int main() {
    int N; scanf("%d", &N);
    vi x(N), y(N), h(N);
    rep(i,N){
        scanf("%d %d %d", &x[i], &y[i], &h[i]);
    }
    vi ans = solve(N,x,y,h);
    printf("%d %d %d\n", ans[0], ans[1], ans[2]);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define delta 1e-9

int main(){
	int i,n;
	double x1,y1,x2,y2,x3,y3,x4,y4;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if(x1==x2){
			if(x3==x4) printf("YES\n");
			else printf("NO\n");
		}else if(y1==y2){
			if(y3==y4) printf("YES\n");
			else printf("NO\n");
		}else if(fabs((y2-y1)/(x2-x1)-(y4-y3)/(x4-x3))<delta){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
int main(){
	int S;cin>>S;
	int a=S/100;int b=S%100;
	if((a>12||a==0)&&(b>12||b==0)){
		cout<<"NA"<<endl;
	}else if(a>12||a==0){
		cout<<"YYMM"<<endl;
	}else if(b>12||b==0){
		cout<<"MMYY"<<endl;
	}else{
		cout<<"AMBIGUOUS"<<endl;
	}
}

Measured memory_bytes: 256
import random
import sys

import numpy as np

global NN
NN = 26

readline = sys.stdin.buffer.readline


class Contest:
    """
    d: ある日付
    i: テストの種類
    self.day: 最後にテストiを開催した日
    """

    def __init__(self, c, s, D):
        self.last = [-1 for _ in range(NN)]
        self.C = c
        self.S = s
        self.score = 0

    def minus_score(self, d, i):
        m = self.C[i] * (d - self.last[i])
        return m

    def sum_minus_scores(self, d):
        m = 0
        for i in range(NN):
            m += self.minus_score(d, i)

        return m

    # テストiを開催したときのスコア
    def update_score(self, i, d):
        self.last[i] = d
        self.score += S[d][i]
        self.score -= self.sum_minus_scores(d)
        return self.score

    # 日付を更新せずにスコアを計算
    def calc_score(self, i, d):
        s = self.score
        last_d = self.last[i]
        self.last = d
        s += S[d][i]
        s -= self.sum_minus_scores(d)
        self.last = last_d

        return s


D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

tests = [int(input()) for _ in range(D)]

tests = [i - 1 for i in tests]

T = Contest(C, S, D)

for d, test in enumerate(tests):
    print(T.update_score(test, d))



Measured memory_bytes: 27300
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int A, B, m;
	cin >> A >> B >> m;
	vector<int> a(A), b(B);
	int ans = 2e5;
	for (auto&& i : a) {
		cin >> i;
	}
	for (auto&& i : b) {
		cin >> i;
	}
	for (int i = 0; i < m; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		ans = min(ans, a[x - 1] + b[y - 1] - c);
	}
	sort(begin(a), end(a));
	sort(begin(b), end(b));
	cout << min(ans, a[0] + b[0]) << "\n";
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() / 3);
        }

    }
}



Measured memory_bytes: 21972