akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int maxi = 0;
    vector<pair<int, int>> areas;
    areas.emplace_back(0, 1); // b, e
    vector<int> as(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    for(int i = 0; i < n; i++){
        int a = as[i];
        maxi += a;
        vector<pair<int, int>> a2 = areas, a3;
        a3.reserve(areas.size() * 2);
        for(auto& area : a2){
            area.first += a;
            area.second += a;
        }
        size_t i1 = 0, i2 = 0;
        a3.push_back(areas[i1]);
        i1++;
        auto push = [&](vector<pair<int, int>> &v, size_t& idx){
            if(a3.back().second < v[idx].first){
                a3.push_back(v[idx]);
            }else{
                a3.back().second = max(a3.back().second, v[idx].second);
            }
            idx++;
        };
        while(i1 < areas.size() || i2 < a2.size()){
            if(i2 == a2.size() || (i1 < areas.size() && areas[i1] < a2[i2])){
                push(areas, i1);
            }else{
                push(a2, i2);
            }
        }
        areas.swap(a3);
    }
    // printd(areas);
    printd(areas.size());
    int ans = M, targ = (maxi + 1) / 2;
    for(auto& area : areas){
        if(area.second - 1 >= targ){
            // printd(ans, area);
            ans = min(ans, max(targ, area.first));
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6080
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;


const double EPS = 1e-9;

const int INF = 100000000;

double kyo(pair<int,int> a,pair<int,int> b){
    return sqrt((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second));
}

bool solve(int ind,double zikan,set<int> &rest,const vector<vector<double> > &kyori,const vector<double> &mao){
    if(rest.size() == 0) return true;
    bool allok = true;
    for(set<int>::iterator it = rest.begin();it!=rest.end();++it){
        allok = allok and (zikan + kyori[ind][*it] < mao[*it]-EPS);
    }
    if(allok){
        bool any = false;
        for(set<int>::iterator it = rest.begin();it!=rest.end();++it){
            rest.erase(*it);
            any = any or solve(*it,zikan+kyori[ind][*it],rest,kyori,mao);
            rest.insert(*it);
        }
        return any;
    }else{
        return false;
    }
}

template<class T>
void cerr_vec(vector<T> vec){
    for(int i=0;i<vec.size();i++){
        cerr << vec[i] << " ";
    }
    cerr << endl;
}

int main(){
    while(true){
        int n,hx,hy,dx,dy;
        cin >> n >> hx >> hy >> dx >> dy;
        if(n == 0) break;
        vector<pair<int,int> > chi(n);
        pair<int,int> m = make_pair(dx,dy);
        pair<int,int> y = make_pair(hx,hy);

        vector<double> yusya(n);
        vector<double> mao(n);
        vector<vector<double> > kyori(n,vector<double>(n));

        set<int> rest;
        for(int i=0;i<n;i++){
            cin >> chi[i].first >> chi[i].second;
            mao[i] = kyo(chi[i],m);
            yusya[i] = kyo(chi[i],y);
            rest.insert(i);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                kyori[i][j] = kyo(chi[i],chi[j]);
            }
        }

        bool any = false;
        for(int i=0;i<n;i++){
            rest.erase(i);
            if(yusya[i] < mao[i]-EPS){
                any = any or solve(i,yusya[i],rest,kyori,mao);
            }
            rest.insert(i);
        }
        if(any){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void)
{
        int n,m,x,y,a[100],b[100],i,j,c,s=0;

        scanf("%d%d%d%d",&n,&m,&x,&y);

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

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


        for (i=x+1;i<=y;i++){
                s=0;
                for (j=0;j<n;j++){
                        if (!(a[j]<i)){
                                s++;
                        }
                }
                for (c=0;c<m;c++){
                        if (!(b[c]>=i)){
                                s++;
                        }
                }
                if (s==0){
                        printf("No War\n");
                        return 0;
                }
        }

        printf("War\n");
        return 0;
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;



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

  li N;
  cin >>N;

  vi X(N);
  Input(X);

  li minans =INF;
  Rep1(i,100){
  	li ans =0;
  	for(auto&& x:X){
  		ans += (x-i)*(x-i);
  	}
  	minans=min(minans,ans);
  }

  cout <<minans;
}

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

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

class Item{
public:
	int n,c,s,g;
	Item(int n=0,int c=0,int s=0,int g=0):n(n),c(c),s(s),g(g){}
};

class State{
public:
	int x,y,cost,sum,visited;
	State(int x=0,int y=0,int c=0,int s=0,int v=0):x(x),y(y),cost(c),sum(s),visited(v){}
};

int main(){
	int h,w;
	while(cin >> w >> h && h && w){
		int a[20][20], n, ans = 0;
        bool G[20][20];
        int n_i[10]; //商品番号を配列の番号に変換
		bool f[20][20][(1<<8)];
		Item item[8];
		queue<State> Q;
		State u,v;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=0;k<(1<<8);k++) f[i][j][k] = false;

				char c;
				cin >> c;
				G[i][j] = true;
				a[i][j] = -1;
				if(c == '.') G[i][j] = false;
				else if(c == 'P'){
					u.y = i;
					u.x = j;
					f[i][j][0] = true;
					G[i][j] = false;
				} else a[i][j] = c - '0';
			}
		}

		cin >> n;
		for(int i=0;i<n;i++){
			cin >> item[i].n >> item[i].c >> item[i].s >> item[i].g;
            n_i[item[i].n] = i;
		}

		Q.push(u);
		while(!Q.empty()){
			u = Q.front();
			Q.pop();
            
			for(int i=0;i<4;i++){
				v = u;
				v.y += dy[i];
				v.x += dx[i];
				v.cost++;
				if(v.y >= 0 && v.y < h && v.x >= 0 && v.x < w && !f[v.y][v.x][v.visited]){
                    if(!G[v.y][v.x]){
                        f[v.y][v.x][v.visited] = true;
                        Q.push(v);
                    }
                    else if((v.visited & (1<<n_i[a[v.y][v.x]])) == 0){
                        if(u.cost >= item[n_i[a[v.y][v.x]]].s && u.cost < item[n_i[a[v.y][v.x]]].g){
                            State v2 = u;
                            f[v2.y][v2.x][v2.visited] = true;
                            v2.visited = v2.visited | (1<<n_i[a[v.y][v.x]]);
                            f[v2.y][v2.x][v2.visited] = true;
                            v2.sum += item[n_i[a[v.y][v.x]]].c;
                            ans = max(ans,v2.sum);
                            if(v2.visited != ((1<<n)-1)) Q.push(v2);
                        } else if(u.cost < item[n_i[a[v.y][v.x]]].s){
                            //変更点
                            State v2 = u;
                            v2.cost += item[n_i[a[v.y][v.x]]].s - v2.cost;
                            Q.push(v2);
                            //ここまで
                        }
                    }
                }
            }
            
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1136
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
lli solve(lli n, lli x1);
int main(void)
{
    lli a, b, x;
    cin >> a >> b >> x;
    cout << solve(b, x) - solve(a - 1, x);
    return 0;
}

lli solve(lli n, lli x1)
{
    if (n >= 0)
    {
        return (n / x1) + 1;
    }
    else
    {
        return 0;
    }
}

Measured memory_bytes: 256
#define _SECURE_NO_WARNINGS

#include <stdio.h>

int main(void)
{
	int a;
	int b;

	scanf("%d", &a);
	scanf("%d", &b);

	printf("%d ", a*b);
	printf("%d\n", 2 * a + 2 * b);

	return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define pr pair<int, int>
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
    char ch; int sign = 1;
    while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
    n = ch - '0';
    while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
    n *= sign;
}
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int N = 3111;
int n, m;
ll c[N][N], s[N][N], po[N], po2[N];

void upd(ll& x, ll y){x += y; if (x >= m) x -= m;}
ll mut(ll a, ll b){
    ll y = 1, t = a;
    for (; b; b >>= 1, t = t * t % m)
        if (b & 1) y = y * t % m;
    return y;
}

int main(){
    read(n), read(m);
    po[0] = po2[0] = 1;
    rep(i, 1, n) po[i] = po[i-1] * 2 % m;
    rep(i, 1, n) po2[i] = po2[i-1] * 2 % (m - 1);
    c[0][0] = s[0][0] = 1;
    rep(i, 1, n) rep(j, 0, n)
        c[i][j] = (c[i-1][j] + (j ? c[i-1][j-1] : 0)) % m;
    rep(i, 1, n) rep(j, 0, n)
        s[i][j] = (s[i-1][j] * j + (j ? s[i-1][j-1] : 0)) % m;
    ll ans = 0;
    rep(i, 0, n){
        ll res = 0;
        rep(j, 0, i){
            ll t = (s[i][j] + s[i][j+1] * (j + 1)) % m;
            t = t * mut(po[n-i], j) % m * mut(2, po2[n-i]) % m;
            upd(res, t);
        }
        (res *= c[n][i]) %= m;
        if (i % 2 == 0) upd(ans, res);
        else ans = (ans - res + m) % m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 149760
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
int main(void)
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b;
}

Measured memory_bytes: 3636
S=input()
l=len(S)
r=0
list5 = ['dream', 'erase']
list81 = ['dreamdre', 'dreamera', 'erasedre', 'eraseera']
list82 = ['dreamerd', 'dreamere']
list83 = ['eraserdr', 'eraserer']
if l<=4:
    print('NO')

while l>=5:
    if S[r:r+5] in list5:
        if r+5==l:
            print('YES')
            break
        elif r+5 == l-1:
            if S[r:r+6] == 'eraser':
                print('YES')
            else:
                print('NO')
            break
        elif r+5 == l-2:
             if S[r:r+7] == 'dreamer':
                 print('YES')
             else:
                 print('NO')
             break
        elif r+5 == l-3 or r+5 == l-4:
            print('NO')
            break
        else:
            if S[r:r+8] in list81:
                r=r+5
            elif S[r:r+8] in list82:
                r=r+7
            elif S[r:r+8] in list83:
                r=r+6
            else:
                print('NO')
                break
    else:
        print('NO')
        break


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a,n) for(int i = 0; i < n; i++) cin >> a[i];
#define ffor(n) for(int i = 0; i < n; i++)
 
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string,int> msi;
typedef map<int,int> mii;
typedef unordered_map<string,int> umsi;
 
 
int32_t main()
{
    int mod=1e9+7;
    fast_io;
    int n, m;
    cin>>n>>m;
    vector<vector<char>>grid(n,vector<char>(m));
    for(int i=0;i<n;i++)
        for(int j=0; j<m; j++)cin>>grid[i][j];
    vii dp(n+2,vi(m+2,0));
    for(int i=1;i<=n;i++){
        if(grid[i-1][0]=='#')break;
        else dp[i][1]=1;
    }
    for(int i=1;i<=m;i++){
        if(grid[0][i-1]=='#')break;
        else dp[1][i]=1;
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=2;j<=m;j++)
        {
            if(grid[i-1][j-1]!='#'){
            dp[i][j]+=dp[i-1][j];
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
            }

        }
    }
    cout<<dp[n][m];
    return 0;
}

Measured memory_bytes: 12176
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		double EPS=1e-3;
		while(N-->0)
		{
			double QR=in.nextDouble();
			double RP=in.nextDouble();
			double PQ=in.nextDouble();
			int n=in.nextInt();
			Point p[]=new Point[n];
			for(int i=0;i<n;i++)
				p[i]=new Point(in.nextDouble(),in.nextDouble(),in.nextDouble());

			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					for(int k=0;k<n;k++)
					{
						if(i==j||j==k||k==i)
							continue;
						double dis1=distance(p[i],p[j]);
						double dis2=distance(p[j],p[k]);
						double dis3=distance(p[k],p[i]);
						boolean judge=false;
						if(dis1/dis2-PQ/QR<EPS)
							if(dis2/dis3-QR/RP<EPS)
								if(dis3/dis1-RP/PQ<EPS)
									judge=true;
						if(judge)
						{
							System.out.println((i+1)+" "+(j+1)+" "+(k+1));
							break;
						}
					}

		}
	}

	static double distance(Point p1,Point p2)
	{
		double d1=Math.hypot(p1.x-p2.x,p1.y-p2.y);
		double dis=Math.hypot(d1,p1.z-p2.z);
		return dis;
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

class Point
{
	double x,y,z;
	Point(double x,double y,double z)
	{
		this.x=x;
		this.y=y;
		this.z=z;
	}
}

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

int main() {
  string a;
  int r=0;
  cin >> a;
  
  if (a[0] == '1') r++;
  if (a[1] == '1') r++;
  if (a[2] == '1') r++;
  
  cout << r << endl;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=200005;
void solve(){
    ll n,x;
    cin>>n;
    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    rep(i,2,n){
        cin>>x;
        dp[x]++;
    }
    rep(i,1,n) cout<<dp[i]<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

void selectionSort(int A[], int N) {
    int count = 0;
    for (int i=0; i<N; i++) {
        int minj = i;
        for (int j=i; j<N; j++) {
            if (A[j] < A[minj]) minj = j;
        }
        if (A[i] != A[minj]) {
        swap(A[i], A[minj]);
        count++;
        }
    }
    
    for (int i=0; i<N; i++) {
        if (i != 0) cout << " ";
        cout << A[i];
    }
    
    cout << "\n" << count << "\n";
}

/*
1 selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 0 から N-1 まで
3     minj = i
4     for j が i から N-1 まで
5       if A[j] < A[minj]
6         minj = j
7     A[i] と A[minj] を交換
*/

int main() {
    int N, A[100];
    cin >> N;
    for (int i=0; i<N; i++) cin >> A[i];
    
    selectionSort(A, N);
    
    return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	long long int N, M; cin >> N >> M;
	priority_queue<pair<long long int, long long int>> que;
	REP(i,N){
		long long int A; cin >> A;
		que.push(make_pair(A, 1));
	}
	REP(i,M){
		long long int B, C; cin >> B >> C;
		que.push(make_pair(C, B));
	}

	long long int cnt = 0;
	long long int ans = 0;
	while(cnt != N){
		if(que.top().second + cnt <= N){
			ans += que.top().first * que.top().second;
			cnt += que.top().second;
		}else{
			long long int c = N - cnt;
			ans += c * que.top().first;
			cnt += c;
		}
		que.pop();
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 6384
#include <iostream>
using namespace std;
typedef long long ll;
ll n, t, res = 1;
ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t;
        res *= t / gcd(t, res);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val total_people = io.StdIn.readLong()
    var min_move_people_onetime = 1000000000000000L
    var min_move_people_num     = 1

    (0 until 5).foreach { i =>
      val input = io.StdIn.readLong()
      if (input < min_move_people_onetime) min_move_people_onetime = input
    }
    println(Math.ceil(total_people/min_move_people_onetime.toDouble).toLong + 4L)
  }
}

Measured memory_bytes: 25400
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):

        x = self.Find_Root(x)
        y = self.Find_Root(y)

        if(x == y):
            return 

        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y

            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
    n,m = map(int,input().split())
    ls = [[int(x) for x in input().split()] for _ in range(m)]
    ans = [0 for _ in range(m+1)]
    ans[m] = n*(n-1)//2
    union = UnionFind(n)
    for i in reversed(range(m)):
        a,b = ls[i]
        if ans[i+1]==0:
            pass
        else:
            if union.isSameGroup(a,b):
                ans[i] = ans[i+1]
            else:
                ans[i] = max(0,ans[i+1] - union.Count(a)*union.Count(b))
                union.Unite(a,b)

    for i in range(1,m+1):
        print(ans[i])



if __name__ == "__main__":
    main()

Measured memory_bytes: 27968
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

string s,t,u;
ll a,b;
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(s==u)a--;
    if(t==u)b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())#50*x 50~20000

l=[]
count=0

for i in range(A+1):#+1 !!
	for j in range(B+1):
		for k in range(C+1):
			if X==(500*i+100*j+50*k):
				count+=1

print(count)
"""
for i in range(A):
	if(X>=500*i):
		Y=X-500*i
		print(Y)
		a+=1
	for j in range(B):
		if(Y>=100*j):
			Z=Y-100*j
			print(Z)
			b+=1
"""


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define mem(x,n) memset(x,n,sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main()
{
	faster;
	
	int n;
	cin >> n;
	cout << !n << endl;
	
	return 0;
}

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

int a[10];
int sum = 0;

int main(){
	int n;
	cin >> n;
	for(int i = 0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 0;i<n-1;i++){
		sum += a[i];
	}
	if(sum <= a[n-1]){
		cout << "No" << '\n';
	}
	else{
		cout << "Yes" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;
i64 giant = 4000000000000000000;

using namespace std;


int main() {
	int x = 0;
	int n, m;
	cin >> n >> m;
	int ans = 1;
	ff(i, 0, n) {
		int l;
		cin >> l;
		x += l;
		if (x <= m)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

struct Country{string name; int wp;};
vector<Country> Allteam;

bool comp(const Country& c1, const Country& c2){
  return (c1.wp > c2.wp);
}

int main(void){
  int n, k = 0;
  while(cin >> n, n){
    if(k != 0) cout << endl;
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      Country c = {tname, w * 3 + d};
      Allteam.push_back(c);
    }
    sort(Allteam.begin(), Allteam.end(), comp);
    for(int i = 0; i < Allteam.size(); i++){
      cout << Allteam[i].name << "," << Allteam[i].wp << endl;
    }
    Allteam.clear();
    k++;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"    "<<"HERE"<<en

int main(){
  int p1,p2,p3;
  cin>>p1>>p2>>p3;
  int p=min(p1, p2);
  p=min(p,p3);
  int j1,j2;
  cin>>j1>>j2;
  int j=min(j1,j2);
  cout<<j+p-50<<en
}





































































































































































































































































































































































































































































































































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

using namespace std;

int main() {
  int x = 0;
  string s, sc, sss;
  cin >> s >> sc;

  x = (int)(sc.length());
  sss = sc.substr(0, x-1);

  if(s == sss){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
def solve():
  ans = ''
  S = input()
  T = input()
  n,m = len(S),len(T)
  dp = [[0]*(m+1) for _ in range(n+1)]
  for i in range(1,n+1):
    for j in range(1,m+1):
      if S[i-1]==T[j-1]:
        dp[i][j] = dp[i-1][j-1]+1
      else:
        dp[i][j] = max(dp[i-1][j],dp[i][j-1])
  i,j = n,m
  while i>0 and j>0:
    if dp[i-1][j]==dp[i][j]:
      i -= 1
    elif dp[i][j-1]==dp[i][j]:
      j -= 1
    else:
      ans = S[i-1]+ans
      i -= 1
      j -= 1
  return ans
print(solve())

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

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll sum = 0;
  rep(i, n) {
    if(i%2) sum -= a[i];
    else sum += a[i];
  }

  vector<ll> ans(n);
  ans[0] = sum;
  rep(i, n-1) ans[i+1] = 2*a[i]-ans[i];

  rep(i, n) cout << ans[i] << (i == n-1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int ac=0;
    int bc=0;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            ac++;
        }
        else
        {
            bc++;
        }
    }
    if(ac==0 || bc==0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

  int N; ll C, K; cin >> N >> C >> K;
  vel T(N); rep(i,N) cin >> T[i];
  sort(all(T));
  
  ll ans = 0;
  while(!T.empty()) {
    ll fast = T[0];
    ll cnt = 0;
    while(cnt < C) {
      if(T.empty()) break;
      if(T[0] <= fast + K ) { remove(T, 0); cnt++; }
      if(T[0] > fast + K) break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef unsigned long long int ull;
ull a1,a2,a3,m1,m2,m3;
bool fin = false;


int rec(int r,ull A,ull M,ull cnt){
  ull foggy = (A*r)%M;
  if(foggy == 1){
    return cnt;
  }
  return rec(foggy,A,M,cnt+1);
}

ull gcd(ull x,ull y){
  if(y == 0)return x;
  return gcd(y,x%y);
}

ull lcm(ull x,ull y){
  return (x*y)/gcd(x,y);
}

int main(){
 ull X,Y,Z;  
  while(true){
    cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
    if(a1+a2+a3+m1+m2+m3 == 0)break;
    X = rec(1,a1,m1,1);
    Y = rec(1,a2,m2,1);
    Z = rec(1,a3,m3,1);
    ull XY = lcm(X,Y);
    cout << lcm(XY,Z) << endl;
    fin = false;
  }
  return 0;
}

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

int main() {
  int a,b;
  int p=0;
  cin>>a>>b;
  if(a>=b){
    p+=a;
    a--;
  }
  else {
    p+=b;
    b--;
  }

  if(a>=b){
    p+=a;
    a--;
  }
  else {
    p+=b;
    b--;
  }

  cout << p<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,m; cin>>n>>m;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    vector <int> b(m); 
    rep(i,m) cin>>b[i];
    vector <int> distx(n-1), disty(m-1); 
    rep(i,n-1) distx[i] = abs(a[i] - a[i+1]);
    //rep(i, n-1) cout<<distx[i]<<endl;
    vector <int> cntx(n-1), cnty(m-1);
    
    int kukan = distx.size();
    int cnt = 0;
    
    for(int i=0;i<kukan;i++){
        cnt++;
        cntx[i] = (kukan-i)*cnt;
    }
    //rep(i,n-1) cout<<cntx[i]<<' ';
    
    rep(i,m-1) disty[i] = abs(b[i] - b[i+1]);
    //rep(i,m-1) cout<<disty[i]<<endl;
    kukan = disty.size();
     
    cnt = 0;
     
    for(int i=0;i<kukan;i++){
        cnt++;
        cnty[i] = (kukan-i)*cnt;
    }
    //cout<<endl;
    //ep(i,n-1) cout<<cnty[i]<<' ';
    
    int yoko=0,tate=0;
    rep(i,n-1) {yoko += (distx[i]*cntx[i]); yoko %= MOD;}
    rep(i,m-1) {tate += (disty[i]*cnty[i]); tate %= MOD;}
    cout<<(yoko*tate) % MOD<<endl;
}


Measured memory_bytes: 4992
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#include<bitset>
#define MAX_N 1100000
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
vector<ll> vs(MAX_N*2),depth(MAX_N*2,-1),id(MAX_N),par(MAX_N,-1);
vector<ll> sum(MAX_N),rm(MAX_N);
vector<ll> G[MAX_N];
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
template <typename Monoid >
struct SegmentTree{
  using F = function< Monoid(Monoid,Monoid) >;

  ll sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M;

  SegmentTree(ll n,const F f,const Monoid &M) : f(f),M(M){
    sz = 1;
    while(sz<n) sz<<=1;
    seg.assign(sz*2,M);
  }
  void set(ll k,const Monoid &v){
    seg[k+sz] = v;
  }
  void build(){
    for(ll k=sz-1;k>0;k--){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  void update(ll k,const Monoid &v){
    k += sz;
    seg[k] = v;
    while(k >>= 1){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  Monoid que(ll a,ll b){
    Monoid L=M,R=M;
    for(a+=sz, b+=sz;a<b;a>>=1,b>>=1){
      if(a&1) L = f(L,seg[a++]);
      if(b&1) R = f(seg[--b],R);
    }
    return f(L,R);
  }
  Monoid operator[](const ll &k) const{
    return seg[k+sz];
  }
};
ll tmp;
void dfs(ll v,ll prev,ll d,ll &c){
  par[v] = prev;
  id[v] = c;
  vs[c] = v;
  depth[c] = d;
  c++;
  for(auto nv:G[v]){
    if(nv!=prev){
      dfs(nv,v,d+1,c);
      vs[c] = v;
      depth[c] = d;
      c++;
    }
  }
}
signed main(){
  init_io();
  ll n,ans=1;
  cin >> n;
  ll q;
  vector<ll> a(n-1),b(n-1),reaf;
  SegmentTree<P> seg(n*2,[](P a,P b)
      {
      if(a.first<b.first) return a;
      else return b;
      },P(10000000,-1));
  for(int i=0;i<n-1;i++){
    ans *= 2;
  }
  for(ll i=0;i<n;i++){
    ll k,x;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> x;
      G[i].push_back(x);
      G[x].push_back(i);
    }
  }
  cin >> q;
  vector<ll> v(q),u(q);
  for(ll i=0;i<q;i++){
    cin >> u[i] >> v[i];
  }
  ll c=0;
  dfs(0,-1,0,c);
  for(ll i=0;i<2*n-1;i++){
    seg.update(i,P(depth[i],i));
  }
  for(int i=0;i<q;i++){
    ll a,b;
    a = id[u[i]],b=id[v[i]];
    if(a>=b) swap(a,b);
    P idx = seg.que(a,b+1);
    cout << vs[idx.second]<<endl;
  }
}



Measured memory_bytes: 119836
n = int(input())

c = [0,0,0,0]

for i in range(n):
    s = input()
    if s == "AC":
        c[0] += 1
    elif s == "WA":
        c[1] += 1
    elif s == "TLE":
        c[2] += 1
    else:
        c[3] += 1

print("AC x " , c[0])
print("WA x " , c[1])
print("TLE x " , c[2])
print("RE x " , c[3])

Measured memory_bytes: 9148
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    string s1,s2;
    cin>>s1>>s2;
    
    reverse(s1.begin(),s1.end());
    if(s1==s2){
        puts("YES");
    }else{
        puts("NO");
    }
 
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<pair<ll,ll>,ll> p1,pair<pair<ll,ll>,ll>p2){
return p1.fi.fi<p2.fi.fi;
}
void solve(){
 string s,t;
 cin>>s>>t;
 ll ans=0;
 fr(i,0,s.length()){
 if(s[i]!=t[i]) ans++;
 }
 cout<<ans<<endl;
}
int main()
{   fast;
    ll t=1;
   //cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


Measured memory_bytes: 3764
from collections import deque

if __name__ == '__main__':
    s = input()
    q = int(input())
    ans = s
    rev_count = 0
    leftList = deque()
    rightList =[]
    alist =[]

    for i in range(q):
        a = [i for i in input().split()]
        alist.append(a)
        if len(a) == 1:
            rev_count = rev_count +1

    if rev_count % 2 ==1:
        ans = ans[::-1]

    for i in alist:
        if len(i) == 1:
            rev_count = rev_count -1
        else:
            if int(i[1]) == 1:
                if rev_count % 2 == 1:
                    rightList.append(i[2])
                else:
                    leftList.appendleft(i[2])

            else:
                if rev_count % 2 == 1:
                    leftList.appendleft(i[2])
                else:
                    rightList.append(i[2])

    ans = ''.join(leftList)+ ans+''.join(rightList)

    print(ans)



Measured memory_bytes: 30068
from collections import Counter

from sys import stdin

input = stdin.readline

N = int(input())

an = Counter([int(i) for i in input().split()])


def main():
    # 要素(k) よりも 要素数(v) が 以上ならば その差(v - k)
    # 要素(k) よりも 要素数(v) が 小さければ 要素数(v)
    print(sum([v - k if k <= v else v for k, v in an.items()]))

    return


main()


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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny")cout << "Cloudy" << endl;
else if (s =="Cloudy") cout << "Rainy" << endl;
else if (s == "Rainy") cout << "Sunny" << endl;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N, K, Q = map( int, input().split())
    A = [ int( input()) for _ in range(Q)]
    Point = [-Q]*N
    for a in A:
        Point[a-1] += 1
    for i in range(N):
        if K + Point[i] <= 0:
            print('No')
        else:
            print('Yes')
if __name__ == '__main__':
    main()


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

int main(int argc, char *argv[])
{
	int i;
    char str[2000];
	char result[2000];
	char auth[1001];
	int w;
	int result_index = 0;

	memset(str, 0, 2000);
	memset(result, 0, 2000);

	cin >> str;
	cin >> w;

	for (i = 0; i < 1000; i++) {
		if (str[i] == '\0')
			break;
		if (i % w == 0) {
			result[result_index] = str[i];
			result_index++;
		}			
	}


    cout << result;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;


int main(){
    ll n, tot = 0;
    string s;
    cin >> n >> s;

    vector<int> r(n, 0);
    vector<int> g(n, 0);
    vector<int> b(n, 0);

    if (s[0] == 'R') r[0] = 1; 
    else if (s[0] == 'G') g[0] = 1; 
    else b[0] = 1; 

    FOR(i, 1, n){
        if (s[i] == 'R'){
            r[i] = r[i-1] + 1;
            g[i] = g[i-1];
            b[i] = b[i-1];
        }
        else if (s[i] == 'G'){
            r[i] = r[i-1];
            g[i] = g[i-1]+1;
            b[i] = b[i-1];
        }
        else{
            r[i] = r[i-1];
            g[i] = g[i-1];
            b[i] = b[i-1]+1;
        }
    }
    // cout << r[n-1] << g[n-1] << b[n-1] << endl;
    REP(i, n){
        FOR(j, i+1, n){
            ll diff = j - i;
            if (s[j] != s[i]){
               if ('R' != s[i] && 'R' != s[j]){
                   tot += r[n-1]-r[j];
                   if (s.length() > j+diff && s[j+diff] == 'R') tot -= 1;
               }
               else if ('G' != s[i] && 'G' != s[j]){
                   tot += g[n-1]-g[j];
                   if (s.length() > j+diff && s[j+diff] == 'G') tot -= 1;
               }
               else{
                   tot += b[n-1]-b[j];
                   if (s.length() > j+diff && s[j+diff] == 'B') tot -= 1;
               }
            }
            
        }
    }

    cout << tot << endl;

}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
int INF = numeric_limits<int>::max();
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

/* if in function
template <class T>
bool contain(vector<T> &vec, T find_it) {
  auto it = find(vec.begin(), vec.end(), find_it);
  return it != vec.end();
}

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}
*/

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  if (n <= k) {
    cout << n * x << endl;
  } else {
    cout << k * x + (n - k) * y << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int m;
	cin >> m;
	int n;
	cin >> n;
	int a[n];
	int sum=0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum+=a[i];
	}
	if(sum>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main() {
	string s;
	cin >> s;
	rep(i, s.size()){
		cout << ((s[i] == '?') ? 'D' : s[i]);
	}
	cout << endl;
}


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

int main(void) {
	int a, b,d,r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = (double)a / b;
	cout << d << " " << r << " ";
	printf("%f", f);
	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 1;
vl flag, color; vll path; vl D; ll S, T;
//***********//
void bfs(ll now) {
	queue<ll> Q;
	Q.push(now);
	D[now] = 0;
	flag[now] = 1;
	ll u;
	ans = K;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		ll color;
		if (D[u] == 0)color = K - 1;
		else color = K - 2;
		for (ll v = 0; v < path[u].size(); v++) {
			ll next = path[u][v];
			if (flag[next] == 0) {
				D[next] = D[u] + 1;
				flag[next] = 1;
				Q.push(next);
				ans = (ans * color) % MOD;
				color--;
			}
		}
	}
}
int main() {
	cin >> N >> K;
	path.resize(N);
	flag.resize(N);
	D.resize(N);
	for (i = 0; i < N; i++) {
		flag[i] = 0;
	}
	for (i = 0; i < N-1; i++) {
		ll a, b;
		cin >> a >> b;
		path[a - 1].push_back(b - 1);
		path[b - 1].push_back(a - 1);
	}
	bfs(0);
	cout << ans;
}


Measured memory_bytes: 8948
#include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <sstream>
#include<vector>
using namespace std;


int main(){
	int n;
	while(cin>>n)
	{
		if(n==0)break;
		int ice[10010]={0};
		for(int i=0; i<n; i++)
		{
			int kari;
			cin>>kari;
			ice[kari]++;
		}
		
		for(int i=0; i<10; i++)
		{
			if(ice[i]==0)cout<<"-";
			while(1)
			{
				if( ice[i]==0 )break;
				ice[i]+= -1;
				cout<<"*";
			}
			cout<<endl;
		}		
	}
	return 0;
}

Measured memory_bytes: 1200
N = int(raw_input())
A = map(int, raw_input().split())
B = map(int, raw_input().split())

M = 0
for i in range(N):
    if A[i] >= B[i]:
        M += B[i]
        A[i] -= B[i]
        B[i] = 0
        continue

    M += A[i]
    B[i] -= A[i]
    A[i] = 0

    if A[i+1] >= B[i]:
        M += B[i]
        A[i+1] -= B[i]
        B[i] = 0
        continue

    M += A[i+1]
    B[i] -= A[i+1]
    A[i+1] = 0

print M

Measured memory_bytes: 14528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M,K; cin>>N>>M>>K;
  vii A(N);
  vi F(N),B(N),memo(N);
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    A[X-1].pb(Y-1);
    A[Y-1].pb(X-1);
  }
  rep(i,0,N) F[i]=i;
  rep(i,0,N){
    if(F[i]==i){
      queue<int> Q;
      Q.push(i);
      int count=0;
      while(Q.size()>0){
        int X=Q.front();
        Q.pop();
        rep(j,0,A[X].size()){
          int Y=A[X][j];
          if(F[Y]==Y&&Y!=i){
            F[Y]=i;
            count++;
            Q.push(Y);
          }
        }
      }
      memo[i]=count;
    }
  }
  rep(i,0,N){
    B[i]=memo[F[i]]-A[i].size();
  }
  rep(i,0,K){
    int X,Y; cin>>X>>Y;
    if(F[X-1]==F[Y-1]){
      B[X-1]--;
      B[Y-1]--;
    }
  }
  rep(i,0,N) cout<<B[i]<<" ";
  cout<<endl;
  }



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  string s; cin>>s;
  int n = s.length();
  for (int i=0; i<n; i++) {
    if (i%2==0 && s[i]=='L') out("No");
    if (i%2==1 && s[i]=='R') out("No");
  }
  out("Yes");
  

  return 0;
}

Measured memory_bytes: 256