akhauriyash/Code-Regression huggingface dataset:
// AtCode_Beginner_160.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <sstream>

using namespace std;

void A();
void B();
void C();
void D();
void E();

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

	B();
}

void A() {
	string s;
	cin >> s;
	


	cout << ((s[2] == s[3]) && (s[4] == s[5]) ? "Yes" : "No") << endl;

}

void B() {
	int n;
	cin >> n;

	int sum = n - n % 500;
	sum *= 2;
	sum += (n % 500) - (n % 5);

	cout << sum << endl;

}

void C() {

	long long N, K;
	cin >> N >> K;

	long long div = N % K;

	long long m = min(div, abs(div - K));

	cout << m << endl;

}

void D() {





}

int helper(int N, int K) {

	while (N >= K) {
		if (N % K == 0) N /= K;
		else N %= K;
	}

	return N == 1;

}

void E() {

	int N;
	cin >> N;

	vector<bool> factor(N, false);

	int count = 2;

	for (int n = 2; n * n < N; n++) {

		int divisible = false;
		if (N % n == 1) count++;
		else if (N % n == 0) if (helper(N, n)) count++;
		/*
		//hasnt been done before
		if (!factor[n]) {

			divisible = (N % n == 0);

			for (int i = n; i < N; i+=n) {
				factor[i] = true;

				if (divisible) {
					if(helper(N, i)) count++;
				}

			}

		}*/

	}

	cout << count;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 1000000007
#define MOD 1000000007
#define SEP " "

int		main(void)
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<int> add(n);
	vector<int> sub(n);
	for (int i = 0; i < n; i++)
	{
		add[i] = i + a[i];
		sub[i] = i - a[i];
	}
	sort(add.begin(), add.end());
	sort(sub.begin(), sub.end());
	ll count = 0;
	auto it = add.begin();
	while (it != add.end())
	{
		ll ci, cj;
		auto tmp = upper_bound(add.begin(), add.end(), *it);
		ci = tmp - it;
		cj = upper_bound(sub.begin(), sub.end(), *it) - lower_bound(sub.begin(), sub.end(), *it);
		count += ci * cj;
		it = tmp;
	}
	cout << count << endl;
}


Measured memory_bytes: 5568
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int i, x[100000], n;
    i=0;
    while (1) {
        i++;
        scanf("%d", &x[i]);
        if (x[i]==0) {
            break;
        }
    }
    for (n=1; n<i; n++) {
        printf("Case %d: %d\n", n, x[n]);
    }
    return 0;
}



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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

struct S{
  vector<int> p;
  int t;
  S(vector<int> p, int t) : p(p),t(t) {}
};

bool operator<(const S& s, const S& t){
  return s.t > t.t;
}

int x[13] = {2,1,2,3,0,1,2,3,4,1,2,3,2};
int y[13] = {4,3,3,3,2,2,2,2,2,1,1,1,0};
vector<int> goal(13);
set<vector<int> > memo;
int distance(S s){
  int count = 0;
  REP(i,13){
    if(s.p[i]){
      count += abs(x[i]-x[s.p[i]]) + abs(y[i]-y[s.p[i]]);
    }
  }
  return count+s.t;
}
void print_s(S s){
  vector<int> v = s.p;
  printf("time:%d\n",s.t);
  printf("    %2d    \n",v[0]);
  printf("  %2d%2d%2d  \n",v[1],v[2],v[3]);
  printf("%2d%2d%2d%2d%2d\n",v[4],v[5],v[6],v[7],v[8]);
  printf("  %2d%2d%2d  \n",v[9],v[10],v[11]);
  printf("    %2d    \n",v[12]);
}
int bfs(S start){
  priority_queue<S> que;
  que.push(start);
  while(!que.empty()){
    S s = que.top(); que.pop();
    //print_s(s);
    if(s.t > 20) return -1;
    if(s.p == goal) return s.t;
    if(memo.find(s.p)!=memo.end()) continue;
    memo.insert(s.p);
    if(distance(s) > 20) continue;
    REP(i,13){
      vector<int> tmp = s.p;
      if(s.p[i]==0){
        switch(i){
          case 0:
          case 2:
            swap(tmp[0],tmp[2]);
            que.push(S(tmp,s.t+1));
            break;
          case 12:
          case 10:
            swap(tmp[12],tmp[10]);
            que.push(S(tmp,s.t+1));
            break;
          case 4:
          case 5:
            swap(tmp[4],tmp[5]);
            que.push(S(tmp,s.t+1));
            break;
          case 8:
          case 7:
            swap(tmp[8],tmp[7]);
            que.push(S(tmp,s.t+1));
            break;
        }
        if(i % 4 == 2 || i % 4 == 3){
          tmp = s.p;
          swap(tmp[i],tmp[i-1]);
          que.push(S(tmp,s.t+1));
        }
        if(i % 4 == 1 || i % 4 == 2){
          tmp = s.p;
          swap(tmp[i],tmp[i+1]);
          que.push(S(tmp,s.t+1));
        }
        if(i % 4 != 0 && i < 8){
          tmp = s.p;
          swap(tmp[i],tmp[i+4]);
          que.push(S(tmp,s.t+1));
        }
        if(i % 4 != 0 && i > 4){
          tmp = s.p;
          swap(tmp[i],tmp[i-4]);
          que.push(S(tmp,s.t+1));
        }
      }
    }
  }
  return -1;
}
int main(){
  int n;
  vector<int> p(13);

  REP(i,11) goal[i+1] = i+1;

  while(cin>>p[0], p[0]!=-1){
    for(int i = 1; i < 13; i++){
      cin>>p[i];
    }
    S start(p,0);
    memo.clear();
    int ans = bfs(start);
    if(ans == -1)cout<<"NA"<<endl;
    else cout<< ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const double pi=acos(-1);
const ll N_MAX=100005;
ll now[N_MAX];
ll now_old[N_MAX];
const ll INF=1e18;

int main(){
  int n,m;
  cin >>n>>m;
  int a,b;
  vector<vector<int>>c(n);
  rep(i,m){
    cin >>a>>b;
    a--; b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  vector<int> visit(n);// 訪れるステップ数
  vector<int> sig(n); //導
  vector<int> next(n),in(n);
  rep(i,n) {
    visit[i]=-1; next[i]=-1; in[i]=-1;
  }
  visit[0]=1;
  next[0]=0;
  in[0]=0;
  int j=0;
  int time=0;
  in[0]=0;
  for(int i=0; i<n;i++){
      int p=next[i];
          for(int q :c[p]){// 
            if(visit[q]<0){
             //cout<<"pq;"<<p<<q<<endl;
             sig[q]=p;
        	 visit[q]=1;
             j++;
             next[j]=q;
             //cout<<q<<endl;
             in[j]=in[i]+1;
            }
          }
  }
 // rep(i,n) cout<<in[i]<<" "<<next[i]<<endl; 
  cout<<"Yes"<<endl;
  for(int i=1;i<n;i++) cout<<sig[i]+1<<endl;
  
}


Measured memory_bytes: 11112
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final long d = 5000000000000000L;
        String S = sc.next();
        long K = sc.nextLong();
        for(int i=0;i<S.length();i++){
            int cur = S.charAt(i)-'0';
            if(cur==1&&i+1<K) continue;
            if(cur==1&&i+1==K){
                System.out.println("1");
                System.exit(0);
            }
            if(cur!=1){
                System.out.println(cur);
                System.exit(0);
            }
        }
        System.out.println("1");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1000000007;
	int n,m,x;
	cin>>n>>m>>x;
	vector<pair<int,vector<int>>> vec(n,{0,vector<int>(m)});
	rep(i,n){
		cin>>vec[i].first;
		rep(j,m)cin>>vec[i].second[j];
	}
	int ans=LLONG_MAX;
	rep(i,(1<<n)){
		vector me(m,0);
		int cnt=0;
		rep(j,n){
			if(i&(1<<j)){
				cnt+=vec[j].first;
				rep(k,m)me[k]+=vec[j].second[k];
			}
		}
		rep(j,m){
			if(me[j]<x)goto joi;
		}
		ans=min(ans,cnt);
		joi:;
	}
	if(ans==LLONG_MAX)cout<<-1<<endl;
	else cout<<ans<<endl;
}


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

int main() {
  int i,j,H,W;
  cin >> H >> W;
  int a[H+2][W+2] = {0};
  for(i = 0; i < H; i++){
    string S;
    cin >> S;
    for(j = 0; j < W; j++){
      if(S.substr(j,1) == "#"){
        a[i][j]++;
        a[i+1][j]++;
        a[i+2][j]++;
        a[i+2][j+1]++;
        a[i+2][j+2]++;
        a[i+1][j+2]++;
        a[i][j+2]++;
        a[i][j+1]++;
        a[i+1][j+1] += 9;
      }
    }
  }
  for(i = 1; i <= H; i++){
    for(j = 1; j <= W; j++){
      if(a[i][j] > 8) cout << "#";
      else cout << a[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
N,K = map(int, input().split())
A = [*map(lambda x:int(x)-1, input().split())]
index = [-1]*N
path = []
pre = 0
while index[pre] < 0:
    index[pre] = len(path)
    path += [pre]
    pre = A[pre]
one = index[pre]
loops = len(path) - one
if K < one: print(path[K]+1)
else: print(path[(K-one) % loops + one]+1)


Measured memory_bytes: 32376
#include<stdio.h>
#include<stdlib.h>

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


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n>= 400 && n<= 599){
		cout << 8 << endl;
	}else if (n>=600 && n<=799){
		cout << 7 << endl;
	}else if (n>= 800 && n<=999){
		cout << 6 << endl;
	}else if (n>= 1000 && n<= 1199){
		cout << 5 << endl;
	}else if(n>= 1200 && n<=1399) {   
		cout << 4 <<endl;
	}else if (n>= 1400 && n<= 1599){
		cout << 3 << endl;
	}else if (n>= 1600 && n<= 1799){
		cout << 2 << endl;
	}else{
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3628
n = int(input())
a = [int(_) for _ in input().split()]

a_sorted = sorted(a, reverse=True)
x = 0
y = 0

while True:
    if len(a_sorted) <= 1:
        break
    max = a_sorted[0]
    if x != 0 and y != 0:
        break
    if a_sorted[1] == max:
        if x == 0:
            x = max
        else:
            y = max
        a_sorted.remove(max)
        a_sorted.remove(max)
    else:
        a_sorted.remove(max)
print(x * y)

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 406
#define mod 1000000007
#define mod2 998244353
#define inf 1e18

int a[N];
int dp[N][N];
int n;
int pref[N];

int sum(int i,int j)
{
    int ans=pref[j]-pref[i-1];
    return ans;
}

int solve(int i,int j)
{
    if(i>=j)
        return 0;
    if(i+1==j)
        return (a[i]+a[j]);


    int &ans=dp[i][j];
    if(ans!=-1)
        return ans;

    ans=inf;

    for(int k=i;k<=j;k++)
    {
        ans=min(ans,solve(i,k)+solve(k+1,j)+sum(i,j));
    }

    return ans;
}







int32_t main()
{
    boost
   // #ifndef ONLINE_JUDGE 
   // NAYAN
   // #endif

    memset(dp,-1,sizeof dp);
    cin >> n;
    int i;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
    }

    pref[0]=0;
    pref[1]=a[1];

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



    int ans=solve(1,n);

    cout << ans;

    
    
    
}

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

int main() {
	int n;
	cin>>n;
	vector<int> arr(n+1);
	int S = 0;
	for(int i=1;i<=n;i++){
	    cin>>arr[i];
	    S+=arr[i];
	}
// 	vector<vector<int>> dp(2,vector<int>(S+1,0));
// 	dp[0][0] = 1;
// 	for(int i=1;i<=n;i++)
// 	    for(int s=0;s<=S;s++){
// 	        dp[i%2][s] = dp[(i-1)%2][s];
// 	        if(s-arr[i]>=0)
// 	            dp[i%2][s] += dp[(i-1)%2][s-arr[i]];
// 	    }
    
    bitset<2000009> dp;
    dp[0] = 1;
    for(int i=1;i<=n;i++){
        dp = dp | (dp<<arr[i]);
    }
	int s;
	for(s=(S+1)/2;s<=S;s++){
	 
	   if(dp[s]>0)
	        break;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define n 8
#define buda -1//表示不会受到攻击
#define da 1//表示受到攻击
int h[n],l[n],zx[2*n],yx[2*n];
int x[n][n];
void init()
{
    for(int i=0; i<n; i++)
    {
        h[i]=buda;
        l[i]=buda;
    }
    for(int i=0; i<2*n; i++)
    {
        zx[i]=buda;
        yx[i]=buda;
    }
}
void str()
{
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(x[i][j])
            {
                if(h[i]!=j)
                    return ;
            }
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(h[i]==j)//如果第i行第j列有一个
                printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}
void app(int i)
{
    if(i==n)
    {
        str();
        return ;
    }
    for(int j=0; j<n; j++)
    {
        if(l[j]==da||zx[i+j]==da||yx[i-j+7]==da)
            continue;
        h[i]=j;// 第i行j列放了一个
        l[j]=zx[i+j]=yx[i-j+7]=da;
        app(i+1);
        h[i]=l[j]=zx[i+j]=yx[i-j+7]=buda;
    }
}
int main()
{
    init();
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            x[i][j]=0;
    int k,a,b;
    scanf("%d",&k);
        for(int i=0; i<k; i++)
        {
            scanf("%d%d",&a,&b);
            x[a][b]=1;
        }
        app(0);
    return 0;
}



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

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

    map<int, int> counts;
    int a;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        counts[a]++;
    }

    int ans = 0;
    for (auto count = counts.begin(); count != counts.end(); count++)
    {
        if (count->second != count->first)
        {
            if (count->second > count->first)
            {
                ans += count->second - count->first;
            }
            else
            {
                ans += count->second;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

struct UnionFind {
	UnionFind(int n) {
		par = new int[n + 1];
		size = new int[n + 1];
		height = new int[n + 1];
		for (int i = 0; i <= n; ++i) {
			par[i] = i;
			size[i] = 1;
			height[i] = 1;
		}
	}

	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (height[a] < height[b]) {
			par[a] = b;
			size[b] += size[a];
		}
		else {
			par[b] = a;
			size[a] += size[b];
			if (height[a] == height[b]) {
				height[a]++;
			}
		}

	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

	int getSize(int a) {
		return size[root(a)];
	}

	bool isSame(int a, int b) {
		return root(a) == root(b);
	}

	int* size;
	int* height;
	int* par;
};

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

  int n,m,k;
	cin >> n >> m >> k;

	UnionFind uf(n);
	vector<int> ans(n, 0);

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		ans[a]--;
		ans[b]--;

		uf.unite(a,b);
	}

	rep(i, k) {
		int c, d;
		cin >> c >> d;
		c--; d--;

		if (uf.isSame(c, d)) {
			ans[c]--;
			ans[d]--;
		}
	}

	rep(i, n) {
		ans[i] += uf.getSize(i)-1;
	}
	rep(i,n) { 
	  cout << ans[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 2432
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long L, R;
    cin >> L >> R;

    int res = 0;

    while (L <= R) {
        L <<= 1;
        ++res;
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,a,b = map(int, input().split())
    if a > b:
        print(0)
    elif n == 1:
        if a == b:
            print(1)
        else:
            print(0)
    elif n == 2:
        print(1)
    else:
        print((b-a)*(n-2)+1)

if __name__ == '__main__':
    main()

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

int main() {
    string n;
    cin >> n;
    int sum = 0;
    for (char i : n) {
        sum += i - '0';
    }
    if (sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;
const ld pi = (acos(-1));

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll n,k; cin >> n >> k;
  vector<ll> h(n);
  rep(i,0,n) cin >> h[i];
  sort(rALL(h));
  ll ans=mod;
  rep(i,0,n+1-k) {
    ans=min(ans,h[i]-h[i+k-1]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A[3][3], N;
  bool appear[3][3];
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  int b[N+1];
  for (int i=0; i<N; i++){
    cin >> b[i];
  }
    for (int j=0; j<3; j++){
      for (int k=0; k<3; k++){
        appear[j][k]=false;
        for (int i=0; i<N; i++){
          if (b[i]==A[j][k]){
            appear[j][k]=true;
          }
        }
      }
    }
  string ans = "No";
  for (int i=0; i<3; i++){
    if (appear[i][0]==true && appear[i][1]==true && appear[i][2]==true) ans = "Yes";
  }
  for (int i=0; i<3; i++){
    if (appear[0][i]==true && appear[1][i]==true && appear[2][i]==true) ans = "Yes";
  }
  if (appear[0][0]==true && appear[1][1]==true && appear[2][2]==true) ans = "Yes";
  if (appear[0][2]==true && appear[1][1]==true && appear[2][0]==true) ans = "Yes";
  cout << ans << 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 rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    rep(i, 4)if(s[i] =='+') ans++; else ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def make_bit(i):
    if i == h - 1:
        solve(t)
        return
    make_bit(i + 1)
    t[i] = 1
    make_bit(i + 1)
    t[i] = 0

def solve(u):
    global ans
    c = sum(u)
    x = [0] * (c + 1)
    y = [0] * h
    for i in range(h - 1):
        y[i + 1] = y[i] + u[i]
    for i in range(w):
        for j in range(h):
            x[y[j]] += int(s[j][i])
        if max(x) > k:
            c += 1
            x = [0] * c
            for j in range(h):
                x[y[j]] += int(s[j][i])
        if max(x) > k:
            c = 1919810
            break
    if ans > c:
        ans = c
    return

h, w, k = map(int, input().split())
s = [list(input()) for _ in range(h)]
t = [0] * (h - 1)
ans = 114514
make_bit(0)
print(ans)

Measured memory_bytes: 49884
<?php
	$n=fgets(STDIN);
	$s=fgets(STDIN);
	$a=0;
	$t=0;
	for($i=0;$i<$n;$i++)
	{
		if($s[$i]=='I')$t++;
		else $t--;
		$a=max($a,$t);
	}
	echo $a;


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n,W;
int dp[110][110000];
int w[1100],v[1100];

signed main(){
  cin>>n>>W;
  rep(i,n){
    cin>>w[i]>>v[i];
  }

  rep(i,110){
    rep(j,110000){
        dp[i][j]=INF;
    }
  }

  dp[0][0]=0;

  FOR(i,1,n+1){
    rep(j,110000){
      dp[i][j]=dp[i-1][j];
      if(j-v[i-1]<0) continue;
      dp[i][j]=min(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);
    }
  }

  rrep(i,110000){
    if(dp[n][i]<=W){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

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

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

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

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

    ll a,b,n;
    cin>>a>>b>>n;

    ll best_remainder = 0;        
    if( b > n )
    {
        best_remainder = n;
    }
    else
    {
        best_remainder = b-1;
    }

    ll ans = (a*best_remainder)/b;
    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int dp[100001];

signed main(void) {
	int n;
	cin >> n;
	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}

	rep(i, 10001) {
		dp[i] = INF;
	}
	dp[0] = 0;
	dp[1] = abs(p[1] - p[0]);

	FOR(i, 2, n) {
		dp[i] = min((dp[i - 2] + abs(p[i - 2] - p[i])), (dp[i - 1] + abs(p[i - 1] - p[i])));
	}
	print(dp[n-1]);
}

Measured memory_bytes: 1792
S = input()
N = len(S)
output = [0] * N
# handle R
l = 0
for i, s in enumerate(S):
  if s == 'R':
    l += 1
  else:
    output[i] += l // 2
    output[i-1] += l - l // 2
    l = 0

# L
l = 0
for i, s in enumerate(S[::-1]):
  if s == 'L':
    l += 1
  else:
    output[N-1-i] += l // 2
    output[N-1-i + 1] += l - l // 2
    l = 0
print(' '.join([str(x) for x in output]))
   


Measured memory_bytes: 10484
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int m = 1000000000;
  int j = 1;
  rep(i, n) {
    int tmp;
    tmp = 1000*t - h[i]*6;
    if (m > abs(tmp - a * 1000)) {
      m = abs(tmp - a * 1000);
      j = i + 1;
    }
  }
  
  cout << j << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>

#include <string.h>
//#include <string>
using namespace std;

int main()
{
	char  str[11] = {0};
	cin >> str;

	uint32_t i = 0;
	while (1) {

		switch (str[i]) {
		case '\0':
			printf("%s\n", str);
			return 0;

		case 'B':
			if (i == 0) {
				memmove(&str[i], &str[i + 1], 10);
			}
			else {
				memmove(&str[i - 1], &str[i + 1], 11 - i - 1);
				i--;
			}
			break;
		default:
			i++;
			break;
		}
	}
	return 0;
//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<cmath>
char c[100];
int main() {
    string input;
    cin >> input;
    copy(input.begin(), input.end(), c);
    int satrt = (input.length()-1)/2;
    int secStart = (input.length()+3)/2-1;
    string S, tagS;
    for (int i = 0;i<satrt; i++) {
        S += c[i];
    }
    for (int i = secStart;i<input.length(); i++) {
          tagS += c[i];
       }
    if (S == tagS){
         cout << "Yes" << endl;
    } else {
         cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

int k, l, m, n;
const int M = 1e9 + 7;


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

    string n;
    cin >> n;

    ll sum = 0;
    for(char x : n) {
        sum += x - '0';
    }

    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char ax;
  cin >> ax;
  vector<char> bx = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  for(int i=0;i<26;i++){
    if(ax==bx.at(i))
    {
      cout << bx.at(i+1) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

B = {}
for i in range(N):
    for j in [-1,0,1]:
        if A[i] + j in B:
            B[A[i]+j] += 1
        else:
            B[A[i]+j] = 1
print(max(B.values()))

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

using namespace std;
#define N 300300
pair <int, int> v[N];
pair <int, int> l[N], c[N];
int i, x, y, ml, mc, h, w, n, ii, jj, j;
long long cntc, cntl, ans;
map<pair<int, int>, bool >sel;
int main(){
    cin >> h >> w >> n;
    for (i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
        sel[v[i]] = 1;
    }
    for (i = 0; i < h; ++i)
        l[i + 1].second = i + 1;
    for (i = 0; i < w; ++i)
        c[i + 1].second = i + 1;

    for (i = 0; i < n; ++i) {
        ++l[v[i].first].first;
        ++c[v[i].second].first;
    }
    sort(l + 1, l + h + 1);
    sort(c + 1, c + w + 1);
    i = h; j = w;
    ans = l[i].first + c[j].first;
    cntl = 0; cntc = 0;
    while (i > 0 && l[i].first == l[h].first){
        --i;
        ++cntl;
    }
    while (j > 0 && c[j].first == c[w].first){
        --j;
        ++cntc;
    }
    if (cntc * cntl > n) {
        cout << ans;
        return 0;
    }
    else {
        for (ii = 0; ii < cntl; ++ii)
        for (jj = 0; jj < cntc; ++jj){
            if (!sel[make_pair(l[h - ii].second, c[w - jj].second)]){
                cout << ans;
                return 0;
            }
        }
    }
    cout << ans - 1;
    return 0;
}


Measured memory_bytes: 29388
import Text.Printf
main = do
  getLine >>= mapM_ (printf "%.5f\n") . calc . map read . words

calc :: [Double] -> [Double]
calc [a,b,c] = let theta = c * pi / 180.0 in
  [a*b*sin(theta)/2,
   a + b + sqrt(a^2 + b^2 - 2*a*b*cos(theta)),
   b*sin(theta)]

Measured memory_bytes: 4152
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
 *
 * @author hsy
 */
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);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int l = -1, r = -1;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'K') {
                    l = i;
                    break;
                }
            }
            for (int i = s.length() - 1; i >= 0; i--) {
                if (s.charAt(i) == 'R') {
                    r = i;
                    break;
                }
            }
            if (l == -1 || r == -1) {
                out.println("NO");
                return;
            }
            if (l > 1 || (s.length() - 1 - r) > 1) {
                out.println("NO");
                return;
            }
            for (int i = 0; i < l; i++) {
                if (s.charAt(i) != 'A') {
                    out.println("NO");
                    return;
                }
            }
            for (int i = r + 1; i < s.length(); i++) {
                if (s.charAt(i) != 'A') {
                    out.println("NO");
                    return;
                }
            }
            String str = s.substring(l, r + 1);
            if (str.equals("KIHABAR") || str.equals("KIHBAR") || str.equals("KIHABR") || str.equals("KIHBR")) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }

    }
}



Measured memory_bytes: 23124
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define INF 1<<28
using namespace std;

int sx, sy, gx, gy;
typedef pair < int, int > P;
vector < P > p[5];
int memo[5][5][1111];
int a, b;

int solve(int k, int t, int q){

  if(k == 4) return abs(p[t][q].first-gx) + abs(p[t][q].second-gy);
  if(memo[k][t][q]) return memo[k][t][q];

  int ans = INF, d = (t+1)%5, s;
  for(int i=0;i<p[d].size();i++){
    if(!k) s = abs(sx-p[d][i].first) + abs(sy-p[d][i].second);
    else s = abs(p[t][q].first-p[d][i].first) + abs(p[t][q].second-p[d][i].second);
    ans = min(ans, solve(k+1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main(){

  int w,h;
  char c;

  while(true){
    scanf("%d %d", &w, &h);
    if(!w && !h) break;

    for(int i=0;i<5;i++) p[i].clear();
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == 'S') sx = j, sy = i;
	if(c == 'G') gx = j, gy = i;
	else if(c != '.') p[c-'1'].push_back(P(j,i));
      }
    }
    
    b = INF;
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i, b = solve(0,i,0);
    }

    if(b == INF) printf("NA\n");
    else printf("%d %d\n", a+1, b);

  }
}

Measured memory_bytes: 1204
import numpy as np

N = int(input())

S = input().split()

array = np.zeros(N)

counter = 0

for i in range(len(S)):
    array[i] = int(S[i])

for i in range(len(S) - 1):
    check = np.min(array[i + 1:])
    if(array[i] > check):
        swap = array[np.argmin(array[i + 1:]) + i + 1]
        array[np.argmin(array[i + 1:]) + i + 1] = array[i]
        array[i] = swap
        counter = counter + 1

if(counter <= 1):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 21384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int n;
    cin>>n;
    vector<int> w(n);
    vector<int> sum(n+1,0);
    REP(i,n){
        cin>>w[i];
        sum[i+1]=sum[i]+w[i];
    }
    int ans=100000;
    for(int t=1;t<n;t++){
        ans=min(ans,abs(sum[n]-2*sum[t]));
    }
    OUT(ans);
	return 0;
}

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

using namespace std;
int aa[100];
int main()
{
    int i,a=0,b=0,c=0,n,d=0,e=0;
    char ch;
    cin>>n;
    getchar();
    for(i=0; i<n; i++){
       cin>>ch;
       if(ch=='P')
        a=1;
       if(ch=='W')
        b=1;
       if(ch=='G')
        d=1;
       if(ch=='Y')
        e=1;
    }
    c=a+b+d+e;
    if(c==4)
        cout<<"Four"<<endl;
    else if(c==3)
        cout<<"Three"<<endl;
}



Measured memory_bytes: 256
n = int(input())
s1 = input()
d = {}

for c in set(s1):
    d[c] = s1.count(c)

key_l = list(d.keys())
key_l.sort()

for _ in range(n-1):
    tmp = input()
    for c in key_l:
        d[c] = min(tmp.count(c), d[c])

ans = ''
for c in key_l:
    if d[c]:
        ans += c*d[c]
print(ans)

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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

ll dp[1024][1024];

int main() {
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    rep(i, K) dp[0][i] = 1;

    for(int i = 1; i < N; i++) {
        rep(j, K) {
            rep(k, K) {
                if(j == k) continue;
                dp[i][j] += dp[i-1][k];
            }
        }
    }

    ll ans = 0;

    rep(i, K) ans += dp[N-1][i];

    cout << ans << endl;
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  string str;
  cin>>N;
  cin>>str;
  for(int i=0;i<str.length();i++)
    if((int)str[i]+N>90){
      int a=(int)str[i]+N-90;
      cout<<(char)(a+64);
    }
   else cout<<(char)((int)str[i]+N);
  cout<<endl;
  
  return 0;
}

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

using namespace std;

int n , a[111] , ans;

int main() {
	scanf("%d" , &n);
	for (int i = 0; i < n; i++) scanf("%d" , &a[i]);
	sort(a , a+n);
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			for (int k = j+1; k < n; k++) {
				if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k] && a[i]+a[j] > a[k]) ans++;
			}
		}
	}
	
	printf("%d" , ans);
	
	return 0;
}

Measured memory_bytes: 3844
#include <cstdio>
#include <queue>
#include <algorithm>

typedef long long int ll;

const int MAXN = 2e5 + 5;

int n, d, a, left, right, cur;
long long int ans;
int flag[MAXN];

struct monster {
    int place, health, diff;

    monster(int pp = 0, int hh = 0) {
        place = pp;
        health = hh;
    }

    bool operator < (const monster &another) const {
        return place < another.place;
    }
}arr[MAXN];

std::priority_queue<monster> q;

int main() {
    scanf("%d%d%d", &n, &d, &a);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &arr[i].place, &arr[i].health);
    }
    std::sort(arr + 1, arr + n + 1);
    for (int i = 1; i < n; ++i) {
        arr[i].diff = arr[i + 1].health - arr[i].health;
    }
    d <<= 1;
    left = right = 1;
    cur = arr[1].health;
    while (left <= n) {
        while (right <= n && arr[right + 1].place - arr[left].place <= d) {
                ++right;
        }
        int tmp = (cur / a + ((cur % a) != 0));
        ans += tmp;
        cur -= tmp * a;
        arr[right].diff += tmp * a;
        //printf("%d %d\n", left, right);
        while (cur <= 0) {
            cur += arr[left].diff;
            ++left;
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  N %= 10;
  if (N == 3) {
    cout << "bon" << endl;
  }
  else if (N == 0 | N == 1 | N == 6 | N == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    map<int,char> mp;
    int n,m;
    string a,b;
    cin>>n>>m>>a>>b;
    int g=__gcd(n,m);
    int lcm=n*m/g;
    rep(i,0,n){
        mp[i*lcm/n]=a[i];
    }
    rep(i,0,m){
        if(mp.count(i*lcm/m)){
            if(mp[i*lcm/m]!=b[i]){
                cout<<-1<<endl;
                return;
            }
        }
        mp[i*lcm/m]=b[i];
    }
    cout<<lcm<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

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

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}
 
LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}

int main(){
  int N,K,X,Y,sum=0;
  cin >> N >> K >> X >> Y;
  
  REP(i,N){
    if(i<K) sum+=X;
    else sum+=Y;
  }
  
  cout << sum << endl;
  
  return 0;
}
  


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

N,Q = map(int,input().split())
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * (N + 1)
for i,j in pLst:
    ansLst[i] += j

def dfs(v, p):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i] += ansLst[v]
        dfs(i, v)


dfs(1, 0)

ans = ' '.join(map(str, ansLst[1:]))
print(ans)


Measured memory_bytes: 285888
#include<bits/stdc++.h>
#define M 100000
#define Y second
#define X first
#define N 500
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> P1;
int n,u,v,m,a[2][N][N],b,f1,f2;
bool usa[N][N],nek[N][N];
int usac[N*2+2],cu;
int nekc[N*2+2],cn;
vector<P1> x;
vector<P> d;
set<int> s;
map<int,P> z[2];

int Bynary_Search(int k){
  int L=0,R=d.size();
  while(L<R){
    int Mid=(L+R)/2;
    if(d[Mid].X<k)L=Mid+1;
    else R=Mid;
  }
  if(d[L].X==k)return L;
  return -1;
}

int main(){
  cin>>n>>u>>v>>m;
  for(int i=0;i<2;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++){
	cin>>a[i][j][k];
	z[i].insert(make_pair(a[i][j][k],P(j,k)));
	s.insert(a[i][j][k]);
      }
  for(int i=0;i<m;i++){
    cin>>b;
    d.push_back(P(b,i));
  }
  sort(d.begin(),d.end());
  set<int>::iterator ite;
  for(ite=s.begin();ite!=s.end();ite++){
    int r=Bynary_Search(*ite);
    if(r>=0){
      if(z[0].find(d[r].X)!=z[0].end())
	x.push_back(P1(P(d[r].Y,0),P(z[0][d[r].X].X,z[0][d[r].X].Y)));
      if(z[1].find(d[r].X)!=z[1].end())
	x.push_back(P1(P(d[r].Y,1),P(z[1][d[r].X].X,z[1][d[r].X].Y)));
    }
  }
  sort(x.begin(),x.end());
  for(int i=0;i<x.size();i++){
    int p=x[i].X.Y,px=x[i].Y.X,py=x[i].Y.Y;
    if(!p){
      usac[px]++;
      if(n!=1){
	usac[py+n]++;
	if(px==py){
	  usac[n*2]++;
	  if(usac[n*2]==n)cu++;
	}
	if(px+py==n-1){
	  usac[n*2+1]++;
	  if(usac[n*2+1]==n)cu++;
	}
      }
      if(usac[px]==n)cu++;
      if(usac[py+n]==n)cu++;
    }else{
      nekc[px]++;
      if(n!=1){
	nekc[py+n]++;
	if(px==py){
	  nekc[n*2]++;
	  if(nekc[n*2]==n)cn++;
	}
	if(px+py==n-1){
	  nekc[n*2+1]++;
	  if(nekc[n*2+1]==n)cn++;
	}
      }
      if(nekc[px]==n)cn++;
      if(nekc[py+n]==n)cn++;
    }
    if(i+1<x.size()&&x[i].X.X!=x[i+1].X.X){
      if(cu>=u)f1=1;
      if(cn>=v)f2=1;
      if(f1||f2)break;
    }
  }
  if(cu>=u)f1=1;
  if(cn>=v)f2=1;
  if((!f1&&!f2)||(f1&&f2))cout<<"DRAW"<<endl;
  else if(f1)cout<<"USAGI"<<endl;
  else cout<<"NEKO"<<endl;
  return 0;
}

Measured memory_bytes: 33736
#include<stdio.h>
int main(void)
{
	int n,a,s[200],i,box,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		s[i]=0;
	}
	for(i=0;i<n;i++){
		scanf("%d",&a);
		while(1){
			if(a%2==0){
				s[i]++;
				a=a/2;
			}
			else{
				break;
			}
		}
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(s[i]>s[j]){
				box=s[i];
				s[i]=s[j];
				s[j]=box;
			}
		}
	}
	printf("%d\n",s[0]);
	return 0;
}

Measured memory_bytes: 128
#include <math.h>

#include <iostream>
using namespace std;

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if ((h == 0) && (w == 0)) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}



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

int main(){
int N = 0;
  cin >> N;
  int K = 0;
  cin >> K;
  int in = 0;
  vector<int> h(N);
  for(int i = 0;i < N ;i++){
    cin >> h[i];
    if(h[i] >= K){
      in++;
    }
  }
  cout << in << endl;
  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

int N,K;
char buf[SIZE];

int main(){

	scanf("%d %d",&N,&K);
	scanf("%s",buf);

	int ans = 0;
	int RL = 0,LR = 0;

	for(int i = 0; i < N; i++){
		if(buf[i] == 'L'){
			if(i == N-1)continue;

			if(buf[i+1] == 'L'){

				ans++;
			}else{

				LR++;
			}

		}else{

			if(i == N-1)continue;

			if(buf[i+1] == 'R'){

				ans++;

			}else{

				RL++;
			}
		}
	}

	ll num = min(LR,RL);

	if(num <= K){ //ペアを全消化できる場合

		ans += 2*num;
		K -= num;

		int rest=LR+RL-2*num; //どちらか多い方が残っている場合あり

		ans += min(K,rest);

	}else{ //ペア消化でKが尽きる場合

		ans += 2*K;
	}

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

	return 0;
}


Measured memory_bytes: 384
S = input()

front = int(S[:2])
rear = int(S[2:])

if (front > 12 and rear > 12) or (front > 12 and rear == 0) or (rear > 12 and front == 0) or (front == 0 and rear == 0):
    print("NA")
    exit()
elif 0 < rear <= 12 and (front > 12 or front == 0):
    print("YYMM")
    exit()
elif 0 < front <= 12 and (rear > 12 or rear == 0):
    print("MMYY")
elif 0 < front <= 12 and 0 < rear <= 12:
    print("AMBIGUOUS")


Measured memory_bytes: 61508
#include <vector>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string	str;
	cin >> str;

	int f = (str[0] - '0') * 10 + (str[1] - '0');
	int b = (str[2] - '0') * 10 + (str[3] - '0');

	if (f > 12 || f == 0)
	{
		//	YY is forward

		if (0 < b && b < 13)
			printf("YYMM");
		else
			printf("NA");

		return 0;
	}

	if (b > 12 || b == 0)
	{
		//	YY is back

		if (0 < f && f < 13)
			printf("MMYY");
		else
			printf("NA");

		return 0;
	}

	if (f == 0 && b == 0)
		printf("NA");
	else
		printf("AMBIGUOUS");
	

	return 0;
}


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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 10

string s;

char d[MAX];

int main() {
	cin >> s;

	int idx =0;
	for( int i = 0; i < s.size(); i++ ) {
		char c = s[i];
		if( c == 'B' ) {
			if( idx > 0 ) {
				idx--;
			}
		}
		else {
			d[idx] = c;
			idx++;
		}
	}

	for( int i = 0; i < idx; i++ ) {
		cout << d[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a, b, c;
    a.push_back(0);
    b.push_back(0);
    c.push_back(0);
    for (int i = 1; i <= n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        a.push_back(x + max(b[i - 1], c[i - 1]));
        b.push_back(y + max(a[i - 1], c[i - 1]));
        c.push_back(z + max(a[i - 1], b[i - 1]));
    }
    cout << max(max(a[n], b[n]), c[n]) << endl;
}


Measured memory_bytes: 1644